forked from Tarig0/thaumcraft-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlockCoordinates.java
108 lines (90 loc) · 2.73 KB
/
BlockCoordinates.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package thaumcraft.api;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class BlockCoordinates implements Comparable
{
public int x;
/** the y coordinate */
public int y;
/** the z coordinate */
public int z;
public BlockCoordinates() {}
public BlockCoordinates(int par1, int par2, int par3)
{
this.x = par1;
this.y = par2;
this.z = par3;
}
public BlockCoordinates(TileEntity tile)
{
this.x = tile.xCoord;
this.y = tile.yCoord;
this.z = tile.zCoord;
}
public BlockCoordinates(BlockCoordinates par1ChunkCoordinates)
{
this.x = par1ChunkCoordinates.x;
this.y = par1ChunkCoordinates.y;
this.z = par1ChunkCoordinates.z;
}
public boolean equals(Object par1Obj)
{
if (!(par1Obj instanceof BlockCoordinates))
{
return false;
}
else
{
BlockCoordinates coordinates = (BlockCoordinates)par1Obj;
return this.x == coordinates.x && this.y == coordinates.y && this.z == coordinates.z ;
}
}
public int hashCode()
{
return this.x + this.y << 8 + this.z << 16;
}
/**
* Compare the coordinate with another coordinate
*/
public int compareWorldCoordinate(BlockCoordinates par1)
{
return this.y == par1.y ? (this.z == par1.z ? this.x - par1.x : this.z - par1.z) : this.y - par1.y;
}
public void set(int par1, int par2, int par3, int d)
{
this.x = par1;
this.y = par2;
this.z = par3;
}
/**
* Returns the squared distance between this coordinates and the coordinates given as argument.
*/
public float getDistanceSquared(int par1, int par2, int par3)
{
float f = (float)(this.x - par1);
float f1 = (float)(this.y - par2);
float f2 = (float)(this.z - par3);
return f * f + f1 * f1 + f2 * f2;
}
/**
* Return the squared distance between this coordinates and the ChunkCoordinates given as argument.
*/
public float getDistanceSquaredToWorldCoordinates(BlockCoordinates par1ChunkCoordinates)
{
return this.getDistanceSquared(par1ChunkCoordinates.x, par1ChunkCoordinates.y, par1ChunkCoordinates.z);
}
public int compareTo(Object par1Obj)
{
return this.compareWorldCoordinate((BlockCoordinates)par1Obj);
}
public void readNBT(NBTTagCompound nbt) {
this.x = nbt.getInteger("b_x");
this.y = nbt.getInteger("b_y");
this.z = nbt.getInteger("b_z");
}
public void writeNBT(NBTTagCompound nbt) {
nbt.setInteger("b_x",x);
nbt.setInteger("b_y",y);
nbt.setInteger("b_z",z);
}
}