try to fix fluid sync again, add support for large fluid pipe capacity, improve water spring gen

This commit is contained in:
Adrian 2015-06-14 11:30:34 +02:00
parent d5422d5cca
commit 7f6b2e72d1
4 changed files with 35 additions and 37 deletions

View file

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

View file

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

View file

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

View file

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