Fix compile errors in API package

This commit is contained in:
Ben Spiers committed 2016-01-16 14:35:01 +00:00
1 parent 1dfba5e6c9
commit 4247ba136a
71 files changed
+387 -452

No files matched your search

+95 -101
View File
@@ -3,18 +3,21 @@ package mekanism.api;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3i;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
@@ -24,11 +27,8 @@ import java.util.ArrayList;
* @author aidancbrady
*
*/
public class Coord4D
public class Coord4D extends BlockPos
{
public int xCoord;
public int yCoord;
public int zCoord;
public int dimensionId;
@@ -40,24 +40,27 @@ public class Coord4D
*/
public Coord4D(int x, int y, int z)
{
xCoord = x;
yCoord = y;
zCoord = z;
super(x, y, z);
dimensionId = 0;
}
public Coord4D(double x, double y, double z)
{
super(x, y, z);
dimensionId = 0;
}
/**
* Creates a Coord4D from an entity's position, rounded down.
* @param entity - entity to create the Coord4D from
*/
public Coord4D(Entity entity)
{
xCoord = (int)entity.posX;
yCoord = (int)entity.posY;
zCoord = (int)entity.posZ;
super(entity);
dimensionId = entity.worldObj.provider.dimensionId;
dimensionId = entity.worldObj.provider.getDimensionId();
}
/**
@@ -69,18 +72,24 @@ public class Coord4D
*/
public Coord4D(int x, int y, int z, int dimension)
{
xCoord = x;
yCoord = y;
zCoord = z;
super(x, y, z);
dimensionId = dimension;
}
public Coord4D(double x, double y, double z, int dimension)
{
super(x, y, z);
dimensionId = dimension;
}
public Coord4D(MovingObjectPosition mop)
{
xCoord = mop.blockX;
yCoord = mop.blockY;
zCoord = mop.blockZ;
super(mop.getBlockPos());
dimensionId = 0;
}
/**
@@ -88,9 +97,9 @@ public class Coord4D
* @param world - world this Coord4D is in
* @return the metadata of this Coord4D's block
*/
public int getMetadata(IBlockAccess world)
public IBlockState getBlockState(IBlockAccess world)
{
return world.getBlockMetadata(xCoord, yCoord, zCoord);
return world.getBlockState(this);
}
/**
@@ -105,7 +114,7 @@ public class Coord4D
return null;
}
return world.getTileEntity(xCoord, yCoord, zCoord);
return world.getTileEntity(this);
}
/**
@@ -120,7 +129,7 @@ public class Coord4D
return null;
}
return world.getBlock(xCoord, yCoord, zCoord);
return world.getBlockState(this).getBlock();
}
/**
@@ -130,9 +139,9 @@ public class Coord4D
*/
public NBTTagCompound write(NBTTagCompound nbtTags)
{
nbtTags.setInteger("x", xCoord);
nbtTags.setInteger("y", yCoord);
nbtTags.setInteger("z", zCoord);
nbtTags.setInteger("x", getX());
nbtTags.setInteger("y", getY());
nbtTags.setInteger("z", getZ());
nbtTags.setInteger("dimensionId", dimensionId);
return nbtTags;
@@ -144,9 +153,9 @@ public class Coord4D
*/
public void write(ArrayList data)
{
data.add(xCoord);
data.add(yCoord);
data.add(zCoord);
data.add(getX());
data.add(getY());
data.add(getZ());
data.add(dimensionId);
}
@@ -156,9 +165,9 @@ public class Coord4D
*/
public void write(ByteBuf dataStream)
{
dataStream.writeInt(xCoord);
dataStream.writeInt(yCoord);
dataStream.writeInt(zCoord);
dataStream.writeInt(getX());
dataStream.writeInt(getY());
dataStream.writeInt(getZ());
dataStream.writeInt(dimensionId);
}
@@ -169,58 +178,52 @@ public class Coord4D
* @param z - z value to translate
* @return translated Coord4D
*/
public Coord4D translate(int x, int y, int z)
public Coord4D add(int x, int y, int z)
{
xCoord += x;
yCoord += y;
zCoord += z;
return this;
return x == 0 && y == 0 && z == 0 ? this : new Coord4D(this.getX() + x, this.getY() + y, this.getZ() + z, dimensionId);
}
public Coord4D add(double x, double y, double z)
{
return x == 0.0D && y == 0.0D && z == 0.0D ? this : new Coord4D((double)this.getX() + x, (double)this.getY() + y, (double)this.getZ() + z, dimensionId);
}
/**
* Translates this Coord4D by the defined Coord4D's coordinates, regardless of dimension.
* @param coord - coordinates to translate by
* @return translated Coord4D
*/
public Coord4D translate(Coord4D coord)
public Coord4D add(Vec3i coord)
{
translate(coord.xCoord, coord.yCoord, coord.zCoord);
return this;
return add(coord.getX(), coord.getY(), coord.getZ());
}
/**
* Creates and returns a new Coord4D translated to the defined offsets of the side.
* @param side - side to translate this Coord4D to
* @return translated Coord4D
* Offset this BlockPos 1 block in the given direction
*/
public Coord4D getFromSide(ForgeDirection side)
public Coord4D offset(EnumFacing facing)
{
return getFromSide(side, 1);
return this.offset(facing, 1);
}
/**
* Creates and returns a new Coord4D translated to the defined offsets of the side by the defined amount.
* @param side - side to translate this Coord4D to
* @param amount - how far to translate this Coord4D
* @return translated Coord4D
* Offsets this BlockPos n blocks in the given direction
*/
public Coord4D getFromSide(ForgeDirection side, int amount)
public Coord4D offset(EnumFacing facing, int n)
{
return new Coord4D(xCoord+(side.offsetX*amount), yCoord+(side.offsetY*amount), zCoord+(side.offsetZ*amount), dimensionId);
return n == 0 ? this : new Coord4D(this.getX() + facing.getFrontOffsetX() * n, this.getY() + facing.getFrontOffsetY() * n, this.getZ() + facing.getFrontOffsetZ() * n);
}
public ItemStack getStack(IBlockAccess world)
{
Block block = getBlock(world);
IBlockState state = getBlockState(world);
if(block == null || block == Blocks.air)
if(state == null || state == Blocks.air)
{
return null;
}
return new ItemStack(block, 1, getMetadata(world));
return new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
}
/**
@@ -230,7 +233,8 @@ public class Coord4D
*/
public static Coord4D get(TileEntity tileEntity)
{
return new Coord4D(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.getWorldObj().provider.dimensionId);
BlockPos pos = tileEntity.getPos();
return new Coord4D(pos.getX(), pos.getY(), pos.getZ(), tileEntity.getWorld().provider.getDimensionId());
}
/**
@@ -255,13 +259,12 @@ public class Coord4D
/**
* Creates and returns a new Coord4D with values representing the difference between the defined Coord4D
* @param other - the Coord4D to subtract from this
* @param vec - the Coord4D to subtract from this
* @return a Coord4D representing the distance between the defined Coord4D
*/
public Coord4D difference(Coord4D other)
public Coord4D difference(Vec3i vec)
{
return new Coord4D(xCoord-other.xCoord, yCoord-other.yCoord, zCoord-other.zCoord, dimensionId);
}
return vec.getX() == 0 && vec.getY() == 0 && vec.getZ() == 0 ? this : new Coord4D(this.getX() - vec.getX(), this.getY() - vec.getY(), this.getZ() - vec.getZ()); }
/**
* A method used to find the ForgeDirection represented by the distance of the defined Coord4D. Most likely won't have many
@@ -269,19 +272,19 @@ public class Coord4D
* @param other - Coord4D to find the side difference of
* @return ForgeDirection representing the side the defined relative Coord4D is on to this
*/
public ForgeDirection sideDifference(Coord4D other)
public EnumFacing sideDifference(Coord4D other)
{
Coord4D diff = difference(other);
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
for(EnumFacing side : EnumFacing.VALUES)
{
if(side.offsetX == diff.xCoord && side.offsetY == diff.yCoord && side.offsetZ == diff.zCoord)
if(side.getDirectionVec().equals(diff))
{
return side;
}
}
return ForgeDirection.UNKNOWN;
return null;
}
/**
@@ -289,11 +292,11 @@ public class Coord4D
* @param obj - the Coord4D to find the distance to
* @return the distance to the defined Coord4D
*/
public int distanceTo(Coord4D obj)
public int distanceTo(Vec3i obj)
{
int subX = xCoord - obj.xCoord;
int subY = yCoord - obj.yCoord;
int subZ = zCoord - obj.zCoord;
int subX = getX() - obj.getX();
int subY = getY() - obj.getY();
int subZ = getZ() - obj.getZ();
return (int)MathHelper.sqrt_double(subX * subX + subY * subY + subZ * subZ);
}
@@ -303,9 +306,9 @@ public class Coord4D
* @param world - world this Coord4D is in
* @return
*/
public boolean sideVisible(ForgeDirection side, IBlockAccess world)
public boolean sideVisible(EnumFacing side, IBlockAccess world)
{
return world.isAirBlock(xCoord+side.offsetX, yCoord+side.offsetY, zCoord+side.offsetZ);
return world.isAirBlock(offset(side));
}
/**
@@ -315,17 +318,7 @@ public class Coord4D
*/
public TargetPoint getTargetPoint(double range)
{
return new TargetPoint(dimensionId, xCoord, yCoord, zCoord, range);
}
/**
* Steps this Coord4D in the defined side's offset without creating a new value.
* @param side - side to step towards
* @return this Coord4D
*/
public Coord4D step(ForgeDirection side)
{
return translate(side.offsetX, side.offsetY, side.offsetZ);
return new TargetPoint(dimensionId, getX(), getY(), getZ(), range);
}
/**
@@ -335,7 +328,7 @@ public class Coord4D
*/
public boolean exists(World world)
{
return world.getChunkProvider() == null || world.getChunkProvider().chunkExists(xCoord >> 4, zCoord >> 4);
return world.getChunkProvider() == null || world.getChunkProvider().chunkExists(getX() >> 4, getZ() >> 4);
}
/**
@@ -345,7 +338,7 @@ public class Coord4D
*/
public Chunk getChunk(World world)
{
return world.getChunkFromBlockCoords(xCoord, zCoord);
return world.getChunkFromBlockCoords(this);
}
/**
@@ -364,7 +357,7 @@ public class Coord4D
*/
public boolean isAirBlock(IBlockAccess world)
{
return world.isAirBlock(xCoord, yCoord, zCoord);
return world.isAirBlock(this);
}
/**
@@ -372,9 +365,9 @@ public class Coord4D
* @param world - world this Coord4D is in
* @return if this Coord4D is replaceable
*/
public boolean isReplaceable(IBlockAccess world)
public boolean isReplaceable(World world)
{
return getBlock(world).isReplaceable(world, xCoord, yCoord, zCoord);
return getBlock(world).isReplaceable(world, this);
}
/**
@@ -383,38 +376,39 @@ public class Coord4D
*/
public AxisAlignedBB getBoundingBox()
{
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1);
return new AxisAlignedBB(this, add(1,1,1));
}
@Override
public Coord4D clone()
{
return new Coord4D(xCoord, yCoord, zCoord, dimensionId);
return new Coord4D(getX(), getY(), getZ(), dimensionId);
}
@Override
public String toString()
{
return "[Coord4D: " + xCoord + ", " + yCoord + ", " + zCoord + ", dim=" + dimensionId + "]";
return "[Coord4D: " + getX() + ", " + getY() + ", " + getZ() + ", dim=" + dimensionId + "]";
}
@Override
public boolean equals(Object obj)
{
return obj instanceof Coord4D &&
((Coord4D)obj).xCoord == xCoord &&
((Coord4D)obj).yCoord == yCoord &&
((Coord4D)obj).zCoord == zCoord &&
((Coord4D)obj).dimensionId == dimensionId;
return obj instanceof Vec3i &&
(
((Vec3i)obj).getX() == getX() &&
((Vec3i)obj).getY() == getY() &&
((Vec3i)obj).getZ() == getZ()
) && !(obj instanceof Coord4D && ((Coord4D)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 + getX();
code = 31 * code + getY();
code = 31 * code + getZ();
code = 31 * code + dimensionId;
return code;
}