Skip to content

Commit

Permalink
Rewrite potion/lava cauldron renderer, fix tipped arrow bugs
Browse files Browse the repository at this point in the history
When using the potion cauldron to make tipped arrows it now makes sounds, and possible bugs when tipped arrows are not enabled.
  • Loading branch information
Roadhog360 committed Dec 19, 2023
1 parent aef5968 commit 63e6a4a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 63e6a4a

Please sign in to comment.