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:
parent
47cc3032c5
commit
1f5ee1225e
2 changed files with 13 additions and 5 deletions
|
@ -14,6 +14,7 @@ import buildcraft.core.liquids.FluidUtils;
|
||||||
import buildcraft.core.liquids.Tank;
|
import buildcraft.core.liquids.Tank;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
import buildcraft.core.utils.BlockUtil;
|
import buildcraft.core.utils.BlockUtil;
|
||||||
|
import buildcraft.core.utils.Utils;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -29,13 +30,14 @@ import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
|
||||||
public class TileFloodGate extends TileBuildCraft implements 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;
|
public static final int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 2;
|
||||||
private final TreeMap<Integer, Deque<BlockIndex>> pumpLayerQueues = new TreeMap<Integer, Deque<BlockIndex>>();
|
private final TreeMap<Integer, Deque<BlockIndex>> pumpLayerQueues = new TreeMap<Integer, Deque<BlockIndex>>();
|
||||||
private final Set<BlockIndex> visitedBlocks = new HashSet<BlockIndex>();
|
private final Set<BlockIndex> visitedBlocks = new HashSet<BlockIndex>();
|
||||||
private Deque<BlockIndex> fluidsFound = new LinkedList<BlockIndex>();
|
private Deque<BlockIndex> fluidsFound = new LinkedList<BlockIndex>();
|
||||||
private final Tank tank;
|
private final Tank tank;
|
||||||
private int rebuildDelay;
|
private int rebuildDelay;
|
||||||
|
private int tick = Utils.RANDOM.nextInt();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
REBUID_DELAY[0] = 128;
|
REBUID_DELAY[0] = 128;
|
||||||
|
@ -45,6 +47,7 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
|
||||||
REBUID_DELAY[4] = 2048;
|
REBUID_DELAY[4] = 2048;
|
||||||
REBUID_DELAY[5] = 4096;
|
REBUID_DELAY[5] = 4096;
|
||||||
REBUID_DELAY[6] = 8192;
|
REBUID_DELAY[6] = 8192;
|
||||||
|
REBUID_DELAY[7] = 16384;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileFloodGate() {
|
public TileFloodGate() {
|
||||||
|
@ -58,10 +61,11 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
|
||||||
if (CoreProxy.proxy.isRenderWorld(worldObj))
|
if (CoreProxy.proxy.isRenderWorld(worldObj))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (worldObj.getWorldTime() % 16 == 0) {
|
tick++;
|
||||||
|
if (tick % 16 == 0) {
|
||||||
FluidStack fluidtoFill = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false);
|
FluidStack fluidtoFill = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false);
|
||||||
if (fluidtoFill != null && fluidtoFill.amount == FluidContainerRegistry.BUCKET_VOLUME && fluidtoFill.getFluid() != null) {
|
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++;
|
rebuildDelay++;
|
||||||
if (rebuildDelay >= REBUID_DELAY.length)
|
if (rebuildDelay >= REBUID_DELAY.length)
|
||||||
rebuildDelay = REBUID_DELAY.length - 1;
|
rebuildDelay = REBUID_DELAY.length - 1;
|
||||||
|
@ -179,12 +183,14 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
|
||||||
public void readFromNBT(NBTTagCompound data) {
|
public void readFromNBT(NBTTagCompound data) {
|
||||||
super.readFromNBT(data);
|
super.readFromNBT(data);
|
||||||
tank.readFromNBT(data);
|
tank.readFromNBT(data);
|
||||||
|
rebuildDelay = data.getByte("rebuildDelay");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound data) {
|
public void writeToNBT(NBTTagCompound data) {
|
||||||
super.writeToNBT(data);
|
super.writeToNBT(data);
|
||||||
tank.writeToNBT(data);
|
tank.writeToNBT(data);
|
||||||
|
data.setByte("rebuildDelay", (byte) rebuildDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,6 +57,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
|
||||||
private PowerHandler powerHandler;
|
private PowerHandler powerHandler;
|
||||||
private TileBuffer[] tileBuffer = null;
|
private TileBuffer[] tileBuffer = null;
|
||||||
private SafeTimeTracker timer = new SafeTimeTracker();
|
private SafeTimeTracker timer = new SafeTimeTracker();
|
||||||
|
private int tick = Utils.RANDOM.nextInt();
|
||||||
|
|
||||||
public TilePump() {
|
public TilePump() {
|
||||||
powerHandler = new PowerHandler(this, Type.MACHINE);
|
powerHandler = new PowerHandler(this, Type.MACHINE);
|
||||||
|
@ -88,7 +89,8 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worldObj.getWorldTime() % 16 != 0)
|
tick++;
|
||||||
|
if (tick % 16 != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BlockIndex index = getNextIndexToPump(false);
|
BlockIndex index = getNextIndexToPump(false);
|
||||||
|
@ -108,7 +110,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (worldObj.getWorldTime() % 128 == 0) {
|
if (tick % 128 == 0) {
|
||||||
// TODO: improve that decision
|
// TODO: improve that decision
|
||||||
|
|
||||||
rebuildQueue();
|
rebuildQueue();
|
||||||
|
|
Loading…
Reference in a new issue