Added a fluid color render cache so fluids that use colors will get properly renderered in pipes

This commit is contained in:
ElConquistador 2013-11-30 17:14:43 +01:00
parent 5dd82d7a95
commit 6c770a90a1
3 changed files with 24 additions and 3 deletions

View file

@ -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;
}
}
}

View file

@ -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)) {

View file

@ -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]);