Desync Pump/FloodGate from world tick

Having all the pumps/floodgates rebuild their queues on the same tick is
probably a bad idea.
This commit is contained in:
CovertJaguar 2013-07-24 01:41:10 -07:00
parent 47cc3032c5
commit 1f5ee1225e
2 changed files with 13 additions and 5 deletions

View file

@ -14,6 +14,7 @@ import buildcraft.core.liquids.FluidUtils;
import buildcraft.core.liquids.Tank;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtil;
import buildcraft.core.utils.Utils;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
@ -29,13 +30,14 @@ import net.minecraftforge.fluids.IFluidHandler;
public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
public static final int[] REBUID_DELAY = new int[7];
public static final int[] REBUID_DELAY = new int[8];
public static final int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 2;
private final TreeMap<Integer, Deque<BlockIndex>> pumpLayerQueues = new TreeMap<Integer, Deque<BlockIndex>>();
private final Set<BlockIndex> visitedBlocks = new HashSet<BlockIndex>();
private Deque<BlockIndex> fluidsFound = new LinkedList<BlockIndex>();
private final Tank tank;
private int rebuildDelay;
private int tick = Utils.RANDOM.nextInt();
static {
REBUID_DELAY[0] = 128;
@ -45,6 +47,7 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
REBUID_DELAY[4] = 2048;
REBUID_DELAY[5] = 4096;
REBUID_DELAY[6] = 8192;
REBUID_DELAY[7] = 16384;
}
public TileFloodGate() {
@ -58,10 +61,11 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
if (CoreProxy.proxy.isRenderWorld(worldObj))
return;
if (worldObj.getWorldTime() % 16 == 0) {
tick++;
if (tick % 16 == 0) {
FluidStack fluidtoFill = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false);
if (fluidtoFill != null && fluidtoFill.amount == FluidContainerRegistry.BUCKET_VOLUME && fluidtoFill.getFluid() != null) {
if (worldObj.getWorldTime() % REBUID_DELAY[rebuildDelay] == 0) {
if (tick % REBUID_DELAY[rebuildDelay] == 0) {
rebuildDelay++;
if (rebuildDelay >= REBUID_DELAY.length)
rebuildDelay = REBUID_DELAY.length - 1;
@ -179,12 +183,14 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
tank.readFromNBT(data);
rebuildDelay = data.getByte("rebuildDelay");
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
tank.writeToNBT(data);
data.setByte("rebuildDelay", (byte) rebuildDelay);
}
@Override

View file

@ -57,6 +57,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
private PowerHandler powerHandler;
private TileBuffer[] tileBuffer = null;
private SafeTimeTracker timer = new SafeTimeTracker();
private int tick = Utils.RANDOM.nextInt();
public TilePump() {
powerHandler = new PowerHandler(this, Type.MACHINE);
@ -88,7 +89,8 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
return;
}
if (worldObj.getWorldTime() % 16 != 0)
tick++;
if (tick % 16 != 0)
return;
BlockIndex index = getNextIndexToPump(false);
@ -108,7 +110,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
}
}
} else {
if (worldObj.getWorldTime() % 128 == 0) {
if (tick % 128 == 0) {
// TODO: improve that decision
rebuildQueue();