diff --git a/common/buildcraft/factory/TileMiningWell.java b/common/buildcraft/factory/TileMiningWell.java index 59adaa8a..39cfc92a 100644 --- a/common/buildcraft/factory/TileMiningWell.java +++ b/common/buildcraft/factory/TileMiningWell.java @@ -8,45 +8,41 @@ */ package buildcraft.factory; -import buildcraft.BuildCraftCore; -import buildcraft.BuildCraftFactory; -import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerHandler; -import buildcraft.api.power.PowerHandler.PowerReceiver; -import buildcraft.api.power.PowerHandler.Type; -import buildcraft.core.IMachine; -import buildcraft.core.TileBuildCraft; -import buildcraft.core.utils.BlockUtil; -import buildcraft.core.utils.Utils; import java.util.List; + import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.BuildCraftCore; +import buildcraft.BuildCraftFactory; +import buildcraft.api.gates.IAction; +import buildcraft.api.mj.MjBattery; +import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; +import buildcraft.core.utils.BlockUtil; +import buildcraft.core.utils.Utils; -public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerReceptor { +public class TileMiningWell extends TileBuildCraft implements IMachine { boolean isDigging = true; - private PowerHandler powerHandler; - public TileMiningWell() { - powerHandler = new PowerHandler(this, Type.MACHINE); - - float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier; - powerHandler.configure(100 * BuildCraftFactory.miningMultiplier, 100 * BuildCraftFactory.miningMultiplier, mj, 1000 * BuildCraftFactory.miningMultiplier); - powerHandler.configurePowerPerdition(1, 1); - } + @MjBattery(maxCapacity = 1000, maxReceivedPerCycle = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK, minimumConsumption = 1) + private double mjStored = 0; /** * Dig the next available piece of land if not done. As soon as it reaches * bedrock, lava or goes below 0, it's considered done. */ @Override - public void doWork(PowerHandler workProvider) { + public void updateEntity () { float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier; - if (powerHandler.useEnergy(mj, mj, true) != mj) + + if (mjStored < mj) { return; + } else { + mjStored -= mj; + } World world = worldObj; @@ -67,21 +63,25 @@ public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerRe world.setBlock(xCoord, depth, zCoord, BuildCraftFactory.plainPipeBlock); - if (wasAir) + if (wasAir) { return; + } - if (stacks == null || stacks.isEmpty()) + if (stacks == null || stacks.isEmpty()) { return; + } for (ItemStack stack : stacks) { stack.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, stack); - if (stack.stackSize <= 0) + if (stack.stackSize <= 0) { continue; + } stack.stackSize -= Utils.addToRandomPipeAround(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN, stack); - if (stack.stackSize <= 0) + if (stack.stackSize <= 0) { continue; + } // Throw the object away. // TODO: factorize that code @@ -116,11 +116,6 @@ public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerRe return isDigging; } - @Override - public PowerReceiver getPowerReceiver(ForgeDirection side) { - return powerHandler.getPowerReceiver(); - } - @Override public boolean manageFluids() { return false; diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index a1ef0b7f..534af253 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -32,10 +32,7 @@ import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerHandler; -import buildcraft.api.power.PowerHandler.PowerReceiver; -import buildcraft.api.power.PowerHandler.Type; +import buildcraft.api.mj.MjBattery; import buildcraft.core.BlockIndex; import buildcraft.core.CoreConstants; import buildcraft.core.EntityBlock; @@ -50,7 +47,7 @@ import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.BlockUtil; import buildcraft.core.utils.Utils; -public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor, IFluidHandler { +public class TilePump extends TileBuildCraft implements IMachine, IFluidHandler { public static final int REBUID_DELAY = 512; public static int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 16; @@ -59,22 +56,15 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor SingleUseTank tank = new SingleUseTank("tank", MAX_LIQUID, this); double tubeY = Double.NaN; int aimY = 0; - private PowerHandler powerHandler; + private TileBuffer[] tileBuffer = null; private SafeTimeTracker timer = new SafeTimeTracker(REBUID_DELAY); private int tick = Utils.RANDOM.nextInt(); private int numFluidBlocksFound = 0; private boolean powered = false; - public TilePump() { - powerHandler = new PowerHandler(this, Type.MACHINE); - initPowerProvider(); - } - - private void initPowerProvider() { - powerHandler.configure(1, 15, 10, 100); - powerHandler.configurePowerPerdition(1, 100); - } + @MjBattery(maxCapacity = 100, maxReceivedPerCycle = 15, minimumConsumption = 1) + private double mjStored = 0; @Override public void updateEntity() { @@ -119,7 +109,9 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor FluidStack fluidToPump = index != null ? BlockUtil.drainBlock(worldObj, index.x, index.y, index.z, false) : null; if (fluidToPump != null) { if (isFluidAllowed(fluidToPump.getFluid()) && tank.fill(fluidToPump, false) == fluidToPump.amount) { - if (powerHandler.useEnergy(10, 10, true) == 10) { + if (mjStored > 10) { + mjStored -= 10; + if (fluidToPump.getFluid() != FluidRegistry.WATER || BuildCraftCore.consumeWaterSources || numFluidBlocksFound < 9) { index = getNextIndexToPump(true); BlockUtil.drainBlock(worldObj, index.x, index.y, index.z, true); @@ -356,7 +348,6 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); - powerHandler.readFromNBT(data); tank.readFromNBT(data); powered = data.getBoolean("powered"); @@ -364,14 +355,13 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor aimY = data.getInteger("aimY"); tubeY = data.getFloat("tubeY"); - initPowerProvider(); + mjStored = data.getDouble("mjStored"); } @Override public void writeToNBT(NBTTagCompound data) { super.writeToNBT(data); - powerHandler.writeToNBT(data); tank.writeToNBT(data); data.setBoolean("powered", powered); @@ -383,6 +373,8 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor } else { data.setFloat("tubeY", yCoord); } + + data.setDouble("mjStored", mjStored); } @Override @@ -396,15 +388,6 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor } } - @Override - public PowerReceiver getPowerReceiver(ForgeDirection side) { - return powerHandler.getPowerReceiver(); - } - - @Override - public void doWork(PowerHandler workProvider) { - } - @Override public PacketPayload getPacketPayload() { PacketPayload payload = new PacketPayload(new PacketPayload.StreamWriter() { diff --git a/common/buildcraft/factory/TileRefinery.java b/common/buildcraft/factory/TileRefinery.java index df583e7c..f97916aa 100644 --- a/common/buildcraft/factory/TileRefinery.java +++ b/common/buildcraft/factory/TileRefinery.java @@ -28,10 +28,7 @@ import net.minecraftforge.fluids.IFluidHandler; import buildcraft.BuildCraftCore; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerHandler; -import buildcraft.api.power.PowerHandler.PowerReceiver; -import buildcraft.api.power.PowerHandler.Type; +import buildcraft.api.mj.MjBattery; import buildcraft.core.IMachine; import buildcraft.core.TileBuildCraft; import buildcraft.core.fluids.SingleUseTank; @@ -41,7 +38,7 @@ import buildcraft.core.network.PacketUpdate; import buildcraft.core.recipes.RefineryRecipeManager; import buildcraft.core.recipes.RefineryRecipeManager.RefineryRecipe; -public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowerReceptor, IInventory, IMachine { +public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInventory, IMachine { public static int LIQUID_PER_SLOT = FluidContainerRegistry.BUCKET_VOLUME * 4; public SingleUseTank tank1 = new SingleUseTank("tank1", LIQUID_PER_SLOT, this); @@ -52,18 +49,10 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe private int animationStage = 0; SafeTimeTracker time = new SafeTimeTracker(); SafeTimeTracker updateNetworkTime = new SafeTimeTracker(); - private PowerHandler powerHandler; private boolean isActive; - public TileRefinery() { - powerHandler = new PowerHandler(this, Type.MACHINE); - initPowerProvider(); - } - - private void initPowerProvider() { - powerHandler.configure(50, 150, 25, 1000); - powerHandler.configurePowerPerdition(1, 1); - } + @MjBattery(maxCapacity = 1000, maxReceivedPerCycle = 150, minimumConsumption = 1) + private double mjStored = 0; @Override public int getSizeInventory() { @@ -109,15 +98,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe return null; } - @Override - public PowerReceiver getPowerReceiver(ForgeDirection side) { - return powerHandler.getPowerReceiver(); - } - - @Override - public void doWork(PowerHandler workProvider) { - } - @Override public void updateEntity() { if (worldObj.isRemote) { @@ -150,7 +130,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe isActive = true; - if (powerHandler.getEnergyStored() >= currentRecipe.energyCost) { + if (mjStored >= currentRecipe.energyCost) { increaseAnimation(); } else { decreaseAnimation(); @@ -160,9 +140,9 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe return; } - double energyUsed = powerHandler.useEnergy(currentRecipe.energyCost, currentRecipe.energyCost, true); + if (mjStored >= currentRecipe.energyCost) { + mjStored -= currentRecipe.energyCost; - if (energyUsed != 0) { if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) { result.fill(currentRecipe.result, true); } @@ -218,8 +198,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe animationStage = data.getInteger("animationStage"); animationSpeed = data.getFloat("animationSpeed"); - powerHandler.readFromNBT(data); - initPowerProvider(); + mjStored = data.getDouble("mjStored"); } @Override @@ -230,7 +209,8 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe data.setInteger("animationStage", animationStage); data.setFloat("animationSpeed", animationSpeed); - powerHandler.writeToNBT(data); + + data.setDouble("mjStored", mjStored); } public int getAnimationStage() { diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index b18dc188..00d2583f 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -22,11 +22,8 @@ import buildcraft.api.core.Position; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; +import buildcraft.api.mj.MjBattery; import buildcraft.api.power.ILaserTarget; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerHandler; -import buildcraft.api.power.PowerHandler.PowerReceiver; -import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.Box; import buildcraft.core.EntityLaser; import buildcraft.core.IMachine; @@ -34,7 +31,7 @@ import buildcraft.core.LaserData; import buildcraft.core.TileBuildCraft; import buildcraft.core.triggers.ActionMachineControl; -public class TileLaser extends TileBuildCraft implements IPowerReceptor, IActionReceptor, IMachine { +public class TileLaser extends TileBuildCraft implements IActionReceptor, IMachine { private static final float LASER_OFFSET = 2.0F / 16.0F; @@ -45,29 +42,20 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction private final SafeTimeTracker searchTracker = new SafeTimeTracker(100, 100); private final SafeTimeTracker networkTracker = new SafeTimeTracker(20, 3); private ILaserTarget laserTarget; - protected PowerHandler powerHandler; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; - private static final PowerHandler.PerditionCalculator PERDITION = new PowerHandler.PerditionCalculator(0.5F); private static final short POWER_AVERAGING = 100; private int powerIndex = 0; + @MjBattery(maxCapacity = 1000, maxReceivedPerCycle = 25, minimumConsumption = 1) + private double mjStored = 0; + @NetworkData private double powerAverage = 0; private final double power[] = new double[POWER_AVERAGING]; - public TileLaser() { - powerHandler = new PowerHandler(this, Type.MACHINE); - initPowerProvider(); - } - - private void initPowerProvider() { - powerHandler.configure(25, 150, 25, 1000); - powerHandler.setPerdition(PERDITION); - } - @Override public void initialize () { super.initialize(); @@ -105,7 +93,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction } // Disable the laser and do nothing if no energy is available. - if (powerHandler.getEnergyStored() == 0) { + if (mjStored == 0) { removeLaser(); return; } @@ -120,7 +108,8 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction } // Consume power and transfer it to the table. - double power = powerHandler.useEnergy(0, getMaxPowerSent(), true); + double power = mjStored > getMaxPowerSent() ? getMaxPowerSent() : mjStored; + mjStored -= power; laserTarget.receiveLaserEnergy(power); if (laser != null) { @@ -261,15 +250,6 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction super.sendNetworkUpdate(); } - @Override - public PowerReceiver getPowerReceiver(ForgeDirection side) { - return powerHandler.getPowerReceiver(); - } - - @Override - public void doWork(PowerHandler workProvider) { - } - @Override public void sendNetworkUpdate() { if (networkTracker.markTimeIfDelay(worldObj)) { @@ -281,15 +261,14 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - powerHandler.readFromNBT(nbttagcompound); - initPowerProvider(); + mjStored = nbttagcompound.getDouble("mjStored"); } @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - powerHandler.writeToNBT(nbttagcompound); + nbttagcompound.setDouble("mjStored", mjStored); } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsObsidian.java b/common/buildcraft/transport/pipes/PipeItemsObsidian.java index 6dfa2a8d..9680a86d 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -24,7 +24,6 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; import buildcraft.api.mj.MjBattery; -import buildcraft.api.power.PowerHandler; import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.Transactor; import buildcraft.core.inventory.filters.StackFilter; @@ -43,7 +42,6 @@ public class PipeItemsObsidian extends Pipe { @MjBattery (maxCapacity = 256, maxReceivedPerCycle = 64, minimumConsumption = 0) private double mjStored = 0; - private static final PowerHandler.PerditionCalculator PERDITION = new PowerHandler.PerditionCalculator(0.5F); private int[] entitiesDropped; private int entitiesDroppedIndex = 0;