add IControllable to most higher-tier BC machines
This commit is contained in:
parent
695313802a
commit
0d75f89a56
13 changed files with 81 additions and 60 deletions
|
@ -146,10 +146,6 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
public static long longUpdateFactor = 40;
|
||||
public static BuildCraftConfiguration mainConfiguration;
|
||||
|
||||
// TODO: This doesn't seem used anymore. Remove if it's the case.
|
||||
public static TreeMap<BlockIndex, PacketUpdate> bufferedDescriptions = new TreeMap<BlockIndex, PacketUpdate>();
|
||||
|
||||
public static final int trackedPassiveEntityId = 156;
|
||||
public static Block springBlock;
|
||||
public static Item woodenGearItem;
|
||||
public static Item stoneGearItem;
|
||||
|
|
|
@ -37,6 +37,7 @@ import buildcraft.api.core.Position;
|
|||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.robots.IRequestProvider;
|
||||
import buildcraft.api.robots.StackRequest;
|
||||
import buildcraft.api.tiles.IControllable;
|
||||
import buildcraft.api.tiles.IHasWork;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.Box.Kind;
|
||||
|
@ -63,7 +64,7 @@ import buildcraft.core.robots.ResourceIdRequest;
|
|||
import buildcraft.core.robots.RobotRegistry;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluidHandler, IRequestProvider {
|
||||
public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluidHandler, IRequestProvider, IControllable {
|
||||
|
||||
private static int POWER_ACTIVATION = 500;
|
||||
|
||||
|
@ -596,10 +597,12 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
|||
|
||||
iterateBpt(false);
|
||||
|
||||
if (getWorldObj().getWorldInfo().getGameType() == GameType.CREATIVE) {
|
||||
build();
|
||||
} else if (getBattery().getEnergyStored() > POWER_ACTIVATION) {
|
||||
build();
|
||||
if (mode != Mode.Off) {
|
||||
if (getWorldObj().getWorldInfo().getGameType() == GameType.CREATIVE) {
|
||||
build();
|
||||
} else if (getBattery().getEnergyStored() > POWER_ACTIVATION) {
|
||||
build();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isBuilding && this.isBuildingBlueprint()) {
|
||||
|
@ -928,6 +931,11 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
|
|||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsControlMode(Mode mode) {
|
||||
return mode == Mode.Off || mode == Mode.On;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf stream) {
|
||||
super.writeData(stream);
|
||||
|
|
|
@ -43,7 +43,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
|
||||
private final Box box = new Box();
|
||||
private boolean done = false;
|
||||
private IControllable.Mode lastMode = IControllable.Mode.Unknown;
|
||||
private SimpleInventory inv = new SimpleInventory(27, "Filler", 64);
|
||||
|
||||
private NBTTagCompound initNBT = null;
|
||||
|
@ -96,7 +95,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
return;
|
||||
}
|
||||
|
||||
if (lastMode == Mode.Off) {
|
||||
if (mode == Mode.Off) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -111,7 +110,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
boolean oldDone = done;
|
||||
|
||||
if (done) {
|
||||
if (lastMode == Mode.Loop) {
|
||||
if (mode == Mode.Loop) {
|
||||
done = false;
|
||||
} else {
|
||||
return;
|
||||
|
@ -186,7 +185,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
}
|
||||
|
||||
done = nbt.getBoolean("done");
|
||||
lastMode = Mode.values()[nbt.getByte("lastMode")];
|
||||
|
||||
// The rest of load has to be done upon initialize.
|
||||
initNBT = (NBTTagCompound) nbt.getCompoundTag("bpt").copy();
|
||||
|
@ -207,7 +205,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
nbt.setTag("box", boxStore);
|
||||
|
||||
nbt.setBoolean("done", done);
|
||||
nbt.setByte("lastMode", (byte) lastMode.ordinal());
|
||||
|
||||
NBTTagCompound bptNBT = new NBTTagCompound();
|
||||
|
||||
|
@ -268,7 +265,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
return !done && lastMode != Mode.Off;
|
||||
return !done && mode != Mode.Off;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -321,16 +318,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mode getControlMode() {
|
||||
return this.lastMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlMode(Mode mode) {
|
||||
this.lastMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsControlMode(Mode mode) {
|
||||
return mode == IControllable.Mode.On ||
|
||||
|
|
|
@ -22,15 +22,24 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import cofh.api.energy.IEnergyHandler;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.core.ISerializable;
|
||||
import buildcraft.api.tiles.IControllable;
|
||||
import buildcraft.core.network.BuildCraftPacket;
|
||||
import buildcraft.core.network.ISynchronizedTile;
|
||||
import buildcraft.core.network.PacketTileUpdate;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
// TODO: Move back to IEnergyReceiver when EIO updates
|
||||
|
||||
/**
|
||||
* For future maintainers: This class intentionally does not implement
|
||||
* just every interface out there. For some of them (such as IControllable),
|
||||
* we expect the tiles supporting it to implement it - but TileBuildCraft
|
||||
* provides all the underlying functionality to stop code repetition.
|
||||
*/
|
||||
public abstract class TileBuildCraft extends TileEntity implements IEnergyHandler, ISynchronizedTile, ISerializable {
|
||||
protected TileBuffer[] cache;
|
||||
protected HashSet<EntityPlayer> guiWatchers = new HashSet<EntityPlayer>();
|
||||
protected IControllable.Mode mode;
|
||||
|
||||
private boolean init = false;
|
||||
private String owner = "[BuildCraft]";
|
||||
|
@ -120,6 +129,9 @@ public abstract class TileBuildCraft extends TileEntity implements IEnergyHandle
|
|||
battery.writeToNBT(batteryNBT);
|
||||
nbt.setTag("battery", batteryNBT);
|
||||
}
|
||||
if (mode != null) {
|
||||
nbt.setByte("lastMode", (byte) mode.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,6 +143,9 @@ public abstract class TileBuildCraft extends TileEntity implements IEnergyHandle
|
|||
if (battery != null) {
|
||||
battery.readFromNBT(nbt.getCompoundTag("battery"));
|
||||
}
|
||||
if (nbt.hasKey("lastMode")) {
|
||||
mode = IControllable.Mode.values()[nbt.getByte("lastMode")];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -210,4 +225,12 @@ public abstract class TileBuildCraft extends TileEntity implements IEnergyHandle
|
|||
}
|
||||
return cache[side.ordinal()].getTile();
|
||||
}
|
||||
|
||||
public IControllable.Mode getControlMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setControlMode(IControllable.Mode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.api.statements.IActionExternal;
|
||||
import buildcraft.api.statements.IActionInternal;
|
||||
import buildcraft.api.statements.IActionProvider;
|
||||
|
@ -51,7 +52,7 @@ public class DefaultActionProvider implements IActionProvider {
|
|||
}
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
FMLLog.log("Buildcraft", Level.FATAL, "Outdated API detected, please update your mods!");
|
||||
BCLog.logger.error("Outdated API detected, please update your mods!");
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.api.blueprints.BuilderAPI;
|
||||
import buildcraft.api.tiles.IControllable;
|
||||
import buildcraft.api.tiles.IHasWork;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
|
@ -19,7 +20,7 @@ import buildcraft.core.RFBattery;
|
|||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.utils.BlockUtils;
|
||||
|
||||
public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeConnection {
|
||||
public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeConnection, IControllable {
|
||||
boolean isDigging = true;
|
||||
private BlockMiner miner;
|
||||
|
||||
|
@ -38,6 +39,15 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon
|
|||
return;
|
||||
}
|
||||
|
||||
if (mode == Mode.Off) {
|
||||
if (miner != null) {
|
||||
miner.invalidate();
|
||||
miner = null;
|
||||
}
|
||||
isDigging = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (getBattery().getEnergyStored() == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -69,6 +79,8 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon
|
|||
}
|
||||
|
||||
if (miner != null) {
|
||||
isDigging = true;
|
||||
|
||||
int usedEnergy = miner.acceptEnergy(getBattery().getEnergyStored());
|
||||
getBattery().useEnergy(usedEnergy, usedEnergy, false);
|
||||
|
||||
|
@ -102,4 +114,9 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon
|
|||
ForgeDirection with) {
|
||||
return type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsControlMode(Mode mode) {
|
||||
return mode == Mode.Off || mode == Mode.On;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import buildcraft.api.core.BuildCraftAPI;
|
|||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.filler.FillerManager;
|
||||
import buildcraft.api.tiles.IControllable;
|
||||
import buildcraft.api.tiles.IHasWork;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.Box.Kind;
|
||||
|
@ -48,7 +49,7 @@ import buildcraft.core.proxy.CoreProxy;
|
|||
import buildcraft.core.utils.BlockUtils;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedInventory {
|
||||
public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedInventory, IControllable {
|
||||
|
||||
private static enum Stage {
|
||||
BUILDING,
|
||||
|
@ -154,6 +155,10 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
return;
|
||||
}
|
||||
|
||||
if (mode == Mode.Off && stage != Stage.MOVING) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stage == Stage.BUILDING) {
|
||||
if (builder != null && !builder.isDone(this)) {
|
||||
builder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
|
||||
|
@ -481,7 +486,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
return stage != Stage.DONE;
|
||||
return mode != Mode.Off && stage != Stage.DONE;
|
||||
}
|
||||
|
||||
private void setBoundaries(boolean useDefaultI) {
|
||||
|
@ -854,4 +859,9 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
public boolean canExtractItem(int p1, ItemStack p2, int p3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsControlMode(Mode mode) {
|
||||
return mode == Mode.Off || mode == Mode.On;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (lastMode == IControllable.Mode.Off) {
|
||||
if (mode == IControllable.Mode.Off) {
|
||||
return;
|
||||
}
|
||||
updateRecipe();
|
||||
|
@ -440,7 +440,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
|
||||
@Override
|
||||
public boolean canCraft() {
|
||||
return craftable && !justCrafted && lastMode != IControllable.Mode.Off;
|
||||
return craftable && !justCrafted && mode != IControllable.Mode.Off;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -80,7 +80,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IInventory,
|
|||
}
|
||||
|
||||
if (getEnergy() >= currentRecipe.craft(this, true).energyCost
|
||||
&& lastMode != IControllable.Mode.Off) {
|
||||
&& mode != IControllable.Mode.Off) {
|
||||
setEnergy(0);
|
||||
|
||||
if (currentRecipe.canBeCrafted(this)) {
|
||||
|
|
|
@ -12,11 +12,12 @@ public class TileChargingTable extends TileLaserTableBase implements IHasWork {
|
|||
return !FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
}
|
||||
|
||||
// WARNING: run only server-side, see canUpdate()!
|
||||
@Override
|
||||
public void updateEntity() { // WARNING: run only server-side, see canUpdate()
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (getEnergy() > 0) {
|
||||
if (getEnergy() > 0 && mode != Mode.Off) {
|
||||
if (getRequiredEnergy() > 0) {
|
||||
ItemStack stack = this.getStackInSlot(0);
|
||||
IEnergyContainerItem containerItem = (IEnergyContainerItem) stack.getItem();
|
||||
|
|
|
@ -80,7 +80,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
|
|||
}
|
||||
|
||||
if (getEnergy() >= craftingPreview.energyCost
|
||||
&& lastMode != IControllable.Mode.Off) {
|
||||
&& mode != IControllable.Mode.Off) {
|
||||
setEnergy(0);
|
||||
craftingPreview = null;
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
|
|||
private final SafeTimeTracker searchTracker = new SafeTimeTracker(100, 100);
|
||||
private final SafeTimeTracker networkTracker = new SafeTimeTracker(20, 3);
|
||||
private ILaserTarget laserTarget;
|
||||
private IControllable.Mode lastMode = IControllable.Mode.Unknown;
|
||||
private int powerIndex = 0;
|
||||
|
||||
private short powerAverage = 0;
|
||||
|
@ -74,7 +73,7 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
|
|||
}
|
||||
|
||||
// If a gate disabled us, remove laser and do nothing.
|
||||
if (lastMode == IControllable.Mode.Off) {
|
||||
if (mode == IControllable.Mode.Off) {
|
||||
removeLaser();
|
||||
return;
|
||||
}
|
||||
|
@ -322,16 +321,6 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
|
|||
return new Box(this).extendToEncompass(laser.tail).getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mode getControlMode() {
|
||||
return this.lastMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlMode(Mode mode) {
|
||||
this.lastMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsControlMode(Mode mode) {
|
||||
return mode == IControllable.Mode.On ||
|
||||
|
|
|
@ -26,7 +26,6 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
|
|||
|
||||
public int clientRequiredEnergy = 0;
|
||||
protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64);
|
||||
protected IControllable.Mode lastMode = IControllable.Mode.Unknown;
|
||||
private int energy = 0;
|
||||
private int recentEnergyAverage;
|
||||
private AverageUtil recentEnergyAverageUtil = new AverageUtil(20);
|
||||
|
@ -198,17 +197,7 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
|
|||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
return lastMode != IControllable.Mode.Off;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mode getControlMode() {
|
||||
return this.lastMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlMode(Mode mode) {
|
||||
this.lastMode = mode;
|
||||
return mode != IControllable.Mode.Off;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue