add IControllable to most higher-tier BC machines

This commit is contained in:
asiekierka 2014-11-30 10:26:41 +01:00
parent 695313802a
commit 0d75f89a56
13 changed files with 81 additions and 60 deletions

View file

@ -146,10 +146,6 @@ public class BuildCraftCore extends BuildCraftMod {
public static long longUpdateFactor = 40; public static long longUpdateFactor = 40;
public static BuildCraftConfiguration mainConfiguration; 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 Block springBlock;
public static Item woodenGearItem; public static Item woodenGearItem;
public static Item stoneGearItem; public static Item stoneGearItem;

View file

@ -37,6 +37,7 @@ import buildcraft.api.core.Position;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IRequestProvider; import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.robots.StackRequest; import buildcraft.api.robots.StackRequest;
import buildcraft.api.tiles.IControllable;
import buildcraft.api.tiles.IHasWork; import buildcraft.api.tiles.IHasWork;
import buildcraft.core.Box; import buildcraft.core.Box;
import buildcraft.core.Box.Kind; import buildcraft.core.Box.Kind;
@ -63,7 +64,7 @@ import buildcraft.core.robots.ResourceIdRequest;
import buildcraft.core.robots.RobotRegistry; import buildcraft.core.robots.RobotRegistry;
import buildcraft.core.utils.Utils; 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; private static int POWER_ACTIVATION = 500;
@ -596,11 +597,13 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
iterateBpt(false); iterateBpt(false);
if (mode != Mode.Off) {
if (getWorldObj().getWorldInfo().getGameType() == GameType.CREATIVE) { if (getWorldObj().getWorldInfo().getGameType() == GameType.CREATIVE) {
build(); build();
} else if (getBattery().getEnergyStored() > POWER_ACTIVATION) { } else if (getBattery().getEnergyStored() > POWER_ACTIVATION) {
build(); build();
} }
}
if (!isBuilding && this.isBuildingBlueprint()) { if (!isBuilding && this.isBuildingBlueprint()) {
updateRequirements(); updateRequirements();
@ -928,6 +931,11 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
return left; return left;
} }
@Override
public boolean acceptsControlMode(Mode mode) {
return mode == Mode.Off || mode == Mode.On;
}
@Override @Override
public void writeData(ByteBuf stream) { public void writeData(ByteBuf stream) {
super.writeData(stream); super.writeData(stream);

View file

@ -43,7 +43,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
private final Box box = new Box(); private final Box box = new Box();
private boolean done = false; private boolean done = false;
private IControllable.Mode lastMode = IControllable.Mode.Unknown;
private SimpleInventory inv = new SimpleInventory(27, "Filler", 64); private SimpleInventory inv = new SimpleInventory(27, "Filler", 64);
private NBTTagCompound initNBT = null; private NBTTagCompound initNBT = null;
@ -96,7 +95,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
return; return;
} }
if (lastMode == Mode.Off) { if (mode == Mode.Off) {
return; return;
} }
@ -111,7 +110,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
boolean oldDone = done; boolean oldDone = done;
if (done) { if (done) {
if (lastMode == Mode.Loop) { if (mode == Mode.Loop) {
done = false; done = false;
} else { } else {
return; return;
@ -186,7 +185,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
} }
done = nbt.getBoolean("done"); done = nbt.getBoolean("done");
lastMode = Mode.values()[nbt.getByte("lastMode")];
// The rest of load has to be done upon initialize. // The rest of load has to be done upon initialize.
initNBT = (NBTTagCompound) nbt.getCompoundTag("bpt").copy(); initNBT = (NBTTagCompound) nbt.getCompoundTag("bpt").copy();
@ -207,7 +205,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
nbt.setTag("box", boxStore); nbt.setTag("box", boxStore);
nbt.setBoolean("done", done); nbt.setBoolean("done", done);
nbt.setByte("lastMode", (byte) lastMode.ordinal());
NBTTagCompound bptNBT = new NBTTagCompound(); NBTTagCompound bptNBT = new NBTTagCompound();
@ -268,7 +265,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
@Override @Override
public boolean hasWork() { public boolean hasWork() {
return !done && lastMode != Mode.Off; return !done && mode != Mode.Off;
} }
@Override @Override
@ -321,16 +318,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
return true; return true;
} }
@Override
public Mode getControlMode() {
return this.lastMode;
}
@Override
public void setControlMode(Mode mode) {
this.lastMode = mode;
}
@Override @Override
public boolean acceptsControlMode(Mode mode) { public boolean acceptsControlMode(Mode mode) {
return mode == IControllable.Mode.On || return mode == IControllable.Mode.On ||

View file

@ -22,15 +22,24 @@ import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyHandler; import cofh.api.energy.IEnergyHandler;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.core.ISerializable; import buildcraft.api.core.ISerializable;
import buildcraft.api.tiles.IControllable;
import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.ISynchronizedTile; import buildcraft.core.network.ISynchronizedTile;
import buildcraft.core.network.PacketTileUpdate; import buildcraft.core.network.PacketTileUpdate;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
// TODO: Move back to IEnergyReceiver when EIO updates // 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 { public abstract class TileBuildCraft extends TileEntity implements IEnergyHandler, ISynchronizedTile, ISerializable {
protected TileBuffer[] cache; protected TileBuffer[] cache;
protected HashSet<EntityPlayer> guiWatchers = new HashSet<EntityPlayer>(); protected HashSet<EntityPlayer> guiWatchers = new HashSet<EntityPlayer>();
protected IControllable.Mode mode;
private boolean init = false; private boolean init = false;
private String owner = "[BuildCraft]"; private String owner = "[BuildCraft]";
@ -120,6 +129,9 @@ public abstract class TileBuildCraft extends TileEntity implements IEnergyHandle
battery.writeToNBT(batteryNBT); battery.writeToNBT(batteryNBT);
nbt.setTag("battery", batteryNBT); nbt.setTag("battery", batteryNBT);
} }
if (mode != null) {
nbt.setByte("lastMode", (byte) mode.ordinal());
}
} }
@Override @Override
@ -131,6 +143,9 @@ public abstract class TileBuildCraft extends TileEntity implements IEnergyHandle
if (battery != null) { if (battery != null) {
battery.readFromNBT(nbt.getCompoundTag("battery")); 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(); return cache[side.ordinal()].getTile();
} }
public IControllable.Mode getControlMode() {
return mode;
}
public void setControlMode(IControllable.Mode mode) {
this.mode = mode;
}
} }

