diff --git a/common/buildcraft/api/core/SafeTimeTracker.java b/common/buildcraft/api/core/SafeTimeTracker.java index 65707d47..2da2cb60 100644 --- a/common/buildcraft/api/core/SafeTimeTracker.java +++ b/common/buildcraft/api/core/SafeTimeTracker.java @@ -14,6 +14,7 @@ import net.minecraft.world.World; public class SafeTimeTracker { private long lastMark = 0; + private long duration = 0; /** * Return true if a given delay has passed since last time marked was called successfully. @@ -28,12 +29,17 @@ public class SafeTimeTracker { lastMark = currentTime; return false; } else if (lastMark + delay <= currentTime) { + duration = currentTime - lastMark; lastMark = world.getWorldTime(); return true; } else return false; } + + public long durationOfLastDelay(){ + return duration; + } public void markTime(World world) { lastMark = world.getWorldTime(); diff --git a/common/buildcraft/api/power/IPowerReceptor.java b/common/buildcraft/api/power/IPowerReceptor.java index 8ac71b77..8effb816 100644 --- a/common/buildcraft/api/power/IPowerReceptor.java +++ b/common/buildcraft/api/power/IPowerReceptor.java @@ -7,14 +7,15 @@ */ package buildcraft.api.power; +import buildcraft.api.power.PowerHandler.PowerReceiver; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; public interface IPowerReceptor { - public PowerProvider getPowerProvider(ForgeDirection side); + public PowerReceiver getPowerReceiver(ForgeDirection side); - public void doWork(PowerProvider workProvider); + public void doWork(PowerHandler workProvider); public World getWorldObj(); } diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerHandler.java similarity index 61% rename from common/buildcraft/api/power/PowerProvider.java rename to common/buildcraft/api/power/PowerHandler.java index ccbec7e9..98f7470c 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerHandler.java @@ -11,7 +11,30 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; -public final class PowerProvider { +public final class PowerHandler { + + public static enum Type { + + ENGINE, GATE, MACHINE, PIPE, STORAGE; + + public boolean canReceiveFromPipes() { + switch (this) { + case MACHINE: + case STORAGE: + return true; + } + return false; + } + + public boolean eatsEngineExcess() { + switch (this) { + case MACHINE: + case STORAGE: + return true; + } + return false; + } + } public static class PerditionCalculator { @@ -30,7 +53,7 @@ public final class PowerProvider { this.powerLoss = powerLoss; } - public float applyPerdition(PowerProvider provider, float current) { + public float applyPerdition(PowerHandler provider, float current) { current -= powerLoss; if (current < 0) { current = 0; @@ -44,56 +67,60 @@ public final class PowerProvider { private float maxEnergyStored; private float activationEnergy; private float energyStored = 0; - public final boolean canAcceptPowerFromPipes; private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); + private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(); + private final SafeTimeTracker perditionTracker = new SafeTimeTracker(); public final int[] powerSources = {0, 0, 0, 0, 0, 0}; public final IPowerReceptor receptor; private PerditionCalculator perdition; + private final PowerReceiver receiver; + private final Type type; - public PowerProvider(IPowerReceptor receptor) { - this(receptor, true); + public PowerHandler(IPowerReceptor receptor, Type type) { + this.receptor = receptor; + this.type = type; + this.receiver = new PowerReceiver(); } - public PowerProvider(IPowerReceptor receptor, boolean canAcceptPowerFromPipes) { - this.canAcceptPowerFromPipes = canAcceptPowerFromPipes; - this.receptor = receptor; + public PowerReceiver getPowerReceiver() { + return receiver; } public float getMinEnergyReceived() { - return this.minEnergyReceived; + return minEnergyReceived; } public float getMaxEnergyReceived() { - return this.maxEnergyReceived; + return maxEnergyReceived; } public float getMaxEnergyStored() { - return this.maxEnergyStored; + return maxEnergyStored; } public float getActivationEnergy() { - return this.activationEnergy; + return activationEnergy; } public float getEnergyStored() { - return this.energyStored; + return energyStored; } /** - * Setup your PowerProvider's settings. + * Setup your PowerHandler's settings. * * @param minEnergyReceived This is the minimum about of power that will be - * accepted by the PowerProvider. This should generally be greater than the + * accepted by the PowerHandler. This should generally be greater than the * activationEnergy if you plan to use the doWork() callback. Anything * greater than 1 will prevent Redstone Engines from powering this Provider. * @param maxEnergyReceived The maximum amount of power accepted by the - * PowerProvider. This should generally be less than 500. Too low and larger + * PowerHandler. This should generally be less than 500. Too low and larger * engines will overheat while trying to power the machine. Too high, and * the engines will never warm up. Greater values also place greater strain * on the power net. * @param activationEnergy If the stored energy is greater than this value, * the doWork() callback is called (once per tick). - * @param maxStoredEnergy The maximum amount of power this PowerProvider can + * @param maxStoredEnergy The maximum amount of power this PowerHandler can * store. Values tend to range between 100 and 5000. With 1000 and 1500 * being common. */ @@ -107,17 +134,6 @@ public final class PowerProvider { this.activationEnergy = activationEnergy; } - public void update() { - applyPerdition(); - applyWork(); - - for (int i = 0; i < 6; ++i) { - if (powerSources[i] > 0) { - powerSources[i]--; - } - } - } - public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { if (powerLoss == 0 || powerLossRegularity == 0) { perdition = new PerditionCalculator(0); @@ -138,11 +154,15 @@ public final class PowerProvider { private void applyPerdition() { if (energyStored > 0) { - float newEnergy = getPerdition().applyPerdition(this, energyStored); - if (newEnergy == 0 || newEnergy < energyStored) { - energyStored = newEnergy; - } else { - energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored); + if (perditionTracker.markTimeIfDelay(receptor.getWorldObj(), 1)) { + for (int i = 0; i < perditionTracker.durationOfLastDelay(); i++) { + float newEnergy = getPerdition().applyPerdition(this, energyStored); + if (newEnergy == 0 || newEnergy < energyStored) { + energyStored = newEnergy; + } else { + energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored); + } + } } } } @@ -155,9 +175,23 @@ public final class PowerProvider { } } + private void updateSources(ForgeDirection source) { + if (sourcesTracker.markTimeIfDelay(receptor.getWorldObj(), 1)) { + for (int i = 0; i < 6; ++i) { + powerSources[i] -= sourcesTracker.durationOfLastDelay(); + if (powerSources[i] < 0) { + powerSources[i] = 0; + } + } + } + + if (source != null) + powerSources[source.ordinal()] = 10; + } + /** - * Extract energy from the PowerProvider. You must call this even if - * doWork() triggers. + * Extract energy from the PowerHandler. You must call this even if doWork() + * triggers. * * @param min * @param max @@ -203,46 +237,76 @@ public final class PowerProvider { data.setCompoundTag(tag, nbt); } - /** - * The amount of power that this PowerProvider currently needs. - * - * @return - */ - public float powerRequest() { - return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); - } + public final class PowerReceiver { - public float receiveEnergy(float quantity, ForgeDirection from) { - return receiveEnergy(quantity, from, false); - } - - /** - * Add power to the Provider from an external source. - * - * @param quantity - * @param from - * @return the amount of power used - */ - public float receiveEnergy(float quantity, ForgeDirection from, boolean boundsCheck) { - if (boundsCheck) { - if (quantity < minEnergyReceived) { - quantity = minEnergyReceived; - } else if (quantity > maxEnergyReceived) { - quantity = maxEnergyReceived; - } + private PowerReceiver() { } - if (from != null) - powerSources[from.ordinal()] = 2; - quantity = addEnergy(quantity); - applyWork(); + public float getMinEnergyReceived() { + return minEnergyReceived; + } - return quantity; + public float getMaxEnergyReceived() { + return maxEnergyReceived; + } + + public float getMaxEnergyStored() { + return maxEnergyStored; + } + + public float getActivationEnergy() { + return activationEnergy; + } + + public float getEnergyStored() { + return energyStored; + } + + public Type getType() { + return type; + } + + /** + * The amount of power that this PowerHandler currently needs. + * + * @return + */ + public float powerRequest() { + return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); + } + + /** + * Add power to the PowerReceiver from an external source. + * + * @param quantity + * @param from + * @return the amount of power used + */ + public float receiveEnergy(Type source, final float quantity, ForgeDirection from) { + float used = quantity; + if (source == Type.ENGINE) { + if (used < minEnergyReceived) { + return 0; + } else if (used > maxEnergyReceived) { + used = maxEnergyReceived; + } + } + + updateSources(from); + + used = addEnergy(used); + + applyWork(); + + if (source == Type.ENGINE && type.eatsEngineExcess()) { + return Math.min(quantity, maxEnergyReceived); + } + + return used; + } } /** - * Internal use only you should NEVER call this function on a PowerProvider - * you don't own. * * @return the amount the power changed by */ @@ -262,10 +326,6 @@ public final class PowerProvider { return quantity; } - /** - * Internal use only you should NEVER call this function on a PowerProvider - * you don't own. - */ public void setEnergy(float quantity) { this.energyStored = quantity; if (energyStored > maxEnergyStored) { diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 734dc38e..a1df022a 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -1,12 +1,10 @@ -/** - * 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.builders; import java.util.Collection; @@ -25,7 +23,9 @@ import buildcraft.api.core.LaserKind; import buildcraft.api.core.Position; import buildcraft.api.gates.IAction; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.BlockIndex; import buildcraft.core.Box; import buildcraft.core.DefaultProps; @@ -49,18 +49,12 @@ import buildcraft.core.utils.Utils; public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IPowerReceptor, IMachine { private final ItemStack items[] = new ItemStack[28]; - private BptBuilderBase bluePrintBuilder; - public @TileNetworkData Box box = new Box(); - - private PowerProvider powerProvider; - + private PowerHandler powerHandler; private LinkedList path; - private LinkedList pathLasers; - private EntityRobot builderRobot; private class PathIterator { @@ -169,16 +163,14 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP return true; } } - public PathIterator currentPathIterator; - private boolean done = true; public TileBuilder() { super(); - powerProvider = new PowerProvider(this); - powerProvider.configure(25, 25, 25, 25); + powerHandler = new PowerHandler(this, Type.MACHINE); + powerHandler.configure(25, 25, 25, 25); } @Override @@ -271,7 +263,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; @@ -281,28 +273,28 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP if (builderRobot != null && !builderRobot.readyToBuild()) return; - if (powerProvider.useEnergy(25, 25, true) < 25) + if (powerHandler.useEnergy(25, 25, true) < 25) return; iterateBpt(); /* Temp fix to make Builders impotent as the World Destroyers they are - if (bluePrintBuilder != null && !bluePrintBuilder.done) { - if (!box.isInitialized()) { - box.initialize(bluePrintBuilder); - } + if (bluePrintBuilder != null && !bluePrintBuilder.done) { + if (!box.isInitialized()) { + box.initialize(bluePrintBuilder); + } - if (builderRobot == null) { - builderRobot = new EntityRobot(worldObj, box); - worldObj.spawnEntityInWorld(builderRobot); - } + if (builderRobot == null) { + builderRobot = new EntityRobot(worldObj, box); + worldObj.spawnEntityInWorld(builderRobot); + } - box.createLasers(worldObj, LaserKind.Stripes); + box.createLasers(worldObj, LaserKind.Stripes); - builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)), - bluePrintBuilder.getContext()); - } - */ + builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)), + bluePrintBuilder.getContext()); + } + */ } public void iterateBpt() { @@ -347,9 +339,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP box.deleteLasers(); box.reset(); /* - box.initialize(bluePrintBuilder); - box.createLasers(worldObj, LaserKind.Stripes); - */ + box.initialize(bluePrintBuilder); + box.createLasers(worldObj, LaserKind.Stripes); + */ } if (builderRobot != null) { @@ -442,7 +434,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP public int getInventoryStackLimit() { return 64; } - + @Override public boolean isStackValidForSlot(int i, ItemStack itemstack) { // TODO Auto-generated method stub @@ -525,8 +517,8 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override @@ -553,12 +545,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP @Override public void openChest() { - } @Override public void closeChest() { - } // @Override @@ -568,7 +558,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP // else // return 0; // } - @Override public void updateEntity() { diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index e0edb14b..6b5bcfdc 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -19,7 +19,9 @@ import buildcraft.api.filler.IFillerPattern; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.Box; import buildcraft.core.IMachine; import buildcraft.core.TileBuildCraft; @@ -45,18 +47,18 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe public IFillerPattern currentPattern; boolean forceDone = false; private ItemStack contents[]; - PowerProvider powerProvider; + private PowerHandler powerHandler; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; public TileFiller() { contents = new ItemStack[getSizeInventory()]; - powerProvider = new PowerProvider(this); + powerHandler = new PowerHandler(this, Type.MACHINE); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(30, 50, 25, 100); - powerProvider.configurePowerPerdition(1, 1); + powerHandler.configure(30, 50, 25, 100); + powerHandler.configurePowerPerdition(1, 1); } @Override @@ -94,20 +96,20 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe return; } - if (powerProvider.getEnergyStored() >= 25) { - doWork(powerProvider); + if (powerHandler.getEnergyStored() >= 25) { + doWork(powerHandler); } } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; if (lastMode == Mode.Off) return; - if (powerProvider.useEnergy(25, 25, true) < 25) + if (powerHandler.useEnergy(25, 25, true) < 25) return; if (box.isInitialized() && currentPattern != null && !done) { @@ -136,7 +138,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe } } - if (powerProvider.getEnergyStored() >= 25) { + if (powerHandler.getEnergyStored() >= 25) { doWork(workProvider); } } @@ -322,8 +324,8 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 4a2c7efd..3d563dc4 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -56,11 +56,6 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized initialize(); init = true; } - - if (this instanceof IPowerReceptor) { - IPowerReceptor receptor = ((IPowerReceptor) this); - receptor.getPowerProvider(null).update(); - } } @Override diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index d46a7b43..40a13592 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -20,7 +20,9 @@ import buildcraft.api.core.Position; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.transport.IPipeConnection; import buildcraft.core.TileBuffer; import buildcraft.core.TileBuildCraft; @@ -44,7 +46,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public static final float MAX_HEAT = 250; protected int progressPart = 0; protected boolean lastPower = false; - protected PowerProvider provider; + protected PowerHandler powerHandler; public float currentOutput = 0; public boolean isRedstonePowered = false; public TileBuffer[] tileCache; @@ -61,8 +63,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto boolean isPumping = false; // Used for SMP synch public TileEngine(int invSize) { - provider = new PowerProvider(this, false); - provider.configurePowerPerdition(1, 100); + powerHandler = new PowerHandler(this, Type.ENGINE); + powerHandler.configurePowerPerdition(1, 100); inv = new SimpleInventory(invSize, "Engine", 64); } @@ -71,7 +73,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public void initialize() { if (!CoreProxy.proxy.isRenderWorld(worldObj)) { tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, true); - provider.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy()); + powerHandler.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy()); checkRedstonePower(); } } @@ -211,7 +213,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto private float getPowerToExtract() { TileEntity tile = tileCache[orientation.ordinal()].getTile(); - PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(orientation.getOpposite()); + PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite()); return extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false); // Comment out for constant power // return extractEnergy(0, getActualOutput(), false); // Uncomment for constant power } @@ -219,11 +221,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto private void sendPower() { TileEntity tile = tileCache[orientation.ordinal()].getTile(); if (isPoweredTile(tile, orientation)) { - PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(orientation.getOpposite()); + PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite()); float extracted = getPowerToExtract(); if (extracted > 0) { - float needed = receptor.receiveEnergy(extracted, orientation.getOpposite(), true); + float needed = receptor.receiveEnergy(PowerHandler.Type.ENGINE, extracted, orientation.getOpposite()); extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power // currentOutput = extractEnergy(0, needed, true); // Uncomment for constant power } @@ -386,16 +388,16 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public abstract int getScaledBurnTime(int scale); @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return provider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; - addEnergy(provider.useEnergy(1, maxEnergyReceived(), true) * 0.95F); + addEnergy(powerHandler.useEnergy(1, maxEnergyReceived(), true) * 0.95F); } public void addEnergy(float addition) { @@ -444,9 +446,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public boolean isPoweredTile(TileEntity tile, ForgeDirection side) { if (tile instanceof IPowerReceptor) { - PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(side.getOpposite()); - - return receptor != null; + return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null; } return false; diff --git a/common/buildcraft/factory/TileMiningWell.java b/common/buildcraft/factory/TileMiningWell.java index 2230f92f..dee4a54d 100644 --- a/common/buildcraft/factory/TileMiningWell.java +++ b/common/buildcraft/factory/TileMiningWell.java @@ -17,7 +17,9 @@ import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; import buildcraft.api.gates.IAction; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.transport.IPipeConnection; import buildcraft.core.IMachine; import buildcraft.core.TileBuildCraft; @@ -27,12 +29,12 @@ import buildcraft.core.utils.Utils; public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerReceptor, IPipeConnection { boolean isDigging = true; - PowerProvider powerProvider; + private PowerHandler powerHandler; public TileMiningWell() { - powerProvider = new PowerProvider(this); - powerProvider.configure(100, 100, 60, 1000); - powerProvider.configurePowerPerdition(1, 1); + powerHandler = new PowerHandler(this, Type.MACHINE); + powerHandler.configure(100, 100, 60, 1000); + powerHandler.configurePowerPerdition(1, 1); } /** @@ -40,8 +42,8 @@ public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerRe * bedrock, lava or goes below 0, it's considered done. */ @Override - public void doWork(PowerProvider workProvider) { - if (powerProvider.useEnergy(60, 60, true) != 60) + public void doWork(PowerHandler workProvider) { + if (powerHandler.useEnergy(60, 60, true) != 60) return; World world = worldObj; @@ -114,8 +116,8 @@ public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerRe } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index ef234b18..20f25289 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -27,7 +27,9 @@ import buildcraft.BuildCraftFactory; import buildcraft.api.core.Position; import buildcraft.api.gates.IAction; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.BlockIndex; import buildcraft.core.EntityBlock; import buildcraft.core.IMachine; @@ -45,17 +47,17 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor LiquidTank tank; double tubeY = Double.NaN; int aimY = 0; - private PowerProvider powerProvider; + private PowerHandler powerHandler; public TilePump() { - powerProvider = new PowerProvider(this); + powerHandler = new PowerHandler(this, Type.MACHINE); initPowerProvider(); tank = new LiquidTank(MAX_LIQUID); } private void initPowerProvider() { - powerProvider.configure(1, 8, 10, 100); - powerProvider.configurePowerPerdition(1, 100); + powerHandler.configure(1, 8, 10, 100); + powerHandler.configurePowerPerdition(1, 100); } // TODO, manage this by different levels (pump what's above first...) @@ -87,7 +89,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor if (tank.fill(liquidToPump, false) == liquidToPump.amount) { - if (powerProvider.useEnergy(10, 10, true) == 10) { + if (powerHandler.useEnergy(10, 10, true) == 10) { index = getNextIndexToPump(true); if (liquidToPump.itemID != Block.waterStill.blockID || BuildCraftCore.consumeWaterSources) { @@ -286,7 +288,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor tubeY = nbttagcompound.getFloat("tubeY"); - powerProvider.readFromNBT(nbttagcompound); + powerHandler.readFromNBT(nbttagcompound); initPowerProvider(); } @@ -294,7 +296,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - powerProvider.writeToNBT(nbttagcompound); + powerHandler.writeToNBT(nbttagcompound); if (tank.getLiquid() != null) { nbttagcompound.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound())); @@ -315,12 +317,12 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { } @Override diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index 989355ee..c6edc385 100755 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -28,7 +28,8 @@ import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.LaserKind; import buildcraft.api.gates.IAction; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.transport.IPipeConnection; import buildcraft.core.Box; import buildcraft.core.DefaultAreaProvider; @@ -68,18 +69,18 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept public EntityRobot builder; BptBuilderBase bluePrintBuilder; public EntityMechanicalArm arm; - public PowerProvider powerProvider; + public PowerHandler powerHandler; boolean isDigging = false; public static final int MAX_ENERGY = 15000; public TileQuarry() { - powerProvider = new PowerProvider(this); + powerHandler = new PowerHandler(this, PowerHandler.Type.MACHINE); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(50, 100, 25, MAX_ENERGY); - powerProvider.configurePowerPerdition(2, 1); + powerHandler.configure(50, 100, 25, MAX_ENERGY); + powerHandler.configurePowerPerdition(2, 1); } public void createUtilsIfNeeded() { @@ -146,9 +147,9 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept } super.updateEntity(); if (inProcess) { - float energyToUse = 2 + powerProvider.getEnergyStored() / 500; + float energyToUse = 2 + powerHandler.getEnergyStored() / 500; - float energy = powerProvider.useEnergy(energyToUse, energyToUse, true); + float energy = powerHandler.useEnergy(energyToUse, energyToUse, true); if (energy > 0) { moveHead(0.1 + energy / 200F); @@ -189,13 +190,13 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { } protected void buildFrame() { - powerProvider.configure(50, 100, 25, MAX_ENERGY); - if (powerProvider.useEnergy(25, 25, true) != 25) + powerHandler.configure(50, 100, 25, MAX_ENERGY); + if (powerHandler.useEnergy(25, 25, true) != 25) return; if (builder == null) { @@ -209,8 +210,8 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept } protected void dig() { - powerProvider.configure(100, 500, 60, MAX_ENERGY); - if (powerProvider.useEnergy(60, 60, true) != 60) + powerHandler.configure(100, 500, 60, MAX_ENERGY); + if (powerHandler.useEnergy(60, 60, true) != 60) return; if (!findTarget(true)) { @@ -334,7 +335,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - powerProvider.readFromNBT(nbttagcompound); + powerHandler.readFromNBT(nbttagcompound); initPowerProvider(); if (nbttagcompound.hasKey("box")) { @@ -372,7 +373,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - powerProvider.writeToNBT(nbttagcompound); + powerHandler.writeToNBT(nbttagcompound); nbttagcompound.setInteger("targetX", targetX); nbttagcompound.setInteger("targetY", targetY); @@ -665,8 +666,8 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override diff --git a/common/buildcraft/factory/TileRefinery.java b/common/buildcraft/factory/TileRefinery.java index d5a9e223..17a61b08 100644 --- a/common/buildcraft/factory/TileRefinery.java +++ b/common/buildcraft/factory/TileRefinery.java @@ -23,7 +23,9 @@ import buildcraft.BuildCraftCore; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.recipes.RefineryRecipe; import buildcraft.core.IMachine; import buildcraft.core.TileBuildCraft; @@ -43,11 +45,11 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow private int animationStage = 0; SafeTimeTracker time = new SafeTimeTracker(); SafeTimeTracker updateNetworkTime = new SafeTimeTracker(); - PowerProvider powerProvider; + private PowerHandler powerHandler; private boolean isActive; public TileRefinery() { - powerProvider = new PowerProvider(this); + powerHandler = new PowerHandler(this, Type.MACHINE); initPowerProvider(); filters[0] = 0; @@ -57,8 +59,8 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow } private void initPowerProvider() { - powerProvider.configure(25, 100, 25, 1000); - powerProvider.configurePowerPerdition(1, 1); + powerHandler.configure(25, 100, 25, 1000); + powerHandler.configurePowerPerdition(1, 1); } @Override @@ -106,12 +108,12 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { } @Override @@ -152,7 +154,7 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow isActive = true; - if (powerProvider.getEnergyStored() >= currentRecipe.energy) { + if (powerHandler.getEnergyStored() >= currentRecipe.energy) { increaseAnimation(); } else { decreaseAnimation(); @@ -161,7 +163,7 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow if (!time.markTimeIfDelay(worldObj, currentRecipe.delay)) return; - float energyUsed = powerProvider.useEnergy(currentRecipe.energy, currentRecipe.energy, true); + float energyUsed = powerHandler.useEnergy(currentRecipe.energy, currentRecipe.energy, true); if (energyUsed != 0) { if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) { @@ -250,7 +252,7 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow animationStage = nbttagcompound.getInteger("animationStage"); animationSpeed = nbttagcompound.getFloat("animationSpeed"); - powerProvider.readFromNBT(nbttagcompound); + powerHandler.readFromNBT(nbttagcompound); initPowerProvider(); filters[0] = nbttagcompound.getInteger("filters_0"); @@ -277,7 +279,7 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow nbttagcompound.setInteger("animationStage", animationStage); nbttagcompound.setFloat("animationSpeed", animationSpeed); - powerProvider.writeToNBT(nbttagcompound); + powerHandler.writeToNBT(nbttagcompound); nbttagcompound.setInteger("filters_0", filters[0]); nbttagcompound.setInteger("filters_1", filters[1]); diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index f133b5fa..e1095f8c 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -18,7 +18,9 @@ import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.BlockIndex; import buildcraft.core.EntityEnergyLaser; import buildcraft.core.IMachine; @@ -33,22 +35,22 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction private final SafeTimeTracker searchTracker = new SafeTimeTracker(); private final SafeTimeTracker networkTracker = new SafeTimeTracker(); private ILaserTarget laserTarget; - public PowerProvider powerProvider; + private PowerHandler powerHandler; private int nextNetworkUpdate = 3; private int nextLaserUpdate = 10; private int nextLaserSearch = 100; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; - + public TileLaser() { - powerProvider = new PowerProvider(this); + powerHandler = new PowerHandler(this, Type.MACHINE); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(25, 150, 25, 1000); - powerProvider.configurePowerPerdition(1, 1); + powerHandler.configure(25, 150, 25, 1000); + powerHandler.configurePowerPerdition(1, 1); } - + @Override public void updateEntity() { super.updateEntity(); @@ -57,7 +59,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction return; // Disable the laser and do nothing if no energy is available. - if (powerProvider.getEnergyStored() == 0) { + if (powerHandler.getEnergyStored() == 0) { removeLaser(); return; } @@ -93,7 +95,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction } // Consume power and transfer it to the table. - float power = powerProvider.useEnergy(0, 4, true); + float power = powerHandler.useEnergy(0, 4, true); laserTarget.receiveLaserEnergy(power); if (laser != null) { @@ -230,14 +232,13 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction } } - @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { } @Override @@ -251,7 +252,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - powerProvider.readFromNBT(nbttagcompound); + powerHandler.readFromNBT(nbttagcompound); initPowerProvider(); } @@ -259,7 +260,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - powerProvider.writeToNBT(nbttagcompound); + powerHandler.writeToNBT(nbttagcompound); } @Override diff --git a/common/buildcraft/transport/EnergyPulser.java b/common/buildcraft/transport/EnergyPulser.java index ab177240..82587b2b 100644 --- a/common/buildcraft/transport/EnergyPulser.java +++ b/common/buildcraft/transport/EnergyPulser.java @@ -3,6 +3,7 @@ package buildcraft.transport; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler.Type; public class EnergyPulser { @@ -26,7 +27,7 @@ public class EnergyPulser { return; if (!singlePulse || !hasPulsed) { - powerReceptor.getPowerProvider(null).receiveEnergy(Math.min(1 << (pulseCount - 1), 64), ForgeDirection.WEST); + powerReceptor.getPowerReceiver(null).receiveEnergy(Type.GATE, Math.min(1 << (pulseCount - 1), 64), ForgeDirection.WEST); hasPulsed = true; } } diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 6fae0d2c..4d271155 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -14,7 +14,8 @@ import buildcraft.BuildCraftCore; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.ITrigger; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.DefaultProps; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; @@ -74,10 +75,10 @@ public class PipeTransportPower extends PipeTransport { if (tile instanceof IPowerReceptor) { IPowerReceptor receptor = (IPowerReceptor) tile; - PowerProvider provider = receptor.getPowerProvider(side.getOpposite()); - if (provider == null) + PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite()); + if (receiver == null) return false; - if (container.pipe instanceof PipePowerWood || provider.canAcceptPowerFromPipes) + if (container.pipe instanceof PipePowerWood || receiver.getType().canReceiveFromPipes()) return true; } @@ -150,11 +151,11 @@ public class PipeTransportPower extends PipeTransport { internalPower[i] -= watts; } else if (tiles[j] instanceof IPowerReceptor) { IPowerReceptor pow = (IPowerReceptor) tiles[j]; - PowerProvider prov = pow.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); + PowerReceiver prov = pow.getPowerReceiver(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); - if (prov != null && prov.canAcceptPowerFromPipes && prov.powerRequest() > 0) { + if (prov != null && prov.getType().canReceiveFromPipes() && prov.powerRequest() > 0) { watts = (internalPower[i] / totalPowerQuery) * powerQuery[j]; - watts = prov.receiveEnergy(watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); + watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); internalPower[i] -= watts; } } @@ -187,8 +188,8 @@ public class PipeTransportPower extends PipeTransport { for (int i = 0; i < 6; ++i) { if (tiles[i] instanceof IPowerReceptor && !(tiles[i] instanceof TileGenericPipe)) { IPowerReceptor receptor = (IPowerReceptor) tiles[i]; - PowerProvider prov = receptor.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); - if (prov != null && prov.canAcceptPowerFromPipes) { + PowerReceiver prov = receptor.getPowerReceiver(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); + if (prov != null && prov.getType().canReceiveFromPipes()) { float request = prov.powerRequest(); if (request > 0) { diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 5cd5b692..a9562931 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -32,7 +32,7 @@ import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeEntry; @@ -189,12 +189,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank refreshRenderState = false; } - PowerProvider provider = getPowerProvider(null); - - if (provider != null) { - provider.update(); - } - if (pipe != null) { pipe.updateEntity(); } @@ -329,17 +323,17 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { + public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) { if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) - return ((IPowerReceptor) pipe).getPowerProvider(null); + return ((IPowerReceptor) pipe).getPowerReceiver(null); else return null; } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { - ((IPowerReceptor) pipe).doWork(null); + ((IPowerReceptor) pipe).doWork(workProvider); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index 4af248e1..5fe552ce 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -77,11 +77,11 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISpecialInventory /* ISELECTIVEINVENTORY */ if (inventory instanceof ISelectiveInventory) { - ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[]{getCurrentFilter()}, false, doRemove, from, (int) powerProvider.getEnergyStored()); + ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[]{getCurrentFilter()}, false, doRemove, from, (int) powerHandler.getEnergyStored()); if (doRemove) { for (ItemStack stack : stacks) { if (stack != null) { - powerProvider.useEnergy(stack.stackSize, stack.stackSize, true); + powerHandler.useEnergy(stack.stackSize, stack.stackSize, true); } } incrementFilter(); @@ -90,7 +90,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISpecialInventory /* ISPECIALINVENTORY */ } else if (inventory instanceof ISpecialInventory) { - ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(false, from, (int) powerProvider.getEnergyStored()); + ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(false, from, (int) powerHandler.getEnergyStored()); if (stacks != null) { for (ItemStack stack : stacks) { if(stack == null) @@ -109,10 +109,10 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISpecialInventory } } if (doRemove) { - stacks = ((ISpecialInventory) inventory).extractItem(true, from, (int) powerProvider.getEnergyStored()); + stacks = ((ISpecialInventory) inventory).extractItem(true, from, (int) powerHandler.getEnergyStored()); for (ItemStack stack : stacks) { if (stack != null) { - powerProvider.useEnergy(stack.stackSize, stack.stackSize, true); + powerHandler.useEnergy(stack.stackSize, stack.stackSize, true); } } } @@ -168,7 +168,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISpecialInventory } if (doRemove) { incrementFilter(); - return inventory.decrStackSize(i, (int) powerProvider.useEnergy(1, stack.stackSize, true)); + return inventory.decrStackSize(i, (int) powerHandler.useEnergy(1, stack.stackSize, true)); } else { return stack; } diff --git a/common/buildcraft/transport/pipes/PipeItemsObsidian.java b/common/buildcraft/transport/pipes/PipeItemsObsidian.java index c72df02e..aa2a9164 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -23,7 +23,9 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.transport.IPipedItem; import buildcraft.core.EntityPassiveItem; import buildcraft.core.proxy.CoreProxy; @@ -36,7 +38,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeItemsObsidian extends Pipe implements IPowerReceptor { - private PowerProvider powerProvider; + private PowerHandler powerHandler; private int[] entitiesDropped; private int entitiesDroppedIndex = 0; @@ -50,9 +52,9 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { entitiesDropped[i] = -1; } - powerProvider = new PowerProvider(this); - powerProvider.configure(1, 64, 1, 256); - powerProvider.configurePowerPerdition(1, 1); + powerHandler = new PowerHandler(this, Type.MACHINE); + powerHandler.configure(1, 64, 1, 256); + powerHandler.configurePowerPerdition(1, 1); } @Override @@ -144,12 +146,12 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { } @Override - public void doWork(PowerProvider workProvider) { + public void doWork(PowerHandler workProvider) { for (int j = 1; j < 5; ++j) if (trySucc(j)) return; - powerProvider.useEnergy(1, 1, true); + powerHandler.useEnergy(1, 1, true); } private boolean trySucc(int distance) { @@ -174,7 +176,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { EntityMinecartChest cart = (EntityMinecartChest) list.get(g); if (!cart.isDead) { ItemStack stack = checkExtractGeneric(cart, true, getOpenOrientation()); - if (stack != null && powerProvider.useEnergy(1, 1, true) == 1) { + if (stack != null && powerHandler.useEnergy(1, 1, true) == 1) { EntityItem entityitem = new EntityItem(worldObj, cart.posX, cart.posY + 0.3F, cart.posZ, stack); entityitem.delayBeforeCanPickup = 10; worldObj.spawnEntityInWorld(entityitem); @@ -223,7 +225,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { CoreProxy.proxy.obsidianPipePickup(worldObj, item, this.container); - float energyUsed = powerProvider.useEnergy(distance, contained.stackSize * distance, true); + float energyUsed = powerHandler.useEnergy(distance, contained.stackSize * distance, true); if (distance == 0 || energyUsed / distance == contained.stackSize) { stack = contained; @@ -239,7 +241,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { speed = 0.01; } } else if (entity instanceof EntityArrow) { - powerProvider.useEnergy(distance, distance, true); + powerHandler.useEnergy(distance, distance, true); stack = new ItemStack(Item.arrow, 1); CoreProxy.proxy.removeEntity(entity); } @@ -276,15 +278,15 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { if (item.entityId == entitiesDropped[i]) return false; - return powerProvider.useEnergy(1, distance, false) >= distance; + return powerHandler.useEnergy(1, distance, false) >= distance; } else if (entity instanceof EntityArrow) - return powerProvider.useEnergy(1, distance, false) >= distance; + return powerHandler.useEnergy(1, distance, false) >= distance; else return false; } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 698d8306..93515f67 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -11,14 +11,15 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; import buildcraft.api.inventory.ISpecialInventory; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.PipeManager; import buildcraft.core.EntityPassiveItem; @@ -32,16 +33,16 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeItemsWood extends Pipe implements IPowerReceptor { - protected PowerProvider powerProvider; + protected PowerHandler powerHandler; protected int standardIconIndex = PipeIconProvider.TYPE.PipeItemsWood_Standard.ordinal(); protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); protected PipeItemsWood(PipeTransportItems transport, PipeLogic logic, int itemID) { super(transport, logic, itemID); - powerProvider = new PowerProvider(this, false); - powerProvider.configure(1, 64, 1, 64); - powerProvider.configurePowerPerdition(0, 0); + powerHandler = new PowerHandler(this, Type.MACHINE); + powerHandler.configure(1, 64, 1, 64); + powerHandler.configurePowerPerdition(0, 0); } protected PipeItemsWood(int itemID, PipeTransportItems transport) { @@ -73,17 +74,17 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override - public void doWork(PowerProvider workProvider) { - if (powerProvider.getEnergyStored() <= 0) + public void doWork(PowerHandler workProvider) { + if (powerHandler.getEnergyStored() <= 0) return; extractItems(); - powerProvider.setEnergy(0); + powerHandler.setEnergy(0); } private void extractItems() { @@ -108,7 +109,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { for (ItemStack stack : extracted) { if (stack == null || stack.stackSize == 0) { - powerProvider.useEnergy(1, 1, true); + powerHandler.useEnergy(1, 1, true); continue; } @@ -132,11 +133,11 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { /* ISPECIALINVENTORY */ if (inventory instanceof ISpecialInventory) { - ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(doRemove, from, (int) powerProvider.getEnergyStored()); + ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(doRemove, from, (int) powerHandler.getEnergyStored()); if (stacks != null && doRemove) { for (ItemStack stack : stacks) { if (stack != null) { - powerProvider.useEnergy(stack.stackSize, stack.stackSize, true); + powerHandler.useEnergy(stack.stackSize, stack.stackSize, true); } } } @@ -164,7 +165,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) { if (doRemove) { - return inventory.decrStackSize(k, (int) powerProvider.useEnergy(1, slot.stackSize, true)); + return inventory.decrStackSize(k, (int) powerHandler.useEnergy(1, slot.stackSize, true)); } else { return slot; } diff --git a/common/buildcraft/transport/pipes/PipeLiquidsWood.java b/common/buildcraft/transport/pipes/PipeLiquidsWood.java index 9ba4ad33..7ec72aa8 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsWood.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsWood.java @@ -18,7 +18,9 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.transport.PipeManager; import buildcraft.core.network.TileNetworkData; import buildcraft.transport.Pipe; @@ -32,7 +34,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { public @TileNetworkData int liquidToExtract; - private PowerProvider powerProvider; + private PowerHandler powerHandler; protected int standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsWood_Standard.ordinal(); protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); @@ -47,17 +49,17 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { protected PipeLiquidsWood(PipeLogic logic, int itemID) { super(new PipeTransportLiquids(), logic, itemID); - powerProvider = new PowerProvider(this, false); - powerProvider.configure(1, 100, 1, 250); - powerProvider.configurePowerPerdition(0, 0); + powerHandler = new PowerHandler(this, Type.MACHINE); + powerHandler.configure(1, 100, 1, 250); + powerHandler.configurePowerPerdition(0, 0); } /** * Extracts a random piece of item outside of a nearby chest. */ @Override - public void doWork(PowerProvider workProvider) { - if (powerProvider.getEnergyStored() <= 0) + public void doWork(PowerHandler workProvider) { + if (powerHandler.getEnergyStored() <= 0) return; World w = worldObj; @@ -76,15 +78,15 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { return; if (liquidToExtract <= LiquidContainerRegistry.BUCKET_VOLUME) { - liquidToExtract += powerProvider.useEnergy(1, 1, true) * LiquidContainerRegistry.BUCKET_VOLUME; + liquidToExtract += powerHandler.useEnergy(1, 1, true) * LiquidContainerRegistry.BUCKET_VOLUME; } } - powerProvider.useEnergy(1, 1, true); + powerHandler.useEnergy(1, 1, true); } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 277a9a7c..0cc28d78 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -11,7 +11,9 @@ import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportPower; @@ -21,7 +23,7 @@ import net.minecraft.nbt.NBTTagCompound; public class PipePowerWood extends Pipe implements IPowerReceptor { - private PowerProvider powerProvider; + private PowerHandler powerHandler; protected int standardIconIndex = PipeIconProvider.TYPE.PipePowerWood_Standard.ordinal(); protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); private boolean[] powerSources = new boolean[6]; @@ -30,14 +32,14 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { public PipePowerWood(int itemID) { super(new PipeTransportPower(), new PipeLogicWood(), itemID); - powerProvider = new PowerProvider(this, false); + powerHandler = new PowerHandler(this, Type.PIPE); initPowerProvider(); ((PipeTransportPower) transport).initFromPipe(getClass()); } private void initPowerProvider() { - powerProvider.configure(2, 1000, 1, 1500); - powerProvider.configurePowerPerdition(1, 10); + powerHandler.configure(2, 1000, 1, 1500); + powerHandler.configurePowerPerdition(1, 10); } @Override @@ -61,13 +63,12 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { } @Override - public PowerProvider getPowerProvider(ForgeDirection side) { - return powerProvider; + public PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); } @Override - public void doWork(PowerProvider workProvider) { - // TODO Auto-generated method stub + public void doWork(PowerHandler workProvider) { } @Override @@ -76,7 +77,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { if (worldObj.isRemote) return; - if (powerProvider.getEnergyStored() <= 0) + if (powerHandler.getEnergyStored() <= 0) return; int sources = 0; @@ -85,7 +86,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { powerSources[o.ordinal()] = false; continue; } - if (powerProvider.isPowerSource(o)) { + if (powerHandler.isPowerSource(o)) { powerSources[o.ordinal()] = true; } if (powerSources[o.ordinal()]) { @@ -98,10 +99,10 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { float energyToRemove; - if (powerProvider.getEnergyStored() > 40) { - energyToRemove = powerProvider.getEnergyStored() / 40 + 4; - } else if (powerProvider.getEnergyStored() > 10) { - energyToRemove = powerProvider.getEnergyStored() / 10; + if (powerHandler.getEnergyStored() > 40) { + energyToRemove = powerHandler.getEnergyStored() / 40 + 4; + } else if (powerHandler.getEnergyStored() > 10) { + energyToRemove = powerHandler.getEnergyStored() / 10; } else { energyToRemove = 1; } @@ -113,37 +114,37 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { if (!powerSources[o.ordinal()]) continue; - float energyUsable = powerProvider.useEnergy(0, energyToRemove, false); + float energyUsable = powerHandler.useEnergy(0, energyToRemove, false); float energySend = trans.receiveEnergy(o, energyUsable); if (energySend > 0) { - powerProvider.useEnergy(0, energySend, true); + powerHandler.useEnergy(0, energySend, true); } } } public boolean requestsPower() { if (full) { - boolean request = powerProvider.getEnergyStored() < powerProvider.getMaxEnergyStored() / 2; + boolean request = powerHandler.getEnergyStored() < powerHandler.getMaxEnergyStored() / 2; if (request) { full = false; } return request; } - full = powerProvider.getEnergyStored() >= powerProvider.getMaxEnergyStored() - 10; + full = powerHandler.getEnergyStored() >= powerHandler.getMaxEnergyStored() - 10; return !full; } @Override public void writeToNBT(NBTTagCompound data) { super.writeToNBT(data); - powerProvider.writeToNBT(data); + powerHandler.writeToNBT(data); } @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); - powerProvider.readFromNBT(data); + powerHandler.readFromNBT(data); initPowerProvider(); } }