2013-04-23 21:36:43 +02:00
|
|
|
package mekanism.api;
|
|
|
|
|
2013-10-22 02:54:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.MathHelper;
|
2013-06-02 23:44:59 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2013-08-19 03:57:57 +02:00
|
|
|
import net.minecraft.world.World;
|
2013-04-23 21:36:43 +02:00
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
2013-10-22 02:54:28 +02:00
|
|
|
import com.google.common.io.ByteArrayDataInput;
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
public class Object3D
|
|
|
|
{
|
|
|
|
public int xCoord;
|
|
|
|
public int yCoord;
|
|
|
|
public int zCoord;
|
2013-06-02 23:44:59 +02:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
public int dimensionId;
|
|
|
|
|
|
|
|
public Object3D(int x, int y, int z)
|
|
|
|
{
|
|
|
|
xCoord = x;
|
|
|
|
yCoord = y;
|
|
|
|
zCoord = z;
|
2013-06-02 23:44:59 +02:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
dimensionId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object3D(int x, int y, int z, int dimension)
|
|
|
|
{
|
|
|
|
xCoord = x;
|
|
|
|
yCoord = y;
|
|
|
|
zCoord = z;
|
2013-06-02 23:44:59 +02:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
dimensionId = dimension;
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
public int getMetadata(IBlockAccess world)
|
2013-04-23 21:36:43 +02:00
|
|
|
{
|
|
|
|
return world.getBlockMetadata(xCoord, yCoord, zCoord);
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
public int getBlockId(IBlockAccess world)
|
2013-04-23 21:36:43 +02:00
|
|
|
{
|
|
|
|
return world.getBlockId(xCoord, yCoord, zCoord);
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
public TileEntity getTileEntity(IBlockAccess world)
|
2013-04-23 21:36:43 +02:00
|
|
|
{
|
2013-08-22 04:32:24 +02:00
|
|
|
if(!(world instanceof World && ((World)world).blockExists(xCoord, yCoord, zCoord)))
|
2013-10-22 02:54:28 +02:00
|
|
|
{
|
2013-08-19 03:57:57 +02:00
|
|
|
return null;
|
2013-10-22 02:54:28 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
return world.getBlockTileEntity(xCoord, yCoord, zCoord);
|
|
|
|
}
|
|
|
|
|
2013-11-09 21:30:30 +01:00
|
|
|
public NBTTagCompound write(NBTTagCompound nbtTags)
|
2013-04-23 21:36:43 +02:00
|
|
|
{
|
|
|
|
nbtTags.setInteger("x", xCoord);
|
|
|
|
nbtTags.setInteger("y", yCoord);
|
|
|
|
nbtTags.setInteger("z", zCoord);
|
|
|
|
nbtTags.setInteger("dimensionId", dimensionId);
|
2013-11-09 21:30:30 +01:00
|
|
|
|
|
|
|
return nbtTags;
|
2013-04-23 21:36:43 +02:00
|
|
|
}
|
|
|
|
|
2013-10-22 02:54:28 +02:00
|
|
|
public void write(ArrayList data)
|
|
|
|
{
|
|
|
|
data.add(xCoord);
|
|
|
|
data.add(yCoord);
|
|
|
|
data.add(zCoord);
|
|
|
|
}
|
|
|
|
|
2013-05-01 05:07:16 +02:00
|
|
|
public Object3D translate(int x, int y, int z)
|
|
|
|
{
|
|
|
|
xCoord += x;
|
|
|
|
yCoord += y;
|
|
|
|
zCoord += z;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
public Object3D getFromSide(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return new Object3D(xCoord+side.offsetX, yCoord+side.offsetY, zCoord+side.offsetZ, dimensionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object3D get(TileEntity tileEntity)
|
|
|
|
{
|
|
|
|
return new Object3D(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.worldObj.provider.dimensionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object3D read(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
return new Object3D(nbtTags.getInteger("x"), nbtTags.getInteger("y"), nbtTags.getInteger("z"), nbtTags.getInteger("dimensionId"));
|
|
|
|
}
|
|
|
|
|
2013-10-22 02:54:28 +02:00
|
|
|
public static Object3D read(ByteArrayDataInput dataStream)
|
|
|
|
{
|
|
|
|
return new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
|
|
|
}
|
|
|
|
|
2013-10-21 04:47:20 +02:00
|
|
|
public Object3D difference(Object3D other)
|
|
|
|
{
|
|
|
|
return new Object3D(xCoord-other.xCoord, yCoord-other.yCoord, zCoord-other.zCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ForgeDirection sideDifference(Object3D other)
|
|
|
|
{
|
|
|
|
Object3D diff = difference(other);
|
|
|
|
|
|
|
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
2013-10-22 05:46:24 +02:00
|
|
|
if(side.offsetX == diff.xCoord && side.offsetY == diff.yCoord && side.offsetZ == diff.zCoord)
|
2013-10-21 04:47:20 +02:00
|
|
|
{
|
|
|
|
return side;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
public int distanceTo(Object3D obj)
|
|
|
|
{
|
|
|
|
int subX = xCoord - obj.xCoord;
|
|
|
|
int subY = yCoord - obj.yCoord;
|
|
|
|
int subZ = zCoord - obj.zCoord;
|
|
|
|
return (int)MathHelper.sqrt_double(subX * subX + subY * subY + subZ * subZ);
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
public boolean sideVisible(ForgeDirection side, IBlockAccess world)
|
2013-05-23 19:30:12 +02:00
|
|
|
{
|
|
|
|
return world.getBlockId(xCoord+side.offsetX, yCoord+side.offsetY, zCoord+side.offsetZ) == 0;
|
|
|
|
}
|
|
|
|
|
2013-10-21 04:47:20 +02:00
|
|
|
public Object3D step(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return translate(side.offsetX, side.offsetY, side.offsetZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return "[Object3D: " + xCoord + ", " + yCoord + ", " + zCoord + "]";
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj)
|
|
|
|
{
|
|
|
|
return obj instanceof Object3D &&
|
|
|
|
((Object3D)obj).xCoord == xCoord &&
|
|
|
|
((Object3D)obj).yCoord == yCoord &&
|
|
|
|
((Object3D)obj).zCoord == zCoord &&
|
|
|
|
((Object3D)obj).dimensionId == dimensionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
int code = 1;
|
|
|
|
code = 31 * code + xCoord;
|
|
|
|
code = 31 * code + yCoord;
|
|
|
|
code = 31 * code + zCoord;
|
|
|
|
code = 31 * code + dimensionId;
|
|
|
|
return code;
|
|
|
|
}
|
2013-06-02 23:44:59 +02:00
|
|
|
}
|