From 6c770a90a1dbd3d0a8401ff6c71873121752f25c Mon Sep 17 00:00:00 2001 From: ElConquistador Date: Sat, 30 Nov 2013 17:14:43 +0100 Subject: [PATCH 1/2] Added a fluid color render cache so fluids that use colors will get properly renderered in pipes --- common/buildcraft/transport/PipeTransportFluids.java | 8 ++++++++ .../transport/network/PacketFluidUpdate.java | 7 ++++++- .../transport/render/PipeRendererTESR.java | 12 ++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/transport/PipeTransportFluids.java b/common/buildcraft/transport/PipeTransportFluids.java index 4704124e..5bae1f60 100644 --- a/common/buildcraft/transport/PipeTransportFluids.java +++ b/common/buildcraft/transport/PipeTransportFluids.java @@ -141,6 +141,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler public short travelDelay = 12; public short flowRate = 10; public FluidStack[] renderCache = new FluidStack[orientations.length]; + public int[] colorRenderCache = new int[orientations.length]; public final PipeSection[] internalTanks = new PipeSection[orientations.length]; private final TransferState[] transferState = new TransferState[directions.length]; private final int[] inputPerTick = new int[directions.length]; @@ -229,6 +230,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler } FluidStack[] renderCache = this.renderCache.clone(); + int[] colorRenderCache = this.colorRenderCache.clone(); for (ForgeDirection dir : orientations) { FluidStack current = internalTanks[dir.ordinal()].getFluid(); @@ -241,6 +243,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler if (prev == null && current != null) { changed = true; renderCache[dir.ordinal()] = current.copy(); + colorRenderCache[dir.ordinal()] = current.getFluid().getColor(current); delta.set(dir.ordinal() * 3 + 0); delta.set(dir.ordinal() * 3 + 1); delta.set(dir.ordinal() * 3 + 2); @@ -250,6 +253,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler if (prev != null && current == null) { changed = true; renderCache[dir.ordinal()] = null; + colorRenderCache[dir.ordinal()] = 0xFFFFFF; delta.set(dir.ordinal() * 3 + 0); delta.set(dir.ordinal() * 3 + 1); delta.set(dir.ordinal() * 3 + 2); @@ -259,6 +263,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler if (!prev.equals(current) || initPacket) { changed = true; renderCache[dir.ordinal()] = current; + colorRenderCache[dir.ordinal()] = current.getFluid().getColor(current); delta.set(dir.ordinal() * 3 + 0); delta.set(dir.ordinal() * 3 + 1); } @@ -278,11 +283,13 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler if (persistChange) { this.renderCache = renderCache; + this.colorRenderCache = colorRenderCache; } if (changed || initPacket) { PacketFluidUpdate packet = new PacketFluidUpdate(container.xCoord, container.yCoord, container.zCoord, initPacket); packet.renderCache = renderCache; + packet.colorRenderCache = colorRenderCache; packet.delta = delta; return packet; } @@ -485,6 +492,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler internalTanks[direction.ordinal()].reset(); transferState[direction.ordinal()] = TransferState.None; renderCache[direction.ordinal()] = null; + colorRenderCache[direction.ordinal()] = 0xFFFFFF; } } } diff --git a/common/buildcraft/transport/network/PacketFluidUpdate.java b/common/buildcraft/transport/network/PacketFluidUpdate.java index a2dd745b..3da63e76 100644 --- a/common/buildcraft/transport/network/PacketFluidUpdate.java +++ b/common/buildcraft/transport/network/PacketFluidUpdate.java @@ -17,6 +17,7 @@ import net.minecraftforge.fluids.FluidStack; public class PacketFluidUpdate extends PacketCoordinates { public FluidStack[] renderCache = new FluidStack[ForgeDirection.values().length]; + public int[] colorRenderCache = new int[ForgeDirection.values().length]; public BitSet delta; public PacketFluidUpdate(int xCoord, int yCoord, int zCoord) { @@ -53,6 +54,7 @@ public class PacketFluidUpdate extends PacketCoordinates { PipeTransportFluids transLiq = ((PipeTransportFluids) pipe.pipe.transport); renderCache = transLiq.renderCache; + colorRenderCache = transLiq.colorRenderCache; byte[] dBytes = new byte[3]; data.read(dBytes); @@ -63,7 +65,8 @@ public class PacketFluidUpdate extends PacketCoordinates { for (ForgeDirection dir : ForgeDirection.values()) { if (delta.get(dir.ordinal() * 3 + 0)) { int amt = renderCache[dir.ordinal()] != null ? renderCache[dir.ordinal()].amount : 0; - renderCache[dir.ordinal()] = new FluidStack(data.readInt(),amt); + renderCache[dir.ordinal()] = new FluidStack(data.readInt(), amt); + colorRenderCache[dir.ordinal()] = data.readInt(); } if (delta.get(dir.ordinal() * 3 + 2)) { if (renderCache[dir.ordinal()] == null) { @@ -88,8 +91,10 @@ public class PacketFluidUpdate extends PacketCoordinates { if (delta.get(dir.ordinal() * 3 + 0)) { if (liquid != null) { data.writeInt(liquid.fluidID); + data.writeInt(colorRenderCache[dir.ordinal()]); } else { data.writeInt(0); + data.writeInt(0xFFFFFF); } } if (delta.get(dir.ordinal() * 3 + 2)) { diff --git a/common/buildcraft/transport/render/PipeRendererTESR.java b/common/buildcraft/transport/render/PipeRendererTESR.java index 1027a983..f8d90d0d 100644 --- a/common/buildcraft/transport/render/PipeRendererTESR.java +++ b/common/buildcraft/transport/render/PipeRendererTESR.java @@ -597,6 +597,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { int i = side.ordinal(); FluidStack fluidStack = trans.renderCache[i]; + int color = trans.colorRenderCache[i]; if (fluidStack == null || fluidStack.amount <= 0) continue; @@ -638,12 +639,16 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { default: } bindTexture(TextureMap.locationBlocksTexture); - FluidRenderer.setColorForFluidStack(fluidStack); + float red = (float) (color >> 16 & 255) / 255.0F; + float green = (float) (color >> 8 & 255) / 255.0F; + float blue = (float) (color & 255) / 255.0F; + GL11.glColor4f(red, green, blue, 1.0F); GL11.glCallList(list); GL11.glPopMatrix(); } // CENTER FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()]; + int color = trans.colorRenderCache[ForgeDirection.UNKNOWN.ordinal()]; if (fluidStack != null && fluidStack.amount > 0) { DisplayFluidList d = getListFromBuffer(fluidStack, pipe.container.worldObj); @@ -652,7 +657,10 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1)); bindTexture(TextureMap.locationBlocksTexture); - FluidRenderer.setColorForFluidStack(fluidStack); + float red = (float) (color >> 16 & 255) / 255.0F; + float green = (float) (color >> 8 & 255) / 255.0F; + float blue = (float) (color & 255) / 255.0F; + GL11.glColor4f(red, green, blue, 1.0F); if (above) { GL11.glCallList(d.centerVertical[stage]); From fb523870941f1de0f875a16db6d736bfff059908 Mon Sep 17 00:00:00 2001 From: ElConquistador Date: Sun, 1 Dec 2013 08:18:19 +0100 Subject: [PATCH 2/2] Added colorRenderCache to Tank and Refinery --- common/buildcraft/core/fluids/Tank.java | 1 + .../buildcraft/core/fluids/TankManager.java | 8 ++++++-- .../factory/render/RenderRefinery.java | 19 ++++++++++++++++--- .../buildcraft/factory/render/RenderTank.java | 6 +++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/common/buildcraft/core/fluids/Tank.java b/common/buildcraft/core/fluids/Tank.java index 1922e79a..e13e5014 100644 --- a/common/buildcraft/core/fluids/Tank.java +++ b/common/buildcraft/core/fluids/Tank.java @@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidTank; public class Tank extends FluidTank { private final String name; + public int colorRenderCache = 0xFFFFFF; public Tank(String name, int capacity, TileEntity tile) { super(capacity); diff --git a/common/buildcraft/core/fluids/TankManager.java b/common/buildcraft/core/fluids/TankManager.java index 0b14f078..39d4abbf 100644 --- a/common/buildcraft/core/fluids/TankManager.java +++ b/common/buildcraft/core/fluids/TankManager.java @@ -115,6 +115,7 @@ public class TankManager extends ForwardingList implements IF if (fluidStack != null && fluidStack.getFluid() != null) { data.writeShort(fluidStack.getFluid().getID()); data.writeInt(fluidStack.amount); + data.writeInt(fluidStack.getFluid().getColor(fluidStack)); } else { data.writeShort(-1); } @@ -125,10 +126,13 @@ public class TankManager extends ForwardingList implements IF public void readData(DataInputStream data) throws IOException { for (Tank tank : tanks) { int fluidId = data.readShort(); - if (fluidId > 0) + if (fluidId > 0) { tank.setFluid(new FluidStack(fluidId, data.readInt())); - else + tank.colorRenderCache = data.readInt(); + } else { tank.setFluid(null); + tank.colorRenderCache = 0xFFFFFF; + } } } } diff --git a/common/buildcraft/factory/render/RenderRefinery.java b/common/buildcraft/factory/render/RenderRefinery.java index 4f2a19ba..c3767b31 100644 --- a/common/buildcraft/factory/render/RenderRefinery.java +++ b/common/buildcraft/factory/render/RenderRefinery.java @@ -70,6 +70,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent private void render(TileRefinery tile, double x, double y, double z) { FluidStack liquid1 = null, liquid2 = null, liquidResult = null; + int color1 = 0xFFFFFF, color2 = 0xFFFFFF, colorResult = 0xFFFFFF; float anim = 0; int angle = 0; @@ -77,14 +78,17 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent if (tile != null) { if (tile.tank1.getFluid() != null) { liquid1 = tile.tank1.getFluid(); + color1 = tile.tank1.colorRenderCache; } if (tile.tank2.getFluid() != null) { liquid2 = tile.tank2.getFluid(); + color2 = tile.tank2.colorRenderCache; } if (tile.result.getFluid() != null) { liquidResult = tile.result.getFluid(); + colorResult = tile.result.colorRenderCache; } anim = tile.getAnimationStage(); @@ -183,7 +187,10 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent if (list1 != null) { bindTexture(FluidRenderer.getFluidSheet(liquid1)); - FluidRenderer.setColorForFluidStack(liquid1); + float red = (float) (color1 >> 16 & 255) / 255.0F; + float green = (float) (color1 >> 8 & 255) / 255.0F; + float blue = (float) (color1 & 255) / 255.0F; + GL11.glColor4f(red, green, blue, 1.0F); GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]); } } @@ -195,7 +202,10 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent GL11.glPushMatrix(); GL11.glTranslatef(0, 0, 1); bindTexture(FluidRenderer.getFluidSheet(liquid2)); - FluidRenderer.setColorForFluidStack(liquid2); + float red = (float) (color2 >> 16 & 255) / 255.0F; + float green = (float) (color2 >> 8 & 255) / 255.0F; + float blue = (float) (color2 & 255) / 255.0F; + GL11.glColor4f(red, green, blue, 1.0F); GL11.glCallList(list2[getDisplayListIndex(tile.tank2)]); GL11.glPopMatrix(); } @@ -209,7 +219,10 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent GL11.glPushMatrix(); GL11.glTranslatef(1, 0, 0.5F); bindTexture(FluidRenderer.getFluidSheet(liquidResult)); - FluidRenderer.setColorForFluidStack(liquidResult); + float red = (float) (colorResult >> 16 & 255) / 255.0F; + float green = (float) (colorResult >> 8 & 255) / 255.0F; + float blue = (float) (colorResult & 255) / 255.0F; + GL11.glColor4f(red, green, blue, 1.0F); GL11.glCallList(list3[getDisplayListIndex(tile.result)]); GL11.glPopMatrix(); } diff --git a/common/buildcraft/factory/render/RenderTank.java b/common/buildcraft/factory/render/RenderTank.java index 0ccefafa..e53afa78 100644 --- a/common/buildcraft/factory/render/RenderTank.java +++ b/common/buildcraft/factory/render/RenderTank.java @@ -22,6 +22,7 @@ public class RenderTank extends TileEntitySpecialRenderer { TileTank tank = ((TileTank) tileentity); FluidStack liquid = tank.tank.getFluid(); + int color = tank.tank.colorRenderCache; if (liquid == null || liquid.amount <= 0) { return; } @@ -39,7 +40,10 @@ public class RenderTank extends TileEntitySpecialRenderer { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); bindTexture(FluidRenderer.getFluidSheet(liquid)); - FluidRenderer.setColorForFluidStack(liquid); + float red = (float) (color >> 16 & 255) / 255.0F; + float green = (float) (color >> 8 & 255) / 255.0F; + float blue = (float) (color & 255) / 255.0F; + GL11.glColor4f(red, green, blue, 1.0F); GL11.glTranslatef((float) x + 0.125F, (float) y + 0.5F, (float) z + 0.125F); GL11.glScalef(0.75F, 0.999F, 0.75F);