Merge pull request #1349 from ItsMeElConquistador/master

Added a fluid color render cache to pipes
This commit is contained in:
CovertJaguar 2013-12-01 06:05:26 -08:00
commit 09ef987875
7 changed files with 52 additions and 9 deletions

View file

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

View file

@ -115,6 +115,7 @@ public class TankManager<T extends Tank> extends ForwardingList<T> 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<T extends Tank> extends ForwardingList<T> 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;
}
}
}
}

View file

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

View file

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

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