Merge pull request #1349 from ItsMeElConquistador/master
Added a fluid color render cache to pipes
This commit is contained in:
commit
09ef987875
7 changed files with 52 additions and 9 deletions
|
@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidTank;
|
||||||
public class Tank extends FluidTank {
|
public class Tank extends FluidTank {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
public int colorRenderCache = 0xFFFFFF;
|
||||||
|
|
||||||
public Tank(String name, int capacity, TileEntity tile) {
|
public Tank(String name, int capacity, TileEntity tile) {
|
||||||
super(capacity);
|
super(capacity);
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class TankManager<T extends Tank> extends ForwardingList<T> implements IF
|
||||||
if (fluidStack != null && fluidStack.getFluid() != null) {
|
if (fluidStack != null && fluidStack.getFluid() != null) {
|
||||||
data.writeShort(fluidStack.getFluid().getID());
|
data.writeShort(fluidStack.getFluid().getID());
|
||||||
data.writeInt(fluidStack.amount);
|
data.writeInt(fluidStack.amount);
|
||||||
|
data.writeInt(fluidStack.getFluid().getColor(fluidStack));
|
||||||
} else {
|
} else {
|
||||||
data.writeShort(-1);
|
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 {
|
public void readData(DataInputStream data) throws IOException {
|
||||||
for (Tank tank : tanks) {
|
for (Tank tank : tanks) {
|
||||||
int fluidId = data.readShort();
|
int fluidId = data.readShort();
|
||||||
if (fluidId > 0)
|
if (fluidId > 0) {
|
||||||
tank.setFluid(new FluidStack(fluidId, data.readInt()));
|
tank.setFluid(new FluidStack(fluidId, data.readInt()));
|
||||||
else
|
tank.colorRenderCache = data.readInt();
|
||||||
|
} else {
|
||||||
tank.setFluid(null);
|
tank.setFluid(null);
|
||||||
|
tank.colorRenderCache = 0xFFFFFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
|
||||||
|
|
||||||
private void render(TileRefinery tile, double x, double y, double z) {
|
private void render(TileRefinery tile, double x, double y, double z) {
|
||||||
FluidStack liquid1 = null, liquid2 = null, liquidResult = null;
|
FluidStack liquid1 = null, liquid2 = null, liquidResult = null;
|
||||||
|
int color1 = 0xFFFFFF, color2 = 0xFFFFFF, colorResult = 0xFFFFFF;
|
||||||
|
|
||||||
float anim = 0;
|
float anim = 0;
|
||||||
int angle = 0;
|
int angle = 0;
|
||||||
|
@ -77,14 +78,17 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
|
||||||
if (tile != null) {
|
if (tile != null) {
|
||||||
if (tile.tank1.getFluid() != null) {
|
if (tile.tank1.getFluid() != null) {
|
||||||
liquid1 = tile.tank1.getFluid();
|
liquid1 = tile.tank1.getFluid();
|
||||||
|
color1 = tile.tank1.colorRenderCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile.tank2.getFluid() != null) {
|
if (tile.tank2.getFluid() != null) {
|
||||||
liquid2 = tile.tank2.getFluid();
|
liquid2 = tile.tank2.getFluid();
|
||||||
|
color2 = tile.tank2.colorRenderCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile.result.getFluid() != null) {
|
if (tile.result.getFluid() != null) {
|
||||||
liquidResult = tile.result.getFluid();
|
liquidResult = tile.result.getFluid();
|
||||||
|
colorResult = tile.result.colorRenderCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
anim = tile.getAnimationStage();
|
anim = tile.getAnimationStage();
|
||||||
|
@ -183,7 +187,10 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
|
||||||
|
|
||||||
if (list1 != null) {
|
if (list1 != null) {
|
||||||
bindTexture(FluidRenderer.getFluidSheet(liquid1));
|
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)]);
|
GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +202,10 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslatef(0, 0, 1);
|
GL11.glTranslatef(0, 0, 1);
|
||||||
bindTexture(FluidRenderer.getFluidSheet(liquid2));
|
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.glCallList(list2[getDisplayListIndex(tile.tank2)]);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
@ -209,7 +219,10 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslatef(1, 0, 0.5F);
|
GL11.glTranslatef(1, 0, 0.5F);
|
||||||
bindTexture(FluidRenderer.getFluidSheet(liquidResult));
|
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.glCallList(list3[getDisplayListIndex(tile.result)]);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class RenderTank extends TileEntitySpecialRenderer {
|
||||||
TileTank tank = ((TileTank) tileentity);
|
TileTank tank = ((TileTank) tileentity);
|
||||||
|
|
||||||
FluidStack liquid = tank.tank.getFluid();
|
FluidStack liquid = tank.tank.getFluid();
|
||||||
|
int color = tank.tank.colorRenderCache;
|
||||||
if (liquid == null || liquid.amount <= 0) {
|
if (liquid == null || liquid.amount <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +40,10 @@ public class RenderTank extends TileEntitySpecialRenderer {
|
||||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
bindTexture(FluidRenderer.getFluidSheet(liquid));
|
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.glTranslatef((float) x + 0.125F, (float) y + 0.5F, (float) z + 0.125F);
|
||||||
GL11.glScalef(0.75F, 0.999F, 0.75F);
|
GL11.glScalef(0.75F, 0.999F, 0.75F);
|
||||||
|
|
|
@ -141,6 +141,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
||||||
public short travelDelay = 12;
|
public short travelDelay = 12;
|
||||||
public short flowRate = 10;
|
public short flowRate = 10;
|
||||||
public FluidStack[] renderCache = new FluidStack[orientations.length];
|
public FluidStack[] renderCache = new FluidStack[orientations.length];
|
||||||
|
public int[] colorRenderCache = new int[orientations.length];
|
||||||
public final PipeSection[] internalTanks = new PipeSection[orientations.length];
|
public final PipeSection[] internalTanks = new PipeSection[orientations.length];
|
||||||
private final TransferState[] transferState = new TransferState[directions.length];
|
private final TransferState[] transferState = new TransferState[directions.length];
|
||||||
private final int[] inputPerTick = new int[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();
|
FluidStack[] renderCache = this.renderCache.clone();
|
||||||
|
int[] colorRenderCache = this.colorRenderCache.clone();
|
||||||
|
|
||||||
for (ForgeDirection dir : orientations) {
|
for (ForgeDirection dir : orientations) {
|
||||||
FluidStack current = internalTanks[dir.ordinal()].getFluid();
|
FluidStack current = internalTanks[dir.ordinal()].getFluid();
|
||||||
|
@ -241,6 +243,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
||||||
if (prev == null && current != null) {
|
if (prev == null && current != null) {
|
||||||
changed = true;
|
changed = true;
|
||||||
renderCache[dir.ordinal()] = current.copy();
|
renderCache[dir.ordinal()] = current.copy();
|
||||||
|
colorRenderCache[dir.ordinal()] = current.getFluid().getColor(current);
|
||||||
delta.set(dir.ordinal() * 3 + 0);
|
delta.set(dir.ordinal() * 3 + 0);
|
||||||
delta.set(dir.ordinal() * 3 + 1);
|
delta.set(dir.ordinal() * 3 + 1);
|
||||||
delta.set(dir.ordinal() * 3 + 2);
|
delta.set(dir.ordinal() * 3 + 2);
|
||||||
|
@ -250,6 +253,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
||||||
if (prev != null && current == null) {
|
if (prev != null && current == null) {
|
||||||
changed = true;
|
changed = true;
|
||||||
renderCache[dir.ordinal()] = null;
|
renderCache[dir.ordinal()] = null;
|
||||||
|
colorRenderCache[dir.ordinal()] = 0xFFFFFF;
|
||||||
delta.set(dir.ordinal() * 3 + 0);
|
delta.set(dir.ordinal() * 3 + 0);
|
||||||
delta.set(dir.ordinal() * 3 + 1);
|
delta.set(dir.ordinal() * 3 + 1);
|
||||||
delta.set(dir.ordinal() * 3 + 2);
|
delta.set(dir.ordinal() * 3 + 2);
|
||||||
|
@ -259,6 +263,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
||||||
if (!prev.equals(current) || initPacket) {
|
if (!prev.equals(current) || initPacket) {
|
||||||
changed = true;
|
changed = true;
|
||||||
renderCache[dir.ordinal()] = current;
|
renderCache[dir.ordinal()] = current;
|
||||||
|
colorRenderCache[dir.ordinal()] = current.getFluid().getColor(current);
|
||||||
delta.set(dir.ordinal() * 3 + 0);
|
delta.set(dir.ordinal() * 3 + 0);
|
||||||
delta.set(dir.ordinal() * 3 + 1);
|
delta.set(dir.ordinal() * 3 + 1);
|
||||||
}
|
}
|
||||||
|
@ -278,11 +283,13 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
||||||
|
|
||||||
if (persistChange) {
|
if (persistChange) {
|
||||||
this.renderCache = renderCache;
|
this.renderCache = renderCache;
|
||||||
|
this.colorRenderCache = colorRenderCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed || initPacket) {
|
if (changed || initPacket) {
|
||||||
PacketFluidUpdate packet = new PacketFluidUpdate(container.xCoord, container.yCoord, container.zCoord, initPacket);
|
PacketFluidUpdate packet = new PacketFluidUpdate(container.xCoord, container.yCoord, container.zCoord, initPacket);
|
||||||
packet.renderCache = renderCache;
|
packet.renderCache = renderCache;
|
||||||
|
packet.colorRenderCache = colorRenderCache;
|
||||||
packet.delta = delta;
|
packet.delta = delta;
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -485,6 +492,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
||||||
internalTanks[direction.ordinal()].reset();
|
internalTanks[direction.ordinal()].reset();
|
||||||
transferState[direction.ordinal()] = TransferState.None;
|
transferState[direction.ordinal()] = TransferState.None;
|
||||||
renderCache[direction.ordinal()] = null;
|
renderCache[direction.ordinal()] = null;
|
||||||
|
colorRenderCache[direction.ordinal()] = 0xFFFFFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
public class PacketFluidUpdate extends PacketCoordinates {
|
public class PacketFluidUpdate extends PacketCoordinates {
|
||||||
|
|
||||||
public FluidStack[] renderCache = new FluidStack[ForgeDirection.values().length];
|
public FluidStack[] renderCache = new FluidStack[ForgeDirection.values().length];
|
||||||
|
public int[] colorRenderCache = new int[ForgeDirection.values().length];
|
||||||
public BitSet delta;
|
public BitSet delta;
|
||||||
|
|
||||||
public PacketFluidUpdate(int xCoord, int yCoord, int zCoord) {
|
public PacketFluidUpdate(int xCoord, int yCoord, int zCoord) {
|
||||||
|
@ -53,6 +54,7 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
||||||
PipeTransportFluids transLiq = ((PipeTransportFluids) pipe.pipe.transport);
|
PipeTransportFluids transLiq = ((PipeTransportFluids) pipe.pipe.transport);
|
||||||
|
|
||||||
renderCache = transLiq.renderCache;
|
renderCache = transLiq.renderCache;
|
||||||
|
colorRenderCache = transLiq.colorRenderCache;
|
||||||
|
|
||||||
byte[] dBytes = new byte[3];
|
byte[] dBytes = new byte[3];
|
||||||
data.read(dBytes);
|
data.read(dBytes);
|
||||||
|
@ -63,7 +65,8 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
||||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||||
if (delta.get(dir.ordinal() * 3 + 0)) {
|
if (delta.get(dir.ordinal() * 3 + 0)) {
|
||||||
int amt = renderCache[dir.ordinal()] != null ? renderCache[dir.ordinal()].amount : 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 (delta.get(dir.ordinal() * 3 + 2)) {
|
||||||
if (renderCache[dir.ordinal()] == null) {
|
if (renderCache[dir.ordinal()] == null) {
|
||||||
|
@ -88,8 +91,10 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
||||||
if (delta.get(dir.ordinal() * 3 + 0)) {
|
if (delta.get(dir.ordinal() * 3 + 0)) {
|
||||||
if (liquid != null) {
|
if (liquid != null) {
|
||||||
data.writeInt(liquid.fluidID);
|
data.writeInt(liquid.fluidID);
|
||||||
|
data.writeInt(colorRenderCache[dir.ordinal()]);
|
||||||
} else {
|
} else {
|
||||||
data.writeInt(0);
|
data.writeInt(0);
|
||||||
|
data.writeInt(0xFFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (delta.get(dir.ordinal() * 3 + 2)) {
|
if (delta.get(dir.ordinal() * 3 + 2)) {
|
||||||
|
|
|
@ -597,6 +597,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
||||||
int i = side.ordinal();
|
int i = side.ordinal();
|
||||||
|
|
||||||
FluidStack fluidStack = trans.renderCache[i];
|
FluidStack fluidStack = trans.renderCache[i];
|
||||||
|
int color = trans.colorRenderCache[i];
|
||||||
|
|
||||||
if (fluidStack == null || fluidStack.amount <= 0)
|
if (fluidStack == null || fluidStack.amount <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -638,12 +639,16 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
bindTexture(TextureMap.locationBlocksTexture);
|
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.glCallList(list);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
// CENTER
|
// CENTER
|
||||||
FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
|
FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
|
||||||
|
int color = trans.colorRenderCache[ForgeDirection.UNKNOWN.ordinal()];
|
||||||
|
|
||||||
if (fluidStack != null && fluidStack.amount > 0) {
|
if (fluidStack != null && fluidStack.amount > 0) {
|
||||||
DisplayFluidList d = getListFromBuffer(fluidStack, pipe.container.worldObj);
|
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));
|
int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
|
||||||
|
|
||||||
bindTexture(TextureMap.locationBlocksTexture);
|
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) {
|
if (above) {
|
||||||
GL11.glCallList(d.centerVertical[stage]);
|
GL11.glCallList(d.centerVertical[stage]);
|
||||||
|
|
Loading…
Reference in a new issue