From 67b15ddfee9bb4338b5881bec253142bc8b0a276 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Tue, 24 Sep 2013 17:53:43 +1000 Subject: [PATCH] New bamboo rendering --- build.xml | 4 +- common/biomesoplenty/ClientProxy.java | 3 + common/biomesoplenty/blocks/BlockBamboo.java | 49 +++++++- .../blocks/renderers/BambooRenderer.java | 105 ++++++++++++++++++ .../blocks/renderers/RenderUtils.java | 1 + .../configuration/BOPBlocks.java | 2 +- .../textures/blocks/bambootop.png | Bin 0 -> 282 bytes 7 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 common/biomesoplenty/blocks/renderers/BambooRenderer.java create mode 100644 resources/assets/biomesoplenty/textures/blocks/bambootop.png diff --git a/build.xml b/build.xml index 85cc2e754..fd1bbb214 100644 --- a/build.xml +++ b/build.xml @@ -4,8 +4,8 @@ - - + + diff --git a/common/biomesoplenty/ClientProxy.java b/common/biomesoplenty/ClientProxy.java index f9f727276..23671b650 100644 --- a/common/biomesoplenty/ClientProxy.java +++ b/common/biomesoplenty/ClientProxy.java @@ -8,6 +8,7 @@ import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.entity.RenderSnowball; import biomesoplenty.api.Items; import biomesoplenty.blocks.renderers.AltarRenderer; +import biomesoplenty.blocks.renderers.BambooRenderer; import biomesoplenty.blocks.renderers.FoliageRenderer; import biomesoplenty.blocks.renderers.GraveRenderer; import biomesoplenty.blocks.renderers.PlantsRenderer; @@ -43,6 +44,7 @@ public class ClientProxy extends CommonProxy { RenderUtils.puddleModel = RenderingRegistry.getNextAvailableRenderId(); RenderUtils.bonesModel = RenderingRegistry.getNextAvailableRenderId(); RenderUtils.graveModel = RenderingRegistry.getNextAvailableRenderId(); + RenderUtils.bambooModel = RenderingRegistry.getNextAvailableRenderId(); RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, new RenderSnowball(Items.mudball.get(), 0)); RenderingRegistry.registerEntityRenderingHandler(EntityDart.class, new RenderDart()); @@ -58,6 +60,7 @@ public class ClientProxy extends CommonProxy { RenderingRegistry.registerBlockHandler(new AltarRenderer()); RenderingRegistry.registerBlockHandler(new PuddleRender()); RenderingRegistry.registerBlockHandler(new GraveRenderer()); + RenderingRegistry.registerBlockHandler(new BambooRenderer()); } @Override diff --git a/common/biomesoplenty/blocks/BlockBamboo.java b/common/biomesoplenty/blocks/BlockBamboo.java index 8cf174d9f..9f2107a34 100644 --- a/common/biomesoplenty/blocks/BlockBamboo.java +++ b/common/biomesoplenty/blocks/BlockBamboo.java @@ -1,29 +1,45 @@ package biomesoplenty.blocks; +import java.util.List; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.blocks.renderers.RenderUtils; public class BlockBamboo extends Block { + private Icon bambooTop; + public BlockBamboo(int par1) { super(par1, Material.plants); - float var3 = 0.15F; setBurnProperties(blockID, 5, 5); - this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 1.0F, 0.5F + var3); this.setTickRandomly(true); this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); } @Override - public void registerIcons(IconRegister par1IconRegister) + public void registerIcons(IconRegister iconRegister) { - blockIcon = par1IconRegister.registerIcon("biomesoplenty:bamboo"); + blockIcon = iconRegister.registerIcon("biomesoplenty:bamboo"); + bambooTop = iconRegister.registerIcon("biomesoplenty:bambootop"); + } + + @Override + public Icon getIcon(int side, int meta) + { + if (side > 1) + return blockIcon; + else + return bambooTop; } @Override @@ -54,6 +70,29 @@ public class BlockBamboo extends Block } } } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) + { + float pixel = 0.0625F; + + return AxisAlignedBB.getAABBPool().getAABB((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 + public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisAlignedBB, List list, Entity entity) + { + float pixel = 0.0625F; + 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); + this.setBlockBoundsForItemRender(); + } + + @Override + public void setBlockBoundsForItemRender() + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } @Override public boolean canBeReplacedByLeaves(World world, int x, int y, int z) @@ -112,7 +151,7 @@ public class BlockBamboo extends Block @Override public int getRenderType() { - return 1; + return RenderUtils.bambooModel; } @Override diff --git a/common/biomesoplenty/blocks/renderers/BambooRenderer.java b/common/biomesoplenty/blocks/renderers/BambooRenderer.java new file mode 100644 index 000000000..865a3b51c --- /dev/null +++ b/common/biomesoplenty/blocks/renderers/BambooRenderer.java @@ -0,0 +1,105 @@ +package biomesoplenty.blocks.renderers; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.world.IBlockAccess; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; + +public class BambooRenderer implements ISimpleBlockRenderingHandler +{ + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) + { + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) + { + block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + + int l = block.colorMultiplier(world, x, y, z); + float f = (float)(l >> 16 & 255) / 255.0F; + float f1 = (float)(l >> 8 & 255) / 255.0F; + float f2 = (float)(l & 255) / 255.0F; + + if (EntityRenderer.anaglyphEnable) + { + float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F; + float f4 = (f * 30.0F + f1 * 70.0F) / 100.0F; + float f5 = (f * 30.0F + f2 * 70.0F) / 100.0F; + f = f3; + f1 = f4; + f2 = f5; + } + + Tessellator tessellator = Tessellator.instance; + boolean flag = false; + float f3 = 0.5F; + float f4 = 1.0F; + float f5 = 0.8F; + float f6 = 0.6F; + float r = f3 * f; + float f8 = f4 * f; + float f9 = f5 * f; + float f10 = f6 * f; + float g = f3 * f1; + float f12 = f4 * f1; + float f13 = f5 * f1; + float f14 = f6 * f1; + float b = f3 * f2; + float f16 = f4 * f2; + float f17 = f5 * f2; + float f18 = f6 * f2; + float pixel = 0.0625F; + int m = block.getMixedBrightnessForBlock(world, x, y, z); + + if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y - 1, z, 0)) + { + tessellator.setBrightness(renderer.renderMinY > 0.0D ? m : block.getMixedBrightnessForBlock(world, x, y - 1, z)); + tessellator.setColorOpaque_F(r, g, b); + renderer.renderFaceYNeg(block, (double)x, (double)y, (double)z, renderer.getBlockIcon(block, world, x, y, z, 0)); + } + + if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y + 1, z, 1)) + { + tessellator.setBrightness(renderer.renderMaxY < 1.0D ? m : block.getMixedBrightnessForBlock(world, x, y + 1, z)); + tessellator.setColorOpaque_F(f8, f12, f16); + renderer.renderFaceYPos(block, (double)x, (double)y, (double)z, renderer.getBlockIcon(block, world, x, y, z, 1)); + } + + tessellator.setBrightness(m); + tessellator.setColorOpaque_F(f9, f13, f17); + tessellator.addTranslation(0.0F, 0.0F, pixel); + renderer.renderFaceZNeg(block, (double)x, (double)y, (double)z + (pixel * 4), renderer.getBlockIcon(block, world, x, y, z, 2)); + tessellator.addTranslation(0.0F, 0.0F, -pixel); + tessellator.addTranslation(0.0F, 0.0F, -pixel); + renderer.renderFaceZPos(block, (double)x, (double)y, (double)z - (pixel * 4), renderer.getBlockIcon(block, world, x, y, z, 3)); + tessellator.addTranslation(0.0F, 0.0F, pixel); + tessellator.setColorOpaque_F(f10, f14, f18); + tessellator.addTranslation(pixel, 0.0F, 0.0F); + renderer.renderFaceXNeg(block, (double)x + (pixel * 4), (double)y, (double)z, renderer.getBlockIcon(block, world, x, y, z, 4)); + tessellator.addTranslation(-pixel, 0.0F, 0.0F); + tessellator.addTranslation(-pixel, 0.0F, 0.0F); + 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; + } + + @Override + public boolean shouldRender3DInInventory() + { + return false; + } + + @Override + public int getRenderId() + { + return RenderUtils.bambooModel; + } +} diff --git a/common/biomesoplenty/blocks/renderers/RenderUtils.java b/common/biomesoplenty/blocks/renderers/RenderUtils.java index 7134ba0b1..d15c58732 100644 --- a/common/biomesoplenty/blocks/renderers/RenderUtils.java +++ b/common/biomesoplenty/blocks/renderers/RenderUtils.java @@ -19,6 +19,7 @@ public class RenderUtils public static int puddleModel = -1; public static int bonesModel = -1; public static int graveModel = -1; + public static int bambooModel = -1; public static void renderStandardInvBlock(RenderBlocks renderblocks, Block block, int meta) { diff --git a/common/biomesoplenty/configuration/BOPBlocks.java b/common/biomesoplenty/configuration/BOPBlocks.java index 241514a4d..2cfa5dd74 100644 --- a/common/biomesoplenty/configuration/BOPBlocks.java +++ b/common/biomesoplenty/configuration/BOPBlocks.java @@ -142,7 +142,7 @@ public class BOPBlocks Blocks.hardIce = Optional.of(new BlockBOPGeneric(BOPConfigurationIDs.hardIceID, Material.rock, BlockType.HARD_ICE)); Blocks.leavesFruit = Optional.of((new BlockBOPAppleLeaves(BOPConfigurationIDs.leavesFruitID)).setUnlocalizedName("bop.leavesFruit")); Blocks.leavesFruit2 = Optional.of((new BlockBOPPersimmonLeaves(BOPConfigurationIDs.leavesFruit2ID)).setUnlocalizedName("bop.leavesFruit2")); - Blocks.bamboo = Optional.of(new BlockBamboo(BOPConfigurationIDs.bambooID).setHardness(0.0F).setStepSound(Block.soundGrassFootstep).setUnlocalizedName("bop.bamboo")); + Blocks.bamboo = Optional.of(new BlockBamboo(BOPConfigurationIDs.bambooID).setHardness(0.2F).setStepSound(Block.soundWoodFootstep).setUnlocalizedName("bop.bamboo")); Blocks.mudBrick = Optional.of(new BlockBOPGeneric(BOPConfigurationIDs.mudBrickBlockID, Material.rock, BlockType.MUD_BRICK)); Blocks.mudBricksStairs = Optional.of((new BlockBOPStairs(BOPConfigurationIDs.mudBrickStairsID, Blocks.redRock.get(), Category.MUD_BRICKS)).setHardness(1.0F).setUnlocalizedName("bop.mudBricksStairs")); Blocks.stoneDoubleSlab = Optional.of((BlockHalfSlab)(new BlockBOPSlab(BOPConfigurationIDs.stoneDoubleSlabID, true, Material.rock, SlabCategory.STONE)).setUnlocalizedName("bop.stoneDoubleSlab")); diff --git a/resources/assets/biomesoplenty/textures/blocks/bambootop.png b/resources/assets/biomesoplenty/textures/blocks/bambootop.png new file mode 100644 index 0000000000000000000000000000000000000000..3635aa105edd9ab9961ebffdbaeafef14371206d GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{^MbQ4*Y=R#Ki=l*$m0n3-3i=jR%tP-d)Ws%L2E{@KYKsA`(0 zi(`m|f3gIt2@|)u`k(k}h0p)zdGGx1_$IXa@<09C6MxBT`AWRmANAq?!|taEHUD2; z`tN^#&AFVdQ&MBb@0BR;{YXATM literal 0 HcmV?d00001