-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockIndex.java
94 lines (76 loc) · 1.75 KB
/
BlockIndex.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
/**
* This class is a comparable container for block positions. TODO: should this be merged with position?
*/
public class BlockIndex implements Comparable<BlockIndex> {
public int i;
public int j;
public int k;
/**
* Creates an index for a block located on i, j. k
*/
public BlockIndex(int i, int j, int k) {
this.i = i;
this.j = j;
this.k = k;
}
public BlockIndex(NBTTagCompound c) {
this.i = c.getInteger("i");
this.j = c.getInteger("j");
this.k = c.getInteger("k");
}
/**
* Provides a deterministic and complete ordering of block positions.
*/
@Override
public int compareTo(BlockIndex o) {
if (o.i < i)
return 1;
else if (o.i > i)
return -1;
else if (o.k < k)
return 1;
else if (o.k > k)
return -1;
else if (o.j < j)
return 1;
else if (o.j > j)
return -1;
else
return 0;
}
public void writeTo(NBTTagCompound c) {
c.setInteger("i", i);
c.setInteger("j", j);
c.setInteger("k", k);
}
public int getBlockId(World world) {
return world.getBlockId(i, j, k);
}
@Override
public String toString() {
return "{" + i + ", " + j + ", " + k + "}";
}
@Override
public boolean equals(Object obj) {
if (obj instanceof BlockIndex) {
BlockIndex b = (BlockIndex) obj;
return b.i == i && b.j == j && b.k == k;
}
return super.equals(obj);
}
@Override
public int hashCode() {
return i + j << 8 + k << 16;
}
}