From c7cd3b343cdbb5d16a121a65a08f93cba14a88cf Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sat, 2 Aug 2014 16:35:25 +1000 Subject: [PATCH] Fixed bamboo on Podzol and Dirt. Closes #300 --- .../client/render/blocks/BambooRenderer.java | 12 -- .../common/blocks/BlockBamboo.java | 123 ++++++++---------- 2 files changed, 52 insertions(+), 83 deletions(-) diff --git a/src/main/java/biomesoplenty/client/render/blocks/BambooRenderer.java b/src/main/java/biomesoplenty/client/render/blocks/BambooRenderer.java index a6be39b40..5288f0018 100644 --- a/src/main/java/biomesoplenty/client/render/blocks/BambooRenderer.java +++ b/src/main/java/biomesoplenty/client/render/blocks/BambooRenderer.java @@ -18,9 +18,6 @@ public class BambooRenderer implements ISimpleBlockRenderingHandler @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { - //TODO: setBlockBounds - block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - //TODO: colorMultiplier int l = block.colorMultiplier(world, x, y, z); float f = (float)(l >> 16 & 255) / 255.0F; @@ -56,22 +53,15 @@ public class BambooRenderer implements ISimpleBlockRenderingHandler float f17 = f5 * f2; float f18 = f6 * f2; float pixel = 0.0625F; - //TODO: getMixedBrightnessForBlock() int m = block.getMixedBrightnessForBlock(world, x, y, z); - - //Need to make public: renderAllFaces, renderMinY, renderMaxY - //TODO: renderAllFaces shouldSideBeRendered() if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y - 1, z, 0)) { - //TODO: renderMinY getMixedBrightnessForBlock() tessellator.setBrightness(renderer.renderMinY > 0.0D ? m : block.getMixedBrightnessForBlock(world, x, y - 1, z)); tessellator.setColorOpaque_F(r, g, b); - //TODO: renderFaceYNeg getBlockIcon() renderer.renderFaceYNeg(block, (double)x, (double)y, (double)z, renderer.getBlockIcon(block, world, x, y, z, 0)); } - //TODO: renderAllFaces shouldSideBeRendered() if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y + 1, z, 1)) { //TODO: renderMaxY getMixedBrightnessForBlock() @@ -101,8 +91,6 @@ public class BambooRenderer implements ISimpleBlockRenderingHandler renderer.renderFaceXPos(block, (double)x - (pixel * 4), (double)y, (double)z, renderer.getBlockIcon(block, world, x, y, z, 5)); tessellator.addTranslation(pixel, 0.0F, 0.0F); - - return true; } diff --git a/src/main/java/biomesoplenty/common/blocks/BlockBamboo.java b/src/main/java/biomesoplenty/common/blocks/BlockBamboo.java index 65e9d5a2f..d90829f9d 100644 --- a/src/main/java/biomesoplenty/common/blocks/BlockBamboo.java +++ b/src/main/java/biomesoplenty/common/blocks/BlockBamboo.java @@ -1,45 +1,40 @@ package biomesoplenty.common.blocks; -import java.util.List; +import static net.minecraftforge.common.EnumPlantType.Plains; + import java.util.Random; 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.init.Blocks; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; +import net.minecraftforge.common.IPlantable; +import net.minecraftforge.common.util.ForgeDirection; import biomesoplenty.BiomesOPlenty; import biomesoplenty.client.render.RenderUtils; -public class BlockBamboo extends Block +public class BlockBamboo extends Block implements IPlantable { private IIcon bambooSide; private IIcon bambooTop; public BlockBamboo() { - //TODO: Material.plants super(Material.plants); - //TODO: this.setHardness this.setHardness(0.2F); - - //TODO setStepSound(Block.soundWoodFootstep) this.setStepSound(Block.soundTypeWood); - - //TODO: setTickRandomly() + this.setTickRandomly(true); - //TODO: this.setCreativeTab() this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); } @Override - //TODO: registerIcons() public void registerBlockIcons(IIconRegister iconRegister) { bambooSide = iconRegister.registerIcon("biomesoplenty:bamboo"); @@ -47,7 +42,6 @@ public class BlockBamboo extends Block } @Override - //TODO: getIcon() public IIcon getIcon(int side, int meta) { if (side > 1) @@ -55,17 +49,32 @@ public class BlockBamboo extends Block else return bambooTop; } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) + { + return getBoundingBox(world, x, y, z); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) + { + return getBoundingBox(world, x, y, z); + } + + private AxisAlignedBB getBoundingBox(World world, int x, int y, int z) + { + float pixel = 0.0625F; + return AxisAlignedBB.getBoundingBox(x + pixel * 4, y, z + pixel * 4, x + 1 - pixel * 4, y + 1, z + 1 - pixel * 4); + } @Override - //TODO: updateTick() public void updateTick(World world, int x, int y, int z, Random random) { - //TODO: isAirBlock() if (world.isAirBlock(x, y + 1, z)) { int var6; - //TODO: getBlock() for (var6 = 1; world.getBlock(x, y - var6, z) == this; ++var6) { ; @@ -77,7 +86,6 @@ public class BlockBamboo extends Block if (var7 == 15) { - //TODO: setBlock() world.setBlock(x, y + 1, z, this, 0, 2); world.setBlockMetadataWithNotify(x, y, z, 0, 2); } @@ -88,53 +96,8 @@ public class BlockBamboo extends Block } } } - - @Override - //TODO: getSelectedBoundingBoxFromPool() - public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) - { - float pixel = 0.0625F; - - return AxisAlignedBB.getBoundingBox((double)x + (1.0F - (pixel * 4)), (double)y, (double)z + (1.0F - (pixel * 4)), (double)x + (pixel * 4), (double)y + 1.0F, (double)z + (pixel * 4)); - } - - @Override - //TODO: addCollisionBoxesToList() - public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisAlignedBB, List list, Entity entity) - { - float pixel = 0.0625F; - //TODO: setBlockBounds - this.setBlockBounds((pixel * 4), 0.0F, (pixel * 4), 1.0F - (pixel * 4), 1.0F, 1.0F - (pixel * 4)); - super.addCollisionBoxesToList(world, x, y, z, axisAlignedBB, list, entity); - //TODO: setBlockBoundsForItemRender() - this.setBlockBoundsForItemRender(); - } - - @Override - //TODO: setBlockBoundsForItemRender() - public void setBlockBoundsForItemRender() - { - //TODO: setBlockBounds - this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - } @Override - //TODO: canPlaceBlockAt - public boolean canPlaceBlockAt(World world, int x, int y, int z) - { - //TODO: getBlock - Block block = world.getBlock(x, y - 1, z); - - if (block == this) - return true; - else if (block == Blocks.grass) - return true; - else - return false; - } - - @Override - //TODO: onNeighborBlockChange() public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) { this.checkBlockCoordValid(world, x, y, z); @@ -142,40 +105,40 @@ public class BlockBamboo extends Block public final void checkBlockCoordValid(World world, int x, int y, int z) { - //TODO: canBlockStay() if (!this.canBlockStay(world, x, y, z)) { - //TODO: dropBlockAsItem() this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0); - //TODO: setBlockToAir world.setBlockToAir(x, y, z); } } + + @Override + public boolean canPlaceBlockAt(World world, int x, int y, int z) + { + return super.canPlaceBlockAt(world, x, y, z) && this.canBlockStay(world, x, y, z); + } @Override - //TODO: canBlockStay() public boolean canBlockStay(World world, int x, int y, int z) { - //TODO: canPlaceBlockAt - return this.canPlaceBlockAt(world, x, y, z); + Block bottomBlock = world.getBlock(x, y - 1, z); + + return bottomBlock.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this) || bottomBlock == this; } @Override - //TODO: isOpaqueCube() public boolean isOpaqueCube() { return false; } @Override - //TODO: renderAsNormalBlock() public boolean renderAsNormalBlock() { return false; } @Override - //TODO getRenderType() public int getRenderType() { return RenderUtils.bambooModel; @@ -193,4 +156,22 @@ public class BlockBamboo extends Block return true; } + @Override + public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z) + { + return Plains; + } + + @Override + public Block getPlant(IBlockAccess world, int x, int y, int z) + { + return this; + } + + @Override + public int getPlantMetadata(IBlockAccess world, int x, int y, int z) + { + return world.getBlockMetadata(x, y, z); + } + }