Added Support for Importing Tile Entities
Added code to SchematicLoader so that we can import tile entities. Empty chests and dispensers will still be filled as before.
This commit is contained in:
@@ -4,9 +4,9 @@ import java.io.Serializable;
|
||||
|
||||
public class Point3D implements Serializable {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public Point3D(int x, int y,int z)
|
||||
{
|
||||
@@ -29,20 +29,20 @@ public class Point3D implements Serializable {
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
public int setY(int y)
|
||||
{
|
||||
return this.y=y;
|
||||
}
|
||||
|
||||
public int setX(int x)
|
||||
{
|
||||
return this. x=x;
|
||||
return this.x = x;
|
||||
}
|
||||
|
||||
public int setY(int y)
|
||||
{
|
||||
return this.y = y;
|
||||
}
|
||||
|
||||
public int setZ(int z)
|
||||
{
|
||||
return this. z=z;
|
||||
return this.z = z;
|
||||
}
|
||||
|
||||
public Point3D clone()
|
||||
@@ -50,14 +50,57 @@ public class Point3D implements Serializable {
|
||||
return new Point3D(x, y, z);
|
||||
}
|
||||
|
||||
public boolean equals(Object other)
|
||||
public boolean equals(Point3D other)
|
||||
{
|
||||
boolean result = false;
|
||||
if (other instanceof Point3D)
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
if (this == other)
|
||||
return true;
|
||||
|
||||
return (this.x == other.x && this.y == other.y && this.z == other.z);
|
||||
}
|
||||
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
return equals((Point3D) other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
//Time for some witchcraft.
|
||||
//The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D.
|
||||
//Source: http://stackoverflow.com/questions/9858376/hashcode-for-3d-integer-coordinates-with-high-spatial-coherence
|
||||
|
||||
//I believe that most of the time, any points we might be hashing will be in close proximity to each other.
|
||||
//For instance, points that are within the same chunk or within a few neighboring chunks. Only the low-order
|
||||
//bits of each component would differ. I'll use 8 bits from Y and the 12 bits from X and Z. ~SenseiKiwi
|
||||
|
||||
//The result of this could be cached but that would break serialization for this class! >_<
|
||||
|
||||
int bit;
|
||||
int hash;
|
||||
int index;
|
||||
|
||||
hash = 0;
|
||||
index = 0;
|
||||
for (bit = 0; bit < 8; bit++)
|
||||
{
|
||||
Point3D that = (Point3D) other;
|
||||
result = (this.getX() == that.getX() && this.getY() == that.getY()&& this.getY() == that.getZ());
|
||||
hash |= ((y >> bit) & 1) << index;
|
||||
index++;
|
||||
hash |= ((x >> bit) & 1) << index;
|
||||
index++;
|
||||
hash |= ((z >> bit) & 1) << index;
|
||||
index++;
|
||||
}
|
||||
return result;
|
||||
for (; bit < 12; bit++)
|
||||
{
|
||||
hash |= ((x >> bit) & 1) << index;
|
||||
index++;
|
||||
hash |= ((z >> bit) & 1) << index;
|
||||
index++;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user