From 4a21711ee7d7d4777076c22d0276b228d9a10906 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Mon, 19 Aug 2013 00:54:04 -0700 Subject: [PATCH] Make Refinery render safer Closes #1139 --- common/buildcraft/factory/render/RenderRefinery.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/factory/render/RenderRefinery.java b/common/buildcraft/factory/render/RenderRefinery.java index 0070669c..89ee424f 100644 --- a/common/buildcraft/factory/render/RenderRefinery.java +++ b/common/buildcraft/factory/render/RenderRefinery.java @@ -9,6 +9,7 @@ package buildcraft.factory.render; import buildcraft.core.DefaultProps; import buildcraft.core.IInventoryRenderer; +import buildcraft.core.fluids.Tank; import buildcraft.core.render.FluidRenderer; import buildcraft.factory.TileRefinery; import net.minecraft.client.model.ModelBase; @@ -183,7 +184,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent if (list1 != null) { func_110628_a(FluidRenderer.getFluidSheet(liquid1)); FluidRenderer.setColorForFluidStack(liquid1); - GL11.glCallList(list1[(int) ((float) liquid1.amount / (float) TileRefinery.LIQUID_PER_SLOT * (FluidRenderer.DISPLAY_STAGES - 1))]); + GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]); } } @@ -195,7 +196,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent GL11.glTranslatef(0, 0, 1); func_110628_a(FluidRenderer.getFluidSheet(liquid2)); FluidRenderer.setColorForFluidStack(liquid2); - GL11.glCallList(list2[(int) ((float) liquid2.amount / (float) TileRefinery.LIQUID_PER_SLOT * (FluidRenderer.DISPLAY_STAGES - 1))]); + GL11.glCallList(list2[getDisplayListIndex(tile.tank2)]); GL11.glPopMatrix(); } } @@ -209,7 +210,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent GL11.glTranslatef(1, 0, 0.5F); func_110628_a(FluidRenderer.getFluidSheet(liquidResult)); FluidRenderer.setColorForFluidStack(liquidResult); - GL11.glCallList(list3[(int) ((float) liquidResult.amount / (float) TileRefinery.LIQUID_PER_SLOT * (FluidRenderer.DISPLAY_STAGES - 1))]); + GL11.glCallList(list3[getDisplayListIndex(tile.result)]); GL11.glPopMatrix(); } } @@ -219,4 +220,8 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent GL11.glPopAttrib(); GL11.glPopMatrix(); } + + private int getDisplayListIndex(Tank tank) { + return Math.min((int) ((float) tank.getFluidAmount() / (float) tank.getCapacity() * (FluidRenderer.DISPLAY_STAGES - 1)), FluidRenderer.DISPLAY_STAGES - 1); + } }