diff --git a/src/main/java/com/hbm/blocks/generic/BlockGrate.java b/src/main/java/com/hbm/blocks/generic/BlockGrate.java index 735c8a89f..767aaed21 100644 --- a/src/main/java/com/hbm/blocks/generic/BlockGrate.java +++ b/src/main/java/com/hbm/blocks/generic/BlockGrate.java @@ -14,6 +14,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayer; @@ -31,8 +32,6 @@ public class BlockGrate extends Block implements ITooltipProvider { public BlockGrate(Material material) { super(material); - - //this.maxY = 0.999D; } @Override @@ -65,16 +64,23 @@ public class BlockGrate extends Block implements ITooltipProvider { return false; } + public float getY(int meta) { + if(meta == 9) return -0.125F; + return meta * 0.125F; + } + @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); - this.setBlockBounds(0F, meta * 0.125F, 0F, 1F, meta * 0.125F + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F); + float fy = getY(meta); + this.setBlockBounds(0F, fy, 0F, 1F, fy + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F); } @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); - this.setBlockBounds(0F, meta * 0.125F, 0F, 1F, meta * 0.125F + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F); + float fy = getY(meta); + this.setBlockBounds(0F, fy, 0F, 1F, fy + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); } @@ -96,6 +102,52 @@ public class BlockGrate extends Block implements ITooltipProvider { return (int)Math.floor(hY * 8D); } + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) { + if(player.isSneaking()) { + int meta = world.getBlockMetadata(x, y, z); + + if(meta == 0) { + // Check that the block below can fit a grate above it + AxisAlignedBB bb = world.getBlock(x, y - 1, z).getCollisionBoundingBoxFromPool(world, x, y - 1, z); + if(bb == null || (int) ((bb.maxY - (y - 1)) * 100) < 90) { + world.setBlockMetadataWithNotify(x, y, z, 9, 3); + } + } else if(meta == 7) { + AxisAlignedBB bb = world.getBlock(x, y + 1, z).getCollisionBoundingBoxFromPool(world, x, y + 1, z); + if(bb == null || (int) ((bb.minY - (y + 1)) * 100) > 10) { + world.setBlockMetadataWithNotify(x, y, z, 8, 3); + } + } + } + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) { + if(world.isRemote) return; + + int meta = world.getBlockMetadata(x, y, z); + + boolean breakIt = false; + + if(meta == 9) { + AxisAlignedBB bb = world.getBlock(x, y - 1, z).getCollisionBoundingBoxFromPool(world, x, y - 1, z); + if(bb != null && (int) ((bb.maxY - (y - 1)) * 100) >= 90) { + breakIt = true; + } + } else if(meta == 8) { + AxisAlignedBB bb = world.getBlock(x, y + 1, z).getCollisionBoundingBoxFromPool(world, x, y + 1, z); + if(bb != null && (int) ((bb.minY - (y + 1)) * 100) <= 10) { + breakIt = true; + } + } + + if(breakIt) { + dropBlockAsItem(world, x, y, z, 0, 0); + world.setBlockToAir(x, y, z); + } + } + @Override public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) { if(this != ModBlocks.steel_grate_wide || !(entity instanceof EntityItem || entity instanceof EntityXPOrb)) { diff --git a/src/main/java/com/hbm/render/block/RenderGrate.java b/src/main/java/com/hbm/render/block/RenderGrate.java index cf8eb161a..f6858c584 100644 --- a/src/main/java/com/hbm/render/block/RenderGrate.java +++ b/src/main/java/com/hbm/render/block/RenderGrate.java @@ -22,7 +22,9 @@ public class RenderGrate implements ISimpleBlockRenderingHandler { tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); tessellator.setColorOpaque_F(1, 1, 1); - renderer.setRenderBounds(0.0D, meta * 0.125D, 0D, 1D, meta * 0.125D + 0.125D, 1D); + float fy = ((BlockGrate)block).getY(meta); + + renderer.setRenderBounds(0.0D, fy, 0D, 1D, fy + 0.125D, 1D); renderer.renderStandardBlock(block, x, y, z); return true; }