From 63e6a4a4688c49b578b612085271935ac8156f43 Mon Sep 17 00:00:00 2001 From: Roadhog360 Date: Tue, 19 Dec 2023 11:16:21 -0600 Subject: [PATCH] Rewrite potion/lava cauldron renderer, fix tipped arrow bugs When using the potion cauldron to make tipped arrows it now makes sounds, and possible bugs when tipped arrows are not enabled. --- .../etfuturum/blocks/BlockPotionCauldron.java | 5 +- .../block/BlockCauldronBaseRenderer.java | 48 +++++++++++++++++++ .../BlockColoredWaterCauldronRenderer.java | 42 ++-------------- .../block/BlockLavaCauldronRenderer.java | 5 +- 4 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockCauldronBaseRenderer.java diff --git a/src/main/java/ganymedes01/etfuturum/blocks/BlockPotionCauldron.java b/src/main/java/ganymedes01/etfuturum/blocks/BlockPotionCauldron.java index 41a2de499..ffb11a50f 100644 --- a/src/main/java/ganymedes01/etfuturum/blocks/BlockPotionCauldron.java +++ b/src/main/java/ganymedes01/etfuturum/blocks/BlockPotionCauldron.java @@ -119,7 +119,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer e world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 1, 3); } return true; - } else if (item == Items.arrow) { + } else if (item == Items.arrow && ModItems.TIPPED_ARROW.isEnabled()) { final int meta = world.getBlockMetadata(x, y, z); final int tipmax = meta == 0 ? 16 : meta == 1 ? 32 : 64; @@ -149,6 +149,9 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer e } else { world.setBlockMetadataWithNotify(x, y, z, setMeta, 3); } + + float liquidLevel = y + getRenderLiquidLevel(world.getBlockMetadata(x, y, z) + 1); + world.playSoundEffect(x + 0.5D, liquidLevel, z + 0.5D, "game.player.swim.splash", 1, 1); return true; } } diff --git a/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockCauldronBaseRenderer.java b/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockCauldronBaseRenderer.java new file mode 100644 index 000000000..b768a7567 --- /dev/null +++ b/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockCauldronBaseRenderer.java @@ -0,0 +1,48 @@ +package ganymedes01.etfuturum.client.renderer.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockCauldron; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +public class BlockCauldronBaseRenderer extends BlockModelBase { + public BlockCauldronBaseRenderer(int modelID) { + super(modelID); + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { + renderer.renderStandardBlock(block, x, y, z); + Tessellator tessellator = Tessellator.instance; + tessellator.setBrightness(block.getMixedBrightnessForBlock(renderer.blockAccess, x, y, z)); + int l = block.colorMultiplier(renderer.blockAccess, 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; + float f4; + + if (EntityRenderer.anaglyphEnable) { + float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F; + 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.setColorOpaque_F(f, f1, f2); + IIcon iicon1 = block.getBlockTextureFromSide(2); + f4 = 0.125F; + renderer.renderFaceXPos(block, (double) x - 1.0F + f4, y, z, iicon1); + renderer.renderFaceXNeg(block, (double) x + 1.0F - f4, y, z, iicon1); + renderer.renderFaceZPos(block, x, y, (double) z - 1.0F + f4, iicon1); + renderer.renderFaceZNeg(block, x, y, (double) z + 1.0F - f4, iicon1); + IIcon iicon2 = BlockCauldron.getCauldronIcon("inner"); + renderer.renderFaceYPos(block, x, (double) y - 1.0F + 0.25F, z, iicon2); + renderer.renderFaceYNeg(block, x, (double) y + 1.0F - 0.75F, z, iicon2); + return true; + } +} diff --git a/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockColoredWaterCauldronRenderer.java b/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockColoredWaterCauldronRenderer.java index c80e0f921..4faae4c29 100644 --- a/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockColoredWaterCauldronRenderer.java +++ b/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockColoredWaterCauldronRenderer.java @@ -5,62 +5,28 @@ import ganymedes01.etfuturum.tileentities.TileEntityCauldronColoredWater; import net.minecraft.block.Block; import net.minecraft.block.BlockCauldron; -import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -public class BlockColoredWaterCauldronRenderer extends BlockModelBase { +public class BlockColoredWaterCauldronRenderer extends BlockCauldronBaseRenderer { public BlockColoredWaterCauldronRenderer(int modelID) { super(modelID); } - @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) { - TileEntityCauldronColoredWater tile = (TileEntityCauldronColoredWater) world.getTileEntity(x, y, z); - renderer.renderStandardBlock(block, x, y, z); - Tessellator tessellator = Tessellator.instance; - tessellator.setBrightness(block.getMixedBrightnessForBlock(renderer.blockAccess, x, y, z)); - int l = block.colorMultiplier(renderer.blockAccess, 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; - float f4; - - if (EntityRenderer.anaglyphEnable) { - float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F; - 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.setColorOpaque_F(f, f1, f2); - IIcon iicon1 = block.getBlockTextureFromSide(2); - f4 = 0.125F; - renderer.renderFaceXPos(block, (double) x - 1.0F + f4, y, z, iicon1); - renderer.renderFaceXNeg(block, (double) x + 1.0F - f4, y, z, iicon1); - renderer.renderFaceZPos(block, x, y, (double) z - 1.0F + f4, iicon1); - renderer.renderFaceZNeg(block, x, y, (double) z + 1.0F - f4, iicon1); - IIcon iicon2 = BlockCauldron.getCauldronIcon("inner"); - renderer.renderFaceYPos(block, x, (double) y - 1.0F + 0.25F, z, iicon2); - renderer.renderFaceYNeg(block, x, (double) y + 1.0F - 0.75F, z, iicon2); - int i1 = renderer.blockAccess.getBlockMetadata(x, y, z); + super.renderWorldBlock(world, x, y, z, block, modelId, renderer); + TileEntityCauldronColoredWater tile = (TileEntityCauldronColoredWater) world.getTileEntity(x, y, z); int color = tile.getWaterColor(); float r = (float) (color >> 16 & 255) / 255.0F; float g = (float) (color >> 8 & 255) / 255.0F; float b = (float) (color & 255) / 255.0F; tessellator.setColorOpaque_F(r, g, b); IIcon iicon = ((BlockPotionCauldron) ModBlocks.POTION_CAULDRON.get()).grayscaleWaterIcon(); - renderer.renderFaceYPos(block, x, (double) y - 1.0F + BlockCauldron.getRenderLiquidLevel(i1 + 1), z, iicon); + renderer.renderFaceYPos(block, x, (double) y - 1.0F + BlockCauldron.getRenderLiquidLevel(renderer.blockAccess.getBlockMetadata(x, y, z) + 1), z, iicon); return true; } diff --git a/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockLavaCauldronRenderer.java b/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockLavaCauldronRenderer.java index e539c27ba..de70f5f52 100644 --- a/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockLavaCauldronRenderer.java +++ b/src/main/java/ganymedes01/etfuturum/client/renderer/block/BlockLavaCauldronRenderer.java @@ -3,11 +3,10 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.init.Blocks; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -public class BlockLavaCauldronRenderer extends BlockModelBase { +public class BlockLavaCauldronRenderer extends BlockCauldronBaseRenderer { public BlockLavaCauldronRenderer(int modelID) { super(modelID); @@ -20,7 +19,7 @@ public void renderInventoryBlock(Block block, int metadata, int modelId, RenderB @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { - renderer.renderBlockCauldron(Blocks.cauldron, x, y, z); + super.renderWorldBlock(world, x, y, z, block, modelId, renderer); IIcon lava = BlockLiquid.getLiquidIcon("lava_still"); renderer.renderFaceYPos(block, x, y - 1.0F + (0.9375F), z, lava); return true;