From 36046ff754551a480bbf5e74e06b70f7ebb5e81e Mon Sep 17 00:00:00 2001 From: brandon3055 Date: Fri, 20 Jun 2014 18:17:14 +1000 Subject: [PATCH] verious bug fixes --- .../common/blocks/PlayerDetector.java | 22 +++++++- .../common/blocks/PlayerDetectorAdvanced.java | 50 +++++++++++++++++-- .../tileentities/TilePlayerDetector.java | 6 +++ .../TilePlayerDetectorAdvanced.java | 7 +++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/main/java/draconicevolution/common/blocks/PlayerDetector.java b/src/main/java/draconicevolution/common/blocks/PlayerDetector.java index 57991e08..67c25998 100644 --- a/src/main/java/draconicevolution/common/blocks/PlayerDetector.java +++ b/src/main/java/draconicevolution/common/blocks/PlayerDetector.java @@ -1,7 +1,11 @@ package draconicevolution.common.blocks; +import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; @@ -82,7 +86,10 @@ public class PlayerDetector extends TolkienBlock @Override public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { - return true; + if (side == 0 || side == 1) + return false; + else + return true; } @Override @@ -141,4 +148,17 @@ public class PlayerDetector extends TolkienBlock } return true; } + + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) + { + super.breakBlock(world, x, y, z, block, meta); + + world.notifyBlocksOfNeighborChange(x - 1, y, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x + 1, y, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y - 1, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y + 1, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y, z - 1, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y, z + 1, world.getBlock(x, y, z)); + } } diff --git a/src/main/java/draconicevolution/common/blocks/PlayerDetectorAdvanced.java b/src/main/java/draconicevolution/common/blocks/PlayerDetectorAdvanced.java index 955ec2c9..013f6839 100644 --- a/src/main/java/draconicevolution/common/blocks/PlayerDetectorAdvanced.java +++ b/src/main/java/draconicevolution/common/blocks/PlayerDetectorAdvanced.java @@ -12,7 +12,9 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; @@ -105,7 +107,10 @@ public class PlayerDetectorAdvanced extends BlockContainer @Override public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { - return true; + if (side == 0 || side == 1) + return false; + else + return true; } @Override @@ -134,10 +139,49 @@ public class PlayerDetectorAdvanced extends BlockContainer TileEntity te = world.getTileEntity(x, y, z); TilePlayerDetectorAdvanced detector = (te != null && te instanceof TilePlayerDetectorAdvanced) ? (TilePlayerDetectorAdvanced) te : null; if(detector != null) - return detector.output ? 15 : 0; + if (!detector.outputInverted) + return detector.output ? 15 : 0; + else + return detector.output ? 0 : 15; else return 0; } - + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) + { + TileEntity te = world.getTileEntity(x, y, z); + if (te != null && te instanceof IInventory) { + IInventory inventory = (IInventory) te; + + for (int i = 0; i < inventory.getSizeInventory(); i++) { + ItemStack stack = inventory.getStackInSlot(i); + + if (stack != null) { + float spawnX = x + world.rand.nextFloat(); + float spawnY = y + world.rand.nextFloat(); + float spawnZ = z + world.rand.nextFloat(); + + EntityItem droppedItem = new EntityItem(world, spawnX, spawnY, spawnZ, stack); + + float mult = 0.05F; + + droppedItem.motionX = (-0.5F + world.rand.nextFloat()) * mult; + droppedItem.motionY = (4 + world.rand.nextFloat()) * mult; + droppedItem.motionZ = (-0.5F + world.rand.nextFloat()) * mult; + + world.spawnEntityInWorld(droppedItem); + } + } + } + + super.breakBlock(world, x, y, z, block, meta); + + world.notifyBlocksOfNeighborChange(x - 1, y, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x + 1, y, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y - 1, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y + 1, z, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y, z - 1, world.getBlock(x, y, z)); + world.notifyBlocksOfNeighborChange(x, y, z + 1, world.getBlock(x, y, z)); + } } diff --git a/src/main/java/draconicevolution/common/tileentities/TilePlayerDetector.java b/src/main/java/draconicevolution/common/tileentities/TilePlayerDetector.java index 0f478202..6a9dd3fb 100644 --- a/src/main/java/draconicevolution/common/tileentities/TilePlayerDetector.java +++ b/src/main/java/draconicevolution/common/tileentities/TilePlayerDetector.java @@ -58,6 +58,12 @@ public class TilePlayerDetector extends TileEntity public void updateBlocks() { worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType); + worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, worldObj.getBlock(xCoord, yCoord, zCoord)); } public Packet getDescriptionPacket() diff --git a/src/main/java/draconicevolution/common/tileentities/TilePlayerDetectorAdvanced.java b/src/main/java/draconicevolution/common/tileentities/TilePlayerDetectorAdvanced.java index cdd22768..751087db 100644 --- a/src/main/java/draconicevolution/common/tileentities/TilePlayerDetectorAdvanced.java +++ b/src/main/java/draconicevolution/common/tileentities/TilePlayerDetectorAdvanced.java @@ -10,6 +10,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -122,6 +123,12 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory public void updateBlocks() { worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType); + worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, worldObj.getBlock(xCoord, yCoord, zCoord)); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, worldObj.getBlock(xCoord, yCoord, zCoord)); } public boolean isPlayerListed(String name)