From 74c631c6914669ae10a06677553b71dee3516a9e Mon Sep 17 00:00:00 2001 From: Henry Mao Date: Wed, 9 Jan 2013 20:43:42 +0800 Subject: [PATCH] Made conveyor belts have stair collision --- .../machine/belt/BlockConveyorBelt.java | 95 +++++++++++++++++++ .../machine/belt/TileEntityConveyorBelt.java | 11 ++- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java index 122229078..ebdca10f5 100644 --- a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java @@ -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) { diff --git a/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java index cd025dee9..9aa402af6 100644 --- a/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/TileEntityConveyorBelt.java @@ -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)); + } } }