Files
Opis/mcp/mobius/opis/data/CoordinatesBlock.java
T
ProfMobius f49abc3ecb Upon clicking on a chunk in MeanTime overlay, the client receive a list of entities for this chunk.
Added a ISerializable interface to make it easier to send/receive complex packets.
2013-10-29 17:48:41 +01:00

92 lines
2.3 KiB
Java

package mcp.mobius.opis.data;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.tileentity.TileEntity;
public final class CoordinatesBlock implements ISerializable {
public final int dim, x, y, z;
public final int chunkX, chunkZ;
//public boolean isChunk;
public CoordinatesBlock(int dim, int x, int y, int z){
this.dim = dim;
this.x = x;
this.y = y;
this.z = z;
this.chunkX = x >> 4;
this.chunkZ = z >> 4;
//this.isChunk = false;
}
public CoordinatesBlock(CoordinatesChunk coord){
this.dim = coord.dim;
this.chunkX = coord.chunkX;
this.chunkZ = coord.chunkZ;
this.x = coord.x;
this.y = coord.y;
this.z = coord.z;
}
/*
public CoordinatesBlock(int dim, int chunkX, int chunkZ){
this.dim = dim;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.x = chunkX << 4;
this.y = 0;
this.z = chunkZ << 4;
this.isChunk = true;
}
*/
public CoordinatesBlock(TileEntity te){
this.dim = te.getWorldObj().provider.dimensionId;
this.x = te.xCoord;
this.y = te.yCoord;
this.z = te.zCoord;
this.chunkX = x >> 4;
this.chunkZ = z >> 4;
//this.isChunk = false;
}
public String toString(){
//if (this.isChunk)
// return String.format("[%6d %6d %6d]", this.dim, this.chunkX, this.chunkZ);
//else
return String.format("[%6d %6d %6d %6d]", this.dim, this.x, this.y, this.z);
}
public boolean equals(Object o) {
CoordinatesBlock c = (CoordinatesBlock)o;
//if (this.isChunk)
// return (this.dim == c.dim) && (this.chunkX == c.chunkX) && (this.chunkZ == c.chunkZ);
//else
return (this.dim == c.dim) && (this.x == c.x) && (this.y == c.y) && (this.z == c.z);
};
public int hashCode() {
//if (this.isChunk)
// return String.format("%s %s %s", this.dim, this.chunkX, this.chunkZ).hashCode();
//else
return String.format("%s %s %s %s", this.dim, this.x, this.y, this.z).hashCode();
}
@Override
public void writeToStream(DataOutputStream stream) throws IOException {
stream.writeInt(this.dim);
stream.writeInt(this.x);
stream.writeInt(this.y);
stream.writeInt(this.z);
}
public static CoordinatesBlock readFromStream(DataInputStream stream) throws IOException {
return new CoordinatesBlock(stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt());
}
}