Revert STT changes
They were broken if you have more than one world.
This commit is contained in:
parent
358b58321a
commit
a53a724b41
14 changed files with 103 additions and 105 deletions
|
@ -26,7 +26,6 @@ import buildcraft.core.ItemSpring;
|
|||
import buildcraft.core.ItemWrench;
|
||||
import buildcraft.core.SpringPopulate;
|
||||
import buildcraft.core.TickHandlerCoreClient;
|
||||
import buildcraft.core.TickHandlerTimeTracker;
|
||||
import buildcraft.core.Version;
|
||||
import buildcraft.core.blueprints.BptItem;
|
||||
import buildcraft.core.network.EntityIds;
|
||||
|
@ -300,8 +299,7 @@ public class BuildCraftCore {
|
|||
BuildCraftAPI.softBlocks[Block.vine.blockID] = true;
|
||||
BuildCraftAPI.softBlocks[Block.fire.blockID] = true;
|
||||
TickRegistry.registerTickHandler(new TickHandlerCoreClient(), Side.CLIENT);
|
||||
TickRegistry.registerTickHandler(new TickHandlerTimeTracker(), Side.CLIENT);
|
||||
TickRegistry.registerTickHandler(new TickHandlerTimeTracker(), Side.SERVER);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -7,27 +7,32 @@
|
|||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SafeTimeTracker {
|
||||
|
||||
public static long worldTime;
|
||||
private long lastMark = worldTime;
|
||||
private long lastMark = Long.MIN_VALUE;
|
||||
private long duration = -1;
|
||||
|
||||
/**
|
||||
* Return true if a given delay has passed since last time marked was called
|
||||
* successfully.
|
||||
*/
|
||||
public boolean markTimeIfDelay(long delay) {
|
||||
long timePassed = worldTime - lastMark;
|
||||
if (timePassed >= delay) {
|
||||
duration = timePassed;
|
||||
lastMark = worldTime;
|
||||
return true;
|
||||
}
|
||||
if (worldTime < lastMark) {
|
||||
lastMark = worldTime;
|
||||
public boolean markTimeIfDelay(World world, long delay) {
|
||||
if (world == null)
|
||||
return false;
|
||||
|
||||
long currentTime = world.getWorldTime();
|
||||
|
||||
if (currentTime < lastMark) {
|
||||
lastMark = currentTime;
|
||||
return false;
|
||||
} else if (lastMark + delay <= currentTime) {
|
||||
duration = currentTime - lastMark;
|
||||
lastMark = currentTime;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,7 +40,7 @@ public class SafeTimeTracker {
|
|||
return duration > 0 ? duration : 0;
|
||||
}
|
||||
|
||||
public void markTime() {
|
||||
lastMark = worldTime;
|
||||
public void markTime(World world) {
|
||||
lastMark = world.getWorldTime();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public final class PowerHandler {
|
|||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public final class PowerHandler {
|
|||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,9 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
public PerditionCalculator(float powerLoss) {
|
||||
if (powerLoss < MIN_POWERLOSS)
|
||||
if (powerLoss < MIN_POWERLOSS) {
|
||||
powerLoss = MIN_POWERLOSS;
|
||||
}
|
||||
this.powerLoss = powerLoss;
|
||||
}
|
||||
|
||||
|
@ -66,8 +67,9 @@ public final class PowerHandler {
|
|||
*/
|
||||
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) {
|
||||
current -= powerLoss * ticksPassed;
|
||||
if (current < 0)
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
@ -136,8 +138,9 @@ public final class PowerHandler {
|
|||
* being common.
|
||||
*/
|
||||
public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy) {
|
||||
if (minEnergyReceived > maxEnergyReceived)
|
||||
if (minEnergyReceived > maxEnergyReceived) {
|
||||
maxEnergyReceived = minEnergyReceived;
|
||||
}
|
||||
this.minEnergyReceived = minEnergyReceived;
|
||||
this.maxEnergyReceived = maxEnergyReceived;
|
||||
this.maxEnergyStored = maxStoredEnergy;
|
||||
|
@ -168,6 +171,8 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
public PerditionCalculator getPerdition() {
|
||||
if (perdition == null)
|
||||
return DEFAULT_PERDITION;
|
||||
return perdition;
|
||||
}
|
||||
|
||||
|
@ -187,8 +192,8 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
private void applyPerdition() {
|
||||
if (perditionTracker.markTimeIfDelay(1) && energyStored > 0) {
|
||||
float newEnergy = perdition.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
|
||||
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (newEnergy == 0 || newEnergy < energyStored)
|
||||
energyStored = newEnergy;
|
||||
else
|
||||
|
@ -198,18 +203,22 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
private void applyWork() {
|
||||
if (energyStored >= activationEnergy)
|
||||
if (doWorkTracker.markTimeIfDelay(1))
|
||||
if (energyStored >= activationEnergy) {
|
||||
if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
|
||||
receptor.doWork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSources(ForgeDirection source) {
|
||||
if (sourcesTracker.markTimeIfDelay(1))
|
||||
if (sourcesTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
powerSources[i] -= sourcesTracker.durationOfLastDelay();
|
||||
if (powerSources[i] < 0)
|
||||
if (powerSources[i] < 0) {
|
||||
powerSources[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null)
|
||||
powerSources[source.ordinal()] = 10;
|
||||
|
@ -229,16 +238,19 @@ public final class PowerHandler {
|
|||
|
||||
float result = 0;
|
||||
|
||||
if (energyStored >= min)
|
||||
if (energyStored >= min) {
|
||||
if (energyStored <= max) {
|
||||
result = energyStored;
|
||||
if (doUse)
|
||||
if (doUse) {
|
||||
energyStored = 0;
|
||||
}
|
||||
} else {
|
||||
result = max;
|
||||
if (doUse)
|
||||
if (doUse) {
|
||||
energyStored -= max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateEnergy();
|
||||
|
||||
|
@ -315,11 +327,13 @@ public final class PowerHandler {
|
|||
*/
|
||||
public float receiveEnergy(Type source, final float quantity, ForgeDirection from) {
|
||||
float used = quantity;
|
||||
if (source == Type.ENGINE)
|
||||
if (used < minEnergyReceived)
|
||||
if (source == Type.ENGINE) {
|
||||
if (used < minEnergyReceived) {
|
||||
return 0;
|
||||
else if (used > maxEnergyReceived)
|
||||
} else if (used > maxEnergyReceived) {
|
||||
used = maxEnergyReceived;
|
||||
}
|
||||
}
|
||||
|
||||
updateSources(from);
|
||||
|
||||
|
@ -327,8 +341,9 @@ public final class PowerHandler {
|
|||
|
||||
applyWork();
|
||||
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess())
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess()) {
|
||||
return Math.min(quantity, maxEnergyReceived);
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
|
@ -364,9 +379,11 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
private void validateEnergy() {
|
||||
if (energyStored < 0)
|
||||
if (energyStored < 0) {
|
||||
energyStored = 0;
|
||||
if (energyStored > maxEnergyStored)
|
||||
}
|
||||
if (energyStored > maxEnergyStored) {
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package buildcraft.core;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import java.util.EnumSet;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TickHandlerTimeTracker implements ITickHandler {
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {
|
||||
SafeTimeTracker.worldTime = ((World) tickData[0]).getWorldTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks() {
|
||||
return EnumSet.of(TickType.WORLD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "BuildCraft - World update tick";
|
||||
}
|
||||
}
|
|
@ -35,26 +35,28 @@ public final class TileBuffer {
|
|||
public final void refresh() {
|
||||
tile = null;
|
||||
blockID = 0;
|
||||
if (!loadUnloaded && !world.blockExists(x, y, z))
|
||||
if (!loadUnloaded && !world.blockExists(x, y, z)) {
|
||||
return;
|
||||
}
|
||||
blockID = world.getBlockId(this.x, this.y, this.z);
|
||||
|
||||
Block block = Block.blocksList[blockID];
|
||||
if (block != null && block.hasTileEntity(world.getBlockMetadata(this.x, this.y, this.z)))
|
||||
if (block != null && block.hasTileEntity(world.getBlockMetadata(this.x, this.y, this.z))) {
|
||||
tile = world.getBlockTileEntity(this.x, this.y, this.z);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int blockID, TileEntity tile) {
|
||||
this.blockID = blockID;
|
||||
this.tile = tile;
|
||||
tracker.markTime();
|
||||
tracker.markTime(world);
|
||||
}
|
||||
|
||||
public int getBlockID() {
|
||||
if (tile != null && !tile.isInvalid())
|
||||
return blockID;
|
||||
|
||||
if (tracker.markTimeIfDelay(20)) {
|
||||
if (tracker.markTimeIfDelay(world, 20)) {
|
||||
refresh();
|
||||
|
||||
if (tile != null && !tile.isInvalid())
|
||||
|
@ -68,7 +70,7 @@ public final class TileBuffer {
|
|||
if (tile != null && !tile.isInvalid())
|
||||
return tile;
|
||||
|
||||
if (tracker.markTimeIfDelay(20)) {
|
||||
if (tracker.markTimeIfDelay(world, 20)) {
|
||||
refresh();
|
||||
|
||||
if (tile != null && !tile.isInvalid())
|
||||
|
|
|
@ -24,7 +24,7 @@ public class TilePollution extends TileEntity {
|
|||
public void updateEntity() {
|
||||
if (!init) {
|
||||
init = true;
|
||||
timeTracker.markTime();
|
||||
timeTracker.markTime(worldObj);
|
||||
BlockIndex index = new BlockIndex(xCoord, yCoord, zCoord);
|
||||
|
||||
if (BuildCraftEnergy.saturationStored.containsKey(index)) {
|
||||
|
@ -33,7 +33,7 @@ public class TilePollution extends TileEntity {
|
|||
saturation = 1;
|
||||
}
|
||||
} else {
|
||||
if (timeTracker.markTimeIfDelay(20)) {
|
||||
if (timeTracker.markTimeIfDelay(worldObj, 20)) {
|
||||
// int remaining = BuildCraftEnergy.createPollution(worldObj,
|
||||
// xCoord, yCoord, zCoord, saturation);
|
||||
//
|
||||
|
|
|
@ -184,7 +184,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
|
|||
|
||||
private BlockIndex getNextIndexToPump(boolean remove) {
|
||||
if (pumpLayerQueues.isEmpty()) {
|
||||
if (timer.markTimeIfDelay(REBUID_DELAY)) {
|
||||
if (timer.markTimeIfDelay(worldObj, REBUID_DELAY)) {
|
||||
rebuildQueue();
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -125,7 +125,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
simpleAnimationIterate();
|
||||
return;
|
||||
|
||||
} else if (CoreProxy.proxy.isSimulating(worldObj) && updateNetworkTime.markTimeIfDelay(2 * BuildCraftCore.updateFactor)) {
|
||||
} else if (CoreProxy.proxy.isSimulating(worldObj) && updateNetworkTime.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
decreaseAnimation();
|
||||
}
|
||||
|
||||
if (!time.markTimeIfDelay(currentRecipe.delay))
|
||||
if (!time.markTimeIfDelay(worldObj, currentRecipe.delay))
|
||||
return;
|
||||
|
||||
float energyUsed = powerHandler.useEnergy(currentRecipe.energy, currentRecipe.energy, true);
|
||||
|
@ -350,7 +350,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
}
|
||||
|
||||
if (doFill && used > 0) {
|
||||
updateNetworkTime.markTime();
|
||||
updateNetworkTime.markTime(worldObj);
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
moveFluidBelow();
|
||||
}
|
||||
|
||||
if (hasUpdate && tracker.markTimeIfDelay(2 * BuildCraftCore.updateFactor)) {
|
||||
if (hasUpdate && tracker.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
sendNetworkUpdate();
|
||||
hasUpdate = false;
|
||||
}
|
||||
|
|
|
@ -51,31 +51,28 @@ public class BlockLaser extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int meta) {
|
||||
public TileEntity createNewTileEntity(World world) {
|
||||
return new TileLaser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(int side, int meta) {
|
||||
if (side == ForgeDirection.getOrientation(meta).getOpposite().ordinal())
|
||||
public Icon getIcon(int i, int j) {
|
||||
if (i == ForgeDirection.values()[j].getOpposite().ordinal())
|
||||
return textureBottom;
|
||||
else if (side == meta)
|
||||
else if (i == j)
|
||||
return textureTop;
|
||||
else
|
||||
return textureSide;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onBlockPlaced(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
|
||||
super.onBlockPlaced(world, x, y, z, side, par6, par7, par8, meta);
|
||||
|
||||
if (side <= 6)
|
||||
if (side <= 6) {
|
||||
meta = side;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
|
|
@ -71,8 +71,9 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
// Check for available tables if none is linked to this laser.
|
||||
if (!isValidTable())
|
||||
if (canFindTable())
|
||||
if (canFindTable()) {
|
||||
findTable();
|
||||
}
|
||||
|
||||
// If we still don't have a valid table or the existing has
|
||||
// become invalid, we disable the laser and do nothing.
|
||||
|
@ -83,20 +84,23 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
// We have a table and can work, so we create a laser if
|
||||
// necessary.
|
||||
if (laser == null)
|
||||
if (laser == null) {
|
||||
createLaser();
|
||||
}
|
||||
|
||||
// We have a laser and may update it
|
||||
if (laser != null && canUpdateLaser())
|
||||
if (laser != null && canUpdateLaser()) {
|
||||
updateLaser();
|
||||
}
|
||||
|
||||
// Consume power and transfer it to the table.
|
||||
float power = powerHandler.useEnergy(0, getMaxPowerSent(), true);
|
||||
laserTarget.receiveLaserEnergy(power);
|
||||
|
||||
if (laser != null)
|
||||
if (laser != null) {
|
||||
laser.pushPower(power);
|
||||
|
||||
}
|
||||
|
||||
onPowerSent(power);
|
||||
|
||||
sendNetworkUpdate();
|
||||
|
@ -108,13 +112,13 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
protected void onPowerSent(float power) {
|
||||
}
|
||||
|
||||
|
||||
protected boolean canFindTable() {
|
||||
return searchTracker.markTimeIfDelay(nextLaserSearch);
|
||||
return searchTracker.markTimeIfDelay(worldObj, nextLaserSearch);
|
||||
}
|
||||
|
||||
protected boolean canUpdateLaser() {
|
||||
return laserTickTracker.markTimeIfDelay(nextLaserUpdate);
|
||||
return laserTickTracker.markTimeIfDelay(worldObj, nextLaserUpdate);
|
||||
}
|
||||
|
||||
protected boolean isValidTable() {
|
||||
|
@ -167,8 +171,9 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
if (tile instanceof ILaserTarget) {
|
||||
|
||||
ILaserTarget table = (ILaserTarget) tile;
|
||||
if (table.hasCurrentWork())
|
||||
if (table.hasCurrentWork()) {
|
||||
targets.add(new BlockIndex(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -222,8 +227,9 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
laser.setPositions(head, tail);
|
||||
|
||||
if (!laser.isVisible())
|
||||
if (!laser.isVisible()) {
|
||||
laser.show();
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeLaser() {
|
||||
|
@ -245,8 +251,9 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
if (networkTracker.markTimeIfDelay(nextNetworkUpdate))
|
||||
if (networkTracker.markTimeIfDelay(worldObj, nextNetworkUpdate)) {
|
||||
super.sendNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -292,9 +299,10 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
@Override
|
||||
public void actionActivated(IAction action) {
|
||||
if (action == BuildCraftCore.actionOn)
|
||||
if (action == BuildCraftCore.actionOn) {
|
||||
lastMode = ActionMachineControl.Mode.On;
|
||||
else if (action == BuildCraftCore.actionOff)
|
||||
} else if (action == BuildCraftCore.actionOff) {
|
||||
lastMode = ActionMachineControl.Mode.Off;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
|||
if (container.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
if (actionTracker.markTimeIfDelay(10)) {
|
||||
if (actionTracker.markTimeIfDelay(container.worldObj, 10)) {
|
||||
resolveActions();
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
|
||||
moveFluids();
|
||||
|
||||
if (tracker.markTimeIfDelay(BuildCraftCore.updateFactor)) {
|
||||
if (tracker.markTimeIfDelay(container.worldObj, BuildCraftCore.updateFactor)) {
|
||||
|
||||
boolean init = false;
|
||||
if (++clientSyncCounter > BuildCraftCore.longUpdateFactor) {
|
||||
|
|
|
@ -245,7 +245,7 @@ public class PipeTransportPower extends PipeTransport {
|
|||
}
|
||||
}
|
||||
|
||||
if (tracker.markTimeIfDelay(2 * BuildCraftCore.updateFactor)) {
|
||||
if (tracker.markTimeIfDelay(container.worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
PacketPowerUpdate packet = new PacketPowerUpdate(container.xCoord, container.yCoord, container.zCoord);
|
||||
|
||||
double displayFactor = MAX_DISPLAY / 1024.0;
|
||||
|
|
Loading…
Reference in a new issue