fix fluid pipe crash on Forge 1355+
This commit is contained in:
parent
180a020fc7
commit
5c767249a6
4 changed files with 62 additions and 39 deletions
|
@ -13,6 +13,7 @@ import java.util.BitSet;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import buildcraft.transport.utils.FluidRenderData;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
|
@ -160,8 +161,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
public byte initClient = 0;
|
||||
public int travelDelay = 12;
|
||||
public int flowRate;
|
||||
public FluidStack[] renderCache = new FluidStack[orientations.length];
|
||||
public int[] colorRenderCache = new int[orientations.length];
|
||||
public FluidRenderData[] renderCache = new FluidRenderData[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];
|
||||
|
@ -258,12 +258,11 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
}
|
||||
}
|
||||
|
||||
FluidStack[] renderCacheCopy = this.renderCache.clone();
|
||||
int[] colorRenderCacheCopy = this.colorRenderCache.clone();
|
||||
FluidRenderData[] renderCacheCopy = this.renderCache.clone();
|
||||
|
||||
for (ForgeDirection dir : orientations) {
|
||||
FluidStack current = internalTanks[dir.ordinal()].getFluid();
|
||||
FluidStack prev = renderCacheCopy[dir.ordinal()];
|
||||
FluidStack prev = renderCacheCopy[dir.ordinal()] != null ? renderCacheCopy[dir.ordinal()].getFluidStack() : null;
|
||||
|
||||
if (current != null && current.getFluid() == null) {
|
||||
continue;
|
||||
|
@ -276,11 +275,9 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
if (prev == null ^ current == null) {
|
||||
changed = true;
|
||||
if (current != null) {
|
||||
renderCacheCopy[dir.ordinal()] = current.copy();
|
||||
colorRenderCacheCopy[dir.ordinal()] = current.getFluid().getColor(current);
|
||||
renderCacheCopy[dir.ordinal()] = new FluidRenderData(current);
|
||||
} else {
|
||||
renderCacheCopy[dir.ordinal()] = null;
|
||||
colorRenderCacheCopy[dir.ordinal()] = 0xFFFFFF;
|
||||
}
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_ID_BIT);
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_AMOUNT_BIT);
|
||||
|
@ -293,8 +290,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
|
||||
if (!prev.equals(current) || initPacket) {
|
||||
changed = true;
|
||||
renderCacheCopy[dir.ordinal()] = current;
|
||||
colorRenderCacheCopy[dir.ordinal()] = current.getFluid().getColor(current);
|
||||
renderCacheCopy[dir.ordinal()] = new FluidRenderData(current);
|
||||
delta.set(dir.ordinal() * PacketFluidUpdate.FLUID_DATA_NUM + PacketFluidUpdate.FLUID_ID_BIT);
|
||||
}
|
||||
|
||||
|
@ -313,13 +309,11 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
|
||||
if (persistChange) {
|
||||
this.renderCache = renderCacheCopy;
|
||||
this.colorRenderCache = colorRenderCacheCopy;
|
||||
}
|
||||
|
||||
if (changed || initPacket) {
|
||||
PacketFluidUpdate packet = new PacketFluidUpdate(container.xCoord, container.yCoord, container.zCoord, initPacket);
|
||||
packet.renderCache = renderCacheCopy;
|
||||
packet.colorRenderCache = colorRenderCacheCopy;
|
||||
packet.delta = delta;
|
||||
return packet;
|
||||
}
|
||||
|
@ -528,7 +522,6 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
internalTanks[direction.ordinal()].reset();
|
||||
transferState[direction.ordinal()] = TransferState.None;
|
||||
renderCache[direction.ordinal()] = null;
|
||||
colorRenderCache[direction.ordinal()] = 0xFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,15 @@ package buildcraft.transport.network;
|
|||
|
||||
import java.util.BitSet;
|
||||
|
||||
import buildcraft.transport.utils.FluidRenderData;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import buildcraft.core.network.PacketCoordinates;
|
||||
|
@ -31,8 +34,7 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
|||
public static int FLUID_AMOUNT_BIT = 1;
|
||||
public static int FLUID_DATA_NUM = 2;
|
||||
|
||||
public FluidStack[] renderCache = new FluidStack[ForgeDirection.values().length];
|
||||
public int[] colorRenderCache = new int[ForgeDirection.values().length];
|
||||
public FluidRenderData[] renderCache = new FluidRenderData[ForgeDirection.values().length];
|
||||
public BitSet delta;
|
||||
|
||||
public PacketFluidUpdate(int xCoord, int yCoord, int zCoord) {
|
||||
|
@ -73,7 +75,6 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
|||
PipeTransportFluids transLiq = (PipeTransportFluids) pipe.pipe.transport;
|
||||
|
||||
renderCache = transLiq.renderCache;
|
||||
colorRenderCache = transLiq.colorRenderCache;
|
||||
|
||||
byte[] dBytes = new byte[2];
|
||||
data.readBytes(dBytes);
|
||||
|
@ -83,15 +84,17 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
|||
|
||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||
if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) {
|
||||
int id = data.readShort();
|
||||
int amt = renderCache[dir.ordinal()] != null ? renderCache[dir.ordinal()].amount : 0;
|
||||
renderCache[dir.ordinal()] = new FluidStack(data.readShort(), amt);
|
||||
colorRenderCache[dir.ordinal()] = data.readInt();
|
||||
int color = data.readInt();
|
||||
|
||||
renderCache[dir.ordinal()] = new FluidRenderData(id, amt, color);
|
||||
}
|
||||
|
||||
if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) {
|
||||
if (renderCache[dir.ordinal()] == null) {
|
||||
renderCache[dir.ordinal()] = new FluidStack(0, 0);
|
||||
}
|
||||
renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readUnsignedShort());
|
||||
if (renderCache[dir.ordinal()] != null) {
|
||||
renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readUnsignedShort());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,12 +108,12 @@ public class PacketFluidUpdate extends PacketCoordinates {
|
|||
data.writeBytes(dBytes);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||
FluidStack liquid = renderCache[dir.ordinal()];
|
||||
FluidRenderData liquid = renderCache[dir.ordinal()];
|
||||
|
||||
if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) {
|
||||
if (liquid != null) {
|
||||
data.writeShort(liquid.fluidID);
|
||||
data.writeInt(colorRenderCache[dir.ordinal()]);
|
||||
data.writeInt(liquid.color);
|
||||
} else {
|
||||
data.writeShort(0);
|
||||
data.writeInt(0xFFFFFF);
|
||||
|
|
|
@ -10,6 +10,7 @@ package buildcraft.transport.render;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import buildcraft.transport.utils.FluidRenderData;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
@ -32,7 +33,6 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftCore.RenderMode;
|
||||
|
@ -669,8 +669,8 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
|
||||
boolean needsRender = false;
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
FluidStack fluidStack = trans.renderCache[i];
|
||||
if (fluidStack != null && fluidStack.amount > 0) {
|
||||
FluidRenderData renderData = trans.renderCache[i];
|
||||
if (renderData != null && renderData.amount > 0) {
|
||||
needsRender = true;
|
||||
break;
|
||||
}
|
||||
|
@ -696,9 +696,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
int i = side.ordinal();
|
||||
|
||||
FluidStack fluidStack = trans.renderCache[i];
|
||||
FluidRenderData fluidRenderData = trans.renderCache[i];
|
||||
|
||||
if (fluidStack == null || fluidStack.amount <= 0) {
|
||||
if (fluidRenderData == null || fluidRenderData.amount <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -706,13 +706,13 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
continue;
|
||||
}
|
||||
|
||||
DisplayFluidList d = getListFromBuffer(fluidStack, pipe.container.getWorldObj());
|
||||
DisplayFluidList d = getListFromBuffer(fluidRenderData, pipe.container.getWorldObj());
|
||||
|
||||
if (d == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
|
||||
int stage = (int) ((float) fluidRenderData.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
|
||||
|
||||
GL11.glPushMatrix();
|
||||
int list = 0;
|
||||
|
@ -741,21 +741,21 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
default:
|
||||
}
|
||||
bindTexture(TextureMap.locationBlocksTexture);
|
||||
RenderUtils.setGLColorFromInt(trans.colorRenderCache[i]);
|
||||
RenderUtils.setGLColorFromInt(fluidRenderData.color);
|
||||
GL11.glCallList(list);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
// CENTER
|
||||
FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
|
||||
FluidRenderData fluidRenderData = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
|
||||
|
||||
if (fluidStack != null && fluidStack.amount > 0) {
|
||||
DisplayFluidList d = getListFromBuffer(fluidStack, pipe.container.getWorldObj());
|
||||
if (fluidRenderData != null && fluidRenderData.amount > 0) {
|
||||
DisplayFluidList d = getListFromBuffer(fluidRenderData, pipe.container.getWorldObj());
|
||||
|
||||
if (d != null) {
|
||||
int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
|
||||
int stage = (int) ((float) fluidRenderData.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
|
||||
|
||||
bindTexture(TextureMap.locationBlocksTexture);
|
||||
RenderUtils.setGLColorFromInt(trans.colorRenderCache[ForgeDirection.UNKNOWN.ordinal()]);
|
||||
RenderUtils.setGLColorFromInt(fluidRenderData.color);
|
||||
|
||||
if (above) {
|
||||
GL11.glCallList(d.centerVertical[stage]);
|
||||
|
@ -772,8 +772,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
|
|||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private DisplayFluidList getListFromBuffer(FluidStack stack, World world) {
|
||||
|
||||
private DisplayFluidList getListFromBuffer(FluidRenderData stack, World world) {
|
||||
int liquidId = stack.fluidID;
|
||||
|
||||
if (liquidId == 0) {
|
||||
|
|
28
common/buildcraft/transport/utils/FluidRenderData.java
Normal file
28
common/buildcraft/transport/utils/FluidRenderData.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package buildcraft.transport.utils;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FluidRenderData {
|
||||
public int fluidID, amount, color;
|
||||
|
||||
public FluidRenderData(int fluidID, int amount, int color) {
|
||||
this.fluidID = fluidID;
|
||||
this.amount = amount;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public FluidRenderData(FluidStack stack) {
|
||||
this(stack.getFluid().getID(), stack.amount, stack.getFluid().getColor(stack));
|
||||
}
|
||||
|
||||
public FluidStack getFluidStack() {
|
||||
Fluid fluid = FluidRegistry.getFluid(fluidID);
|
||||
if (fluid != null) {
|
||||
return new FluidStack(fluid, amount);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue