Some performance improvements related to STT
This commit is contained in:
parent
91a84f2062
commit
fc3e3d19cb
16 changed files with 161 additions and 135 deletions
|
@ -26,6 +26,7 @@ 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;
|
||||
|
@ -299,7 +300,8 @@ 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
|
||||
|
|
|
@ -22,6 +22,7 @@ import buildcraft.silicon.SiliconProxy;
|
|||
import buildcraft.silicon.TileAdvancedCraftingTable;
|
||||
import buildcraft.silicon.TileAssemblyTable;
|
||||
import buildcraft.silicon.TileLaser;
|
||||
import buildcraft.silicon.TileLaserStandard;
|
||||
import buildcraft.silicon.network.PacketHandlerSilicon;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
|
@ -74,7 +75,7 @@ public class BuildCraftSilicon {
|
|||
@EventHandler
|
||||
public void init(FMLInitializationEvent evt) {
|
||||
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler());
|
||||
CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser");
|
||||
CoreProxy.proxy.registerTileEntity(TileLaserStandard.class, "net.minecraft.src.buildcraft.factory.TileLaser");
|
||||
CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyTable");
|
||||
CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench");
|
||||
|
||||
|
|
|
@ -1,49 +1,41 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SafeTimeTracker {
|
||||
|
||||
private long lastMark = Long.MIN_VALUE;
|
||||
private long duration = 0;
|
||||
private boolean marked;
|
||||
|
||||
public static long worldTime;
|
||||
private long lastMark = worldTime;
|
||||
private long duration = -1;
|
||||
/**
|
||||
* Return true if a given delay has passed since last time marked was called successfully.
|
||||
* Return true if a given delay has passed since last time marked was called
|
||||
* successfully.
|
||||
*/
|
||||
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 = world.getWorldTime();
|
||||
marked = true;
|
||||
public boolean markTimeIfDelay(long delay) {
|
||||
long timePassed = worldTime - lastMark;
|
||||
if (timePassed >= delay) {
|
||||
duration = timePassed;
|
||||
lastMark = worldTime;
|
||||
return true;
|
||||
} else
|
||||
}
|
||||
if (worldTime < lastMark) {
|
||||
lastMark = worldTime;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public long durationOfLastDelay(){
|
||||
return marked ? duration : 0;
|
||||
|
||||
public long durationOfLastDelay() {
|
||||
return duration > 0 ? duration : 0;
|
||||
}
|
||||
|
||||
public void markTime(World world) {
|
||||
lastMark = world.getWorldTime();
|
||||
public void markTime() {
|
||||
lastMark = worldTime;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,9 +49,8 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
public PerditionCalculator(float powerLoss) {
|
||||
if (powerLoss < MIN_POWERLOSS) {
|
||||
if (powerLoss < MIN_POWERLOSS)
|
||||
powerLoss = MIN_POWERLOSS;
|
||||
}
|
||||
this.powerLoss = powerLoss;
|
||||
}
|
||||
|
||||
|
@ -67,9 +66,8 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -137,9 +135,8 @@ 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;
|
||||
|
@ -164,12 +161,12 @@ public final class PowerHandler {
|
|||
* @param perdition
|
||||
*/
|
||||
public void setPerdition(PerditionCalculator perdition) {
|
||||
if (perdition == null)
|
||||
perdition = DEFUALT_PERDITION;
|
||||
this.perdition = perdition;
|
||||
}
|
||||
|
||||
public PerditionCalculator getPerdition() {
|
||||
if (perdition == null)
|
||||
return DEFUALT_PERDITION;
|
||||
return perdition;
|
||||
}
|
||||
|
||||
|
@ -189,34 +186,29 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
private void applyPerdition() {
|
||||
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
|
||||
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (newEnergy == 0 || newEnergy < energyStored) {
|
||||
if (perditionTracker.markTimeIfDelay(1) && energyStored > 0) {
|
||||
float newEnergy = perdition.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (newEnergy == 0 || newEnergy < energyStored)
|
||||
energyStored = newEnergy;
|
||||
} else {
|
||||
else
|
||||
energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
}
|
||||
validateEnergy();
|
||||
}
|
||||
}
|
||||
|
||||
private void applyWork() {
|
||||
if (energyStored >= activationEnergy) {
|
||||
if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
|
||||
if (energyStored >= activationEnergy)
|
||||
if (doWorkTracker.markTimeIfDelay(1))
|
||||
receptor.doWork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSources(ForgeDirection source) {
|
||||
if (sourcesTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
|
||||
if (sourcesTracker.markTimeIfDelay(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;
|
||||
|
@ -236,19 +228,16 @@ 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();
|
||||
|
||||
|
@ -325,13 +314,11 @@ 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);
|
||||
|
||||
|
@ -339,9 +326,8 @@ public final class PowerHandler {
|
|||
|
||||
applyWork();
|
||||
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess()) {
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess())
|
||||
return Math.min(quantity, maxEnergyReceived);
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
|
@ -377,11 +363,9 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
private void validateEnergy() {
|
||||
if (energyStored < 0) {
|
||||
if (energyStored < 0)
|
||||
energyStored = 0;
|
||||
}
|
||||
if (energyStored > maxEnergyStored) {
|
||||
if (energyStored > maxEnergyStored)
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
29
common/buildcraft/core/TickHandlerTimeTracker.java
Normal file
29
common/buildcraft/core/TickHandlerTimeTracker.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
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,28 +35,26 @@ 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(world);
|
||||
tracker.markTime();
|
||||
}
|
||||
|
||||
public int getBlockID() {
|
||||
if (tile != null && !tile.isInvalid())
|
||||
return blockID;
|
||||
|
||||
if (tracker.markTimeIfDelay(world, 20)) {
|
||||
if (tracker.markTimeIfDelay(20)) {
|
||||
refresh();
|
||||
|
||||
if (tile != null && !tile.isInvalid())
|
||||
|
@ -70,7 +68,7 @@ public final class TileBuffer {
|
|||
if (tile != null && !tile.isInvalid())
|
||||
return tile;
|
||||
|
||||
if (tracker.markTimeIfDelay(world, 20)) {
|
||||
if (tracker.markTimeIfDelay(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(worldObj);
|
||||
timeTracker.markTime();
|
||||
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(worldObj, 20)) {
|
||||
if (timeTracker.markTimeIfDelay(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(worldObj, REBUID_DELAY)) {
|
||||
if (timer.markTimeIfDelay(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(worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
} else if (CoreProxy.proxy.isSimulating(worldObj) && updateNetworkTime.markTimeIfDelay(2 * BuildCraftCore.updateFactor)) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
decreaseAnimation();
|
||||
}
|
||||
|
||||
if (!time.markTimeIfDelay(worldObj, currentRecipe.delay))
|
||||
if (!time.markTimeIfDelay(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(worldObj);
|
||||
updateNetworkTime.markTime();
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
moveFluidBelow();
|
||||
}
|
||||
|
||||
if (hasUpdate && tracker.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
if (hasUpdate && tracker.markTimeIfDelay(2 * BuildCraftCore.updateFactor)) {
|
||||
sendNetworkUpdate();
|
||||
hasUpdate = false;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.silicon;
|
||||
|
||||
import buildcraft.core.CreativeTabBuildCraft;
|
||||
|
@ -24,8 +22,8 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
|
||||
public class BlockLaser extends BlockContainer {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private Icon textureTop, textureBottom, textureSide;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private Icon textureTop, textureBottom, textureSide;
|
||||
|
||||
public BlockLaser(int i) {
|
||||
super(i, Material.iron);
|
||||
|
@ -53,33 +51,36 @@ public class BlockLaser extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1) {
|
||||
return new TileLaser();
|
||||
public TileEntity createTileEntity(World world, int meta) {
|
||||
return new TileLaserStandard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(int i, int j) {
|
||||
if (i == ForgeDirection.values()[j].getOpposite().ordinal())
|
||||
public TileEntity createNewTileEntity(World world) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(int side, int meta) {
|
||||
if (side == ForgeDirection.getOrientation(meta).getOpposite().ordinal())
|
||||
return textureBottom;
|
||||
else if (i == j)
|
||||
else if (side == meta)
|
||||
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;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void addCreativeItems(ArrayList itemList) {
|
||||
itemList.add(new ItemStack(this));
|
||||
|
@ -87,10 +88,9 @@ public class BlockLaser extends BlockContainer {
|
|||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IconRegister par1IconRegister)
|
||||
{
|
||||
textureTop = par1IconRegister.registerIcon("buildcraft:laser_top");
|
||||
textureBottom = par1IconRegister.registerIcon("buildcraft:laser_bottom");
|
||||
textureSide = par1IconRegister.registerIcon("buildcraft:laser_side");
|
||||
public void registerIcons(IconRegister par1IconRegister) {
|
||||
textureTop = par1IconRegister.registerIcon("buildcraft:laser_top");
|
||||
textureBottom = par1IconRegister.registerIcon("buildcraft:laser_bottom");
|
||||
textureSide = par1IconRegister.registerIcon("buildcraft:laser_side");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileLaser extends TileBuildCraft implements IPowerReceptor, IActionReceptor, IMachine {
|
||||
public abstract class TileLaser extends TileBuildCraft implements IPowerReceptor, IActionReceptor, IMachine {
|
||||
|
||||
private EntityEnergyLaser laser = null;
|
||||
private final SafeTimeTracker laserTickTracker = new SafeTimeTracker();
|
||||
private final SafeTimeTracker searchTracker = new SafeTimeTracker();
|
||||
private final SafeTimeTracker networkTracker = new SafeTimeTracker();
|
||||
private ILaserTarget laserTarget;
|
||||
private PowerHandler powerHandler;
|
||||
protected PowerHandler powerHandler;
|
||||
private int nextNetworkUpdate = 3;
|
||||
private int nextLaserUpdate = 10;
|
||||
private int nextLaserSearch = 100;
|
||||
|
@ -71,9 +71,8 @@ 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.
|
||||
|
@ -84,32 +83,36 @@ 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, 4, true);
|
||||
float power = powerHandler.useEnergy(0, getMaxPowerSent(), true);
|
||||
laserTarget.receiveLaserEnergy(power);
|
||||
|
||||
if (laser != null) {
|
||||
if (laser != null)
|
||||
laser.pushPower(power);
|
||||
}
|
||||
|
||||
onPowerSent(power);
|
||||
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
protected abstract float getMaxPowerSent();
|
||||
|
||||
protected void onPowerSent(float power) {
|
||||
}
|
||||
|
||||
protected boolean canFindTable() {
|
||||
return searchTracker.markTimeIfDelay(worldObj, nextLaserSearch);
|
||||
return searchTracker.markTimeIfDelay(nextLaserSearch);
|
||||
}
|
||||
|
||||
protected boolean canUpdateLaser() {
|
||||
return laserTickTracker.markTimeIfDelay(worldObj, nextLaserUpdate);
|
||||
return laserTickTracker.markTimeIfDelay(nextLaserUpdate);
|
||||
}
|
||||
|
||||
protected boolean isValidTable() {
|
||||
|
@ -162,9 +165,8 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -218,9 +220,8 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
laser.setPositions(head, tail);
|
||||
|
||||
if (!laser.isVisible()) {
|
||||
if (!laser.isVisible())
|
||||
laser.show();
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeLaser() {
|
||||
|
@ -242,9 +243,8 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
|
|||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
if (networkTracker.markTimeIfDelay(worldObj, nextNetworkUpdate)) {
|
||||
if (networkTracker.markTimeIfDelay(nextNetworkUpdate))
|
||||
super.sendNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -290,10 +290,9 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
common/buildcraft/silicon/TileLaserStandard.java
Normal file
21
common/buildcraft/silicon/TileLaserStandard.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.silicon;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class TileLaserStandard extends TileLaser {
|
||||
|
||||
@Override
|
||||
protected float getMaxPowerSent() {
|
||||
return 8;
|
||||
}
|
||||
}
|
|
@ -134,7 +134,7 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
|||
if (container.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
if (actionTracker.markTimeIfDelay(container.worldObj, 10)) {
|
||||
if (actionTracker.markTimeIfDelay(10)) {
|
||||
resolveActions();
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
|
|||
|
||||
moveFluids();
|
||||
|
||||
if (tracker.markTimeIfDelay(container.worldObj, BuildCraftCore.updateFactor)) {
|
||||
if (tracker.markTimeIfDelay(BuildCraftCore.updateFactor)) {
|
||||
|
||||
boolean init = false;
|
||||
if (++clientSyncCounter > BuildCraftCore.longUpdateFactor) {
|
||||
|
|
|
@ -245,7 +245,7 @@ public class PipeTransportPower extends PipeTransport {
|
|||
}
|
||||
}
|
||||
|
||||
if (tracker.markTimeIfDelay(container.worldObj, 2 * BuildCraftCore.updateFactor)) {
|
||||
if (tracker.markTimeIfDelay(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