Liquid Packets should not send before chunks on client join

This commit is contained in:
NeverCast 2012-12-15 21:04:25 +13:00
parent eccf88b0ea
commit f23ddb476a
2 changed files with 101 additions and 67 deletions

View file

@ -20,6 +20,7 @@ import buildcraft.core.utils.Utils;
import buildcraft.transport.network.PacketLiquidUpdate;
import java.util.BitSet;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Packet;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
@ -195,77 +196,100 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
if (tracker.markTimeIfDelay(worldObj, BuildCraftCore.updateFactor)) {
boolean changed = false;
BitSet delta = new BitSet(21);
if (initClient > 0) {
initClient--;
if (initClient == 1) {
changed = true;
delta.set(0, 21);
}
}
for (ForgeDirection dir : orientations) {
LiquidStack current = internalTanks[dir.ordinal()].getLiquid();
LiquidStack prev = renderCache[dir.ordinal()];
if (prev == null && current == null) {
continue;
}
if (prev == null && current != null) {
changed = true;
renderCache[dir.ordinal()] = current.copy();
delta.set(dir.ordinal() * 3 + 0);
delta.set(dir.ordinal() * 3 + 1);
delta.set(dir.ordinal() * 3 + 2);
continue;
}
if (prev != null && current == null) {
changed = true;
renderCache[dir.ordinal()] = null;
delta.set(dir.ordinal() * 3 + 0);
delta.set(dir.ordinal() * 3 + 1);
delta.set(dir.ordinal() * 3 + 2);
continue;
}
if (prev.itemID != current.itemID) {
changed = true;
renderCache[dir.ordinal()].itemID = current.itemID;
delta.set(dir.ordinal() * 3 + 0);
}
if (prev.itemMeta != current.itemMeta) {
changed = true;
renderCache[dir.ordinal()].itemMeta = current.itemMeta;
delta.set(dir.ordinal() * 3 + 1);
}
int displayQty = (prev.amount * 4 + current.amount) / 5;
if (displayQty == 0 && current.amount > 0) {
displayQty = current.amount;
}
displayQty = Math.min(getCapacity(), displayQty);
if (prev.amount != displayQty) {
changed = true;
renderCache[dir.ordinal()].amount = displayQty;
delta.set(dir.ordinal() * 3 + 2);
}
}
if (changed) {
PacketLiquidUpdate packet = new PacketLiquidUpdate(xCoord, yCoord, zCoord);
packet.renderCache = this.renderCache;
packet.delta = delta;
PacketLiquidUpdate packet = computeLiquidUpdate(false, true);
if(packet != null){
CoreProxy.proxy.sendToPlayers(packet.getPacket(), worldObj, xCoord, yCoord, zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST);
}
}
}
/**
* Computes the PacketLiquidUpdate packet for transmission to a client
* @param initPacket everything is sent, no delta stuff ( first packet )
* @param persistChange The render cache change is persisted
* @return PacketLiquidUpdate liquid update packet
*/
private PacketLiquidUpdate computeLiquidUpdate(boolean initPacket, boolean persistChange){
boolean changed = false;
BitSet delta = new BitSet(21);
if (initClient > 0) {
initClient--;
if (initClient == 1) {
changed = true;
delta.set(0, 21);
}
}
LiquidStack[] renderCache = this.renderCache.clone();
for (ForgeDirection dir : orientations) {
LiquidStack current = internalTanks[dir.ordinal()].getLiquid();
LiquidStack prev = renderCache[dir.ordinal()];
if (prev == null && current == null) {
continue;
}
if (prev == null && current != null) {
changed = true;
renderCache[dir.ordinal()] = current.copy();
delta.set(dir.ordinal() * 3 + 0);
delta.set(dir.ordinal() * 3 + 1);
delta.set(dir.ordinal() * 3 + 2);
continue;
}
if (prev != null && current == null) {
changed = true;
renderCache[dir.ordinal()] = null;
delta.set(dir.ordinal() * 3 + 0);
delta.set(dir.ordinal() * 3 + 1);
delta.set(dir.ordinal() * 3 + 2);
continue;
}
if (prev.itemID != current.itemID || initPacket) {
changed = true;
renderCache[dir.ordinal()].itemID = current.itemID;
delta.set(dir.ordinal() * 3 + 0);
}
if (prev.itemMeta != current.itemMeta || initPacket) {
changed = true;
renderCache[dir.ordinal()].itemMeta = current.itemMeta;
delta.set(dir.ordinal() * 3 + 1);
}
int displayQty = (prev.amount * 4 + current.amount) / 5;
if (displayQty == 0 && current.amount > 0 || initPacket) {
displayQty = current.amount;
}
displayQty = Math.min(getCapacity(), displayQty);
if (prev.amount != displayQty || initPacket) {
changed = true;
renderCache[dir.ordinal()].amount = displayQty;
delta.set(dir.ordinal() * 3 + 2);
}
}
if(persistChange){
this.renderCache = renderCache;
}
if (changed || initPacket) {
PacketLiquidUpdate packet = new PacketLiquidUpdate(xCoord, yCoord, zCoord, initPacket);
packet.renderCache = renderCache;
packet.delta = delta;
return packet;
}
return null;
}
/**
* Initializes client
*/
@ -273,9 +297,14 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
public void sendDescriptionPacket() {
super.sendDescriptionPacket();
PacketLiquidUpdate packet = computeLiquidUpdate(true, false);
if(packet != null){
CoreProxy.proxy.sendToPlayers(packet.getPacket(), worldObj, xCoord, yCoord, zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST);
}
initClient = 6;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);

View file

@ -23,6 +23,11 @@ public class PacketLiquidUpdate extends PacketCoordinates {
super(PacketIds.PIPE_LIQUID, xCoord, yCoord, zCoord);
}
public PacketLiquidUpdate(int xCoord, int yCoord, int zCoord, boolean chunkPacket) {
super(PacketIds.PIPE_LIQUID, xCoord, yCoord, zCoord);
this.isChunkDataPacket = chunkPacket;
}
public PacketLiquidUpdate() {
}