From 7f6b2e72d167f1b8f96b7f2a1de2921339585ec7 Mon Sep 17 00:00:00 2001 From: Adrian Date: Sun, 14 Jun 2015 11:30:34 +0200 Subject: [PATCH] try to fix fluid sync again, add support for large fluid pipe capacity, improve water spring gen --- common/buildcraft/core/SpringPopulate.java | 9 ++---- .../core/lib/engines/TileEngineBase.java | 1 - .../transport/PipeTransportFluids.java | 30 +++++++---------- .../transport/network/PacketFluidUpdate.java | 32 ++++++++++++------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/common/buildcraft/core/SpringPopulate.java b/common/buildcraft/core/SpringPopulate.java index 4d22de53..3d7c4c01 100644 --- a/common/buildcraft/core/SpringPopulate.java +++ b/common/buildcraft/core/SpringPopulate.java @@ -41,9 +41,9 @@ public class SpringPopulate { private void doPopulate(World world, Random random, int x, int z) { // A spring will be generated every 40th chunk. - if (random.nextFloat() > 0.025f) { + /* if (random.nextFloat() > 0.025f) { return; - } + } */ // Do not generate water in the End or the Nether BiomeGenBase biomegenbase = world.getWorldChunkManager().getBiomeGenAt(x, z); @@ -64,13 +64,10 @@ public class SpringPopulate { // Handle flat bedrock maps int y = i > 0 ? i : i - 1; - int toGround = 50 - random.nextInt(25); - world.setBlock(posX, y + 1, posZ, BuildCraftCore.springBlock); - for (int j = y + 2; j < toGround; j++) { + for (int j = y + 2; j < world.getActualHeight(); j++) { if (world.isAirBlock(posX, j, posZ)) { - world.setBlock(posX, j, posZ, Blocks.water); break; } else { world.setBlock(posX, j, posZ, Blocks.water); diff --git a/common/buildcraft/core/lib/engines/TileEngineBase.java b/common/buildcraft/core/lib/engines/TileEngineBase.java index ecc4019e..6c496ef0 100644 --- a/common/buildcraft/core/lib/engines/TileEngineBase.java +++ b/common/buildcraft/core/lib/engines/TileEngineBase.java @@ -14,7 +14,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; diff --git a/common/buildcraft/transport/PipeTransportFluids.java b/common/buildcraft/transport/PipeTransportFluids.java index 1c35aa32..d0aa7c9d 100644 --- a/common/buildcraft/transport/PipeTransportFluids.java +++ b/common/buildcraft/transport/PipeTransportFluids.java @@ -51,7 +51,6 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler public static short OUTPUT_COOLDOWN = 30; // 30 private static int NETWORK_SYNC_TICKS = BuildCraftCore.updateFactor / 2; - private static byte CLIENT_INIT_DELAY = (byte) 12; private static final ForgeDirection[] directions = ForgeDirection.VALID_DIRECTIONS; private static final ForgeDirection[] orientations = ForgeDirection.values(); @@ -119,7 +118,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler } public int getMaxFillRate() { - return Math.min(capacity - amount, flowRate - incoming[currentTime]); + return Math.min(getCapacity() - amount, flowRate - incoming[currentTime]); } public void readFromNBT(NBTTagCompound compoundTag) { @@ -151,7 +150,6 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler private final short[] outputTTL = new short[]{OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL, OUTPUT_TTL}; private final short[] outputCooldown = new short[]{0, 0, 0, 0, 0, 0}; private final boolean[] canReceiveCache = new boolean[6]; - private byte initClient = 0; private int clientSyncCounter = 0; private int capacity, flowRate; private int travelDelay = MAX_TRAVEL_DELAY; @@ -168,6 +166,10 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler sections[6] = new PipeSection(); } + /** + * This value has to be the same on client and server! + * @return + */ public int getCapacity() { return capacity; } @@ -230,7 +232,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler if (networkSyncTracker.markTimeIfDelay(container.getWorldObj())) { boolean init = false; - if (++clientSyncCounter > BuildCraftCore.longUpdateFactor) { + if (++clientSyncCounter > BuildCraftCore.longUpdateFactor * 2) { clientSyncCounter = 0; init = true; } @@ -330,7 +332,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler private void moveToCenter() { int transferInCount = 0; - int spaceAvailable = capacity - sections[6].amount; + int spaceAvailable = getCapacity() - sections[6].amount; for (ForgeDirection dir : directions) { inputPerTick[dir.ordinal()] = 0; @@ -410,18 +412,9 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler boolean changed = false; BitSet delta = new BitSet(8); - if (initClient > 0) { - initClient--; - if (initClient <= 1) { - changed = true; - initClient = 0; - delta.set(0, 8); - } - } - FluidRenderData renderCacheCopy = this.renderCache; - if ((fluidType == null && renderCacheCopy.fluidID != 0) + if (initPacket || (fluidType == null && renderCacheCopy.fluidID != 0) || (fluidType != null && renderCacheCopy.fluidID != fluidType.getFluid().getID())) { changed = true; renderCache.fluidID = fluidType != null ? fluidType.getFluid().getID() : 0; @@ -436,7 +429,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler if (displayQty == 0 && camount > 0 || initPacket) { displayQty = camount; } - displayQty = Math.min(capacity, displayQty); + displayQty = Math.min(getCapacity(), displayQty); if (pamount != displayQty || initPacket) { changed = true; @@ -450,7 +443,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler } 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, getCapacity() > 255); packet.renderCache = renderCacheCopy; packet.delta = delta; return packet; @@ -470,7 +463,8 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler public void sendDescriptionPacket() { super.sendDescriptionPacket(); - initClient = CLIENT_INIT_DELAY; + PacketFluidUpdate update = computeFluidUpdate(true, true); + BuildCraftTransport.instance.sendToPlayers(update, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST); } public FluidStack getStack(ForgeDirection direction) { diff --git a/common/buildcraft/transport/network/PacketFluidUpdate.java b/common/buildcraft/transport/network/PacketFluidUpdate.java index 5d86ac64..4feccdc0 100644 --- a/common/buildcraft/transport/network/PacketFluidUpdate.java +++ b/common/buildcraft/transport/network/PacketFluidUpdate.java @@ -16,25 +16,28 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.transport.IPipeTile; import buildcraft.core.lib.network.PacketCoordinates; import buildcraft.core.lib.utils.BitSetUtils; import buildcraft.core.network.PacketIds; import buildcraft.core.proxy.CoreProxy; +import buildcraft.transport.Pipe; import buildcraft.transport.PipeTransportFluids; -import buildcraft.transport.TileGenericPipe; import buildcraft.transport.utils.FluidRenderData; public class PacketFluidUpdate extends PacketCoordinates { public FluidRenderData renderCache = new FluidRenderData(); public BitSet delta; + private boolean largeFluidCapacity; public PacketFluidUpdate(int xCoord, int yCoord, int zCoord) { super(PacketIds.PIPE_LIQUID, xCoord, yCoord, zCoord); } - public PacketFluidUpdate(int xCoord, int yCoord, int zCoord, boolean chunkPacket) { + public PacketFluidUpdate(int xCoord, int yCoord, int zCoord, boolean chunkPacket, boolean largeFluidCapacity) { super(PacketIds.PIPE_LIQUID, xCoord, yCoord, zCoord); this.isChunkDataPacket = chunkPacket; + this.largeFluidCapacity = largeFluidCapacity; } public PacketFluidUpdate() { @@ -50,29 +53,30 @@ public class PacketFluidUpdate extends PacketCoordinates { } TileEntity entity = world.getTileEntity(posX, posY, posZ); - if (!(entity instanceof TileGenericPipe)) { + if (!(entity instanceof IPipeTile)) { return; } - TileGenericPipe pipe = (TileGenericPipe) entity; - if (pipe.pipe == null) { + IPipeTile pipeTile = (IPipeTile) entity; + if (!(pipeTile.getPipe() instanceof Pipe)) { return; } - if (!(pipe.pipe.transport instanceof PipeTransportFluids)) { + Pipe pipe = (Pipe) pipeTile.getPipe(); + + if (!(pipe.transport instanceof PipeTransportFluids)) { return; } - PipeTransportFluids transLiq = (PipeTransportFluids) pipe.pipe.transport; + PipeTransportFluids transLiq = (PipeTransportFluids) pipe.transport; + this.largeFluidCapacity = transLiq.getCapacity() > 255; renderCache = transLiq.renderCache; byte[] dBytes = new byte[1]; data.readBytes(dBytes); delta = BitSetUtils.fromByteArray(dBytes); - // System.out.printf("read %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta); - if (delta.get(0)) { renderCache.fluidID = data.readShort(); renderCache.color = renderCache.fluidID != 0 ? data.readInt() : 0xFFFFFF; @@ -80,7 +84,8 @@ public class PacketFluidUpdate extends PacketCoordinates { for (ForgeDirection dir : ForgeDirection.values()) { if (delta.get(dir.ordinal() + 1)) { - renderCache.amount[dir.ordinal()] = Math.min(transLiq.getCapacity(), data.readUnsignedByte()); + renderCache.amount[dir.ordinal()] = Math.min(transLiq.getCapacity(), + largeFluidCapacity ? data.readUnsignedShort() : data.readUnsignedByte()); } } } @@ -90,7 +95,6 @@ public class PacketFluidUpdate extends PacketCoordinates { super.writeData(data); byte[] dBytes = BitSetUtils.toByteArray(delta, 1); - // System.out.printf("write %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta); data.writeBytes(dBytes); if (delta.get(0)) { @@ -102,7 +106,11 @@ public class PacketFluidUpdate extends PacketCoordinates { for (ForgeDirection dir : ForgeDirection.values()) { if (delta.get(dir.ordinal() + 1)) { - data.writeByte(renderCache.amount[dir.ordinal()]); + if (largeFluidCapacity) { + data.writeShort(renderCache.amount[dir.ordinal()]); + } else { + data.writeByte(renderCache.amount[dir.ordinal()]); + } } } }