View file

@ -17,6 +17,7 @@ import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.core.BCLog;
import buildcraft.api.statements.IActionExternal; import buildcraft.api.statements.IActionExternal;
import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IActionInternal;
import buildcraft.api.statements.IActionProvider; import buildcraft.api.statements.IActionProvider;
@ -51,7 +52,7 @@ public class DefaultActionProvider implements IActionProvider {
} }
} }
} catch (Throwable error) { } 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; return res;

View file

@ -12,6 +12,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftFactory; import buildcraft.BuildCraftFactory;
import buildcraft.api.blueprints.BuilderAPI; import buildcraft.api.blueprints.BuilderAPI;
import buildcraft.api.tiles.IControllable;
import buildcraft.api.tiles.IHasWork; import buildcraft.api.tiles.IHasWork;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile.PipeType; import buildcraft.api.transport.IPipeTile.PipeType;
@ -19,7 +20,7 @@ import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft; import buildcraft.core.TileBuildCraft;
import buildcraft.core.utils.BlockUtils; 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; boolean isDigging = true;
private BlockMiner miner; private BlockMiner miner;
@ -38,6 +39,15 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon
return; return;
} }
if (mode == Mode.Off) {
if (miner != null) {
miner.invalidate();
miner = null;
}
isDigging = false;
return;
}
if (getBattery().getEnergyStored() == 0) { if (getBattery().getEnergyStored() == 0) {
return; return;
} }
@ -69,6 +79,8 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon
} }
if (miner != null) { if (miner != null) {
isDigging = true;
int usedEnergy = miner.acceptEnergy(getBattery().getEnergyStored()); int usedEnergy = miner.acceptEnergy(getBattery().getEnergyStored());
getBattery().useEnergy(usedEnergy, usedEnergy, false); getBattery().useEnergy(usedEnergy, usedEnergy, false);
@ -102,4 +114,9 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon
ForgeDirection with) { ForgeDirection with) {
return type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT; return type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
} }
@Override
public boolean acceptsControlMode(Mode mode) {
return mode == Mode.Off || mode == Mode.On;
}
} }

View file

