Made conveyor belts have stair collision

This commit is contained in:
Henry Mao 2013-01-09 20:43:42 +08:00
parent 52abadc662
commit 74c631c691
2 changed files with 103 additions and 3 deletions

View file

@ -1,10 +1,13 @@
package assemblyline.common.machine.belt;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@ -30,6 +33,98 @@ public class BlockConveyorBelt extends BlockMachine
this.setCreativeTab(TabAssemblyLine.INSTANCE);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
if (t != null && t instanceof TileEntityConveyorBelt)
{
TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) t;
if (tileEntity.getSlant() != SlantType.NONE) { return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double) x + this.minX, (double) y + this.minY, (double) z + this.minZ, (double) x + 1, (double) y + 1, (double) z + 1); }
}
return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double) x + this.minX, (double) y + this.minY, (double) z + this.minZ, (double) x + this.maxX, (double) y + this.maxY, (double) z + this.maxZ);
}
@Override
public void addCollidingBlockToList(World world, int x, int y, int z, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
if (t != null && t instanceof TileEntityConveyorBelt)
{
TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) t;
if (tileEntity.getSlant() != SlantType.NONE)
{
AxisAlignedBB boundBottom = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z, x + 1, y + 0.3, z + 1);
AxisAlignedBB boundTop = null;
ForgeDirection direction = tileEntity.getDirection();
if (tileEntity.getSlant() == SlantType.UP)
{
if (direction.offsetX > 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x + (float) direction.offsetX / 2, y, z, x + 1, y + 0.8, z + 1);
}
else if (direction.offsetX < 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z, x + (float) direction.offsetX / -2, y + 0.8, z + 1);
}
else if (direction.offsetZ > 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z + (float) direction.offsetZ / 2, x + 1, y + 0.8, z + 1);
}
else if (direction.offsetZ < 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z, x + 1, y + 0.8, z + (float) direction.offsetZ / -2);
}
}
else
{
if (direction.offsetX > 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z, x + (float) direction.offsetX / 2, y + 0.8, z + 1);
}
else if (direction.offsetX < 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x + (float) direction.offsetX / -2, y, z, x + 1, y + 0.8, z + 1);
}
else if (direction.offsetZ > 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z, x + 1, y + 0.8, z + (float) direction.offsetZ / 2);
}
else if (direction.offsetZ < 0)
{
boundTop = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z + (float) direction.offsetZ / -2, x + 1, y + 0.8, z + 1);
}
}
if (par5AxisAlignedBB.intersectsWith(boundBottom))
{
par6List.add(boundBottom);
}
if (boundTop != null && par5AxisAlignedBB.intersectsWith(boundTop))
{
par6List.add(boundTop);
}
return;
}
}
AxisAlignedBB newBounds = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool(x, y, z, x + 1, y + 0.3, z + 1);
if (newBounds != null && par5AxisAlignedBB.intersectsWith(newBounds))
{
par6List.add(newBounds);
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving)
{

View file

@ -282,8 +282,11 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
{
super.readFromNBT(nbt);
this.slantType = SlantType.values()[nbt.getByte("slant")];
if (worldObj != null)
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, nbt.getInteger("rotation"));
{
worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, nbt.getInteger("rotation"));
}
}
/**
@ -293,9 +296,11 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setByte("slant", (byte) this.slantType.ordinal());
if (worldObj != null)
nbt.setInteger("rotation", worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); //for some reason the metadata is getting out of sync between client and server so we store it in the Tile Entity
{
nbt.setInteger("rotation", worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord));
}
}
}