@ -34,6 +34,7 @@ import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.filler.FillerManager; import buildcraft.api.filler.FillerManager;
import buildcraft.api.tiles.IControllable;
import buildcraft.api.tiles.IHasWork; import buildcraft.api.tiles.IHasWork;
import buildcraft.core.Box; import buildcraft.core.Box;
import buildcraft.core.Box.Kind; import buildcraft.core.Box.Kind;
@ -48,7 +49,7 @@ import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtils; import buildcraft.core.utils.BlockUtils;
import buildcraft.core.utils.Utils; 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 { private static enum Stage {
BUILDING, BUILDING,
@ -154,6 +155,10 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
return; return;
} }
if (mode == Mode.Off && stage != Stage.MOVING) {
return;
}
if (stage == Stage.BUILDING) { if (stage == Stage.BUILDING) {
if (builder != null && !builder.isDone(this)) { if (builder != null && !builder.isDone(this)) {
builder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord); builder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
@ -481,7 +486,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
@Override @Override
public boolean hasWork() { public boolean hasWork() {
return stage != Stage.DONE; return mode != Mode.Off && stage != Stage.DONE;
} }
private void setBoundaries(boolean useDefaultI) { 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) { public boolean canExtractItem(int p1, ItemStack p2, int p3) {
return false; return false;
} }
@Override
public boolean acceptsControlMode(Mode mode) {
return mode == Mode.Off || mode == Mode.On;
}
} }

View file

@ -233,7 +233,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
if (worldObj.isRemote) { if (worldObj.isRemote) {
return; return;
} }
if (lastMode == IControllable.Mode.Off) { if (mode == IControllable.Mode.Off) {
return; return;
} }
updateRecipe(); updateRecipe();
@ -440,7 +440,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
@Override @Override
public boolean canCraft() { public boolean canCraft() {
return craftable && !justCrafted && lastMode != IControllable.Mode.Off; return craftable && !justCrafted && mode != IControllable.Mode.Off;
} }
@Override @Override

View file

@ -80,7 +80,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IInventory,
} }
if (getEnergy() >= currentRecipe.craft(this, true).energyCost if (getEnergy() >= currentRecipe.craft(this, true).energyCost
&& lastMode != IControllable.Mode.Off) { && mode != IControllable.Mode.Off) {
setEnergy(0); setEnergy(0);
if (currentRecipe.canBeCrafted(this)) { if (currentRecipe.canBeCrafted(this)) {

View file

@ -12,11 +12,12 @@ public class TileChargingTable extends TileLaserTableBase implements IHasWork {
return !FMLCommonHandler.instance().getEffectiveSide().isClient(); return !FMLCommonHandler.instance().getEffectiveSide().isClient();
} }
// WARNING: run only server-side, see canUpdate()!
@Override @Override
public void updateEntity() { // WARNING: run only server-side, see canUpdate() public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (getEnergy() > 0) { if (getEnergy() > 0 && mode != Mode.Off) {
if (getRequiredEnergy() > 0) { if (getRequiredEnergy() > 0) {
ItemStack stack = this.getStackInSlot(0); ItemStack stack = this.getStackInSlot(0);
IEnergyContainerItem containerItem = (IEnergyContainerItem) stack.getItem(); IEnergyContainerItem containerItem = (IEnergyContainerItem) stack.getItem();

View file

@ -80,7 +80,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
} }
if (getEnergy() >= craftingPreview.energyCost if (getEnergy() >= craftingPreview.energyCost
&& lastMode != IControllable.Mode.Off) { && mode != IControllable.Mode.Off) {
setEnergy(0); setEnergy(0);
craftingPreview = null; craftingPreview = null;

View file

@ -40,7 +40,6 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
private final SafeTimeTracker searchTracker = new SafeTimeTracker(100, 100); private final SafeTimeTracker searchTracker = new SafeTimeTracker(100, 100);
private final SafeTimeTracker networkTracker = new SafeTimeTracker(20, 3); private final SafeTimeTracker networkTracker = new SafeTimeTracker(20, 3);
private ILaserTarget laserTarget; private ILaserTarget laserTarget;
private IControllable.Mode lastMode = IControllable.Mode.Unknown;
private int powerIndex = 0; private int powerIndex = 0;
private short powerAverage = 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 a gate disabled us, remove laser and do nothing.
if (lastMode == IControllable.Mode.Off) { if (mode == IControllable.Mode.Off) {
removeLaser(); removeLaser();
return; return;
} }
@ -322,16 +321,6 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable
return new Box(this).extendToEncompass(laser.tail).getBoundingBox(); 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 @Override
public boolean acceptsControlMode(Mode mode) { public boolean acceptsControlMode(Mode mode) {
return mode == IControllable.Mode.On || return mode == IControllable.Mode.On ||

View file

@ -26,7 +26,6 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
public int clientRequiredEnergy = 0; public int clientRequiredEnergy = 0;
protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64); protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64);
protected IControllable.Mode lastMode = IControllable.Mode.Unknown;
private int energy = 0; private int energy = 0;
private int recentEnergyAverage; private int recentEnergyAverage;
private AverageUtil recentEnergyAverageUtil = new AverageUtil(20); private AverageUtil recentEnergyAverageUtil = new AverageUtil(20);
@ -198,17 +197,7 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
@Override @Override
public boolean hasWork() { public boolean hasWork() {
return lastMode != IControllable.Mode.Off; return mode != IControllable.Mode.Off;
}
@Override
public Mode getControlMode() {
return this.lastMode;
}
@Override
public void setControlMode(Mode mode) {
this.lastMode = mode;
} }
@Override @Override