From 1f8c9f78eeb6d64ed5ca20b618f5d6a54da78683 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 01:00:24 -0700 Subject: [PATCH 01/29] Power API rewrite PowerFrameWork is gone. PowerProvider is final. Can have multiple PowerProviders (one for each block side). PowerProviders can either accept power from pipes or they can't, defined in constructor. Removed a bunch of excess code that just cluttered the API. --- common/buildcraft/BuildCraftCore.java | 13 --- .../buildcraft/api/power/IPowerProvider.java | 41 ------- .../buildcraft/api/power/IPowerReceptor.java | 17 +-- .../buildcraft/api/power/PowerFramework.java | 55 --------- .../buildcraft/api/power/PowerProvider.java | 110 ++++++------------ common/buildcraft/builders/TileBuilder.java | 32 +++-- common/buildcraft/builders/TileFiller.java | 26 ++--- .../core/RedstonePowerFramework.java | 22 ---- .../core/RedstonePowerProvider.java | 75 ------------ common/buildcraft/core/TileBuildCraft.java | 2 +- .../energy/PneumaticPowerFramework.java | 22 ---- .../energy/PneumaticPowerProvider.java | 23 ---- common/buildcraft/energy/TileEngine.java | 30 ++--- common/buildcraft/factory/TileMachine.java | 24 ---- common/buildcraft/factory/TileMiningWell.java | 21 ++-- common/buildcraft/factory/TilePump.java | 25 ++-- common/buildcraft/factory/TileQuarry.java | 32 ++--- common/buildcraft/factory/TileRefinery.java | 25 ++-- common/buildcraft/silicon/TileLaser.java | 28 ++--- common/buildcraft/transport/EnergyPulser.java | 2 +- .../transport/PipeTransportPower.java | 23 ++-- .../buildcraft/transport/TileGenericPipe.java | 27 +---- .../transport/pipes/PipeItemsEmerald.java | 12 +- .../transport/pipes/PipeItemsObsidian.java | 23 +--- .../transport/pipes/PipeItemsWood.java | 31 +---- .../transport/pipes/PipeLiquidsWood.java | 31 +---- .../transport/pipes/PipePowerWood.java | 23 ++-- 27 files changed, 175 insertions(+), 620 deletions(-) delete mode 100644 common/buildcraft/api/power/IPowerProvider.java delete mode 100644 common/buildcraft/api/power/PowerFramework.java delete mode 100644 common/buildcraft/core/RedstonePowerFramework.java delete mode 100644 common/buildcraft/core/RedstonePowerProvider.java delete mode 100644 common/buildcraft/energy/PneumaticPowerFramework.java delete mode 100644 common/buildcraft/energy/PneumaticPowerProvider.java delete mode 100644 common/buildcraft/factory/TileMachine.java diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 5c5a49a0..5bdb699d 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -28,7 +28,6 @@ import net.minecraftforge.event.ForgeSubscribe; import buildcraft.api.core.BuildCraftAPI; import buildcraft.api.core.IIconProvider; import buildcraft.api.gates.ActionManager; -import buildcraft.api.power.PowerFramework; import buildcraft.core.BlockIndex; import buildcraft.core.BlockSpring; import buildcraft.core.BuildCraftConfiguration; @@ -41,7 +40,6 @@ import buildcraft.core.EntityRobot; import buildcraft.core.ItemBuildCraft; import buildcraft.core.ItemSpring; import buildcraft.core.ItemWrench; -import buildcraft.core.RedstonePowerFramework; import buildcraft.core.SpringPopulate; import buildcraft.core.TickHandlerCoreClient; import buildcraft.core.Version; @@ -212,17 +210,6 @@ public class BuildCraftCore { longFactor.comment = "delay between full client sync packets, increasing it saves bandwidth, decreasing makes for better client syncronization."; longUpdateFactor = longFactor.getInt(40); - String powerFrameworkClassName = "buildcraft.energy.PneumaticPowerFramework"; - if (!forcePneumaticPower) { - powerFrameworkClassName = powerFrameworkClass.getString(); - } - try { - PowerFramework.currentFramework = (PowerFramework) Class.forName(powerFrameworkClassName).getConstructor().newInstance(); - } catch (Throwable e) { - bcLog.throwing("BuildCraftCore", "loadConfiguration", e); - PowerFramework.currentFramework = new RedstonePowerFramework(); - } - Property wrenchId = BuildCraftCore.mainConfiguration.getItem("wrench.id", DefaultProps.WRENCH_ID); wrenchItem = (new ItemWrench(wrenchId.getInt(DefaultProps.WRENCH_ID))).setUnlocalizedName("wrenchItem"); diff --git a/common/buildcraft/api/power/IPowerProvider.java b/common/buildcraft/api/power/IPowerProvider.java deleted file mode 100644 index 92cb041d..00000000 --- a/common/buildcraft/api/power/IPowerProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -package buildcraft.api.power; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.ForgeDirection; -import buildcraft.api.core.SafeTimeTracker; - -public interface IPowerProvider { - - int getLatency(); - - int getMinEnergyReceived(); - - int getMaxEnergyReceived(); - - int getMaxEnergyStored(); - - int getActivationEnergy(); - - float getEnergyStored(); - - void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy); - - void configurePowerPerdition(int powerLoss, int powerLossRegularity); - - boolean update(IPowerReceptor receptor); - - boolean preConditions(IPowerReceptor receptor); - - float useEnergy(float min, float max, boolean doUse); - - void readFromNBT(NBTTagCompound nbttagcompound); - - void writeToNBT(NBTTagCompound nbttagcompound); - - void receiveEnergy(float quantity, ForgeDirection from); - - boolean isPowerSource(ForgeDirection from); - - SafeTimeTracker getTimeTracker(); - -} diff --git a/common/buildcraft/api/power/IPowerReceptor.java b/common/buildcraft/api/power/IPowerReceptor.java index 405f108d..b1eea8fd 100644 --- a/common/buildcraft/api/power/IPowerReceptor.java +++ b/common/buildcraft/api/power/IPowerReceptor.java @@ -11,20 +11,7 @@ import net.minecraftforge.common.ForgeDirection; public interface IPowerReceptor { - public void setPowerProvider(IPowerProvider provider); + public PowerProvider getPowerProvider(ForgeDirection side); - public IPowerProvider getPowerProvider(); - - public void doWork(); - - /** - * Used to request power from pipes. The return cannot be relied on to be - * anything more than a approximate guide to the power needed. When - * transferring power, you much check the return value of - * PowerProvider.receiverEnergy(). - * - * @param from - * @return - */ - public int powerRequest(ForgeDirection from); + public void doWork(PowerProvider workProvider); } diff --git a/common/buildcraft/api/power/PowerFramework.java b/common/buildcraft/api/power/PowerFramework.java deleted file mode 100644 index 87e00b64..00000000 --- a/common/buildcraft/api/power/PowerFramework.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ - -package buildcraft.api.power; - -import net.minecraft.nbt.NBTTagCompound; - -public abstract class PowerFramework { - - static private String baseNBTName = "net.minecraft.src.buildcarft.Power"; - - public static PowerFramework currentFramework; - - public abstract IPowerProvider createPowerProvider(); - - public void loadPowerProvider(IPowerReceptor receptor, NBTTagCompound compound) { - - IPowerProvider provider = createPowerProvider(); - - if (compound.hasKey(baseNBTName)) { - NBTTagCompound cpt = compound.getCompoundTag(baseNBTName); - if (cpt.getString("class").equals(this.getClass().getName())) { - provider.readFromNBT(cpt.getCompoundTag("contents")); - } - } - - receptor.setPowerProvider(provider); - } - - public void savePowerProvider(IPowerReceptor receptor, NBTTagCompound compound) { - - IPowerProvider provider = receptor.getPowerProvider(); - - if (provider == null) - return; - - NBTTagCompound cpt = new NBTTagCompound(); - - cpt.setString("class", this.getClass().getName()); - - NBTTagCompound contents = new NBTTagCompound(); - - provider.writeToNBT(contents); - - cpt.setTag("contents", contents); - compound.setTag(baseNBTName, cpt); - } - -} diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index 6f99f4f5..72f1cd32 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.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.api.power; import net.minecraft.nbt.NBTTagCompound; @@ -14,91 +12,66 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; -public abstract class PowerProvider implements IPowerProvider { +public final class PowerProvider { - protected int latency; protected int minEnergyReceived; protected int maxEnergyReceived; protected int maxEnergyStored; protected int minActivationEnergy; protected float energyStored = 0; - protected int powerLoss = 1; protected int powerLossRegularity = 1; - - public SafeTimeTracker timeTracker = new SafeTimeTracker(); + public final boolean canAcceptPowerFromPipes; public SafeTimeTracker energyLossTracker = new SafeTimeTracker(); + public int[] powerSources = {0, 0, 0, 0, 0, 0}; - public int[] powerSources = { 0, 0, 0, 0, 0, 0 }; - - @Override - public SafeTimeTracker getTimeTracker() { - return this.timeTracker; + public PowerProvider() { + this.canAcceptPowerFromPipes = true; } - @Override - public int getLatency() { - return this.latency; + public PowerProvider(boolean canAcceptPowerFromPipes) { + this.canAcceptPowerFromPipes = canAcceptPowerFromPipes; } - @Override public int getMinEnergyReceived() { return this.minEnergyReceived; } - @Override public int getMaxEnergyReceived() { return this.maxEnergyReceived; } - @Override public int getMaxEnergyStored() { return this.maxEnergyStored; } - @Override public int getActivationEnergy() { return this.minActivationEnergy; } - @Override public float getEnergyStored() { return this.energyStored; } - @Override - public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) { - this.latency = latency; + public void configure(int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) { this.minEnergyReceived = minEnergyReceived; this.maxEnergyReceived = maxEnergyReceived; this.maxEnergyStored = maxStoredEnergy; this.minActivationEnergy = minActivationEnergy; } - @Override public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { this.powerLoss = powerLoss; this.powerLossRegularity = powerLossRegularity; } - @Override public boolean update(IPowerReceptor receptor) { - if (!preConditions(receptor)) - return false; - TileEntity tile = (TileEntity) receptor; boolean result = false; if (energyStored >= minActivationEnergy) { - if (latency == 0) { - receptor.doWork(); - result = true; - } else { - if (timeTracker.markTimeIfDelay(tile.worldObj, latency)) { - receptor.doWork(); - result = true; - } - } + receptor.doWork(this); + result = true; } if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) { @@ -118,12 +91,6 @@ public abstract class PowerProvider implements IPowerProvider { return result; } - @Override - public boolean preConditions(IPowerReceptor receptor) { - return true; - } - - @Override public float useEnergy(float min, float max, boolean doUse) { float result = 0; @@ -144,43 +111,42 @@ public abstract class PowerProvider implements IPowerProvider { return result; } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - latency = nbttagcompound.getInteger("latency"); - minEnergyReceived = nbttagcompound.getInteger("minEnergyReceived"); - maxEnergyReceived = nbttagcompound.getInteger("maxEnergyReceived"); - maxEnergyStored = nbttagcompound.getInteger("maxStoreEnergy"); - minActivationEnergy = nbttagcompound.getInteger("minActivationEnergy"); - - try { - energyStored = nbttagcompound.getFloat("storedEnergy"); - } catch (Throwable c) { - energyStored = 0; - } + public void readFromNBT(NBTTagCompound data) { + readFromNBT(data, "powerProvider"); } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - nbttagcompound.setInteger("latency", latency); - nbttagcompound.setInteger("minEnergyReceived", minEnergyReceived); - nbttagcompound.setInteger("maxEnergyReceived", maxEnergyReceived); - nbttagcompound.setInteger("maxStoreEnergy", maxEnergyStored); - nbttagcompound.setInteger("minActivationEnergy", minActivationEnergy); - nbttagcompound.setFloat("storedEnergy", energyStored); + public void readFromNBT(NBTTagCompound data, String tag) { + NBTTagCompound nbt = data.getCompoundTag(tag); + energyStored = nbt.getFloat("storedEnergy"); } - @Override - public void receiveEnergy(float quantity, ForgeDirection from) { + public void writeToNBT(NBTTagCompound data) { + writeToNBT(data, "powerProvider"); + } + + public void writeToNBT(NBTTagCompound data, String tag) { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setFloat("storedEnergy", energyStored); + data.setCompoundTag(tag, nbt); + } + + public int powerRequest() { + float needed = maxEnergyStored - energyStored; + return (int) Math.ceil(Math.min(maxEnergyReceived, needed)); + } + + public float receiveEnergy(float quantity, ForgeDirection from) { powerSources[from.ordinal()] = 2; energyStored += quantity; if (energyStored > maxEnergyStored) { + quantity -= energyStored - maxEnergyStored; energyStored = maxEnergyStored; } + return quantity; } - @Override public boolean isPowerSource(ForgeDirection from) { return powerSources[from.ordinal()] != 0; } diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 419565ed..d13e7da6 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -24,9 +24,8 @@ import buildcraft.BuildCraftBuilders; import buildcraft.api.core.LaserKind; import buildcraft.api.core.Position; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.core.BlockIndex; import buildcraft.core.Box; import buildcraft.core.DefaultProps; @@ -56,7 +55,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP public @TileNetworkData Box box = new Box(); - private IPowerProvider powerProvider; + private PowerProvider powerProvider; private LinkedList path; @@ -178,8 +177,8 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP public TileBuilder() { super(); - powerProvider = PowerFramework.currentFramework.createPowerProvider(); - powerProvider.configure(10, 25, 25, 25, 25); + powerProvider = new PowerProvider(); + powerProvider.configure(25, 25, 25, 25); } @Override @@ -272,7 +271,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; @@ -526,12 +525,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @@ -567,13 +561,13 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP } - @Override - public int powerRequest(ForgeDirection from) { - if ((bluePrintBuilder != null || currentPathIterator != null) && !done) - return powerProvider.getMaxEnergyReceived(); - else - return 0; - } +// @Override +// public int powerRequest(ForgeDirection from) { +// if ((bluePrintBuilder != null || currentPathIterator != null) && !done) +// return powerProvider.getMaxEnergyReceived(); +// else +// return 0; +// } @Override public void updateEntity() { diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index 9e05f2a6..986a700f 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -18,22 +18,21 @@ import buildcraft.api.filler.FillerManager; import buildcraft.api.filler.IFillerPattern; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.core.Box; import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.TileNetworkData; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.triggers.ActionMachineControl; import buildcraft.core.triggers.ActionMachineControl.Mode; import buildcraft.core.utils.Utils; -import buildcraft.factory.TileMachine; import net.minecraft.block.Block; import net.minecraft.inventory.ISidedInventory; -public class TileFiller extends TileMachine implements ISidedInventory, IPowerReceptor, IMachine, IActionReceptor { +public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowerReceptor, IMachine, IActionReceptor { private static int[] SLOTS_GRID = Utils.createSlotArray(0, 9); private static int[] SLOTS_INPUT = Utils.createSlotArray(9, 27); @@ -46,17 +45,17 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe public IFillerPattern currentPattern; boolean forceDone = false; private ItemStack contents[]; - IPowerProvider powerProvider; + PowerProvider powerProvider; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; public TileFiller() { contents = new ItemStack[getSizeInventory()]; - powerProvider = PowerFramework.currentFramework.createPowerProvider(); + powerProvider = new PowerProvider(); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(20, 25, 50, 25, 100); + powerProvider.configure(25, 50, 25, 100); powerProvider.configurePowerPerdition(1, 1); } @@ -96,12 +95,12 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe } if (powerProvider.getEnergyStored() >= 25) { - doWork(); + doWork(null); } } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; @@ -138,7 +137,7 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe } if (powerProvider.getEnergyStored() >= 25) { - doWork(); + doWork(null); } } @@ -323,12 +322,7 @@ public class TileFiller extends TileMachine implements ISidedInventory, IPowerRe } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } diff --git a/common/buildcraft/core/RedstonePowerFramework.java b/common/buildcraft/core/RedstonePowerFramework.java deleted file mode 100644 index 0ce95580..00000000 --- a/common/buildcraft/core/RedstonePowerFramework.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 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.core; - -import buildcraft.api.power.IPowerProvider; -import buildcraft.api.power.PowerFramework; - -public class RedstonePowerFramework extends PowerFramework { - - @Override - public IPowerProvider createPowerProvider() { - return new RedstonePowerProvider(); - } - -} diff --git a/common/buildcraft/core/RedstonePowerProvider.java b/common/buildcraft/core/RedstonePowerProvider.java deleted file mode 100644 index 717deac6..00000000 --- a/common/buildcraft/core/RedstonePowerProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.core; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import buildcraft.BuildCraftCore; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerProvider; - -public class RedstonePowerProvider extends PowerProvider { - - private boolean lastPower = false; - - public RedstonePowerProvider() { - this.powerLoss = 0; - this.powerLossRegularity = 0; - } - - @Override - public boolean preConditions(IPowerReceptor receptor) { - TileEntity tile = (TileEntity) receptor; - - boolean currentPower = tile.worldObj.isBlockIndirectlyGettingPowered(tile.xCoord, tile.yCoord, tile.zCoord); - - if (BuildCraftCore.continuousCurrentModel) { - if (currentPower) - return true; - } else if (currentPower != lastPower) { - lastPower = currentPower; - - if (currentPower) - return true; - } - - return false; - } - - @Override - public float useEnergy(float min, float max, boolean doUse) { - return min; - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - lastPower = nbttagcompound.getBoolean("lastPower"); - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - nbttagcompound.setBoolean("lastPower", lastPower); - } - - @Override - public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) { - super.configure(latency, minEnergyReceived, maxEnergyReceived, minActivationEnergy, maxStoredEnergy); - - this.minActivationEnergy = 0; - this.energyStored = 1; - } - - @Override - public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { - - } -} diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index d34a6edf..4d0591c3 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -59,7 +59,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized if (this instanceof IPowerReceptor) { IPowerReceptor receptor = ((IPowerReceptor) this); - receptor.getPowerProvider().update(receptor); + receptor.getPowerProvider(null).update(receptor); } } diff --git a/common/buildcraft/energy/PneumaticPowerFramework.java b/common/buildcraft/energy/PneumaticPowerFramework.java deleted file mode 100644 index a5b0256b..00000000 --- a/common/buildcraft/energy/PneumaticPowerFramework.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 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.energy; - -import buildcraft.api.power.IPowerProvider; -import buildcraft.api.power.PowerFramework; - -public class PneumaticPowerFramework extends PowerFramework { - - @Override - public IPowerProvider createPowerProvider() { - return new PneumaticPowerProvider(); - } - -} diff --git a/common/buildcraft/energy/PneumaticPowerProvider.java b/common/buildcraft/energy/PneumaticPowerProvider.java deleted file mode 100644 index 05aa46c3..00000000 --- a/common/buildcraft/energy/PneumaticPowerProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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.energy; - -import buildcraft.api.power.PowerProvider; - -public class PneumaticPowerProvider extends PowerProvider { - - @Override - public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) { - super.configure(latency, minEnergyReceived, maxEnergyReceived, minActivationEnergy, maxStoredEnergy); - - this.latency = 0; - } - -} diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 6a45608b..fdb83438 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -27,9 +27,7 @@ import buildcraft.BuildCraftEnergy; import buildcraft.api.core.Position; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipeConnection; import buildcraft.core.IBuilderInventory; @@ -56,12 +54,12 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven public int orientation; - IPowerProvider provider; + PowerProvider provider; public boolean isRedstonePowered = false; public TileEngine() { - provider = PowerFramework.currentFramework.createPowerProvider(); + provider = new PowerProvider(false); provider.configurePowerPerdition(1, 100); } @@ -73,7 +71,7 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven } engine.orientation = ForgeDirection.VALID_DIRECTIONS[orientation]; - provider.configure(0, engine.minEnergyReceived(), engine.maxEnergyReceived(), 1, engine.maxEnergy); + provider.configure(engine.minEnergyReceived(), engine.maxEnergyReceived(), 1, engine.maxEnergy); checkRedstonePower(); } } @@ -119,7 +117,7 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (isPoweredTile(tile)) { - IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(); + PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite()); float extracted = engine.extractEnergy(receptor.getMinEnergyReceived(), Math.min(receptor.getMaxEnergyReceived(), receptor.getMaxEnergyStored() - (int) receptor.getEnergyStored()), true); @@ -139,7 +137,7 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (isPoweredTile(tile)) { - IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(); + PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite()); if (engine.extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false) > 0) { progressPart = 1; @@ -359,17 +357,12 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven } @Override - public void setPowerProvider(IPowerProvider provider) { - this.provider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return provider; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (CoreProxy.proxy.isRenderWorld(worldObj)) return; @@ -378,9 +371,9 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven public boolean isPoweredTile(TileEntity tile) { if (tile instanceof IPowerReceptor) { - IPowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(); + PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite()); - return receptor != null && receptor.getClass().getSuperclass().equals(PowerProvider.class); + return receptor != null; } return false; @@ -396,11 +389,6 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven } - @Override - public int powerRequest(ForgeDirection from) { - return 0; - } - @Override public Engine getEngine() { return engine; diff --git a/common/buildcraft/factory/TileMachine.java b/common/buildcraft/factory/TileMachine.java deleted file mode 100644 index 1650a9e0..00000000 --- a/common/buildcraft/factory/TileMachine.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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.factory; - -import buildcraft.api.power.IPowerProvider; -import net.minecraftforge.common.ForgeDirection; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.core.IMachine; -import buildcraft.core.TileBuildCraft; - -public abstract class TileMachine extends TileBuildCraft implements IMachine, IPowerReceptor { - - @Override - public int powerRequest(ForgeDirection from) { - IPowerProvider p = getPowerProvider(); - float needed = p.getMaxEnergyStored() - p.getEnergyStored(); - return (int) Math.ceil(Math.min(p.getMaxEnergyReceived(), needed)); - } -} diff --git a/common/buildcraft/factory/TileMiningWell.java b/common/buildcraft/factory/TileMiningWell.java index a2731ce6..b942020f 100644 --- a/common/buildcraft/factory/TileMiningWell.java +++ b/common/buildcraft/factory/TileMiningWell.java @@ -16,22 +16,22 @@ import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipeConnection; import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; import buildcraft.core.utils.BlockUtil; import buildcraft.core.utils.Utils; -public class TileMiningWell extends TileMachine implements IMachine, IPowerReceptor, IPipeConnection { +public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerReceptor, IPipeConnection { boolean isDigging = true; - IPowerProvider powerProvider; + PowerProvider powerProvider; public TileMiningWell() { - powerProvider = PowerFramework.currentFramework.createPowerProvider(); - powerProvider.configure(50, 100, 100, 60, 1000); + powerProvider = new PowerProvider(); + powerProvider.configure(100, 100, 60, 1000); powerProvider.configurePowerPerdition(1, 1); } @@ -40,7 +40,7 @@ public class TileMiningWell extends TileMachine implements IMachine, IPowerRecep * bedrock, lava or goes below 0, it's considered done. */ @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (powerProvider.useEnergy(60, 60, true) != 60) return; @@ -114,12 +114,7 @@ public class TileMiningWell extends TileMachine implements IMachine, IPowerRecep } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index f7aa54bc..5e7ff4a7 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -26,18 +26,18 @@ import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; import buildcraft.api.core.Position; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.core.BlockIndex; import buildcraft.core.EntityBlock; import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; -public class TilePump extends TileMachine implements IMachine, IPowerReceptor, ITankContainer { +public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor, ITankContainer { public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME; EntityBlock tube; @@ -45,16 +45,16 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I LiquidTank tank; double tubeY = Double.NaN; int aimY = 0; - private IPowerProvider powerProvider; + private PowerProvider powerProvider; public TilePump() { - powerProvider = PowerFramework.currentFramework.createPowerProvider(); + powerProvider = new PowerProvider(); initPowerProvider(); tank = new LiquidTank(MAX_LIQUID); } private void initPowerProvider() { - powerProvider.configure(20, 1, 8, 10, 100); + powerProvider.configure(1, 8, 10, 100); powerProvider.configurePowerPerdition(1, 100); } @@ -286,7 +286,7 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I tubeY = nbttagcompound.getFloat("tubeY"); - PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); + powerProvider.readFromNBT(nbttagcompound); initPowerProvider(); } @@ -294,7 +294,7 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); + powerProvider.writeToNBT(nbttagcompound); if (tank.getLiquid() != null) { nbttagcompound.setTag("tank", tank.getLiquid().writeToNBT(new NBTTagCompound())); @@ -315,17 +315,12 @@ public class TilePump extends TileMachine implements IMachine, IPowerReceptor, I } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { } @Override diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index a96012fa..10dfdcf2 100755 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -27,15 +27,15 @@ import buildcraft.BuildCraftFactory; import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.LaserKind; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipeConnection; import buildcraft.core.Box; import buildcraft.core.DefaultAreaProvider; import buildcraft.core.EntityRobot; import buildcraft.core.IBuilderInventory; import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; import buildcraft.core.blueprints.BptBlueprint; import buildcraft.core.blueprints.BptBuilderBase; import buildcraft.core.blueprints.BptBuilderBlueprint; @@ -51,7 +51,7 @@ import com.google.common.collect.Sets; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; -public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, IPipeConnection, IBuilderInventory { +public class TileQuarry extends TileBuildCraft implements IMachine, IPowerReceptor, IPipeConnection, IBuilderInventory { public @TileNetworkData Box box = new Box(); @@ -68,17 +68,17 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, public EntityRobot builder; BptBuilderBase bluePrintBuilder; public EntityMechanicalArm arm; - public IPowerProvider powerProvider; + public PowerProvider powerProvider; boolean isDigging = false; public static final int MAX_ENERGY = 15000; public TileQuarry() { - powerProvider = PowerFramework.currentFramework.createPowerProvider(); + powerProvider = new PowerProvider(); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(20, 50, 100, 25, MAX_ENERGY); + powerProvider.configure(50, 100, 25, MAX_ENERGY); powerProvider.configurePowerPerdition(2, 1); } @@ -189,17 +189,15 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { } protected void buildFrame() { - powerProvider.configure(20, 50, 100, 25, MAX_ENERGY); + powerProvider.configure(50, 100, 25, MAX_ENERGY); if (powerProvider.useEnergy(25, 25, true) != 25) return; - powerProvider.getTimeTracker().markTime(worldObj); - if (builder == null) { builder = new EntityRobot(worldObj, box); worldObj.spawnEntityInWorld(builder); @@ -211,7 +209,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, } protected void dig() { - powerProvider.configure(20, 100, 500, 60, MAX_ENERGY); + powerProvider.configure(100, 500, 60, MAX_ENERGY); if (powerProvider.useEnergy(60, 60, true) != 60) return; @@ -336,7 +334,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); + powerProvider.readFromNBT(nbttagcompound); initPowerProvider(); if (nbttagcompound.hasKey("box")) { @@ -374,7 +372,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); + powerProvider.writeToNBT(nbttagcompound); nbttagcompound.setInteger("targetX", targetX); nbttagcompound.setInteger("targetY", targetY); @@ -402,7 +400,6 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, int blockId = worldObj.getBlockId(i, j, k); if (isQuarriableBlock(i, j, k)) { - powerProvider.getTimeTracker().markTime(worldObj); // Share this with mining well! @@ -666,14 +663,9 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, isDigging = true; } - @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - - } @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } diff --git a/common/buildcraft/factory/TileRefinery.java b/common/buildcraft/factory/TileRefinery.java index 94f4754f..4a690ef0 100644 --- a/common/buildcraft/factory/TileRefinery.java +++ b/common/buildcraft/factory/TileRefinery.java @@ -22,16 +22,16 @@ import net.minecraftforge.liquids.LiquidTank; import buildcraft.BuildCraftCore; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.api.recipes.RefineryRecipe; import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; -public class TileRefinery extends TileMachine implements ITankContainer, IPowerReceptor, IInventory, IMachine { +public class TileRefinery extends TileBuildCraft implements ITankContainer, IPowerReceptor, IInventory, IMachine { private int[] filters = new int[2]; private int[] filtersMeta = new int[2]; @@ -43,11 +43,11 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR private int animationStage = 0; SafeTimeTracker time = new SafeTimeTracker(); SafeTimeTracker updateNetworkTime = new SafeTimeTracker(); - IPowerProvider powerProvider; + PowerProvider powerProvider; private boolean isActive; public TileRefinery() { - powerProvider = PowerFramework.currentFramework.createPowerProvider(); + powerProvider = new PowerProvider(); initPowerProvider(); filters[0] = 0; @@ -57,7 +57,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR } private void initPowerProvider() { - powerProvider.configure(20, 25, 100, 25, 1000); + powerProvider.configure(25, 100, 25, 1000); powerProvider.configurePowerPerdition(1, 1); } @@ -106,17 +106,12 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { } @Override @@ -255,7 +250,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR animationStage = nbttagcompound.getInteger("animationStage"); animationSpeed = nbttagcompound.getFloat("animationSpeed"); - PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); + powerProvider.readFromNBT(nbttagcompound); initPowerProvider(); filters[0] = nbttagcompound.getInteger("filters_0"); @@ -282,7 +277,7 @@ public class TileRefinery extends TileMachine implements ITankContainer, IPowerR nbttagcompound.setInteger("animationStage", animationStage); nbttagcompound.setFloat("animationSpeed", animationSpeed); - PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); + powerProvider.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 735f13a2..9b223a45 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -17,35 +17,35 @@ import buildcraft.api.core.Position; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IAction; import buildcraft.api.gates.IActionReceptor; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.core.BlockIndex; import buildcraft.core.EntityEnergyLaser; +import buildcraft.core.IMachine; +import buildcraft.core.TileBuildCraft; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.triggers.ActionMachineControl; -import buildcraft.factory.TileMachine; -public class TileLaser extends TileMachine implements IPowerReceptor, IActionReceptor { +public class TileLaser extends TileBuildCraft implements IPowerReceptor, IActionReceptor, IMachine { private EntityEnergyLaser laser = null; private final SafeTimeTracker laserTickTracker = new SafeTimeTracker(); private final SafeTimeTracker searchTracker = new SafeTimeTracker(); private final SafeTimeTracker networkTracker = new SafeTimeTracker(); private ILaserTarget laserTarget; - public IPowerProvider powerProvider; + public PowerProvider powerProvider; private int nextNetworkUpdate = 3; private int nextLaserUpdate = 10; private int nextLaserSearch = 100; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; public TileLaser() { - powerProvider = PowerFramework.currentFramework.createPowerProvider(); + powerProvider = new PowerProvider(); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(20, 25, 25, 25, 1000); + powerProvider.configure(25, 25, 25, 1000); powerProvider.configurePowerPerdition(1, 1); } @@ -230,18 +230,14 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec } } + @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { } @Override @@ -255,7 +251,7 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - PowerFramework.currentFramework.loadPowerProvider(this, nbttagcompound); + powerProvider.readFromNBT(nbttagcompound); initPowerProvider(); } @@ -263,7 +259,7 @@ public class TileLaser extends TileMachine implements IPowerReceptor, IActionRec public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - PowerFramework.currentFramework.savePowerProvider(this, nbttagcompound); + powerProvider.writeToNBT(nbttagcompound); } @Override diff --git a/common/buildcraft/transport/EnergyPulser.java b/common/buildcraft/transport/EnergyPulser.java index 5f034c2c..ab177240 100644 --- a/common/buildcraft/transport/EnergyPulser.java +++ b/common/buildcraft/transport/EnergyPulser.java @@ -26,7 +26,7 @@ public class EnergyPulser { return; if (!singlePulse || !hasPulsed) { - powerReceptor.getPowerProvider().receiveEnergy(Math.min(1 << (pulseCount - 1), 64), ForgeDirection.WEST); + powerReceptor.getPowerProvider(null).receiveEnergy(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 66d288fa..e30243a5 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -13,8 +13,8 @@ import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftCore; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.ITrigger; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerProvider; import buildcraft.core.DefaultProps; import buildcraft.core.IMachine; import buildcraft.core.proxy.CoreProxy; @@ -141,14 +141,12 @@ public class PipeTransportPower extends PipeTransport { internalPower[i] -= watts; } else if (tiles[j] instanceof IPowerReceptor) { IPowerReceptor pow = (IPowerReceptor) tiles[j]; - if (pow.powerRequest(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()) > 0) { - watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); - IPowerProvider prov = pow.getPowerProvider(); + PowerProvider prov = pow.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); - if (prov != null) { - prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); - internalPower[i] -= watts; - } + if (prov != null && prov.canAcceptPowerFromPipes && prov.powerRequest() > 0) { + watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); + prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); + internalPower[i] -= watts; } } @@ -180,10 +178,13 @@ 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]; - int request = receptor.powerRequest(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); + PowerProvider prov = receptor.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); + if (prov != null && prov.canAcceptPowerFromPipes) { + int request = prov.powerRequest(); - if (request > 0) { - requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request); + if (request > 0) { + requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request); + } } } } diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index f2fa39e1..98a94f0f 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -31,8 +31,8 @@ import buildcraft.api.core.Position; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeEntry; @@ -189,7 +189,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank refreshRenderState = false; } - IPowerProvider provider = getPowerProvider(); + PowerProvider provider = getPowerProvider(null); if (provider != null) { provider.update(this); @@ -329,25 +329,17 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank } @Override - public void setPowerProvider(IPowerProvider provider) { - if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { - ((IPowerReceptor) pipe).setPowerProvider(provider); - } - - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) - return ((IPowerReceptor) pipe).getPowerProvider(); + return ((IPowerReceptor) pipe).getPowerProvider(null); else return null; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { - ((IPowerReceptor) pipe).doWork(); + ((IPowerReceptor) pipe).doWork(null); } } @@ -422,13 +414,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank return packet.getPacket(); } - @Override - public int powerRequest(ForgeDirection from) { - if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) - return ((IPowerReceptor) pipe).powerRequest(from); - return 0; - } - @Override public LinkedList getTriggers() { LinkedList result = new LinkedList(); diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index 44ffb90d..b1bfe351 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) getPowerProvider().getEnergyStored()); + ItemStack[] stacks = ((ISelectiveInventory) inventory).extractItem(new ItemStack[]{getCurrentFilter()}, false, doRemove, from, (int) powerProvider.getEnergyStored()); if (doRemove) { for (ItemStack stack : stacks) { if (stack != null) { - getPowerProvider().useEnergy(stack.stackSize, stack.stackSize, true); + powerProvider.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) getPowerProvider().getEnergyStored()); + ItemStack[] stacks = ((ISpecialInventory) inventory).extractItem(false, from, (int) powerProvider.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) getPowerProvider().getEnergyStored()); + stacks = ((ISpecialInventory) inventory).extractItem(true, from, (int) powerProvider.getEnergyStored()); for (ItemStack stack : stacks) { if (stack != null) { - getPowerProvider().useEnergy(stack.stackSize, stack.stackSize, true); + powerProvider.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) getPowerProvider().useEnergy(1, stack.stackSize, true)); + return inventory.decrStackSize(i, (int) powerProvider.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 fa2f20bc..a8e871c0 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -22,9 +22,8 @@ import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipedItem; import buildcraft.core.EntityPassiveItem; import buildcraft.core.proxy.CoreProxy; @@ -37,7 +36,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeItemsObsidian extends Pipe implements IPowerReceptor { - private IPowerProvider powerProvider; + private PowerProvider powerProvider; private int[] entitiesDropped; private int entitiesDroppedIndex = 0; @@ -51,8 +50,8 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { entitiesDropped[i] = -1; } - powerProvider = PowerFramework.currentFramework.createPowerProvider(); - powerProvider.configure(25, 1, 64, 1, 256); + powerProvider = new PowerProvider(); + powerProvider.configure(1, 64, 1, 256); powerProvider.configurePowerPerdition(1, 1); } @@ -145,7 +144,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { for (int j = 1; j < 5; ++j) if (trySucc(j)) return; @@ -285,17 +284,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } - - @Override - public int powerRequest(ForgeDirection from) { - return getPowerProvider().getMaxEnergyReceived(); - } } diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 6283c140..28d672b5 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -17,13 +17,11 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; import buildcraft.api.inventory.ISpecialInventory; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipedItem; import buildcraft.api.transport.PipeManager; import buildcraft.core.EntityPassiveItem; -import buildcraft.core.RedstonePowerFramework; import buildcraft.core.inventory.InventoryWrapper; import buildcraft.core.utils.Utils; import buildcraft.transport.Pipe; @@ -34,15 +32,15 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeItemsWood extends Pipe implements IPowerReceptor { - private IPowerProvider powerProvider; + protected PowerProvider powerProvider; protected int standardIconIndex = PipeIconProvider.PipeItemsWood_Standard; protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; protected PipeItemsWood(PipeTransportItems transport, PipeLogic logic, int itemID) { super(transport, logic, itemID); - powerProvider = PowerFramework.currentFramework.createPowerProvider(); - powerProvider.configure(50, 1, 64, 1, 64); + powerProvider = new PowerProvider(false); + powerProvider.configure(1, 64, 1, 64); powerProvider.configurePowerPerdition(64, 1); } @@ -75,17 +73,12 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (powerProvider.getEnergyStored() <= 0) return; @@ -177,16 +170,4 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { return null; } - - @Override - public int powerRequest(ForgeDirection from) { - return getPowerProvider().getMaxEnergyReceived(); - } - - @Override - public boolean canConnectRedstone() { - if (PowerFramework.currentFramework instanceof RedstonePowerFramework) - return true; - return super.canConnectRedstone(); - } } diff --git a/common/buildcraft/transport/pipes/PipeLiquidsWood.java b/common/buildcraft/transport/pipes/PipeLiquidsWood.java index c670f551..b7eec1ed 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsWood.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsWood.java @@ -17,11 +17,9 @@ import net.minecraftforge.liquids.LiquidStack; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.PipeManager; -import buildcraft.core.RedstonePowerFramework; import buildcraft.core.network.TileNetworkData; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; @@ -34,7 +32,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { public @TileNetworkData int liquidToExtract; - private IPowerProvider powerProvider; + private PowerProvider powerProvider; protected int standardIconIndex = PipeIconProvider.PipeLiquidsWood_Standard; protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; @@ -49,8 +47,8 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { protected PipeLiquidsWood(PipeLogic logic, int itemID) { super(new PipeTransportLiquids(), logic, itemID); - powerProvider = PowerFramework.currentFramework.createPowerProvider(); - powerProvider.configure(50, 1, 100, 1, 250); + powerProvider = new PowerProvider(false); + powerProvider.configure(1, 100, 1, 250); powerProvider.configurePowerPerdition(1, 1); } @@ -58,7 +56,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { * Extracts a random piece of item outside of a nearby chest. */ @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { if (powerProvider.getEnergyStored() <= 0) return; @@ -84,12 +82,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { } @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } - - @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @@ -143,16 +136,4 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { return standardIconIndex; } } - - @Override - public int powerRequest(ForgeDirection from) { - return getPowerProvider().getMaxEnergyReceived(); - } - - @Override - public boolean canConnectRedstone() { - if (PowerFramework.currentFramework instanceof RedstonePowerFramework) - return true; - return super.canConnectRedstone(); - } } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index a75465c6..745d6a46 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -10,9 +10,8 @@ package buildcraft.transport.pipes; import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; -import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerFramework; +import buildcraft.api.power.PowerProvider; import buildcraft.core.utils.Utils; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; @@ -25,7 +24,7 @@ import net.minecraft.tileentity.TileEntity; public class PipePowerWood extends Pipe implements IPowerReceptor { - private IPowerProvider powerProvider; + private PowerProvider powerProvider; protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard; protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; private boolean[] powerSources = new boolean[6]; @@ -34,13 +33,13 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { public PipePowerWood(int itemID) { super(new PipeTransportPower(), new PipeLogicWood(), itemID); - powerProvider = PowerFramework.currentFramework.createPowerProvider(); + powerProvider = new PowerProvider(false); initPowerProvider(); ((PipeTransportPower) transport).initFromPipe(getClass()); } private void initPowerProvider() { - powerProvider.configure(50, 2, 1000, 1, 1500); + powerProvider.configure(2, 1000, 1, 1500); powerProvider.configurePowerPerdition(1, 10); } @@ -64,18 +63,14 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { } } - @Override - public void setPowerProvider(IPowerProvider provider) { - powerProvider = provider; - } @Override - public IPowerProvider getPowerProvider() { + public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; } @Override - public void doWork() { + public void doWork(PowerProvider workProvider) { // TODO Auto-generated method stub } @@ -143,10 +138,6 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { return !full; } - @Override - public int powerRequest(ForgeDirection from) { - return getPowerProvider().getMaxEnergyReceived(); - } @Override public void writeToNBT(NBTTagCompound data) { @@ -157,7 +148,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); - PowerFramework.currentFramework.loadPowerProvider(this, data); + powerProvider.readFromNBT(data); initPowerProvider(); } } From 8d1b33b268b232d12c24b6c638214f60581b5394 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 01:29:11 -0700 Subject: [PATCH 02/29] Pipes won't connect to a receptor with no provider And a tweak to powerRequest() --- common/buildcraft/api/power/PowerProvider.java | 5 ++--- common/buildcraft/transport/IPipeTransportPowerHook.java | 2 +- common/buildcraft/transport/PipeTransportPower.java | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index 72f1cd32..a905d0cc 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -130,9 +130,8 @@ public final class PowerProvider { data.setCompoundTag(tag, nbt); } - public int powerRequest() { - float needed = maxEnergyStored - energyStored; - return (int) Math.ceil(Math.min(maxEnergyReceived, needed)); + public float powerRequest() { + return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); } public float receiveEnergy(float quantity, ForgeDirection from) { diff --git a/common/buildcraft/transport/IPipeTransportPowerHook.java b/common/buildcraft/transport/IPipeTransportPowerHook.java index 0bd9393f..48cae72e 100644 --- a/common/buildcraft/transport/IPipeTransportPowerHook.java +++ b/common/buildcraft/transport/IPipeTransportPowerHook.java @@ -15,5 +15,5 @@ public interface IPipeTransportPowerHook { public double receiveEnergy(ForgeDirection from, double val); - public void requestEnergy(ForgeDirection from, int i); + public void requestEnergy(ForgeDirection from, float amount); } diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index e30243a5..44e129b3 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -70,9 +70,10 @@ public class PipeTransportPower extends PipeTransport { Pipe pipe2 = ((TileGenericPipe) tile).pipe; if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportPower)) return false; + return true; } - return tile instanceof TileGenericPipe || tile instanceof IMachine || tile instanceof IPowerReceptor; + return tile instanceof IPowerReceptor && ((IPowerReceptor)tile).getPowerProvider(side) != null; } @Override @@ -180,7 +181,7 @@ public class PipeTransportPower extends PipeTransport { IPowerReceptor receptor = (IPowerReceptor) tiles[i]; PowerProvider prov = receptor.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); if (prov != null && prov.canAcceptPowerFromPipes) { - int request = prov.powerRequest(); + float request = prov.powerRequest(); if (request > 0) { requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request); @@ -284,7 +285,7 @@ public class PipeTransportPower extends PipeTransport { return val; } - public void requestEnergy(ForgeDirection from, int amount) { + public void requestEnergy(ForgeDirection from, float amount) { step(); if (this.container.pipe instanceof IPipeTransportPowerHook) { ((IPipeTransportPowerHook) this.container.pipe).requestEnergy(from, amount); From 4f6ba954cd734ac94a8a83236d34c31a2ba2c192 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 05:23:41 -0700 Subject: [PATCH 03/29] Better connection rules --- common/buildcraft/transport/PipeTransportPower.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 44e129b3..9b094529 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -73,7 +73,16 @@ public class PipeTransportPower extends PipeTransport { return true; } - return tile instanceof IPowerReceptor && ((IPowerReceptor)tile).getPowerProvider(side) != null; + if (tile instanceof IPowerReceptor) { + IPowerReceptor receptor = (IPowerReceptor) tile; + PowerProvider provider = receptor.getPowerProvider(side.getOpposite()); + if (provider == null) + return false; + if (container.pipe instanceof PipePowerWood || provider.canAcceptPowerFromPipes) + return true; + } + + return false; } @Override From 013fe4ecb4a2ceee8a74b4d0eab2795faab39cab Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 19:46:07 -0700 Subject: [PATCH 04/29] Possible Tickless compatible system PowerProvider doWork() callback is now handled in receiveEnergy() as well as in the tick update. So you can respond more effectively even if you don't want to tick. --- .../buildcraft/api/power/PowerProvider.java | 68 +++++++++++-------- common/buildcraft/builders/TileBuilder.java | 2 +- common/buildcraft/builders/TileFiller.java | 2 +- common/buildcraft/energy/TileEngine.java | 2 +- common/buildcraft/factory/TileMiningWell.java | 2 +- common/buildcraft/factory/TilePump.java | 2 +- common/buildcraft/factory/TileQuarry.java | 2 +- common/buildcraft/factory/TileRefinery.java | 2 +- common/buildcraft/silicon/TileLaser.java | 2 +- .../transport/pipes/PipeItemsObsidian.java | 2 +- .../transport/pipes/PipeItemsWood.java | 2 +- .../transport/pipes/PipeLiquidsWood.java | 2 +- .../transport/pipes/PipePowerWood.java | 11 +-- 13 files changed, 55 insertions(+), 46 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index a905d0cc..b69136f1 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -14,23 +14,26 @@ import buildcraft.api.core.SafeTimeTracker; public final class PowerProvider { - protected int minEnergyReceived; - protected int maxEnergyReceived; - protected int maxEnergyStored; - protected int minActivationEnergy; - protected float energyStored = 0; - protected int powerLoss = 1; - protected int powerLossRegularity = 1; + private int minEnergyReceived; + private int maxEnergyReceived; + private int maxEnergyStored; + private int minActivationEnergy; + private float energyStored = 0; + private int powerLoss = 1; + private int powerLossRegularity = 1; public final boolean canAcceptPowerFromPipes; - public SafeTimeTracker energyLossTracker = new SafeTimeTracker(); - public int[] powerSources = {0, 0, 0, 0, 0, 0}; + private SafeTimeTracker energyLossTracker = new SafeTimeTracker(); + private SafeTimeTracker doWorkTracker = new SafeTimeTracker(); + public final int[] powerSources = {0, 0, 0, 0, 0, 0}; + private final IPowerReceptor receptor; - public PowerProvider() { - this.canAcceptPowerFromPipes = true; + public PowerProvider(IPowerReceptor receptor) { + this(receptor, true); } - public PowerProvider(boolean canAcceptPowerFromPipes) { + public PowerProvider(IPowerReceptor receptor, boolean canAcceptPowerFromPipes) { this.canAcceptPowerFromPipes = canAcceptPowerFromPipes; + this.receptor = receptor; } public int getMinEnergyReceived() { @@ -66,21 +69,9 @@ public final class PowerProvider { } public boolean update(IPowerReceptor receptor) { - TileEntity tile = (TileEntity) receptor; - boolean result = false; + applyPerdition(); - if (energyStored >= minActivationEnergy) { - receptor.doWork(this); - result = true; - } - - if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) { - - energyStored -= powerLoss; - if (energyStored < 0) { - energyStored = 0; - } - } + boolean work = applyWork(); for (int i = 0; i < 6; ++i) { if (powerSources[i] > 0) { @@ -88,7 +79,26 @@ public final class PowerProvider { } } - return result; + return work; + } + + private void applyPerdition() { + TileEntity tile = (TileEntity) receptor; + if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) { + energyStored -= powerLoss; + if (energyStored < 0) { + energyStored = 0; + } + } + } + + private boolean applyWork() { + TileEntity tile = (TileEntity) receptor; + if (energyStored >= minActivationEnergy && doWorkTracker.markTimeIfDelay(tile.worldObj, 1)) { + receptor.doWork(this); + return true; + } + return false; } public float useEnergy(float min, float max, boolean doUse) { @@ -143,6 +153,10 @@ public final class PowerProvider { quantity -= energyStored - maxEnergyStored; energyStored = maxEnergyStored; } + + applyPerdition(); + applyWork(); + return quantity; } diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index d13e7da6..734dc38e 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -177,7 +177,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP public TileBuilder() { super(); - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); powerProvider.configure(25, 25, 25, 25); } diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index 986a700f..5e43903e 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -50,7 +50,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe public TileFiller() { contents = new ItemStack[getSizeInventory()]; - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); initPowerProvider(); } diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index fdb83438..9067d1b2 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -59,7 +59,7 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven public boolean isRedstonePowered = false; public TileEngine() { - provider = new PowerProvider(false); + provider = new PowerProvider(this, false); provider.configurePowerPerdition(1, 100); } diff --git a/common/buildcraft/factory/TileMiningWell.java b/common/buildcraft/factory/TileMiningWell.java index b942020f..2230f92f 100644 --- a/common/buildcraft/factory/TileMiningWell.java +++ b/common/buildcraft/factory/TileMiningWell.java @@ -30,7 +30,7 @@ public class TileMiningWell extends TileBuildCraft implements IMachine, IPowerRe PowerProvider powerProvider; public TileMiningWell() { - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); powerProvider.configure(100, 100, 60, 1000); powerProvider.configurePowerPerdition(1, 1); } diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index 5e7ff4a7..ef234b18 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -48,7 +48,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor private PowerProvider powerProvider; public TilePump() { - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); initPowerProvider(); tank = new LiquidTank(MAX_LIQUID); } diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index 10dfdcf2..989355ee 100755 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -73,7 +73,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept public static final int MAX_ENERGY = 15000; public TileQuarry() { - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); initPowerProvider(); } diff --git a/common/buildcraft/factory/TileRefinery.java b/common/buildcraft/factory/TileRefinery.java index 4a690ef0..d5a9e223 100644 --- a/common/buildcraft/factory/TileRefinery.java +++ b/common/buildcraft/factory/TileRefinery.java @@ -47,7 +47,7 @@ public class TileRefinery extends TileBuildCraft implements ITankContainer, IPow private boolean isActive; public TileRefinery() { - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); initPowerProvider(); filters[0] = 0; diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index 9b223a45..76b3f3ec 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -40,7 +40,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; public TileLaser() { - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); initPowerProvider(); } diff --git a/common/buildcraft/transport/pipes/PipeItemsObsidian.java b/common/buildcraft/transport/pipes/PipeItemsObsidian.java index a8e871c0..de173bf9 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -50,7 +50,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { entitiesDropped[i] = -1; } - powerProvider = new PowerProvider(); + powerProvider = new PowerProvider(this); powerProvider.configure(1, 64, 1, 256); powerProvider.configurePowerPerdition(1, 1); } diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 28d672b5..17c0fef7 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -39,7 +39,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { protected PipeItemsWood(PipeTransportItems transport, PipeLogic logic, int itemID) { super(transport, logic, itemID); - powerProvider = new PowerProvider(false); + powerProvider = new PowerProvider(this, false); powerProvider.configure(1, 64, 1, 64); powerProvider.configurePowerPerdition(64, 1); } diff --git a/common/buildcraft/transport/pipes/PipeLiquidsWood.java b/common/buildcraft/transport/pipes/PipeLiquidsWood.java index b7eec1ed..7ada3d95 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsWood.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsWood.java @@ -47,7 +47,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { protected PipeLiquidsWood(PipeLogic logic, int itemID) { super(new PipeTransportLiquids(), logic, itemID); - powerProvider = new PowerProvider(false); + powerProvider = new PowerProvider(this, false); powerProvider.configure(1, 100, 1, 250); powerProvider.configurePowerPerdition(1, 1); } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 745d6a46..4cb69a56 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -12,15 +12,12 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerProvider; -import buildcraft.core.utils.Utils; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportPower; -import buildcraft.transport.TileGenericPipe; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; public class PipePowerWood extends Pipe implements IPowerReceptor { @@ -33,7 +30,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { public PipePowerWood(int itemID) { super(new PipeTransportPower(), new PipeLogicWood(), itemID); - powerProvider = new PowerProvider(false); + powerProvider = new PowerProvider(this, false); initPowerProvider(); ((PipeTransportPower) transport).initFromPipe(getClass()); } @@ -63,7 +60,6 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { } } - @Override public PowerProvider getPowerProvider(ForgeDirection side) { return powerProvider; @@ -96,10 +92,10 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { sources++; } } - + if (sources <= 0) return; - + float energyToRemove; if (powerProvider.getEnergyStored() > 40) { @@ -138,7 +134,6 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { return !full; } - @Override public void writeToNBT(NBTTagCompound data) { super.writeToNBT(data); From 475d6cd2f556e7d247c61db555af34e9a84ade32 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 20:08:22 -0700 Subject: [PATCH 05/29] Make receptor public --- common/buildcraft/api/power/PowerProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index b69136f1..d738d1fa 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -25,7 +25,7 @@ public final class PowerProvider { private SafeTimeTracker energyLossTracker = new SafeTimeTracker(); private SafeTimeTracker doWorkTracker = new SafeTimeTracker(); public final int[] powerSources = {0, 0, 0, 0, 0, 0}; - private final IPowerReceptor receptor; + public final IPowerReceptor receptor; public PowerProvider(IPowerReceptor receptor) { this(receptor, true); From 73aa6260a623f8e4014c4f28bc5081d8fcec87fe Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 20:21:01 -0700 Subject: [PATCH 06/29] Removed update return value, meaningless, unused --- common/buildcraft/api/power/PowerProvider.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index d738d1fa..f8a42356 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -68,18 +68,15 @@ public final class PowerProvider { this.powerLossRegularity = powerLossRegularity; } - public boolean update(IPowerReceptor receptor) { + public void update(IPowerReceptor receptor) { applyPerdition(); - - boolean work = applyWork(); + applyWork(); for (int i = 0; i < 6; ++i) { if (powerSources[i] > 0) { powerSources[i]--; } } - - return work; } private void applyPerdition() { @@ -92,13 +89,11 @@ public final class PowerProvider { } } - private boolean applyWork() { + private void applyWork() { TileEntity tile = (TileEntity) receptor; if (energyStored >= minActivationEnergy && doWorkTracker.markTimeIfDelay(tile.worldObj, 1)) { receptor.doWork(this); - return true; } - return false; } public float useEnergy(float min, float max, boolean doUse) { From 2d281c56d1a8f992a9a97081a06787963029780e Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 20:25:03 -0700 Subject: [PATCH 07/29] Opts --- .../buildcraft/api/power/PowerProvider.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index f8a42356..947cc4a5 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -80,19 +80,23 @@ public final class PowerProvider { } private void applyPerdition() { - TileEntity tile = (TileEntity) receptor; - if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) { - energyStored -= powerLoss; - if (energyStored < 0) { - energyStored = 0; + if (powerLoss > 0) { + TileEntity tile = (TileEntity) receptor; + if (energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) { + energyStored -= powerLoss; + if (energyStored < 0) { + energyStored = 0; + } } } } private void applyWork() { - TileEntity tile = (TileEntity) receptor; - if (energyStored >= minActivationEnergy && doWorkTracker.markTimeIfDelay(tile.worldObj, 1)) { - receptor.doWork(this); + if (energyStored >= minActivationEnergy) { + TileEntity tile = (TileEntity) receptor; + if (doWorkTracker.markTimeIfDelay(tile.worldObj, 1)) { + receptor.doWork(this); + } } } From 91a3ac95c67260bcf53da76b55baf64dbcb7254a Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 25 Jun 2013 20:54:21 -0700 Subject: [PATCH 08/29] Don't need to pass receptor, already have it --- common/buildcraft/api/power/PowerProvider.java | 2 +- common/buildcraft/core/TileBuildCraft.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index 947cc4a5..ae6d2cb3 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -68,7 +68,7 @@ public final class PowerProvider { this.powerLossRegularity = powerLossRegularity; } - public void update(IPowerReceptor receptor) { + public void update() { applyPerdition(); applyWork(); diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 4d0591c3..53745f3e 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -58,8 +58,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized if (this instanceof IPowerReceptor) { IPowerReceptor receptor = ((IPowerReceptor) this); - - receptor.getPowerProvider(null).update(receptor); + receptor.getPowerProvider(null).update(); } } From b92c81f63819e423559d141100e89cc91984988a Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 26 Jun 2013 07:26:07 -0700 Subject: [PATCH 09/29] Changes for KL and cpw Added set/add for KL Added perdition calculator for cpw --- .../buildcraft/api/power/PowerProvider.java | 89 +++++++++++++++---- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index ae6d2cb3..9f3905ac 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -14,18 +14,42 @@ import buildcraft.api.core.SafeTimeTracker; public final class PowerProvider { + public static class PerditionCalculator { + + protected SafeTimeTracker energyLossTracker = new SafeTimeTracker(); + private final float powerLoss; + + public PerditionCalculator() { + powerLoss = 10; + } + + public PerditionCalculator(float powerLoss) { + if (powerLoss < 0) { + powerLoss = 10; + } + this.powerLoss = powerLoss; + } + + public float applyPerdition(PowerProvider provider, float current) { + current -= powerLoss; + if (current < 0) { + current = 0; + } + return current; + } + } + public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator(10); private int minEnergyReceived; private int maxEnergyReceived; private int maxEnergyStored; private int minActivationEnergy; private float energyStored = 0; - private int powerLoss = 1; - private int powerLossRegularity = 1; public final boolean canAcceptPowerFromPipes; - private SafeTimeTracker energyLossTracker = new SafeTimeTracker(); private SafeTimeTracker doWorkTracker = new SafeTimeTracker(); + private SafeTimeTracker energyLossTracker = new SafeTimeTracker(); public final int[] powerSources = {0, 0, 0, 0, 0, 0}; public final IPowerReceptor receptor; + private PerditionCalculator perdition; public PowerProvider(IPowerReceptor receptor) { this(receptor, true); @@ -63,11 +87,6 @@ public final class PowerProvider { this.minActivationEnergy = minActivationEnergy; } - public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { - this.powerLoss = powerLoss; - this.powerLossRegularity = powerLossRegularity; - } - public void update() { applyPerdition(); applyWork(); @@ -79,13 +98,32 @@ public final class PowerProvider { } } + public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { + if (powerLossRegularity == 0) { + return; + } + perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity * 10.0F); + } + + public void setPerdition(PerditionCalculator perdition) { + this.perdition = perdition; + } + + public PerditionCalculator getPerdition() { + if (perdition == null) + return DEFUALT_PERDITION; + return perdition; + } + private void applyPerdition() { - if (powerLoss > 0) { + if (energyStored > 0) { TileEntity tile = (TileEntity) receptor; - if (energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) { - energyStored -= powerLoss; - if (energyStored < 0) { - energyStored = 0; + if (energyLossTracker.markTimeIfDelay(tile.worldObj, 10)) { + float newEnergy = getPerdition().applyPerdition(this, energyStored); + if (newEnergy == 0 || newEnergy < energyStored) { + energyStored = newEnergy; + } else { + energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored); } } } @@ -144,21 +182,42 @@ public final class PowerProvider { } public float receiveEnergy(float quantity, ForgeDirection from) { - powerSources[from.ordinal()] = 2; + if (from != null) + powerSources[from.ordinal()] = 2; + quantity = addEnergy(quantity); + applyWork(); + + return quantity; + } + + /** + * Internal use only you should NEVER call this function on a PowerProvider + * you don't own. + */ + public float addEnergy(float quantity) { energyStored += quantity; if (energyStored > maxEnergyStored) { quantity -= energyStored - maxEnergyStored; energyStored = maxEnergyStored; + } else if (energyStored < 0) { + energyStored = 0; } applyPerdition(); - applyWork(); return quantity; } + /** + * Internal use only you should NEVER call this function on a PowerProvider + * you don't own. + */ + public void setEnergy(float energy) { + this.energyStored = energy; + } + public boolean isPowerSource(ForgeDirection from) { return powerSources[from.ordinal()] != 0; } From 2b5dc5c9ff9ba0a1a8bbe559d183dd0ec73c6727 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 26 Jun 2013 07:29:32 -0700 Subject: [PATCH 10/29] Minor stuff --- common/buildcraft/api/power/PowerProvider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index 9f3905ac..6362431f 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -16,7 +16,7 @@ public final class PowerProvider { public static class PerditionCalculator { - protected SafeTimeTracker energyLossTracker = new SafeTimeTracker(); + protected final SafeTimeTracker energyLossTracker = new SafeTimeTracker(); private final float powerLoss; public PerditionCalculator() { @@ -45,8 +45,8 @@ public final class PowerProvider { private int minActivationEnergy; private float energyStored = 0; public final boolean canAcceptPowerFromPipes; - private SafeTimeTracker doWorkTracker = new SafeTimeTracker(); - private SafeTimeTracker energyLossTracker = new SafeTimeTracker(); + private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); + private final SafeTimeTracker energyLossTracker = new SafeTimeTracker(); public final int[] powerSources = {0, 0, 0, 0, 0, 0}; public final IPowerReceptor receptor; private PerditionCalculator perdition; From fe6d2e6b3a7c656dee68dec65b9d61d614c2180d Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 26 Jun 2013 08:02:05 -0700 Subject: [PATCH 11/29] Add some Javadocs --- .../buildcraft/api/power/PowerProvider.java | 59 ++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index 6362431f..c10b99ca 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -16,16 +16,17 @@ public final class PowerProvider { public static class PerditionCalculator { + public static final float DEFAULT = 10F; protected final SafeTimeTracker energyLossTracker = new SafeTimeTracker(); private final float powerLoss; public PerditionCalculator() { - powerLoss = 10; + powerLoss = DEFAULT; } public PerditionCalculator(float powerLoss) { if (powerLoss < 0) { - powerLoss = 10; + powerLoss = DEFAULT; } this.powerLoss = powerLoss; } @@ -38,11 +39,11 @@ public final class PowerProvider { return current; } } - public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator(10); + public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator(); private int minEnergyReceived; private int maxEnergyReceived; private int maxEnergyStored; - private int minActivationEnergy; + private int activationEnergy; private float energyStored = 0; public final boolean canAcceptPowerFromPipes; private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); @@ -73,18 +74,39 @@ public final class PowerProvider { } public int getActivationEnergy() { - return this.minActivationEnergy; + return this.activationEnergy; } public float getEnergyStored() { return this.energyStored; } - public void configure(int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) { + /** + * Setup your PowerProvider'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 + * 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 + * 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 + * store. Values tend to range between 100 and 5000. With 1000 and 1500 + * being common. + */ + public void configure(int minEnergyReceived, int maxEnergyReceived, int activationEnergy, int maxStoredEnergy) { + if (minEnergyReceived > maxEnergyReceived) { + maxEnergyReceived = minEnergyReceived; + } this.minEnergyReceived = minEnergyReceived; this.maxEnergyReceived = maxEnergyReceived; this.maxEnergyStored = maxStoredEnergy; - this.minActivationEnergy = minActivationEnergy; + this.activationEnergy = activationEnergy; } public void update() { @@ -130,7 +152,7 @@ public final class PowerProvider { } private void applyWork() { - if (energyStored >= minActivationEnergy) { + if (energyStored >= activationEnergy) { TileEntity tile = (TileEntity) receptor; if (doWorkTracker.markTimeIfDelay(tile.worldObj, 1)) { receptor.doWork(this); @@ -177,11 +199,29 @@ 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); } + /** + * 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) { + if (quantity < minEnergyReceived) { + return 0; + } + if (quantity > maxEnergyReceived) { + quantity -= quantity - maxEnergyReceived; + } if (from != null) powerSources[from.ordinal()] = 2; @@ -194,6 +234,8 @@ public final class PowerProvider { /** * Internal use only you should NEVER call this function on a PowerProvider * you don't own. + * + * @return the amount the power changed by */ public float addEnergy(float quantity) { energyStored += quantity; @@ -202,6 +244,7 @@ public final class PowerProvider { quantity -= energyStored - maxEnergyStored; energyStored = maxEnergyStored; } else if (energyStored < 0) { + quantity -= energyStored; energyStored = 0; } From 080a4d6ca44b023a287610a2be7b594849bf61e8 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 26 Jun 2013 08:22:19 -0700 Subject: [PATCH 12/29] Added bounds checks for set --- common/buildcraft/api/power/PowerProvider.java | 9 +++++++-- common/buildcraft/transport/TileGenericPipe.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index c10b99ca..bb1cc69b 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -257,8 +257,13 @@ public final class PowerProvider { * Internal use only you should NEVER call this function on a PowerProvider * you don't own. */ - public void setEnergy(float energy) { - this.energyStored = energy; + public void setEnergy(float quantity) { + this.energyStored = quantity; + if (energyStored > maxEnergyStored) { + energyStored = maxEnergyStored; + } else if (energyStored < 0) { + energyStored = 0; + } } public boolean isPowerSource(ForgeDirection from) { diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 98a94f0f..5cd5b692 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -192,7 +192,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank PowerProvider provider = getPowerProvider(null); if (provider != null) { - provider.update(this); + provider.update(); } if (pipe != null) { From 1d7e160d2fa8fa169db8bcf2c7955dc9a60f2841 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 26 Jun 2013 08:35:34 -0700 Subject: [PATCH 13/29] Some cleanup --- .../buildcraft/api/power/PowerProvider.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index bb1cc69b..cba8a105 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -16,17 +16,18 @@ public final class PowerProvider { public static class PerditionCalculator { - public static final float DEFAULT = 10F; + public static final float DEFAULT_POWERLOSS = 10F; + public static final float MIN_POWERLOSS = 0.01F; protected final SafeTimeTracker energyLossTracker = new SafeTimeTracker(); private final float powerLoss; public PerditionCalculator() { - powerLoss = DEFAULT; + powerLoss = DEFAULT_POWERLOSS; } public PerditionCalculator(float powerLoss) { - if (powerLoss < 0) { - powerLoss = DEFAULT; + if (powerLoss < MIN_POWERLOSS) { + powerLoss = MIN_POWERLOSS; } this.powerLoss = powerLoss; } @@ -121,7 +122,8 @@ public final class PowerProvider { } public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { - if (powerLossRegularity == 0) { + if (powerLoss == 0 || powerLossRegularity == 0) { + perdition = new PerditionCalculator(0); return; } perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity * 10.0F); @@ -160,6 +162,15 @@ public final class PowerProvider { } } + /** + * Extract energy from the PowerProvider. You must call this even if + * doWork() triggers. + * + * @param min + * @param max + * @param doUse + * @return amount used + */ public float useEnergy(float min, float max, boolean doUse) { float result = 0; From 42181dbc7fcd7d09923c6185a4db56e7cacc874e Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 26 Jun 2013 08:50:25 -0700 Subject: [PATCH 14/29] Remove min check on receive The check broke pipes --- common/buildcraft/api/power/PowerProvider.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index cba8a105..b2b2a4eb 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -227,9 +227,6 @@ public final class PowerProvider { * @return the amount of power used */ public float receiveEnergy(float quantity, ForgeDirection from) { - if (quantity < minEnergyReceived) { - return 0; - } if (quantity > maxEnergyReceived) { quantity -= quantity - maxEnergyReceived; } From 12de71213a6a91e44cff7c6f3b9bd3a856c8c080 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Thu, 27 Jun 2013 13:10:01 -0700 Subject: [PATCH 15/29] Convert Pipe Icon Prov to enum And fixed a issue with the PowerProvider casting objects to TileEntities that aren't TileEntities. Fixed by adding a getWorldObj() function to IPowerReceptor. --- .../buildcraft/api/power/IPowerReceptor.java | 3 + .../buildcraft/api/power/PowerProvider.java | 7 +- common/buildcraft/core/TileBuildCraft.java | 1 + .../transport/BlockGenericPipe.java | 2 +- common/buildcraft/transport/Pipe.java | 4 + .../transport/PipeIconProvider.java | 169 +++++++----------- .../transport/pipes/PipeItemsCobblestone.java | 2 +- .../transport/pipes/PipeItemsDiamond.java | 14 +- .../transport/pipes/PipeItemsEmerald.java | 4 +- .../transport/pipes/PipeItemsGold.java | 2 +- .../transport/pipes/PipeItemsIron.java | 6 +- .../transport/pipes/PipeItemsObsidian.java | 2 +- .../transport/pipes/PipeItemsQuartz.java | 2 +- .../transport/pipes/PipeItemsSandstone.java | 2 +- .../transport/pipes/PipeItemsStone.java | 2 +- .../transport/pipes/PipeItemsVoid.java | 2 +- .../transport/pipes/PipeItemsWood.java | 4 +- .../pipes/PipeLiquidsCobblestone.java | 2 +- .../transport/pipes/PipeLiquidsEmerald.java | 4 +- .../transport/pipes/PipeLiquidsGold.java | 2 +- .../transport/pipes/PipeLiquidsIron.java | 4 +- .../transport/pipes/PipeLiquidsSandstone.java | 2 +- .../transport/pipes/PipeLiquidsStone.java | 2 +- .../transport/pipes/PipeLiquidsVoid.java | 2 +- .../transport/pipes/PipeLiquidsWood.java | 4 +- .../transport/pipes/PipePowerCobblestone.java | 2 +- .../transport/pipes/PipePowerDiamond.java | 2 +- .../transport/pipes/PipePowerGold.java | 2 +- .../transport/pipes/PipePowerQuartz.java | 2 +- .../transport/pipes/PipePowerStone.java | 2 +- .../transport/pipes/PipePowerWood.java | 4 +- .../pipes/PipeStructureCobblestone.java | 2 +- .../transport/render/FacadeItemRenderer.java | 2 +- .../transport/render/PipeWorldRenderer.java | 6 +- .../transport/render/PlugItemRenderer.java | 2 +- .../transport/render/RenderPipe.java | 4 +- 36 files changed, 126 insertions(+), 154 deletions(-) diff --git a/common/buildcraft/api/power/IPowerReceptor.java b/common/buildcraft/api/power/IPowerReceptor.java index b1eea8fd..8ac71b77 100644 --- a/common/buildcraft/api/power/IPowerReceptor.java +++ b/common/buildcraft/api/power/IPowerReceptor.java @@ -7,6 +7,7 @@ */ package buildcraft.api.power; +import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; public interface IPowerReceptor { @@ -14,4 +15,6 @@ public interface IPowerReceptor { public PowerProvider getPowerProvider(ForgeDirection side); public void doWork(PowerProvider workProvider); + + public World getWorldObj(); } diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index b2b2a4eb..c2d757ed 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -8,7 +8,6 @@ package buildcraft.api.power; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; @@ -141,8 +140,7 @@ public final class PowerProvider { private void applyPerdition() { if (energyStored > 0) { - TileEntity tile = (TileEntity) receptor; - if (energyLossTracker.markTimeIfDelay(tile.worldObj, 10)) { + if (energyLossTracker.markTimeIfDelay(receptor.getWorldObj(), 10)) { float newEnergy = getPerdition().applyPerdition(this, energyStored); if (newEnergy == 0 || newEnergy < energyStored) { energyStored = newEnergy; @@ -155,8 +153,7 @@ public final class PowerProvider { private void applyWork() { if (energyStored >= activationEnergy) { - TileEntity tile = (TileEntity) receptor; - if (doWorkTracker.markTimeIfDelay(tile.worldObj, 1)) { + if (doWorkTracker.markTimeIfDelay(receptor.getWorldObj(), 1)) { receptor.doWork(this); } } diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 53745f3e..4a2c7efd 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -22,6 +22,7 @@ import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.TilePacketWrapper; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; +import net.minecraft.world.World; public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile { diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 782d56ca..a7e860eb 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -918,7 +918,7 @@ public class BlockGenericPipe extends BlockContainer { @Override @SideOnly(Side.CLIENT) public Icon getIcon(int par1, int par2) { - return BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.Stripes); + return BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Stripes.ordinal()); } /** diff --git a/common/buildcraft/transport/Pipe.java b/common/buildcraft/transport/Pipe.java index 5a41bb48..097d432f 100644 --- a/common/buildcraft/transport/Pipe.java +++ b/common/buildcraft/transport/Pipe.java @@ -728,5 +728,9 @@ public abstract class Pipe implements IPipe, IDropControlInventory { fixedTriggers = true; } + + public World getWorldObj(){ + return worldObj; + } } diff --git a/common/buildcraft/transport/PipeIconProvider.java b/common/buildcraft/transport/PipeIconProvider.java index e5786ecb..cedf1ade 100644 --- a/common/buildcraft/transport/PipeIconProvider.java +++ b/common/buildcraft/transport/PipeIconProvider.java @@ -7,115 +7,82 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class PipeIconProvider implements IIconProvider { - - public static final int PipeStructureCobblestone = 0; - public static final int PipeItemsCobbleStone = 1; - public static final int PipeItemsDiamond_Center = 2; - public static final int PipeItemsDiamond_Down = 3; - public static final int PipeItemsDiamond_Up = 4; - public static final int PipeItemsDiamond_North = 5; - public static final int PipeItemsDiamond_South = 6; - public static final int PipeItemsDiamond_West = 7; - public static final int PipeItemsDiamond_East = 8; - public static final int PipeItemsWood_Standard = 9; - public static final int PipeAllWood_Solid = 10; - public static final int PipeItemsEmerald_Standard = 11; - public static final int PipeAllEmerald_Solid = 12; - public static final int PipeItemsGold = 13; - public static final int PipeItemsIron_Standard = 14; - public static final int PipeAllIron_Solid = 15; - public static final int PipeItemsObsidian = 16; - public static final int PipeItemsSandstone = 17; - public static final int PipeItemsStone = 18; - public static final int PipeItemsVoid = 19; - public static final int PipeLiquidsCobblestone = 20; - public static final int PipeLiquidsWood_Standard = 21; - public static final int PipeLiquidsEmerald_Standard = 22; - public static final int PipeLiquidsGold = 23; - public static final int PipeLiquidsIron_Standard = 24; - public static final int PipeLiquidsSandstone = 25; - public static final int PipeLiquidsStone = 26; - public static final int PipeLiquidsVoid = 27; - public static final int PipePowerGold = 28; - public static final int PipePowerStone = 29; - public static final int PipePowerWood_Standard = 30; - - public static final int Power_Normal = 31; - public static final int Power_Overload = 32; - - public static final int Stripes = 33; - - public static final int PipePowerCobblestone = 34; - public static final int PipePowerDiamond = 35; - public static final int PipePowerQuartz = 36; - public static final int PipeItemsQuartz = 37; - - public static final int MAX = 38; - - - @SideOnly(Side.CLIENT) - private Icon[] _icons; + + public enum TYPE { + + PipeStructureCobblestone("pipeStructureCobblestone"), + // + PipeItemsCobbleStone("pipeItemsCobblestone"), + // + PipeItemsDiamond_Center("pipeItemsDiamond_center"), + PipeItemsDiamond_Down("pipeItemsDiamond_down"), + PipeItemsDiamond_Up("pipeItemsDiamond_up"), + PipeItemsDiamond_North("pipeItemsDiamond_north"), + PipeItemsDiamond_South("pipeItemsDiamond_south"), + PipeItemsDiamond_West("pipeItemsDiamond_west"), + PipeItemsDiamond_East("pipeItemsDiamond_east"), + // + PipeItemsWood_Standard("pipeItemsWood_standard"), + PipeAllWood_Solid("pipeAllWood_solid"), + // + PipeItemsEmerald_Standard("pipeItemsEmerald_standard"), + PipeAllEmerald_Solid("pipeAllEmerald_solid"), + // + PipeItemsGold("pipeItemsGold"), + // + PipeItemsIron_Standard("pipeItemsIron_standard"), + PipeAllIron_Solid("pipeAllIron_solid"), + // + PipeItemsObsidian("pipeItemsObsidian"), + PipeItemsSandstone("pipeItemsSandstone"), + PipeItemsStone("pipeItemsStone"), + PipeItemsQuartz("pipeItemsQuartz"), + PipeItemsVoid("pipeItemsVoid"), + // + PipeLiquidsCobblestone("pipeLiquidsCobblestone"), + PipeLiquidsWood_Standard("pipeLiquidsWood_standard"), + PipeLiquidsEmerald_Standard("pipeLiquidsEmerald_standard"), + PipeLiquidsGold("pipeLiquidsGold"), + PipeLiquidsIron_Standard("pipeLiquidsIron_standard"), + PipeLiquidsSandstone("pipeLiquidsSandstone"), + PipeLiquidsStone("pipeLiquidsStone"), + PipeLiquidsVoid("pipeLiquidsVoid"), + // + PipePowerDiamond("pipePowerDiamond"), + PipePowerGold("pipePowerGold"), + PipePowerQuartz("pipePowerQuartz"), + PipePowerStone("pipePowerStone"), + PipePowerCobblestone("pipePowerCobblestone"), + PipePowerWood_Standard("pipePowerWood_standard"), + // + Power_Normal("texture_cyan"), + Power_Overload("texture_red_lit"), + Stripes("pipeStripes"); + // + public static final TYPE[] VALUES = values(); + private final String iconTag; + private Icon icon; + + private TYPE(String iconTag) { + this.iconTag = iconTag; + } + + private void registerIcon(IconRegister iconRegister) { + icon = iconRegister.registerIcon("buildcraft:" + iconTag); + } + } @Override @SideOnly(Side.CLIENT) public Icon getIcon(int pipeIconIndex) { - return _icons[pipeIconIndex]; + return TYPE.VALUES[pipeIconIndex].icon; } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { - - _icons = new Icon[PipeIconProvider.MAX]; - - _icons[PipeIconProvider.PipeStructureCobblestone] = iconRegister.registerIcon("buildcraft:pipeStructureCobblestone"); - - _icons[PipeIconProvider.PipeItemsCobbleStone] = iconRegister.registerIcon("buildcraft:pipeItemsCobblestone"); - - _icons[PipeIconProvider.PipeItemsDiamond_Center] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_center"); - _icons[PipeIconProvider.PipeItemsDiamond_Down] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_down"); - _icons[PipeIconProvider.PipeItemsDiamond_Up] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_up"); - _icons[PipeIconProvider.PipeItemsDiamond_North] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_north"); - _icons[PipeIconProvider.PipeItemsDiamond_South] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_south"); - _icons[PipeIconProvider.PipeItemsDiamond_West] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_west"); - _icons[PipeIconProvider.PipeItemsDiamond_East] = iconRegister.registerIcon("buildcraft:pipeItemsDiamond_east"); - - _icons[PipeIconProvider.PipeItemsWood_Standard] = iconRegister.registerIcon("buildcraft:pipeItemsWood_standard"); - _icons[PipeIconProvider.PipeAllWood_Solid] = iconRegister.registerIcon("buildcraft:pipeAllWood_solid"); - - _icons[PipeIconProvider.PipeItemsEmerald_Standard] = iconRegister.registerIcon("buildcraft:pipeItemsEmerald_standard"); - _icons[PipeIconProvider.PipeAllEmerald_Solid] = iconRegister.registerIcon("buildcraft:pipeAllEmerald_solid"); - - _icons[PipeIconProvider.PipeItemsGold] = iconRegister.registerIcon("buildcraft:pipeItemsGold"); - - _icons[PipeIconProvider.PipeItemsIron_Standard] = iconRegister.registerIcon("buildcraft:pipeItemsIron_standard"); - _icons[PipeIconProvider.PipeAllIron_Solid] = iconRegister.registerIcon("buildcraft:pipeAllIron_solid"); - - _icons[PipeIconProvider.PipeItemsObsidian] = iconRegister.registerIcon("buildcraft:pipeItemsObsidian"); - _icons[PipeIconProvider.PipeItemsSandstone] = iconRegister.registerIcon("buildcraft:pipeItemsSandstone"); - _icons[PipeIconProvider.PipeItemsStone] = iconRegister.registerIcon("buildcraft:pipeItemsStone"); - _icons[PipeIconProvider.PipeItemsQuartz] = iconRegister.registerIcon("buildcraft:pipeItemsQuartz"); - _icons[PipeIconProvider.PipeItemsVoid] = iconRegister.registerIcon("buildcraft:pipeItemsVoid"); - - _icons[PipeIconProvider.PipeLiquidsCobblestone] = iconRegister.registerIcon("buildcraft:pipeLiquidsCobblestone"); - _icons[PipeIconProvider.PipeLiquidsWood_Standard] = iconRegister.registerIcon("buildcraft:pipeLiquidsWood_standard"); - _icons[PipeIconProvider.PipeLiquidsEmerald_Standard] = iconRegister.registerIcon("buildcraft:pipeLiquidsEmerald_standard"); - _icons[PipeIconProvider.PipeLiquidsGold] = iconRegister.registerIcon("buildcraft:pipeLiquidsGold"); - _icons[PipeIconProvider.PipeLiquidsIron_Standard] = iconRegister.registerIcon("buildcraft:pipeLiquidsIron_standard"); - _icons[PipeIconProvider.PipeLiquidsSandstone] = iconRegister.registerIcon("buildcraft:pipeLiquidsSandstone"); - _icons[PipeIconProvider.PipeLiquidsStone] = iconRegister.registerIcon("buildcraft:pipeLiquidsStone"); - _icons[PipeIconProvider.PipeLiquidsVoid] = iconRegister.registerIcon("buildcraft:pipeLiquidsVoid"); - - _icons[PipeIconProvider.PipePowerDiamond] = iconRegister.registerIcon("buildcraft:pipePowerDiamond"); - _icons[PipeIconProvider.PipePowerGold] = iconRegister.registerIcon("buildcraft:pipePowerGold"); - _icons[PipeIconProvider.PipePowerQuartz] = iconRegister.registerIcon("buildcraft:pipePowerQuartz"); - _icons[PipeIconProvider.PipePowerStone] = iconRegister.registerIcon("buildcraft:pipePowerStone"); - _icons[PipeIconProvider.PipePowerCobblestone] = iconRegister.registerIcon("buildcraft:pipePowerCobblestone"); - _icons[PipeIconProvider.PipePowerWood_Standard] = iconRegister.registerIcon("buildcraft:pipePowerWood_standard"); - - _icons[PipeIconProvider.Power_Normal] = iconRegister.registerIcon("buildcraft:texture_cyan"); - _icons[PipeIconProvider.Power_Overload] = iconRegister.registerIcon("buildcraft:texture_red_lit"); - _icons[PipeIconProvider.Stripes] = iconRegister.registerIcon("buildcraft:pipeStripes"); + for (TYPE type : TYPE.VALUES) { + type.registerIcon(iconRegister); + } } - } diff --git a/common/buildcraft/transport/pipes/PipeItemsCobblestone.java b/common/buildcraft/transport/pipes/PipeItemsCobblestone.java index 2f693abe..5c8dca15 100644 --- a/common/buildcraft/transport/pipes/PipeItemsCobblestone.java +++ b/common/buildcraft/transport/pipes/PipeItemsCobblestone.java @@ -32,7 +32,7 @@ public class PipeItemsCobblestone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsCobbleStone; + return PipeIconProvider.TYPE.PipeItemsCobbleStone.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsDiamond.java b/common/buildcraft/transport/pipes/PipeItemsDiamond.java index e8f2abac..bef5814f 100644 --- a/common/buildcraft/transport/pipes/PipeItemsDiamond.java +++ b/common/buildcraft/transport/pipes/PipeItemsDiamond.java @@ -45,13 +45,13 @@ public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook, I @Override public int getIconIndex(ForgeDirection direction) { switch(direction){ - case UNKNOWN: return PipeIconProvider.PipeItemsDiamond_Center; - case DOWN: return PipeIconProvider.PipeItemsDiamond_Down; - case UP: return PipeIconProvider.PipeItemsDiamond_Up; - case NORTH: return PipeIconProvider.PipeItemsDiamond_North; - case SOUTH: return PipeIconProvider.PipeItemsDiamond_South; - case WEST: return PipeIconProvider.PipeItemsDiamond_West; - case EAST: return PipeIconProvider.PipeItemsDiamond_East; + case UNKNOWN: return PipeIconProvider.TYPE.PipeItemsDiamond_Center.ordinal(); + case DOWN: return PipeIconProvider.TYPE.PipeItemsDiamond_Down.ordinal(); + case UP: return PipeIconProvider.TYPE.PipeItemsDiamond_Up.ordinal(); + case NORTH: return PipeIconProvider.TYPE.PipeItemsDiamond_North.ordinal(); + case SOUTH: return PipeIconProvider.TYPE.PipeItemsDiamond_South.ordinal(); + case WEST: return PipeIconProvider.TYPE.PipeItemsDiamond_West.ordinal(); + case EAST: return PipeIconProvider.TYPE.PipeItemsDiamond_East.ordinal(); default: throw new IllegalArgumentException("direction out of bounds"); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index b1bfe351..4af248e1 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -40,8 +40,8 @@ public class PipeItemsEmerald extends PipeItemsWood implements ISpecialInventory protected PipeItemsEmerald(int itemID, PipeTransportItems transport) { super(transport, new PipeLogicEmerald(), itemID); - standardIconIndex = PipeIconProvider.PipeItemsEmerald_Standard; - solidIconIndex = PipeIconProvider.PipeAllEmerald_Solid; + standardIconIndex = PipeIconProvider.TYPE.PipeItemsEmerald_Standard.ordinal(); + solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal(); } public PipeItemsEmerald(int itemID) { diff --git a/common/buildcraft/transport/pipes/PipeItemsGold.java b/common/buildcraft/transport/pipes/PipeItemsGold.java index d39653a7..7e89fb09 100644 --- a/common/buildcraft/transport/pipes/PipeItemsGold.java +++ b/common/buildcraft/transport/pipes/PipeItemsGold.java @@ -37,7 +37,7 @@ public class PipeItemsGold extends Pipe implements IPipeTransportItemsHook { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsGold; + return PipeIconProvider.TYPE.PipeItemsGold.ordinal(); } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsIron.java b/common/buildcraft/transport/pipes/PipeItemsIron.java index 8fd64a62..949b1e3b 100644 --- a/common/buildcraft/transport/pipes/PipeItemsIron.java +++ b/common/buildcraft/transport/pipes/PipeItemsIron.java @@ -19,8 +19,8 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeItemsIron extends Pipe { - private int standardIconIndex = PipeIconProvider.PipeItemsIron_Standard; - private int solidIconIndex = PipeIconProvider.PipeAllIron_Solid; + private int standardIconIndex = PipeIconProvider.TYPE.PipeItemsIron_Standard.ordinal(); + private int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal(); public PipeItemsIron(int itemID) { super(new PipeTransportItems(), new PipeLogicIron(), itemID); @@ -35,7 +35,7 @@ public class PipeItemsIron extends Pipe { else { int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); - if (metadata == direction.ordinal()) + if (metadata != direction.ordinal()) return solidIconIndex; else return standardIconIndex; diff --git a/common/buildcraft/transport/pipes/PipeItemsObsidian.java b/common/buildcraft/transport/pipes/PipeItemsObsidian.java index de173bf9..c72df02e 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -63,7 +63,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsObsidian; + return PipeIconProvider.TYPE.PipeItemsObsidian.ordinal(); } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsQuartz.java b/common/buildcraft/transport/pipes/PipeItemsQuartz.java index c7ff6ba0..8a4fe7b9 100644 --- a/common/buildcraft/transport/pipes/PipeItemsQuartz.java +++ b/common/buildcraft/transport/pipes/PipeItemsQuartz.java @@ -37,7 +37,7 @@ public class PipeItemsQuartz extends Pipe implements IPipeTransportItemsHook { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsQuartz; + return PipeIconProvider.TYPE.PipeItemsQuartz.ordinal(); } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsSandstone.java b/common/buildcraft/transport/pipes/PipeItemsSandstone.java index dd2a79e6..84c2d63e 100644 --- a/common/buildcraft/transport/pipes/PipeItemsSandstone.java +++ b/common/buildcraft/transport/pipes/PipeItemsSandstone.java @@ -31,6 +31,6 @@ public class PipeItemsSandstone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsSandstone; + return PipeIconProvider.TYPE.PipeItemsSandstone.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsStone.java b/common/buildcraft/transport/pipes/PipeItemsStone.java index 0b07ac2d..86029578 100644 --- a/common/buildcraft/transport/pipes/PipeItemsStone.java +++ b/common/buildcraft/transport/pipes/PipeItemsStone.java @@ -38,7 +38,7 @@ public class PipeItemsStone extends Pipe implements IPipeTransportItemsHook { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsStone; + return PipeIconProvider.TYPE.PipeItemsStone.ordinal(); } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsVoid.java b/common/buildcraft/transport/pipes/PipeItemsVoid.java index 225aa334..90271b02 100644 --- a/common/buildcraft/transport/pipes/PipeItemsVoid.java +++ b/common/buildcraft/transport/pipes/PipeItemsVoid.java @@ -36,7 +36,7 @@ public class PipeItemsVoid extends Pipe implements IItemTravelingHook { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeItemsVoid; + return PipeIconProvider.TYPE.PipeItemsVoid.ordinal(); } // This is called if the void pipe is only connected to one pipe diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 17c0fef7..42794dc2 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -33,8 +33,8 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeItemsWood extends Pipe implements IPowerReceptor { protected PowerProvider powerProvider; - protected int standardIconIndex = PipeIconProvider.PipeItemsWood_Standard; - protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; + 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); diff --git a/common/buildcraft/transport/pipes/PipeLiquidsCobblestone.java b/common/buildcraft/transport/pipes/PipeLiquidsCobblestone.java index ff9fca16..c4354404 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsCobblestone.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsCobblestone.java @@ -31,6 +31,6 @@ public class PipeLiquidsCobblestone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeLiquidsCobblestone; + return PipeIconProvider.TYPE.PipeLiquidsCobblestone.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipeLiquidsEmerald.java b/common/buildcraft/transport/pipes/PipeLiquidsEmerald.java index 6b8e1726..feec1f9d 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsEmerald.java @@ -20,8 +20,8 @@ public class PipeLiquidsEmerald extends PipeLiquidsWood { public PipeLiquidsEmerald(int itemID) { super(new PipeLogicEmerald(), itemID); - standardIconIndex = PipeIconProvider.PipeLiquidsEmerald_Standard; - solidIconIndex = PipeIconProvider.PipeAllEmerald_Solid; + standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsEmerald_Standard.ordinal(); + solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal(); ((PipeTransportLiquids) transport).flowRate = 40; ((PipeTransportLiquids) transport).travelDelay = 4; diff --git a/common/buildcraft/transport/pipes/PipeLiquidsGold.java b/common/buildcraft/transport/pipes/PipeLiquidsGold.java index dfe2372f..664c1d8c 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsGold.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsGold.java @@ -34,7 +34,7 @@ public class PipeLiquidsGold extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeLiquidsGold; + return PipeIconProvider.TYPE.PipeLiquidsGold.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipeLiquidsIron.java b/common/buildcraft/transport/pipes/PipeLiquidsIron.java index a7cf4990..a634416a 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsIron.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsIron.java @@ -19,8 +19,8 @@ import cpw.mods.fml.relauncher.SideOnly; public class PipeLiquidsIron extends Pipe { - protected int standardIconIndex = PipeIconProvider.PipeLiquidsIron_Standard; - protected int solidIconIndex = PipeIconProvider.PipeAllIron_Solid; + protected int standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsIron_Standard.ordinal(); + protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal(); public PipeLiquidsIron(int itemID) { diff --git a/common/buildcraft/transport/pipes/PipeLiquidsSandstone.java b/common/buildcraft/transport/pipes/PipeLiquidsSandstone.java index b787858c..65fbf405 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsSandstone.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsSandstone.java @@ -34,7 +34,7 @@ public class PipeLiquidsSandstone extends Pipe implements IPipeTransportLiquidsH @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeLiquidsSandstone; + return PipeIconProvider.TYPE.PipeLiquidsSandstone.ordinal(); } @Override diff --git a/common/buildcraft/transport/pipes/PipeLiquidsStone.java b/common/buildcraft/transport/pipes/PipeLiquidsStone.java index 51e8c37f..cd18c34d 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsStone.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsStone.java @@ -33,7 +33,7 @@ public class PipeLiquidsStone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeLiquidsStone; + return PipeIconProvider.TYPE.PipeLiquidsStone.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipeLiquidsVoid.java b/common/buildcraft/transport/pipes/PipeLiquidsVoid.java index 56665e95..8640e00e 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsVoid.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsVoid.java @@ -34,7 +34,7 @@ public class PipeLiquidsVoid extends Pipe implements IPipeTransportLiquidsHook { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeLiquidsVoid; + return PipeIconProvider.TYPE.PipeLiquidsVoid.ordinal(); } @Override diff --git a/common/buildcraft/transport/pipes/PipeLiquidsWood.java b/common/buildcraft/transport/pipes/PipeLiquidsWood.java index 7ada3d95..a95dba46 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsWood.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsWood.java @@ -34,8 +34,8 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { private PowerProvider powerProvider; - protected int standardIconIndex = PipeIconProvider.PipeLiquidsWood_Standard; - protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; + protected int standardIconIndex = PipeIconProvider.TYPE.PipeLiquidsWood_Standard.ordinal(); + protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); long lastMining = 0; boolean lastPower = false; diff --git a/common/buildcraft/transport/pipes/PipePowerCobblestone.java b/common/buildcraft/transport/pipes/PipePowerCobblestone.java index 151dbee9..b8ed7ab3 100644 --- a/common/buildcraft/transport/pipes/PipePowerCobblestone.java +++ b/common/buildcraft/transport/pipes/PipePowerCobblestone.java @@ -31,6 +31,6 @@ public class PipePowerCobblestone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipePowerCobblestone; + return PipeIconProvider.TYPE.PipePowerCobblestone.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipePowerDiamond.java b/common/buildcraft/transport/pipes/PipePowerDiamond.java index b60caab8..54f8103b 100644 --- a/common/buildcraft/transport/pipes/PipePowerDiamond.java +++ b/common/buildcraft/transport/pipes/PipePowerDiamond.java @@ -31,6 +31,6 @@ public class PipePowerDiamond extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipePowerDiamond; + return PipeIconProvider.TYPE.PipePowerDiamond.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipePowerGold.java b/common/buildcraft/transport/pipes/PipePowerGold.java index b8a8dcd4..920b55ab 100644 --- a/common/buildcraft/transport/pipes/PipePowerGold.java +++ b/common/buildcraft/transport/pipes/PipePowerGold.java @@ -31,6 +31,6 @@ public class PipePowerGold extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipePowerGold; + return PipeIconProvider.TYPE.PipePowerGold.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipePowerQuartz.java b/common/buildcraft/transport/pipes/PipePowerQuartz.java index 6a3f5bdb..c80678aa 100644 --- a/common/buildcraft/transport/pipes/PipePowerQuartz.java +++ b/common/buildcraft/transport/pipes/PipePowerQuartz.java @@ -31,6 +31,6 @@ public class PipePowerQuartz extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipePowerQuartz; + return PipeIconProvider.TYPE.PipePowerQuartz.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipePowerStone.java b/common/buildcraft/transport/pipes/PipePowerStone.java index e98c7c92..8d2236c8 100644 --- a/common/buildcraft/transport/pipes/PipePowerStone.java +++ b/common/buildcraft/transport/pipes/PipePowerStone.java @@ -31,6 +31,6 @@ public class PipePowerStone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipePowerStone; + return PipeIconProvider.TYPE.PipePowerStone.ordinal(); } } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 4cb69a56..bcdcc74a 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -22,8 +22,8 @@ import net.minecraft.nbt.NBTTagCompound; public class PipePowerWood extends Pipe implements IPowerReceptor { private PowerProvider powerProvider; - protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard; - protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; + protected int standardIconIndex = PipeIconProvider.TYPE.PipePowerWood_Standard.ordinal(); + protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal(); private boolean[] powerSources = new boolean[6]; private boolean full; diff --git a/common/buildcraft/transport/pipes/PipeStructureCobblestone.java b/common/buildcraft/transport/pipes/PipeStructureCobblestone.java index 450051ba..f5e6b4f6 100644 --- a/common/buildcraft/transport/pipes/PipeStructureCobblestone.java +++ b/common/buildcraft/transport/pipes/PipeStructureCobblestone.java @@ -23,6 +23,6 @@ public class PipeStructureCobblestone extends Pipe { @Override public int getIconIndex(ForgeDirection direction) { - return PipeIconProvider.PipeStructureCobblestone; + return PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal(); } } diff --git a/common/buildcraft/transport/render/FacadeItemRenderer.java b/common/buildcraft/transport/render/FacadeItemRenderer.java index a53da19f..92238b8b 100644 --- a/common/buildcraft/transport/render/FacadeItemRenderer.java +++ b/common/buildcraft/transport/render/FacadeItemRenderer.java @@ -62,7 +62,7 @@ public class FacadeItemRenderer implements IItemRenderer { // Render StructurePipe block = BuildCraftTransport.genericPipeBlock; - Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure pipe + Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe block.setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos - 1F / 16F); block.setBlockBoundsForItemRender(); diff --git a/common/buildcraft/transport/render/PipeWorldRenderer.java b/common/buildcraft/transport/render/PipeWorldRenderer.java index e8c6b6f8..90de08b0 100644 --- a/common/buildcraft/transport/render/PipeWorldRenderer.java +++ b/common/buildcraft/transport/render/PipeWorldRenderer.java @@ -267,7 +267,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler { zeroState[2][0] = Utils.pipeMinPos; zeroState[2][1] = Utils.pipeMaxPos; - state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure Pipe + state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (state.facadeMatrix.getFacadeBlockId(direction) != 0 && !state.pipeConnectionMatrix.isConnected(direction)) { @@ -296,7 +296,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler { zeroState[2][0] = 0.25F + zFightOffset; zeroState[2][1] = 0.75F - zFightOffset; - state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure Pipe + state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (state.plugMatrix.isConnected(direction)) { @@ -319,7 +319,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler { zeroState[2][0] = 0.25F + 0.125F/2; zeroState[2][1] = 0.75F - 0.125F/2; - state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure Pipe + state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (state.plugMatrix.isConnected(direction)) { diff --git a/common/buildcraft/transport/render/PlugItemRenderer.java b/common/buildcraft/transport/render/PlugItemRenderer.java index 7fabb646..c50f768d 100644 --- a/common/buildcraft/transport/render/PlugItemRenderer.java +++ b/common/buildcraft/transport/render/PlugItemRenderer.java @@ -20,7 +20,7 @@ public class PlugItemRenderer implements IItemRenderer{ Tessellator tessellator = Tessellator.instance; block = BuildCraftTransport.genericPipeBlock; - Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.PipeStructureCobblestone); // Structure pipe + Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe block.setBlockBounds(0.25F, 0.25F, 0.25F, 0.75F, 0.375F, 0.75F); block.setBlockBoundsForItemRender(); diff --git a/common/buildcraft/transport/render/RenderPipe.java b/common/buildcraft/transport/render/RenderPipe.java index 228180d5..52bc862a 100644 --- a/common/buildcraft/transport/render/RenderPipe.java +++ b/common/buildcraft/transport/render/RenderPipe.java @@ -196,7 +196,7 @@ public class RenderPipe extends TileEntitySpecialRenderer { initialized = true; BlockInterface block = new BlockInterface(); - block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.Power_Normal); + block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Normal.ordinal()); float size = Utils.pipeMaxPos - Utils.pipeMinPos; @@ -222,7 +222,7 @@ public class RenderPipe extends TileEntitySpecialRenderer { GL11.glEndList(); } - block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.Power_Overload); + block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Overload.ordinal()); size = Utils.pipeMaxPos - Utils.pipeMinPos; From f9374eb0e5c84f7ebeca06bcefe509f6c759e9ad Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Thu, 27 Jun 2013 14:33:33 -0700 Subject: [PATCH 16/29] Fixed Wooden Item and Liquid Pipes --- common/buildcraft/transport/pipes/PipeItemsWood.java | 5 +++-- common/buildcraft/transport/pipes/PipeLiquidsWood.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 42794dc2..3ab253a5 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -41,7 +41,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { powerProvider = new PowerProvider(this, false); powerProvider.configure(1, 64, 1, 64); - powerProvider.configurePowerPerdition(64, 1); + powerProvider.configurePowerPerdition(0, 0); } protected PipeItemsWood(int itemID, PipeTransportItems transport) { @@ -105,7 +105,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { for (ItemStack stack : extracted) { if (stack == null || stack.stackSize == 0) { - powerProvider.useEnergy(1, 1, false); + powerProvider.useEnergy(1, 1, true); continue; } @@ -118,6 +118,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { ((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation); } } + powerProvider.setEnergy(0); } /** diff --git a/common/buildcraft/transport/pipes/PipeLiquidsWood.java b/common/buildcraft/transport/pipes/PipeLiquidsWood.java index a95dba46..9ba4ad33 100644 --- a/common/buildcraft/transport/pipes/PipeLiquidsWood.java +++ b/common/buildcraft/transport/pipes/PipeLiquidsWood.java @@ -49,7 +49,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { powerProvider = new PowerProvider(this, false); powerProvider.configure(1, 100, 1, 250); - powerProvider.configurePowerPerdition(1, 1); + powerProvider.configurePowerPerdition(0, 0); } /** @@ -79,6 +79,7 @@ public class PipeLiquidsWood extends Pipe implements IPowerReceptor { liquidToExtract += powerProvider.useEnergy(1, 1, true) * LiquidContainerRegistry.BUCKET_VOLUME; } } + powerProvider.useEnergy(1, 1, true); } @Override From b25b08c827dd8d3969d48cb92da32e979e2e934a Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sat, 29 Jun 2013 01:33:21 -0700 Subject: [PATCH 17/29] Engine rewrite Killed Engine class, merged into TileEngine and subclasses. Converted to Forge rotation API. Split heat from stored energy and set proper temp bounds. Rewrote IronEngineCoolant API, changed to degree based temp reductions (its 0.0025 times the previous values). Added support for solid coolants (they have to melt into a liquid coolant, like Ice to Water). There is a commented out alternative implementation for constant power output instead of pulsed. --- .../lang/buildcraft/en_US.properties | 4 + common/buildcraft/BuildCraftEnergy.java | 13 +- .../api/fuels/IronEngineCoolant.java | 89 ++- .../buildcraft/api/power/PowerProvider.java | 49 +- common/buildcraft/builders/TileFiller.java | 6 +- common/buildcraft/energy/BlockEngine.java | 83 +-- common/buildcraft/energy/BptBlockEngine.java | 4 +- common/buildcraft/energy/EnergyProxy.java | 5 +- common/buildcraft/energy/Engine.java | 212 ------ common/buildcraft/energy/EngineIron.java | 446 ------------ common/buildcraft/energy/EngineStone.java | 234 ------- common/buildcraft/energy/EngineWood.java | 106 --- common/buildcraft/energy/IEngineProvider.java | 15 - common/buildcraft/energy/TileEngine.java | 646 +++++++++--------- common/buildcraft/energy/TileEngineIron.java | 407 +++++++++++ .../buildcraft/energy/TileEngineLegacy.java | 77 +++ common/buildcraft/energy/TileEngineStone.java | 163 +++++ common/buildcraft/energy/TileEngineWood.java | 119 ++++ .../buildcraft/energy/TriggerEngineHeat.java | 54 +- .../energy/gui/ContainerEngine.java | 22 +- .../energy/gui/GuiCombustionEngine.java | 11 +- common/buildcraft/energy/gui/GuiEngine.java | 13 +- .../energy/render/RenderEngine.java | 15 +- common/buildcraft/silicon/TileLaser.java | 4 +- .../transport/IPipeTransportPowerHook.java | 2 +- .../transport/PipeTransportPower.java | 31 +- .../transport/pipes/PipeItemsWood.java | 16 +- .../transport/pipes/PipePowerWood.java | 6 +- 28 files changed, 1337 insertions(+), 1515 deletions(-) delete mode 100644 common/buildcraft/energy/Engine.java delete mode 100644 common/buildcraft/energy/EngineIron.java delete mode 100644 common/buildcraft/energy/EngineStone.java delete mode 100644 common/buildcraft/energy/EngineWood.java delete mode 100644 common/buildcraft/energy/IEngineProvider.java create mode 100644 common/buildcraft/energy/TileEngineIron.java create mode 100644 common/buildcraft/energy/TileEngineLegacy.java create mode 100644 common/buildcraft/energy/TileEngineStone.java create mode 100644 common/buildcraft/energy/TileEngineWood.java diff --git a/buildcraft_resources/lang/buildcraft/en_US.properties b/buildcraft_resources/lang/buildcraft/en_US.properties index 50f77da3..b4a42195 100644 --- a/buildcraft_resources/lang/buildcraft/en_US.properties +++ b/buildcraft_resources/lang/buildcraft/en_US.properties @@ -6,6 +6,10 @@ gate.pipe.containsLiquids=Liquid Traversing gate.pipe.containsEnergy=Power Traversing gate.pipe.requestsEnergy=Power Requested gate.pipe.tooMuchEnergy=Power Overloaded +gate.engine.blue=Engine Blue +gate.engine.green=Engine Green +gate.engine.yellow=Engine Yellow +gate.engine.red=Engine Red gui.building.resources=Building Resources gui.del=Del gui.filling.resources=Filling Resources diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 90b08048..50937ba9 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -42,11 +42,11 @@ import buildcraft.energy.BlockOilFlowing; import buildcraft.energy.BlockOilStill; import buildcraft.energy.BptBlockEngine; import buildcraft.energy.EnergyProxy; -import buildcraft.energy.Engine.EnergyStage; import buildcraft.energy.GuiHandler; import buildcraft.energy.ItemBucketOil; import buildcraft.energy.ItemEngine; import buildcraft.energy.OilBucketHandler; +import buildcraft.energy.TileEngine.EnergyStage; import buildcraft.energy.worldgen.BiomeGenOilDesert; import buildcraft.energy.worldgen.OilPopulate; import buildcraft.energy.TriggerEngineHeat; @@ -86,10 +86,10 @@ public class BuildCraftEnergy { public static LiquidStack fuelLiquid; public static boolean canOilBurn; public static TreeMap saturationStored = new TreeMap(); - public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.Blue); - public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.Green); - public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.Yellow); - public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.Red); + public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.BLUE); + public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.GREEN); + public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.YELLOW); + public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.RED); @Instance("BuildCraft|Energy") public static BuildCraftEnergy instance; @@ -177,7 +177,8 @@ public class BuildCraftEnergy { IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME), 6, 100000)); // Iron Engine Coolants - IronEngineCoolant.coolants.add(new IronEngineCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 1.0f)); + IronEngineCoolant.addCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 0.0025F); + IronEngineCoolant.addCoolant(Block.ice.blockID, 0, new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME * 2)); LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Oil", LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack( bucketOil), new ItemStack(Item.bucketEmpty))); diff --git a/common/buildcraft/api/fuels/IronEngineCoolant.java b/common/buildcraft/api/fuels/IronEngineCoolant.java index 45ed04b7..5ddb3d2e 100644 --- a/common/buildcraft/api/fuels/IronEngineCoolant.java +++ b/common/buildcraft/api/fuels/IronEngineCoolant.java @@ -1,32 +1,95 @@ package buildcraft.api.fuels; -import java.util.LinkedList; +import java.util.HashMap; +import java.util.Map; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.liquids.LiquidDictionary; import net.minecraftforge.liquids.LiquidStack; -public class IronEngineCoolant { +public final class IronEngineCoolant { - public static LinkedList coolants = new LinkedList(); + public static Map liquidCoolants = new HashMap(); + public static Map solidCoolants = new HashMap(); - public static IronEngineCoolant getCoolantForLiquid(LiquidStack liquid) { + public static LiquidStack getLiquidCoolant(ItemStack stack) { + return solidCoolants.get(new ItemData(stack.itemID, stack.getItemDamage())); + } + + public static Coolant getCoolant(ItemStack stack) { + return getCoolant(getLiquidCoolant(stack)); + } + + public static Coolant getCoolant(LiquidStack liquid) { if (liquid == null) return null; if (liquid.itemID <= 0) return null; - for (IronEngineCoolant coolant : coolants) - if (coolant.liquid.isLiquidEqual(liquid)) - return coolant; + String fluidId = LiquidDictionary.findLiquidName(liquid); + if (fluidId != null) { + return liquidCoolants.get(fluidId); + } return null; } - public final LiquidStack liquid; - public final float coolingPerUnit; - - public IronEngineCoolant(LiquidStack liquid, float coolingPerUnit) { - this.liquid = liquid; - this.coolingPerUnit = coolingPerUnit; + private IronEngineCoolant() { } + public static interface Coolant { + + float getDegreesCoolingPerMB(float currentHeat); + } + + public static void addCoolant(final LiquidStack liquid, final float degreesCoolingPerMB) { + String fluidId = LiquidDictionary.findLiquidName(liquid); + if (fluidId != null) { + liquidCoolants.put(fluidId, new Coolant() { + @Override + public float getDegreesCoolingPerMB(float currentHeat) { + return degreesCoolingPerMB; + } + }); + } + } + + public static void addCoolant(final int itemId, final int metadata, final LiquidStack coolant) { + if (Item.itemsList[itemId] != null && coolant != null && coolant.amount > 0) { + solidCoolants.put(new ItemData(itemId, metadata), coolant); + } + } + + public static class ItemData { + + public final int itemId, meta; + + public ItemData(int itemId, int meta) { + this.itemId = itemId; + this.meta = meta; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 67 * hash + this.itemId; + hash = 67 * hash + this.meta; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final ItemData other = (ItemData) obj; + if (this.itemId != other.itemId) + return false; + if (this.meta != other.meta) + return false; + return true; + } + } } diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index c2d757ed..b8cbfa8d 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -15,9 +15,8 @@ public final class PowerProvider { public static class PerditionCalculator { - public static final float DEFAULT_POWERLOSS = 10F; + public static final float DEFAULT_POWERLOSS = 1F; public static final float MIN_POWERLOSS = 0.01F; - protected final SafeTimeTracker energyLossTracker = new SafeTimeTracker(); private final float powerLoss; public PerditionCalculator() { @@ -40,14 +39,13 @@ public final class PowerProvider { } } public static final PerditionCalculator DEFUALT_PERDITION = new PerditionCalculator(); - private int minEnergyReceived; - private int maxEnergyReceived; - private int maxEnergyStored; - private int activationEnergy; + private float minEnergyReceived; + private float maxEnergyReceived; + private float maxEnergyStored; + private float activationEnergy; private float energyStored = 0; public final boolean canAcceptPowerFromPipes; private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); - private final SafeTimeTracker energyLossTracker = new SafeTimeTracker(); public final int[] powerSources = {0, 0, 0, 0, 0, 0}; public final IPowerReceptor receptor; private PerditionCalculator perdition; @@ -61,19 +59,19 @@ public final class PowerProvider { this.receptor = receptor; } - public int getMinEnergyReceived() { + public float getMinEnergyReceived() { return this.minEnergyReceived; } - public int getMaxEnergyReceived() { + public float getMaxEnergyReceived() { return this.maxEnergyReceived; } - public int getMaxEnergyStored() { + public float getMaxEnergyStored() { return this.maxEnergyStored; } - public int getActivationEnergy() { + public float getActivationEnergy() { return this.activationEnergy; } @@ -99,7 +97,7 @@ public final class PowerProvider { * store. Values tend to range between 100 and 5000. With 1000 and 1500 * being common. */ - public void configure(int minEnergyReceived, int maxEnergyReceived, int activationEnergy, int maxStoredEnergy) { + public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy) { if (minEnergyReceived > maxEnergyReceived) { maxEnergyReceived = minEnergyReceived; } @@ -140,13 +138,11 @@ public final class PowerProvider { private void applyPerdition() { if (energyStored > 0) { - if (energyLossTracker.markTimeIfDelay(receptor.getWorldObj(), 10)) { - float newEnergy = getPerdition().applyPerdition(this, energyStored); - if (newEnergy == 0 || newEnergy < energyStored) { - energyStored = newEnergy; - } else { - energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored); - } + float newEnergy = getPerdition().applyPerdition(this, energyStored); + if (newEnergy == 0 || newEnergy < energyStored) { + energyStored = newEnergy; + } else { + energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored); } } } @@ -216,6 +212,10 @@ public final class PowerProvider { return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); } + public float receiveEnergy(float quantity, ForgeDirection from) { + return receiveEnergy(quantity, from, false); + } + /** * Add power to the Provider from an external source. * @@ -223,9 +223,14 @@ public final class PowerProvider { * @param from * @return the amount of power used */ - public float receiveEnergy(float quantity, ForgeDirection from) { - if (quantity > maxEnergyReceived) { - quantity -= quantity - maxEnergyReceived; + public float receiveEnergy(float quantity, ForgeDirection from, boolean boundsCheck) { + if (boundsCheck) { + if (quantity < minEnergyReceived) { + quantity = minEnergyReceived; + } + if (quantity > maxEnergyReceived) { + quantity = maxEnergyReceived; + } } if (from != null) powerSources[from.ordinal()] = 2; diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index 5e43903e..e0edb14b 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -55,7 +55,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe } private void initPowerProvider() { - powerProvider.configure(25, 50, 25, 100); + powerProvider.configure(30, 50, 25, 100); powerProvider.configurePowerPerdition(1, 1); } @@ -95,7 +95,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe } if (powerProvider.getEnergyStored() >= 25) { - doWork(null); + doWork(powerProvider); } } @@ -137,7 +137,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe } if (powerProvider.getEnergyStored() >= 25) { - doWork(null); + doWork(workProvider); } } diff --git a/common/buildcraft/energy/BlockEngine.java b/common/buildcraft/energy/BlockEngine.java index 3a655572..061f9199 100644 --- a/common/buildcraft/energy/BlockEngine.java +++ b/common/buildcraft/energy/BlockEngine.java @@ -15,23 +15,16 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftCore; -import buildcraft.BuildCraftEnergy; -import buildcraft.api.tools.IToolWrench; import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.GuiIds; import buildcraft.core.IItemPipe; -import buildcraft.core.liquids.LiquidUtils; -import buildcraft.core.proxy.CoreProxy; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraftforge.liquids.LiquidContainerRegistry; public class BlockEngine extends BlockContainer { @@ -71,15 +64,20 @@ public class BlockEngine extends BlockContainer { } @Override - public TileEntity createNewTileEntity(World var1) { - return new TileEngine(); + public TileEntity createTileEntity(World world, int metadata) { + if (metadata == 1) + return new TileEngineStone(); + else if (metadata == 2) + return new TileEngineIron(); + else + return new TileEngineWood(); } @Override public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) { TileEntity tile = world.getBlockTileEntity(x, y, z); if (tile instanceof TileEngine) { - return ForgeDirection.getOrientation(((TileEngine) tile).orientation).getOpposite() == side; + return ((TileEngine) tile).orientation.getOpposite() == side; } return false; } @@ -94,6 +92,15 @@ public class BlockEngine extends BlockContainer { super.breakBlock(world, x, y, z, par5, par6); } + @Override + public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) { + TileEntity tile = world.getBlockTileEntity(x, y, z); + if (tile instanceof TileEngine) { + return ((TileEngine) tile).switchOrientation(); + } + return false; + } + @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int side, float par7, float par8, float par9) { @@ -103,50 +110,15 @@ public class BlockEngine extends BlockContainer { if (player.isSneaking()) return false; - // Switch orientation if whacked with a wrench. - Item equipped = player.getCurrentEquippedItem() != null ? player.getCurrentEquippedItem().getItem() : null; - if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, i, j, k)) { - - tile.switchOrientation(); - ((IToolWrench) equipped).wrenchUsed(player, i, j, k); - return true; - - } else { - - // Do not open guis when having a pipe in hand - if (player.getCurrentEquippedItem() != null) { - if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) { - return false; - } - if (tile.engine instanceof EngineIron) { - ItemStack current = player.getCurrentEquippedItem(); - if (current != null && current.itemID != Item.bucketEmpty.itemID) { - if (CoreProxy.proxy.isSimulating(world)) { - if (LiquidUtils.handleRightClick(tile, ForgeDirection.getOrientation(side), player, true, false)) { - return true; - } - } else { - if (LiquidContainerRegistry.isContainer(current)) { - return true; - } - } - } - } - } - - if (tile.engine instanceof EngineStone) { - if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) { - player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, world, i, j, k); - } - return true; - - } else if (tile.engine instanceof EngineIron) { - if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) { - player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_IRON, world, i, j, k); - } - return true; + // Do not open guis when having a pipe in hand + if (player.getCurrentEquippedItem() != null) { + if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) { + return false; } + } + if (tile instanceof TileEngine) { + return ((TileEngine) tile).onBlockActivated(player, ForgeDirection.getOrientation(side)); } return false; @@ -155,7 +127,7 @@ public class BlockEngine extends BlockContainer { @Override public void onPostBlockPlaced(World world, int x, int y, int z, int par5) { TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z); - tile.orientation = ForgeDirection.UP.ordinal(); + tile.orientation = ForgeDirection.UP; tile.switchOrientation(); } @@ -215,4 +187,9 @@ public class BlockEngine extends BlockContainer { return null; } } + + @Override + public TileEntity createNewTileEntity(World world) { + return null; + } } diff --git a/common/buildcraft/energy/BptBlockEngine.java b/common/buildcraft/energy/BptBlockEngine.java index d0a2f187..51701faa 100644 --- a/common/buildcraft/energy/BptBlockEngine.java +++ b/common/buildcraft/energy/BptBlockEngine.java @@ -37,7 +37,7 @@ public class BptBlockEngine extends BptBlock { public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { TileEngine engine = (TileEngine) context.world().getBlockTileEntity(x, y, z); - bptSlot.cpt.setInteger("orientation", engine.engine.orientation.ordinal()); + bptSlot.cpt.setInteger("orientation", engine.orientation.ordinal()); } @Override @@ -46,7 +46,7 @@ public class BptBlockEngine extends BptBlock { TileEngine engine = (TileEngine) context.world().getBlockTileEntity(slot.x, slot.y, slot.z); - engine.orientation = slot.cpt.getInteger("orientation"); + engine.orientation = ForgeDirection.getOrientation(slot.cpt.getInteger("orientation")); } @Override diff --git a/common/buildcraft/energy/EnergyProxy.java b/common/buildcraft/energy/EnergyProxy.java index 0a241d4a..299b847e 100644 --- a/common/buildcraft/energy/EnergyProxy.java +++ b/common/buildcraft/energy/EnergyProxy.java @@ -8,7 +8,10 @@ public class EnergyProxy { public static EnergyProxy proxy; public void registerTileEntities() { - GameRegistry.registerTileEntity(TileEngine.class, "net.minecraft.src.buildcraft.energy.Engine"); + GameRegistry.registerTileEntity(TileEngineLegacy.class, "net.minecraft.src.buildcraft.energy.Engine"); + GameRegistry.registerTileEntity(TileEngineWood.class, "net.minecraft.src.buildcraft.energy.TileEngineWood"); + GameRegistry.registerTileEntity(TileEngineStone.class, "net.minecraft.src.buildcraft.energy.TileEngineStone"); + GameRegistry.registerTileEntity(TileEngineIron.class, "net.minecraft.src.buildcraft.energy.TileEngineIron"); } public void registerBlockRenderers() { diff --git a/common/buildcraft/energy/Engine.java b/common/buildcraft/energy/Engine.java deleted file mode 100644 index a8d0e460..00000000 --- a/common/buildcraft/energy/Engine.java +++ /dev/null @@ -1,212 +0,0 @@ -/** - * 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.energy; - -import net.minecraft.inventory.ICrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.liquids.ILiquidTank; -import net.minecraftforge.liquids.LiquidStack; -import net.minecraftforge.liquids.LiquidTank; -import buildcraft.core.network.TileNetworkData; -import buildcraft.core.proxy.CoreProxy; -import buildcraft.energy.gui.ContainerEngine; - -public abstract class Engine { - - public int maxEnergy; - - protected float currentOutput = 0; - public @TileNetworkData - float progress; - public @TileNetworkData - ForgeDirection orientation; - public float energy; - public @TileNetworkData - EnergyStage energyStage = EnergyStage.Blue; - - public int maxEnergyExtracted = 1; - - protected TileEngine tile; - - public enum EnergyStage { - Blue, Green, Yellow, Red, Explosion - } - - public Engine(TileEngine tile) { - this.tile = tile; - } - - protected void computeEnergyStage() { - double level = energy / (double) maxEnergy * 100.0; - if (level <= 25.0) { - energyStage = EnergyStage.Blue; - } else if (level <= 50.0) { - energyStage = EnergyStage.Green; - } else if (level <= 75.0) { - energyStage = EnergyStage.Yellow; - } else if (level <= 100.0) { - energyStage = EnergyStage.Red; - } else { - energyStage = EnergyStage.Explosion; - } - } - - public final EnergyStage getEnergyStage() { - if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) { - computeEnergyStage(); - } - - return energyStage; - } - - public void update() { - if (!tile.isRedstonePowered) { - if (energy >= 1) { - energy -= 1; - } else if (energy < 1) { - energy = 0; - } - } - } - - public abstract String getTextureFile(); - - public abstract int explosionRange(); - - public int minEnergyReceived() { - return 2; - } - - public abstract int maxEnergyReceived(); - - public abstract float getPistonSpeed(); - - public abstract boolean isBurning(); - - public abstract void delete(); - - public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) { - return 0; - } - - public void addEnergy(float addition) { - energy += addition; - - if (getEnergyStage() == EnergyStage.Explosion) { - tile.worldObj.createExplosion(null, tile.xCoord, tile.yCoord, tile.zCoord, explosionRange(), true); - } - - if (energy > maxEnergy) { - energy = maxEnergy; - } - } - - public float extractEnergy(int min, int max, boolean doExtract) { - if (energy < min) - return 0; - - int actualMax; - - if (max > maxEnergyExtracted) { - actualMax = maxEnergyExtracted; - } else { - actualMax = max; - } - - if (actualMax < min) - return 0; - - float extracted; - - if (energy >= actualMax) { - extracted = actualMax; - if (doExtract) { - energy -= actualMax; - } - } else { - extracted = energy; - if (doExtract) { - energy = 0; - } - } - - return extracted; - } - - public abstract int getScaledBurnTime(int i); - - public abstract void burn(); - - public void readFromNBT(NBTTagCompound nbttagcompound) { - - } - - public void writeToNBT(NBTTagCompound nbttagcompound) { - - } - - public void getGUINetworkData(int i, int j) { - - } - - public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) { - - } - - public boolean isActive() { - return true; - } - - public int getHeat() { - return 0; - } - - public float getEnergyStored() { - return energy; - } - - public float getCurrentOutput() { - return currentOutput; - } - - /* ILIQUIDCONTAINER */ - public LiquidTank[] getLiquidSlots() { - return new LiquidTank[0]; - } - - /* IINVENTORY */ - public int getSizeInventory() { - return 0; - } - - public ItemStack getStackInSlot(int i) { - return null; - } - - public ItemStack decrStackSize(int i, int j) { - return null; - } - - public ItemStack getStackInSlotOnClosing(int i) { - return getStackInSlot(i); - } - - public void setInventorySlotContents(int i, ItemStack itemstack) { - } - - public boolean isStackValidForSlot(int i, ItemStack itemstack){ - return false; - } - - public abstract ILiquidTank getTank(ForgeDirection direction, LiquidStack type); - -} diff --git a/common/buildcraft/energy/EngineIron.java b/common/buildcraft/energy/EngineIron.java deleted file mode 100644 index a6b70cae..00000000 --- a/common/buildcraft/energy/EngineIron.java +++ /dev/null @@ -1,446 +0,0 @@ -/** - * 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.energy; - -import net.minecraft.block.Block; -import net.minecraft.inventory.ICrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.liquids.ILiquidTank; -import net.minecraftforge.liquids.LiquidContainerRegistry; -import net.minecraftforge.liquids.LiquidStack; -import net.minecraftforge.liquids.LiquidTank; -import buildcraft.api.fuels.IronEngineCoolant; -import buildcraft.api.fuels.IronEngineFuel; -import buildcraft.core.DefaultProps; -import buildcraft.core.utils.Utils; -import buildcraft.energy.gui.ContainerEngine; - -public class EngineIron extends Engine { - - public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME * 10; - public static int MAX_HEAT = 100000; - public static int COOLANT_THRESHOLD = 49000; - - private ItemStack itemInInventory; - - int burnTime = 0; - int heat = 0; - private LiquidTank fuelTank; - private LiquidTank coolantTank; - private IronEngineFuel currentFuel = null; - - public int penaltyCooling = 0; - - boolean lastPowered = false; - - public EngineIron(TileEngine engine) { - super(engine); - - maxEnergy = 100000; - maxEnergyExtracted = 500; - fuelTank = new LiquidTank(MAX_LIQUID); - coolantTank = new LiquidTank(MAX_LIQUID); - } - - @Override - public String getTextureFile() { - return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png"; - } - - @Override - public int explosionRange() { - return 8; - } - - @Override - public int maxEnergyReceived() { - return 2000; - } - - @Override - public float getPistonSpeed() { - switch (getEnergyStage()) { - case Blue: - return 0.04F; - case Green: - return 0.05F; - case Yellow: - return 0.06F; - case Red: - return 0.07F; - default: - return 0.0f; - } - } - - @Override - public boolean isBurning() { - LiquidStack fuel = fuelTank.getLiquid(); - return fuel != null && fuel.amount > 0 && penaltyCooling == 0 && tile.isRedstonePowered; - } - - @Override - public void burn() { - currentOutput = 0; - LiquidStack fuel = this.fuelTank.getLiquid(); - if(currentFuel == null) { - currentFuel = IronEngineFuel.getFuelForLiquid(fuel); - } - - if (currentFuel == null) - return; - - if (penaltyCooling <= 0 && tile.isRedstonePowered) { - - lastPowered = true; - - if (burnTime > 0 || fuel.amount > 0) { - if (burnTime > 0) { - burnTime--; - } - if (burnTime <= 0) { - if(fuel != null) { - if (--fuel.amount <= 0) { - fuelTank.setLiquid(null); - } - burnTime = currentFuel.totalBurningTime / LiquidContainerRegistry.BUCKET_VOLUME; - } else { - currentFuel = null; - return; - } - } - currentOutput = currentFuel.powerPerCycle; - addEnergy(currentFuel.powerPerCycle); - heat += currentFuel.powerPerCycle; - } - } else if (penaltyCooling <= 0) { - if (lastPowered) { - lastPowered = false; - penaltyCooling = 30 * 20; - // 30 sec of penalty on top of the cooling - } - } - } - - @Override - public void update() { - super.update(); - - if (itemInInventory != null) { - LiquidStack liquid; - if (Block.ice.blockID == itemInInventory.itemID && heat > COOLANT_THRESHOLD) { - liquid = LiquidContainerRegistry.getLiquidForFilledItem(new ItemStack(Item.bucketWater)); - } else { - liquid = LiquidContainerRegistry.getLiquidForFilledItem(itemInInventory); - } - - if (liquid != null) { - if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount) { - fill(ForgeDirection.UNKNOWN, liquid, true); - tile.setInventorySlotContents(0, Utils.consumeItem(itemInInventory)); - } - } - } - - if (heat > COOLANT_THRESHOLD) { - int extraHeat = heat - COOLANT_THRESHOLD; - - LiquidStack coolant = this.coolantTank.getLiquid(); - IronEngineCoolant currentCoolant = IronEngineCoolant.getCoolantForLiquid(coolant); - if (currentCoolant != null) { - if (coolant.amount * currentCoolant.coolingPerUnit > extraHeat) { - coolant.amount -= Math.round(extraHeat / currentCoolant.coolingPerUnit); - heat = COOLANT_THRESHOLD; - } else { - heat -= coolant.amount * currentCoolant.coolingPerUnit; - coolantTank.setLiquid(null); - } - } - } - - if (heat > 0 && (penaltyCooling > 0 || !tile.isRedstonePowered)) { - heat -= 10; - - } - - if (heat <= 0) { - heat = 0; - } - - if (heat == 0 && penaltyCooling > 0) { - penaltyCooling--; - } - } - - @Override - public void computeEnergyStage() { - if (heat <= MAX_HEAT / 4) { - energyStage = EnergyStage.Blue; - } else if (heat <= MAX_HEAT / 2) { - energyStage = EnergyStage.Green; - } else if (heat <= MAX_HEAT * 3F / 4F) { - energyStage = EnergyStage.Yellow; - } else if (heat <= MAX_HEAT) { - energyStage = EnergyStage.Red; - } else { - energyStage = EnergyStage.Explosion; - } - } - - @Override - public int getScaledBurnTime(int i) { - return this.fuelTank.getLiquid() != null ? (int) (((float) this.fuelTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0; - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - if (nbttagcompound.hasKey("liquidId")) { - fuelTank.setLiquid(new LiquidStack(nbttagcompound.getInteger("liquidId"), nbttagcompound.getInteger("liquidQty"), nbttagcompound - .getInteger("liquidMeta"))); - } else { - fuelTank.readFromNBT(nbttagcompound.getCompoundTag("fuelTank")); - } - - burnTime = nbttagcompound.getInteger("burnTime"); - - if (nbttagcompound.hasKey("coolantId")) { - coolantTank.setLiquid(new LiquidStack(nbttagcompound.getInteger("coolantId"), nbttagcompound.getInteger("coolantQty"), nbttagcompound - .getInteger("coolantMeta"))); - } else { - coolantTank.readFromNBT(nbttagcompound.getCompoundTag("coolantTank")); - } - - heat = nbttagcompound.getInteger("heat"); - penaltyCooling = nbttagcompound.getInteger("penaltyCooling"); - - if (nbttagcompound.hasKey("itemInInventory")) { - NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory"); - itemInInventory = ItemStack.loadItemStackFromNBT(cpt); - } - - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - nbttagcompound.setTag("fuelTank", fuelTank.writeToNBT(new NBTTagCompound())); - nbttagcompound.setTag("coolantTank", coolantTank.writeToNBT(new NBTTagCompound())); - - nbttagcompound.setInteger("burnTime", burnTime); - nbttagcompound.setInteger("heat", heat); - nbttagcompound.setInteger("penaltyCooling", penaltyCooling); - - if (itemInInventory != null) { - NBTTagCompound cpt = new NBTTagCompound(); - itemInInventory.writeToNBT(cpt); - nbttagcompound.setTag("itemInInventory", cpt); - } - - } - - public int getScaledCoolant(int i) { - return coolantTank.getLiquid() != null ? (int) (((float) coolantTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0; - } - - @Override - public void delete() { - ItemStack stack = tile.getStackInSlot(0); - if (stack != null) { - Utils.dropItems(tile.worldObj, stack, tile.xCoord, tile.yCoord, tile.zCoord); - } - } - - @Override - public void getGUINetworkData(int i, int j) { - switch (i) { - case 0: - int iEnergy = Math.round(energy * 10); - iEnergy = (iEnergy & 0xffff0000) | (j & 0xffff); - energy = iEnergy / 10; - break; - case 1: - iEnergy = Math.round(energy * 10); - iEnergy = (iEnergy & 0xffff) | ((j & 0xffff) << 16); - energy = iEnergy / 10; - break; - case 2: - currentOutput = j / 10; - break; - case 3: - heat = (heat & 0xffff0000) | (j & 0xffff); - break; - case 4: - heat = (heat & 0xffff) | ((j & 0xffff) << 16); - break; - case 5: - if (fuelTank.getLiquid() == null) { - fuelTank.setLiquid(new LiquidStack(0, j)); - } else { - fuelTank.getLiquid().amount = j; - } - break; - case 6: - if (fuelTank.getLiquid() == null) { - fuelTank.setLiquid(new LiquidStack(j, 0)); - } else { - fuelTank.setLiquid(new LiquidStack(j,fuelTank.getLiquid().amount,fuelTank.getLiquid().itemMeta)); - } - break; - case 7: - if (coolantTank.getLiquid() == null) { - coolantTank.setLiquid(new LiquidStack(0, j)); - } else { - coolantTank.getLiquid().amount = j; - } - break; - case 8: - if (coolantTank.getLiquid() == null) { - coolantTank.setLiquid(new LiquidStack(j, 0)); - } else { - coolantTank.setLiquid(new LiquidStack(j,coolantTank.getLiquid().amount,coolantTank.getLiquid().itemMeta)); - } - break; - case 9: - if (fuelTank.getLiquid() == null) { - fuelTank.setLiquid(new LiquidStack(0, 0, j)); - } else { - fuelTank.setLiquid(new LiquidStack(fuelTank.getLiquid().itemID,fuelTank.getLiquid().amount,j)); - } - break; - case 10: - if (coolantTank.getLiquid() == null) { - coolantTank.setLiquid(new LiquidStack(0, 0, j)); - } else { - coolantTank.setLiquid(new LiquidStack(coolantTank.getLiquid().itemID,coolantTank.getLiquid().amount,j)); - } - } - } - - @Override - public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) { - iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy * 10) & 0xffff); - iCrafting.sendProgressBarUpdate(containerEngine, 1, (Math.round(energy * 10) & 0xffff0000) >> 16); - iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10)); - iCrafting.sendProgressBarUpdate(containerEngine, 3, heat & 0xffff); - iCrafting.sendProgressBarUpdate(containerEngine, 4, (heat & 0xffff0000) >> 16); - iCrafting.sendProgressBarUpdate(containerEngine, 5, fuelTank.getLiquid() != null ? fuelTank.getLiquid().amount : 0); - iCrafting.sendProgressBarUpdate(containerEngine, 6, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemID : 0); - iCrafting.sendProgressBarUpdate(containerEngine, 7, coolantTank.getLiquid() != null ? coolantTank.getLiquid().amount : 0); - iCrafting.sendProgressBarUpdate(containerEngine, 8, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemID : 0); - iCrafting.sendProgressBarUpdate(containerEngine, 9, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemMeta : 0); - iCrafting.sendProgressBarUpdate(containerEngine, 10, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemMeta : 0); - } - - @Override - public boolean isActive() { - return penaltyCooling <= 0; - } - - @Override - public int getHeat() { - return heat; - } - - /* ITANKCONTAINER */ - @Override - public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) { - - // Handle coolant - if (IronEngineCoolant.getCoolantForLiquid(resource) != null) - return fillCoolant(from, resource, doFill); - - if (IronEngineFuel.getFuelForLiquid(resource) != null) - return fuelTank.fill(resource, doFill); - - return 0; - } - - private int fillCoolant(ForgeDirection from, LiquidStack resource, boolean doFill) { - return coolantTank.fill(resource, doFill); - } - - @Override - public LiquidTank[] getLiquidSlots() { - return new LiquidTank[] { fuelTank, coolantTank }; - } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return 1; - } - - @Override - public ItemStack getStackInSlot(int i) { - return itemInInventory; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - itemInInventory = itemstack; - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - if (itemInInventory != null) { - if (itemInInventory.stackSize <= 0) { - itemInInventory = null; - return null; - } - ItemStack newStack = itemInInventory; - if (amount >= newStack.stackSize) { - itemInInventory = null; - } else { - newStack = itemInInventory.splitStack(amount); - } - - return newStack; - } - return null; - } - - @Override - public boolean isStackValidForSlot(int i, ItemStack itemstack) { - if (itemstack == null) return false; - if (Block.ice.blockID == itemstack.itemID) return true; - return LiquidContainerRegistry.getLiquidForFilledItem(itemstack) != null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) { - if (itemInInventory == null) - return null; - ItemStack toReturn = itemInInventory; - itemInInventory = null; - return toReturn; - } - - @Override - public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) { - switch (direction) { - case UP: - return fuelTank; - case DOWN: - return coolantTank; - default: - return null; - } - } - - public LiquidStack getFuel() { - return fuelTank.getLiquid(); - } - - public LiquidStack getCoolant() { - return coolantTank.getLiquid(); - } -} diff --git a/common/buildcraft/energy/EngineStone.java b/common/buildcraft/energy/EngineStone.java deleted file mode 100644 index 6aeb5446..00000000 --- a/common/buildcraft/energy/EngineStone.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * 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.energy; - -import net.minecraft.inventory.ICrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.liquids.ILiquidTank; -import net.minecraftforge.liquids.LiquidStack; -import buildcraft.core.DefaultProps; -import buildcraft.core.utils.Utils; -import buildcraft.energy.gui.ContainerEngine; - -public class EngineStone extends Engine { - final float maxProduction = 1f; - final float minProduction = maxProduction / 3; - final float target = 0.375f; - final float kp = 1f; - final float ki = 0.05f; - final float eLimit = (maxProduction - minProduction) / ki; - - int burnTime = 0; - int totalBurnTime = 0; - float esum = 0; - - private ItemStack itemInInventory; - - public EngineStone(TileEngine engine) { - super(engine); - - maxEnergy = 10000; - maxEnergyExtracted = 100; - } - - @Override - public String getTextureFile() { - return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_stone.png"; - } - - @Override - public int explosionRange() { - return 4; - } - - @Override - public int maxEnergyReceived() { - return 200; - } - - @Override - public float getPistonSpeed() { - switch (getEnergyStage()) { - case Blue: - return 0.02F; - case Green: - return 0.04F; - case Yellow: - return 0.08F; - case Red: - return 0.16F; - default: - return 0; - } - } - - @Override - public boolean isBurning() { - return burnTime > 0; - } - - @Override - public void burn() { - currentOutput = 0; - if (burnTime > 0) { - burnTime--; - - float e = target * maxEnergy - energy; - - esum = Math.min(Math.max(esum + e, -eLimit), eLimit); - currentOutput = Math.min(Math.max(e * kp + esum * ki, minProduction), maxProduction); - - addEnergy(currentOutput); - } - - if (burnTime == 0 && tile.isRedstonePowered) { - - burnTime = totalBurnTime = getItemBurnTime(tile.getStackInSlot(0)); - - if (burnTime > 0) { - tile.setInventorySlotContents(0, Utils.consumeItem(tile.getStackInSlot(0))); - } - } - } - - @Override - public int getScaledBurnTime(int i) { - return (int) (((float) burnTime / (float) totalBurnTime) * i); - } - - private int getItemBurnTime(ItemStack itemstack) { - if (itemstack == null) - return 0; - - return TileEntityFurnace.getItemBurnTime(itemstack); - } - - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - burnTime = nbttagcompound.getInteger("burnTime"); - totalBurnTime = nbttagcompound.getInteger("totalBurnTime"); - - if (nbttagcompound.hasKey("itemInInventory")) { - NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory"); - itemInInventory = ItemStack.loadItemStackFromNBT(cpt); - } - - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - nbttagcompound.setInteger("burnTime", burnTime); - nbttagcompound.setInteger("totalBurnTime", totalBurnTime); - - if (itemInInventory != null) { - NBTTagCompound cpt = new NBTTagCompound(); - itemInInventory.writeToNBT(cpt); - nbttagcompound.setTag("itemInInventory", cpt); - } - - } - - @Override - public void delete() { - ItemStack stack = tile.getStackInSlot(0); - if (stack != null) { - Utils.dropItems(tile.worldObj, stack, tile.xCoord, tile.yCoord, tile.zCoord); - } - } - - @Override - public void getGUINetworkData(int i, int j) { - switch (i) { - case 0: - energy = j; - break; - case 1: - currentOutput = j / 100f; - break; - case 2: - burnTime = j; - break; - case 3: - totalBurnTime = j; - break; - } - } - - @Override - public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) { - iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy)); - iCrafting.sendProgressBarUpdate(containerEngine, 1, Math.round(currentOutput * 100f)); - iCrafting.sendProgressBarUpdate(containerEngine, 2, burnTime); - iCrafting.sendProgressBarUpdate(containerEngine, 3, totalBurnTime); - } - - @Override - public int getHeat() { - return Math.round(energy); - } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return 1; - } - - @Override - public ItemStack getStackInSlot(int i) { - return itemInInventory; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - itemInInventory = itemstack; - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - if (itemInInventory != null) { - if (itemInInventory.stackSize <= 0) { - itemInInventory = null; - return null; - } - ItemStack newStack = itemInInventory; - if (amount >= newStack.stackSize) { - itemInInventory = null; - } else { - newStack = itemInInventory.splitStack(amount); - } - - return newStack; - } - return null; - } - - @Override - public boolean isStackValidForSlot(int i, ItemStack itemstack) { - return getItemBurnTime(itemstack) > 0; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) { - if (itemInInventory == null) - return null; - ItemStack toReturn = itemInInventory; - itemInInventory = null; - return toReturn; - } - - @Override - public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) { - return null; - } -} \ No newline at end of file diff --git a/common/buildcraft/energy/EngineWood.java b/common/buildcraft/energy/EngineWood.java deleted file mode 100644 index 8c9c39a0..00000000 --- a/common/buildcraft/energy/EngineWood.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * 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.energy; - -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.liquids.ILiquidTank; -import net.minecraftforge.liquids.LiquidStack; -import buildcraft.core.DefaultProps; - -public class EngineWood extends Engine { - - public EngineWood(TileEngine engine) { - super(engine); - - maxEnergy = 1000; - } - - @Override - public String getTextureFile() { - return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png"; - } - - @Override - public int explosionRange() { - return 1; - } - - @Override - public int minEnergyReceived() { - return 1; - } - - @Override - public int maxEnergyReceived() { - return 50; - } - - @Override - protected void computeEnergyStage() { - double level = energy / (double) maxEnergy * 100.0; - if (level <= 25.0) { - energyStage = EnergyStage.Blue; - } else if (level <= 50.0) { - energyStage = EnergyStage.Green; - } else if (level <= 75.0) { - energyStage = EnergyStage.Yellow; - } else { - energyStage = EnergyStage.Red; - } - } - - @Override - public float getPistonSpeed() { - switch (getEnergyStage()) { - case Blue: - return 0.01F; - case Green: - return 0.02F; - case Yellow: - return 0.04F; - case Red: - return 0.08F; - default: - return 0; - } - } - - @Override - public void update() { - super.update(); - - if (tile.isRedstonePowered) { - if ((tile.worldObj.getWorldTime() % 20) == 0) { - addEnergy(1); - } - } - } - - @Override - public boolean isBurning() { - return tile.isRedstonePowered; - } - - @Override - public int getScaledBurnTime(int i) { - return 0; - } - - @Override - public void delete() { - } - - @Override - public void burn() { - } - - @Override - public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) { - return null; - } -} diff --git a/common/buildcraft/energy/IEngineProvider.java b/common/buildcraft/energy/IEngineProvider.java deleted file mode 100644 index 0882761c..00000000 --- a/common/buildcraft/energy/IEngineProvider.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * 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.energy; - -public interface IEngineProvider { - - public Engine getEngine(); -} diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 9067d1b2..11dc8e18 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -1,12 +1,10 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.energy; import java.util.LinkedList; @@ -15,14 +13,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.liquids.ILiquidTank; -import net.minecraftforge.liquids.ITankContainer; -import net.minecraftforge.liquids.LiquidStack; -import net.minecraftforge.liquids.LiquidTank; -import buildcraft.BuildCraftCore; import buildcraft.BuildCraftEnergy; import buildcraft.api.core.Position; import buildcraft.api.gates.IOverrideDefaultTriggers; @@ -30,274 +22,345 @@ import buildcraft.api.gates.ITrigger; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerProvider; import buildcraft.api.transport.IPipeConnection; -import buildcraft.core.IBuilderInventory; +import buildcraft.core.TileBuffer; import buildcraft.core.TileBuildCraft; -import buildcraft.core.network.PacketUpdate; +import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.network.TileNetworkData; import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; +import buildcraft.energy.gui.ContainerEngine; +import net.minecraft.inventory.ICrafting; -//TODO: All Engines need to take func_48081_b into account +public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, IOverrideDefaultTriggers, IPipeConnection { -public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, ITankContainer, IEngineProvider, IOverrideDefaultTriggers, - IPipeConnection, IBuilderInventory { - - public @TileNetworkData - Engine engine; - public @TileNetworkData - int progressPart = 0; - public @TileNetworkData - float serverPistonSpeed = 0; - public @TileNetworkData - boolean isActive = false; // Used for SMP synch - - boolean lastPower = false; - - public int orientation; - - PowerProvider provider; + public enum EnergyStage { + BLUE, GREEN, YELLOW, RED, OVERHEAT + } + public static final float MIN_HEAT = 20; + public static final float IDEAL_HEAT = 100; + public static final float MAX_HEAT = 250; + protected int progressPart = 0; + protected boolean lastPower = false; + protected PowerProvider provider; + public float currentOutput = 0; public boolean isRedstonePowered = false; + public TileBuffer[] tileCache; + public float progress; + public float energy; + public float heat = MIN_HEAT; + private final SimpleInventory inv; + // + public @TileNetworkData + EnergyStage energyStage = EnergyStage.BLUE; + public @TileNetworkData + ForgeDirection orientation = ForgeDirection.UP; + public @TileNetworkData + boolean isPumping = false; // Used for SMP synch - public TileEngine() { + public TileEngine(int invSize) { provider = new PowerProvider(this, false); provider.configurePowerPerdition(1, 100); + + inv = new SimpleInventory(invSize, "Engine", 64); } @Override public void initialize() { if (!CoreProxy.proxy.isRenderWorld(worldObj)) { - if (engine == null) { - createEngineIfNeeded(); - } - - engine.orientation = ForgeDirection.VALID_DIRECTIONS[orientation]; - provider.configure(engine.minEnergyReceived(), engine.maxEnergyReceived(), 1, engine.maxEnergy); + tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, true); + provider.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy()); checkRedstonePower(); } } + public abstract String getTextureFile(); + + public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) { + return false; + } + + public float getEnergyLevel() { + return energy / getMaxEnergy(); + } + + protected EnergyStage computeEnergyStage() { + float energyLevel = getHeatLevel(); + if (energyLevel < 0.25f) { + return EnergyStage.BLUE; + } else if (energyLevel < 0.5f) { + return EnergyStage.GREEN; + } else if (energyLevel < 0.75f) { + return EnergyStage.YELLOW; + } else if (energyLevel < 1f) { + return EnergyStage.RED; + } else { + return EnergyStage.OVERHEAT; + } + } + + public final EnergyStage getEnergyStage() { + if (CoreProxy.proxy.isSimulating(worldObj)) { + if (energyStage == EnergyStage.OVERHEAT) { + return energyStage; + } + EnergyStage newStage = computeEnergyStage(); + + if (energyStage != newStage) { + energyStage = newStage; + sendNetworkUpdate(); + } + } + + return energyStage; + } + + public void updateHeatLevel() { + heat = ((MAX_HEAT - MIN_HEAT) * getEnergyLevel()) + MIN_HEAT; + } + + public float getHeatLevel() { + return (heat - MIN_HEAT) / (MAX_HEAT - MIN_HEAT); + } + + public float getIdealHeatLevel() { + return heat / IDEAL_HEAT; + } + + public float getHeat() { + return heat; + } + + public float getPistonSpeed() { + if (CoreProxy.proxy.isSimulating(worldObj)) { + return Math.max(0.16f * getHeatLevel(), 0.01f); + } + switch (getEnergyStage()) { + case BLUE: + return 0.02F; + case GREEN: + return 0.04F; + case YELLOW: + return 0.08F; + case RED: + return 0.16F; + default: + return 0; + } + } + @Override public void updateEntity() { super.updateEntity(); - if (engine == null) - return; - if (CoreProxy.proxy.isRenderWorld(worldObj)) { if (progressPart != 0) { - engine.progress += serverPistonSpeed; + progress += getPistonSpeed(); - if (engine.progress > 1) { + if (progress > 1) { progressPart = 0; - engine.progress = 0; + progress = 0; } - } else if (this.isActive) { + } else if (this.isPumping) { progressPart = 1; } return; } - engine.update(); + updateHeatLevel(); + engineUpdate(); - float newPistonSpeed = engine.getPistonSpeed(); - if (newPistonSpeed != serverPistonSpeed) { - serverPistonSpeed = newPistonSpeed; - sendNetworkUpdate(); - } + TileEntity tile = tileCache[orientation.ordinal()].getTile(); if (progressPart != 0) { - engine.progress += engine.getPistonSpeed(); + progress += getPistonSpeed(); - if (engine.progress > 0.5 && progressPart == 1) { + if (progress > 0.5 && progressPart == 1) { progressPart = 2; - - Position pos = new Position(xCoord, yCoord, zCoord, engine.orientation); - pos.moveForwards(1.0); - TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); - - if (isPoweredTile(tile)) { - PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite()); - - float extracted = engine.extractEnergy(receptor.getMinEnergyReceived(), - Math.min(receptor.getMaxEnergyReceived(), receptor.getMaxEnergyStored() - (int) receptor.getEnergyStored()), true); - - if (extracted > 0) { - receptor.receiveEnergy(extracted, engine.orientation.getOpposite()); - } - } - } else if (engine.progress >= 1) { - engine.progress = 0; + sendPower(); // Comment out for constant power + } else if (progress >= 1) { + progress = 0; progressPart = 0; } - } else if (isRedstonePowered && engine.isActive()) { - - Position pos = new Position(xCoord, yCoord, zCoord, engine.orientation); - pos.moveForwards(1.0); - TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); - - if (isPoweredTile(tile)) { - PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite()); - - if (engine.extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false) > 0) { + } else if (isRedstonePowered && isActive()) { + if (isPoweredTile(tile, orientation)) { + if (getPowerToExtract() > 0) { progressPart = 1; - setActive(true); + setPumping(true); } else { - setActive(false); + setPumping(false); } } else { - setActive(false); + setPumping(false); } } else { - setActive(false); + setPumping(false); } - engine.burn(); + // Uncomment for constant power +// if (isRedstonePowered && isActive()) { +// sendPower(); +// } else currentOutput = 0; + + burn(); } - private void setActive(boolean isActive) { - if (this.isActive == isActive) - return; - - this.isActive = isActive; - sendNetworkUpdate(); + private float getPowerToExtract() { + TileEntity tile = tileCache[orientation.ordinal()].getTile(); + PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(orientation.getOpposite()); + return extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false); // Comment out for constant power +// return extractEnergy(0, getActualOutput(), false); // Uncomment for constant power } - private void createEngineIfNeeded() { - if (engine == null) { - int kind = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); + private void sendPower() { + TileEntity tile = tileCache[orientation.ordinal()].getTile(); + if (isPoweredTile(tile, orientation)) { + PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(orientation.getOpposite()); - engine = newEngine(kind); - - engine.orientation = ForgeDirection.VALID_DIRECTIONS[orientation]; - worldObj.notifyBlockChange(xCoord, yCoord, zCoord, BuildCraftEnergy.engineBlock.blockID); + float extracted = getPowerToExtract(); + if (extracted > 0) { + float needed = receptor.receiveEnergy(extracted, orientation.getOpposite(), true); + extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power +// extractEnergy(0, needed, true); // Uncomment for constant power + } } } + + // Uncomment out for constant power +// public float getActualOutput() { +// float heatLevel = getIdealHeatLevel(); +// return getCurrentOutput() * heatLevel; +// } - public void switchOrientation() { - for (int i = orientation + 1; i <= orientation + 6; ++i) { - ForgeDirection o = ForgeDirection.values()[i % 6]; + protected void burn() { + } - Position pos = new Position(xCoord, yCoord, zCoord, o); - - pos.moveForwards(1); - - TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); - - if (isPoweredTile(tile)) { - if (engine != null) { - engine.orientation = o; - } - orientation = o.ordinal(); - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord)); - break; + protected void engineUpdate() { + if (!isRedstonePowered) { + if (energy >= 1) { + energy -= 1; + } else if (energy < 1) { + energy = 0; } } } - public void delete() { - if (engine != null) { - engine.delete(); - } + public boolean isActive() { + return true; } - public Engine newEngine(int meta) { - if (meta == 1) - return new EngineStone(this); - else if (meta == 2) - return new EngineIron(this); - else - return new EngineWood(this); + protected final void setPumping(boolean isActive) { + if (this.isPumping == isActive) + return; + + this.isPumping = isActive; + sendNetworkUpdate(); } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); + public boolean switchOrientation() { + for (int i = orientation.ordinal() + 1; i <= orientation.ordinal() + 6; ++i) { + ForgeDirection o = ForgeDirection.VALID_DIRECTIONS[i % 6]; - int kind = nbttagcompound.getInteger("kind"); + Position pos = new Position(xCoord, yCoord, zCoord, o); + pos.moveForwards(1); + TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); - engine = newEngine(kind); + if (isPoweredTile(tile, o)) { + orientation = o; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord)); - orientation = nbttagcompound.getInteger("orientation"); - - if (engine != null) { - engine.progress = nbttagcompound.getFloat("progress"); - engine.energy = nbttagcompound.getFloat("energyF"); - engine.orientation = ForgeDirection.values()[orientation]; - } - - if (engine != null) { - engine.readFromNBT(nbttagcompound); - } - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - - nbttagcompound.setInteger("kind", worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); - - if (engine != null) { - nbttagcompound.setInteger("orientation", orientation); - nbttagcompound.setFloat("progress", engine.progress); - nbttagcompound.setFloat("energyF", engine.energy); - } - - if (engine != null) { - engine.writeToNBT(nbttagcompound); - } - } - - /* IINVENTORY IMPLEMENTATION */ - @Override - public int getSizeInventory() { - if (engine != null) - return engine.getSizeInventory(); - else - return 0; - } - - @Override - public ItemStack getStackInSlot(int i) { - if (engine != null) - return engine.getStackInSlot(i); - else - return null; - } - - @Override - public ItemStack decrStackSize(int i, int j) { - if (engine != null) - return engine.decrStackSize(i, j); - else - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) { - if (engine != null) - return engine.getStackInSlotOnClosing(i); - else - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - if (engine != null) { - engine.setInventorySlotContents(i, itemstack); - } - } - - @Override - public boolean isStackValidForSlot(int i, ItemStack itemstack) { - if (engine != null){ - return engine.isStackValidForSlot(i, itemstack); + return true; + } } return false; } + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + orientation = ForgeDirection.getOrientation(data.getInteger("orientation")); + progress = data.getFloat("progress"); + energy = data.getFloat("energyF"); + heat = data.getFloat("heat"); + inv.readFromNBT(data); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + data.setInteger("orientation", orientation.ordinal()); + data.setFloat("progress", progress); + data.setFloat("energyF", energy); + data.setFloat("heat", heat); + inv.writeToNBT(data); + } + + public void getGUINetworkData(int id, int value) { + switch (id) { + case 0: + int iEnergy = Math.round(energy * 10); + iEnergy = (iEnergy & 0xffff0000) | (value & 0xffff); + energy = iEnergy / 10; + break; + case 1: + iEnergy = Math.round(energy * 10); + iEnergy = (iEnergy & 0xffff) | ((value & 0xffff) << 16); + energy = iEnergy / 10; + break; + case 2: + currentOutput = value / 10F; + break; + case 3: + heat = value / 100F; + break; + } + } + + public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) { + iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy * 10) & 0xffff); + iCrafting.sendProgressBarUpdate(containerEngine, 1, (Math.round(energy * 10) & 0xffff0000) >> 16); + iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10)); + iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100)); + } + /* IINVENTORY IMPLEMENTATION */ + + @Override + public int getSizeInventory() { + return inv.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int slot) { + return inv.getStackInSlot(slot); + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + return inv.decrStackSize(slot, amount); + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return inv.getStackInSlotOnClosing(slot); + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemstack) { + inv.setInventorySlotContents(slot, itemstack); + } + + @Override + public boolean isStackValidForSlot(int i, ItemStack itemstack) { + return true; + } + + public void delete() { + Utils.dropItems(worldObj, inv, xCoord, yCoord, zCoord); + } + @Override public String getInvName() { return "Engine"; @@ -314,47 +377,9 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven } /* STATE INFORMATION */ - public boolean isBurning() { - return engine != null && engine.isBurning(); - } + public abstract boolean isBurning(); - public int getScaledBurnTime(int i) { - if (engine != null) - return engine.getScaledBurnTime(i); - else - return 0; - } - - /* SMP UPDATING */ - @Override - public Packet getDescriptionPacket() { - createEngineIfNeeded(); - - return super.getDescriptionPacket(); - } - - @Override - public Packet getUpdatePacket() { - if (engine != null) { - serverPistonSpeed = engine.getPistonSpeed(); - } - - return super.getUpdatePacket(); - } - - @Override - public void handleDescriptionPacket(PacketUpdate packet) { - createEngineIfNeeded(); - - super.handleDescriptionPacket(packet); - } - - @Override - public void handleUpdatePacket(PacketUpdate packet) { - createEngineIfNeeded(); - - super.handleUpdatePacket(packet); - } + public abstract int getScaledBurnTime(int scale); @Override public PowerProvider getPowerProvider(ForgeDirection side) { @@ -366,12 +391,56 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven if (CoreProxy.proxy.isRenderWorld(worldObj)) return; - engine.addEnergy(provider.useEnergy(1, engine.maxEnergyReceived(), true) * 0.95F); + addEnergy(provider.useEnergy(1, maxEnergyReceived(), true) * 0.95F); } - public boolean isPoweredTile(TileEntity tile) { + public void addEnergy(float addition) { + energy += addition; + + if (getEnergyStage() == EnergyStage.OVERHEAT) { + worldObj.createExplosion(null, xCoord, yCoord, zCoord, explosionRange(), true); + } + + if (energy > getMaxEnergy()) { + energy = getMaxEnergy(); + } + } + + public float extractEnergy(float min, float max, boolean doExtract) { + if (energy < min) + return 0; + + float actualMax; + + if (max > maxEnergyExtracted()) { + actualMax = maxEnergyExtracted(); + } else { + actualMax = max; + } + + if (actualMax < min) + return 0; + + float extracted; + + if (energy >= actualMax) { + extracted = actualMax; + if (doExtract) { + energy -= actualMax; + } + } else { + extracted = energy; + if (doExtract) { + energy = 0; + } + } + + return extracted; + } + + public boolean isPoweredTile(TileEntity tile, ForgeDirection side) { if (tile instanceof IPowerReceptor) { - PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(engine.orientation.getOpposite()); + PowerProvider receptor = ((IPowerReceptor) tile).getPowerProvider(side.getOpposite()); return receptor != null; } @@ -381,19 +450,30 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven @Override public void openChest() { - } @Override public void closeChest() { - } - @Override - public Engine getEngine() { - return engine; + public abstract float getMaxEnergy(); + + public float minEnergyReceived() { + return 2; } + public abstract float maxEnergyReceived(); + + public abstract float maxEnergyExtracted(); + + public abstract float explosionRange(); + + public float getEnergyStored() { + return energy; + } + + public abstract float getCurrentOutput(); + @Override public LinkedList getTriggers() { LinkedList triggers = new LinkedList(); @@ -403,73 +483,15 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven triggers.add(BuildCraftEnergy.triggerYellowEngineHeat); triggers.add(BuildCraftEnergy.triggerRedEngineHeat); - if (engine instanceof EngineIron) { - triggers.add(BuildCraftCore.triggerEmptyLiquid); - triggers.add(BuildCraftCore.triggerContainsLiquid); - triggers.add(BuildCraftCore.triggerSpaceLiquid); - triggers.add(BuildCraftCore.triggerFullLiquid); - } else if (engine instanceof EngineStone) { - triggers.add(BuildCraftCore.triggerEmptyInventory); - triggers.add(BuildCraftCore.triggerContainsInventory); - triggers.add(BuildCraftCore.triggerSpaceInventory); - triggers.add(BuildCraftCore.triggerFullInventory); - } - return triggers; } @Override public boolean isPipeConnected(ForgeDirection with) { - if (engine instanceof EngineWood) - return false; - - return with.ordinal() != orientation; - } - - @Override - public boolean isBuildingMaterial(int i) { - return false; + return with != orientation; } public void checkRedstonePower() { isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); } - - /* ILIQUIDCONTAINER */ - @Override - public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) { - if (engine == null) - return 0; - return engine.fill(from, resource, doFill); - } - - @Override - public int fill(int tankIndex, LiquidStack resource, boolean doFill) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - return null; - } - - @Override - public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) { - return null; - } - - @Override - public LiquidTank[] getTanks(ForgeDirection direction) { - if (engine == null) - return new LiquidTank[0]; - else - return engine.getLiquidSlots(); - } - - @Override - public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) { - return engine != null ? engine.getTank(direction, type) : null; - } - } diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java new file mode 100644 index 00000000..2964f0e9 --- /dev/null +++ b/common/buildcraft/energy/TileEngineIron.java @@ -0,0 +1,407 @@ +/** + * 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.energy; + +import buildcraft.BuildCraftCore; +import buildcraft.BuildCraftEnergy; +import net.minecraft.block.Block; +import net.minecraft.inventory.ICrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.liquids.ILiquidTank; +import net.minecraftforge.liquids.LiquidContainerRegistry; +import net.minecraftforge.liquids.LiquidStack; +import net.minecraftforge.liquids.LiquidTank; +import buildcraft.api.fuels.IronEngineCoolant; +import buildcraft.api.fuels.IronEngineCoolant.Coolant; +import buildcraft.api.fuels.IronEngineFuel; +import buildcraft.api.gates.ITrigger; +import buildcraft.core.DefaultProps; +import buildcraft.core.GuiIds; +import buildcraft.core.IItemPipe; +import buildcraft.core.liquids.LiquidUtils; +import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; +import static buildcraft.energy.TileEngine.EnergyStage.BLUE; +import static buildcraft.energy.TileEngine.EnergyStage.GREEN; +import static buildcraft.energy.TileEngine.EnergyStage.RED; +import static buildcraft.energy.TileEngine.EnergyStage.YELLOW; +import static buildcraft.energy.TileEngine.IDEAL_HEAT; +import static buildcraft.energy.TileEngine.MIN_HEAT; +import buildcraft.energy.gui.ContainerEngine; +import java.util.LinkedList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.liquids.ITankContainer; + +public class TileEngineIron extends TileEngine implements ITankContainer { + + public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME * 10; + public static float HEAT_PER_MJ = 0.01F; + public static float COOLDOWN_RATE = 0.005F; + int burnTime = 0; + private LiquidTank fuelTank; + private LiquidTank coolantTank; + private IronEngineFuel currentFuel = null; + public int penaltyCooling = 0; + boolean lastPowered = false; + + public TileEngineIron() { + super(1); + fuelTank = new LiquidTank(MAX_LIQUID); + coolantTank = new LiquidTank(MAX_LIQUID); + } + + @Override + public String getTextureFile() { + return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png"; + } + + @Override + public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) { + if (player.getCurrentEquippedItem() != null) { + if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) { + return false; + } + ItemStack current = player.getCurrentEquippedItem(); + if (current != null && current.itemID != Item.bucketEmpty.itemID) { + if (CoreProxy.proxy.isSimulating(worldObj)) { + if (LiquidUtils.handleRightClick(this, side, player, true, false)) { + return true; + } + } else { + if (LiquidContainerRegistry.isContainer(current)) { + return true; + } + } + } + } + if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_IRON, worldObj, xCoord, yCoord, zCoord); + } + return true; + } + + @Override + public float explosionRange() { + return 4; + } + + @Override + public float getPistonSpeed() { + if (CoreProxy.proxy.isSimulating(worldObj)) { + return Math.max(0.07f * getHeatLevel(), 0.01f); + } + switch (getEnergyStage()) { + case BLUE: + return 0.04F; + case GREEN: + return 0.05F; + case YELLOW: + return 0.06F; + case RED: + return 0.07F; + default: + return 0; + } + } + + @Override + public boolean isBurning() { + LiquidStack fuel = fuelTank.getLiquid(); + return fuel != null && fuel.amount > 0 && penaltyCooling == 0 && isRedstonePowered; + } + + @Override + public void burn() { + LiquidStack fuel = this.fuelTank.getLiquid(); + if (currentFuel == null) { + currentFuel = IronEngineFuel.getFuelForLiquid(fuel); + } + + if (currentFuel == null) + return; + + if (penaltyCooling <= 0 && isRedstonePowered) { + + lastPowered = true; + + if (burnTime > 0 || fuel.amount > 0) { + if (burnTime > 0) { + burnTime--; + } + if (burnTime <= 0) { + if (fuel != null) { + if (--fuel.amount <= 0) { + fuelTank.setLiquid(null); + } + burnTime = currentFuel.totalBurningTime / LiquidContainerRegistry.BUCKET_VOLUME; + } else { + currentFuel = null; + return; + } + } + currentOutput = currentFuel.powerPerCycle; // Comment out for constant power + addEnergy(currentFuel.powerPerCycle); + heat += currentFuel.powerPerCycle * HEAT_PER_MJ; + } + } else if (penaltyCooling <= 0) { + if (lastPowered) { + lastPowered = false; + penaltyCooling = 30 * 20; + // 30 sec of penalty on top of the cooling + } + } + } + + @Override + public void updateHeatLevel() { + } + + @Override + public void engineUpdate() { + + final ItemStack stack = getStackInSlot(0); + if (stack != null) { + LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(stack); + if (liquid == null && heat > IDEAL_HEAT) { + liquid = IronEngineCoolant.getLiquidCoolant(stack); + } + + if (liquid != null) { + if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount) { + fill(ForgeDirection.UNKNOWN, liquid, true); + setInventorySlotContents(0, Utils.consumeItem(stack)); + } + } + } + + if (heat > IDEAL_HEAT) { + float extraHeat = heat - IDEAL_HEAT; + + LiquidStack coolant = this.coolantTank.getLiquid(); + Coolant currentCoolant = IronEngineCoolant.getCoolant(coolant); + if (currentCoolant != null) { + float cooling = currentCoolant.getDegreesCoolingPerMB(heat); + if (coolant.amount * cooling > extraHeat) { + coolant.amount -= Math.round(extraHeat / cooling); + heat = IDEAL_HEAT; + } else { + heat -= coolant.amount * cooling; + coolantTank.setLiquid(null); + } + } + } + + if (heat > 0 && (penaltyCooling > 0 || !isRedstonePowered)) { + heat -= COOLDOWN_RATE; + + } + + if (heat <= MIN_HEAT) { + heat = MIN_HEAT; + } + + if (heat <= MIN_HEAT && penaltyCooling > 0) { + penaltyCooling--; + } + } + + @Override + public int getScaledBurnTime(int i) { + return this.fuelTank.getLiquid() != null ? (int) (((float) this.fuelTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0; + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + fuelTank.readFromNBT(data.getCompoundTag("fuelTank")); + coolantTank.readFromNBT(data.getCompoundTag("coolantTank")); + + burnTime = data.getInteger("burnTime"); + penaltyCooling = data.getInteger("penaltyCooling"); + + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + data.setTag("fuelTank", fuelTank.writeToNBT(new NBTTagCompound())); + data.setTag("coolantTank", coolantTank.writeToNBT(new NBTTagCompound())); + + data.setInteger("burnTime", burnTime); + data.setInteger("penaltyCooling", penaltyCooling); + + } + + public int getScaledCoolant(int i) { + return coolantTank.getLiquid() != null ? (int) (((float) coolantTank.getLiquid().amount / (float) (MAX_LIQUID)) * i) : 0; + } + + @Override + public void getGUINetworkData(int id, int value) { + super.getGUINetworkData(id, value); + switch (id) { + case 15: + if (fuelTank.getLiquid() == null) { + fuelTank.setLiquid(new LiquidStack(0, value)); + } else { + fuelTank.getLiquid().amount = value; + } + break; + case 16: + if (fuelTank.getLiquid() == null) { + fuelTank.setLiquid(new LiquidStack(value, 0)); + } else { + fuelTank.setLiquid(new LiquidStack(value, fuelTank.getLiquid().amount, fuelTank.getLiquid().itemMeta)); + } + break; + case 17: + if (coolantTank.getLiquid() == null) { + coolantTank.setLiquid(new LiquidStack(0, value)); + } else { + coolantTank.getLiquid().amount = value; + } + break; + case 18: + if (coolantTank.getLiquid() == null) { + coolantTank.setLiquid(new LiquidStack(value, 0)); + } else { + coolantTank.setLiquid(new LiquidStack(value, coolantTank.getLiquid().amount, coolantTank.getLiquid().itemMeta)); + } + break; + case 19: + if (fuelTank.getLiquid() == null) { + fuelTank.setLiquid(new LiquidStack(0, 0, value)); + } else { + fuelTank.setLiquid(new LiquidStack(fuelTank.getLiquid().itemID, fuelTank.getLiquid().amount, value)); + } + break; + case 20: + if (coolantTank.getLiquid() == null) { + coolantTank.setLiquid(new LiquidStack(0, 0, value)); + } else { + coolantTank.setLiquid(new LiquidStack(coolantTank.getLiquid().itemID, coolantTank.getLiquid().amount, value)); + } + } + } + + @Override + public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) { + super.sendGUINetworkData(containerEngine, iCrafting); + iCrafting.sendProgressBarUpdate(containerEngine, 15, fuelTank.getLiquid() != null ? fuelTank.getLiquid().amount : 0); + iCrafting.sendProgressBarUpdate(containerEngine, 16, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemID : 0); + iCrafting.sendProgressBarUpdate(containerEngine, 17, coolantTank.getLiquid() != null ? coolantTank.getLiquid().amount : 0); + iCrafting.sendProgressBarUpdate(containerEngine, 18, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemID : 0); + iCrafting.sendProgressBarUpdate(containerEngine, 19, fuelTank.getLiquid() != null ? fuelTank.getLiquid().itemMeta : 0); + iCrafting.sendProgressBarUpdate(containerEngine, 20, coolantTank.getLiquid() != null ? coolantTank.getLiquid().itemMeta : 0); + } + + @Override + public boolean isActive() { + return penaltyCooling <= 0; + } + + /* ITANKCONTAINER */ + @Override + public int fill(int tankIndex, LiquidStack resource, boolean doFill) { + return 0; + } + + @Override + public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + return null; + } + + @Override + public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) { + return null; + } + + @Override + public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) { + + // Handle coolant + if (IronEngineCoolant.getCoolant(resource) != null) + return coolantTank.fill(resource, doFill); + + if (IronEngineFuel.getFuelForLiquid(resource) != null) + return fuelTank.fill(resource, doFill); + + return 0; + } + + @Override + public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) { + switch (direction) { + case UP: + return fuelTank; + case DOWN: + return coolantTank; + default: + return null; + } + } + + @Override + public ILiquidTank[] getTanks(ForgeDirection direction) { + return new ILiquidTank[]{fuelTank, coolantTank}; + } + + @Override + public boolean isStackValidForSlot(int i, ItemStack itemstack) { + if (itemstack == null) + return false; + if (Block.ice.blockID == itemstack.itemID) + return true; + return LiquidContainerRegistry.getLiquidForFilledItem(itemstack) != null; + } + + public LiquidStack getFuel() { + return fuelTank.getLiquid(); + } + + public LiquidStack getCoolant() { + return coolantTank.getLiquid(); + } + + @Override + public float maxEnergyReceived() { + return 2000; + } + + @Override + public float maxEnergyExtracted() { + return 500; + } + + @Override + public float getMaxEnergy() { + return 10000; + } + + @Override + public float getCurrentOutput() { + if (currentFuel == null) { + return 0; + } + return currentFuel.powerPerCycle; + } + + @Override + public LinkedList getTriggers() { + LinkedList triggers = super.getTriggers(); + triggers.add(BuildCraftCore.triggerEmptyLiquid); + triggers.add(BuildCraftCore.triggerContainsLiquid); + triggers.add(BuildCraftCore.triggerSpaceLiquid); + triggers.add(BuildCraftCore.triggerFullLiquid); + + return triggers; + } +} diff --git a/common/buildcraft/energy/TileEngineLegacy.java b/common/buildcraft/energy/TileEngineLegacy.java new file mode 100644 index 00000000..21883cf4 --- /dev/null +++ b/common/buildcraft/energy/TileEngineLegacy.java @@ -0,0 +1,77 @@ +/** + * 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.energy; + +import buildcraft.BuildCraftEnergy; +import buildcraft.core.DefaultProps; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +/** + * This class is just intended to update pre 4.0 engines to the design. + * + * It can be deleted someday. + * + * @author CovertJaguar + */ +public class TileEngineLegacy extends TileEngine { + + public TileEngineLegacy() { + super(0); + } + + @Override + public void updateEntity() { + int meta = getBlockMetadata(); + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + TileEntity newTile = BuildCraftEnergy.engineBlock.createTileEntity(worldObj, meta); + newTile.readFromNBT(nbt); + worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, newTile); + } + + @Override + public String getTextureFile() { + return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png"; + } + + @Override + public float getMaxEnergy() { + return 1; + } + + @Override + public float maxEnergyReceived() { + return 0; + } + + @Override + public float explosionRange() { + return 0; + } + + @Override + public boolean isBurning() { + return false; + } + + @Override + public int getScaledBurnTime(int scale) { + return 0; + } + + @Override + public float getCurrentOutput() { + return 1; + } + + @Override + public float maxEnergyExtracted() { + return 1; + } +} diff --git a/common/buildcraft/energy/TileEngineStone.java b/common/buildcraft/energy/TileEngineStone.java new file mode 100644 index 00000000..52c47386 --- /dev/null +++ b/common/buildcraft/energy/TileEngineStone.java @@ -0,0 +1,163 @@ +/** + * 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.energy; + +import buildcraft.BuildCraftCore; +import buildcraft.BuildCraftEnergy; +import buildcraft.api.gates.ITrigger; +import net.minecraft.inventory.ICrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntityFurnace; +import buildcraft.core.DefaultProps; +import buildcraft.core.GuiIds; +import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; +import buildcraft.energy.gui.ContainerEngine; +import java.util.LinkedList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.ForgeDirection; + +public class TileEngineStone extends TileEngine { + + final float MAX_OUTPUT = 1f; + final float MIN_OUTPUT = MAX_OUTPUT / 3; + final float TARGET_OUTPUT = 0.375f; + final float kp = 1f; + final float ki = 0.05f; + final float eLimit = (MAX_OUTPUT - MIN_OUTPUT) / ki; + int burnTime = 0; + int totalBurnTime = 0; + float esum = 0; + + public TileEngineStone() { + super(1); + } + + @Override + public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) { + if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, worldObj, xCoord, yCoord, zCoord); + } + return true; + } + + @Override + public String getTextureFile() { + return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_stone.png"; + } + + @Override + public float explosionRange() { + return 2; + } + + @Override + public boolean isBurning() { + return burnTime > 0; + } + + @Override + public void burn() { + if (burnTime > 0) { + burnTime--; + + float output = getCurrentOutput(); + currentOutput = output; // Comment out for constant power + addEnergy(output); + } + + if (burnTime == 0 && isRedstonePowered) { + burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(0)); + + if (burnTime > 0) { + setInventorySlotContents(0, Utils.consumeItem(getStackInSlot(0))); + } + } + } + + @Override + public int getScaledBurnTime(int i) { + return (int) (((float) burnTime / (float) totalBurnTime) * i); + } + + private int getItemBurnTime(ItemStack itemstack) { + if (itemstack == null) + return 0; + + return TileEntityFurnace.getItemBurnTime(itemstack); + } + + /* SAVING & LOADING */ + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + burnTime = data.getInteger("burnTime"); + totalBurnTime = data.getInteger("totalBurnTime"); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + data.setInteger("burnTime", burnTime); + data.setInteger("totalBurnTime", totalBurnTime); + } + + @Override + public void getGUINetworkData(int id, int value) { + super.getGUINetworkData(id, value); + switch (id) { + case 15: + burnTime = value; + break; + case 16: + totalBurnTime = value; + break; + } + } + + @Override + public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) { + super.sendGUINetworkData(containerEngine, iCrafting); + iCrafting.sendProgressBarUpdate(containerEngine, 15, burnTime); + iCrafting.sendProgressBarUpdate(containerEngine, 16, totalBurnTime); + } + + @Override + public float maxEnergyReceived() { + return 200; + } + + @Override + public float maxEnergyExtracted() { + return 100; + } + + @Override + public float getMaxEnergy() { + return 1000; + } + + @Override + public float getCurrentOutput() { + float e = TARGET_OUTPUT * getMaxEnergy() - energy; + esum = Math.min(Math.max(esum + e, -eLimit), eLimit); + return Math.min(Math.max(e * kp + esum * ki, MIN_OUTPUT), MAX_OUTPUT); + } + + @Override + public LinkedList getTriggers() { + LinkedList triggers = super.getTriggers(); + triggers.add(BuildCraftCore.triggerEmptyInventory); + triggers.add(BuildCraftCore.triggerContainsInventory); + triggers.add(BuildCraftCore.triggerSpaceInventory); + triggers.add(BuildCraftCore.triggerFullInventory); + + return triggers; + } +} \ No newline at end of file diff --git a/common/buildcraft/energy/TileEngineWood.java b/common/buildcraft/energy/TileEngineWood.java new file mode 100644 index 00000000..b9bc0e07 --- /dev/null +++ b/common/buildcraft/energy/TileEngineWood.java @@ -0,0 +1,119 @@ +/** + * 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.energy; + +import buildcraft.core.DefaultProps; +import buildcraft.core.proxy.CoreProxy; +import static buildcraft.energy.TileEngine.EnergyStage.BLUE; +import static buildcraft.energy.TileEngine.EnergyStage.GREEN; +import static buildcraft.energy.TileEngine.EnergyStage.RED; +import static buildcraft.energy.TileEngine.EnergyStage.YELLOW; +import net.minecraftforge.common.ForgeDirection; + +public class TileEngineWood extends TileEngine { + + public static final float OUTPUT = 0.05F; + + public TileEngineWood() { + super(0); + } + + @Override + public String getTextureFile() { + return DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png"; + } + + @Override + public float explosionRange() { + return 1; + } + + @Override + public float minEnergyReceived() { + return 0; + } + + @Override + public float maxEnergyReceived() { + return 50; + } + + @Override + protected EnergyStage computeEnergyStage() { + float energyLevel = getEnergyLevel(); + if (energyLevel < 0.25f) { + return EnergyStage.BLUE; + } else if (energyLevel < 0.5f) { + return EnergyStage.GREEN; + } else if (energyLevel < 0.75f) { + return EnergyStage.YELLOW; + } else { + return EnergyStage.RED; + } + } + + @Override + public float getPistonSpeed() { + if (CoreProxy.proxy.isSimulating(worldObj)) { + return Math.max(0.8f * getHeatLevel(), 0.01f); + } + switch (getEnergyStage()) { + case BLUE: + return 0.01F; + case GREEN: + return 0.02F; + case YELLOW: + return 0.04F; + case RED: + return 0.08F; + default: + return 0; + } + } + + @Override + public void engineUpdate() { + super.engineUpdate(); + + if (isRedstonePowered) { + if (worldObj.getWorldTime() % 20 == 0) { + addEnergy(1); + } + } + } + + @Override + public boolean isPipeConnected(ForgeDirection with) { + return false; + } + + @Override + public boolean isBurning() { + return isRedstonePowered; + } + + @Override + public int getScaledBurnTime(int i) { + return 0; + } + + @Override + public float getMaxEnergy() { + return 100; + } + + @Override + public float getCurrentOutput() { + return OUTPUT; + } + + @Override + public float maxEnergyExtracted() { + return 1; + } +} diff --git a/common/buildcraft/energy/TriggerEngineHeat.java b/common/buildcraft/energy/TriggerEngineHeat.java index 6edc1586..a094a049 100644 --- a/common/buildcraft/energy/TriggerEngineHeat.java +++ b/common/buildcraft/energy/TriggerEngineHeat.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.energy; import net.minecraft.tileentity.TileEntity; @@ -14,12 +12,14 @@ import net.minecraftforge.common.ForgeDirection; import buildcraft.api.gates.ITriggerParameter; import buildcraft.core.triggers.ActionTriggerIconProvider; import buildcraft.core.triggers.BCTrigger; +import buildcraft.core.utils.StringUtils; +import buildcraft.energy.TileEngine.EnergyStage; public class TriggerEngineHeat extends BCTrigger { - public Engine.EnergyStage stage; + public EnergyStage stage; - public TriggerEngineHeat(int id, Engine.EnergyStage stage) { + public TriggerEngineHeat(int id, EnergyStage stage) { super(id); this.stage = stage; @@ -28,23 +28,23 @@ public class TriggerEngineHeat extends BCTrigger { @Override public String getDescription() { switch (stage) { - case Blue: - return "Engine Blue"; - case Green: - return "Engine Green"; - case Yellow: - return "Engine Yellow"; - default: - return "Engine Red"; + case BLUE: + return StringUtils.localize("gate.engine.blue"); + case GREEN: + return StringUtils.localize("gate.engine.green"); + case YELLOW: + return StringUtils.localize("gate.engine.yellow"); + default: + return StringUtils.localize("gate.engine.red"); } } @Override public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) { if (tile instanceof TileEngine) { - Engine engine = ((TileEngine) tile).engine; + TileEngine engine = ((TileEngine) tile); - return engine != null && engine.getEnergyStage() == stage; + return engine.getEnergyStage() == stage; } return false; @@ -53,14 +53,14 @@ public class TriggerEngineHeat extends BCTrigger { @Override public int getIconIndex() { switch (stage) { - case Blue: - return ActionTriggerIconProvider.Trigger_EngineHeat_Blue; - case Green: - return ActionTriggerIconProvider.Trigger_EngineHeat_Green; - case Yellow: - return ActionTriggerIconProvider.Trigger_EngineHeat_Yellow; - default: - return ActionTriggerIconProvider.Trigger_EngineHeat_Red; + case BLUE: + return ActionTriggerIconProvider.Trigger_EngineHeat_Blue; + case GREEN: + return ActionTriggerIconProvider.Trigger_EngineHeat_Green; + case YELLOW: + return ActionTriggerIconProvider.Trigger_EngineHeat_Yellow; + default: + return ActionTriggerIconProvider.Trigger_EngineHeat_Red; } } } diff --git a/common/buildcraft/energy/gui/ContainerEngine.java b/common/buildcraft/energy/gui/ContainerEngine.java index 27855183..ec28e30a 100644 --- a/common/buildcraft/energy/gui/ContainerEngine.java +++ b/common/buildcraft/energy/gui/ContainerEngine.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.energy.gui; import net.minecraft.entity.player.EntityPlayer; @@ -14,7 +12,7 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import buildcraft.core.gui.BuildCraftContainer; -import buildcraft.energy.EngineStone; +import buildcraft.energy.TileEngineStone; import buildcraft.energy.TileEngine; public class ContainerEngine extends BuildCraftContainer { @@ -26,7 +24,7 @@ public class ContainerEngine extends BuildCraftContainer { engine = tileEngine; - if (tileEngine.engine instanceof EngineStone) { + if (tileEngine instanceof TileEngineStone) { addSlotToContainer(new Slot(tileEngine, 0, 80, 41)); } else { addSlotToContainer(new Slot(tileEngine, 0, 52, 41)); @@ -49,15 +47,13 @@ public class ContainerEngine extends BuildCraftContainer { super.detectAndSendChanges(); for (int i = 0; i < crafters.size(); i++) { - engine.engine.sendGUINetworkData(this, (ICrafting) crafters.get(i)); + engine.sendGUINetworkData(this, (ICrafting) crafters.get(i)); } } @Override public void updateProgressBar(int i, int j) { - if (engine.engine != null) { - engine.engine.getGUINetworkData(i, j); - } + engine.getGUINetworkData(i, j); } public boolean isUsableByPlayer(EntityPlayer entityplayer) { diff --git a/common/buildcraft/energy/gui/GuiCombustionEngine.java b/common/buildcraft/energy/gui/GuiCombustionEngine.java index 1c8ce39e..7501e07b 100644 --- a/common/buildcraft/energy/gui/GuiCombustionEngine.java +++ b/common/buildcraft/energy/gui/GuiCombustionEngine.java @@ -19,7 +19,7 @@ import org.lwjgl.opengl.GL11; import buildcraft.core.DefaultProps; import buildcraft.core.utils.StringUtils; -import buildcraft.energy.EngineIron; +import buildcraft.energy.TileEngineIron; import buildcraft.energy.TileEngine; public class GuiCombustionEngine extends GuiEngine { @@ -44,15 +44,14 @@ public class GuiCombustionEngine extends GuiEngine { int k = (height - ySize) / 2; drawTexturedModalRect(j, k, 0, 0, xSize, ySize); - TileEngine engine = (TileEngine) tile; - EngineIron engineIron = ((EngineIron) engine.engine); + TileEngineIron engine = (TileEngineIron) tile; if (engine.getScaledBurnTime(58) > 0) { - displayGauge(j, k, 19, 104, engine.getScaledBurnTime(58), engineIron.getFuel()); + displayGauge(j, k, 19, 104, engine.getScaledBurnTime(58), engine.getFuel()); } - if (engineIron.getScaledCoolant(58) > 0) { - displayGauge(j, k, 19, 122, engineIron.getScaledCoolant(58), engineIron.getCoolant()); + if (engine.getScaledCoolant(58) > 0) { + displayGauge(j, k, 19, 122, engine.getScaledCoolant(58), engine.getCoolant()); } } diff --git a/common/buildcraft/energy/gui/GuiEngine.java b/common/buildcraft/energy/gui/GuiEngine.java index 7d847ccc..feb11673 100644 --- a/common/buildcraft/energy/gui/GuiEngine.java +++ b/common/buildcraft/energy/gui/GuiEngine.java @@ -7,19 +7,18 @@ import buildcraft.core.CoreIconProvider; import buildcraft.core.gui.BuildCraftContainer; import buildcraft.core.gui.GuiBuildCraft; import buildcraft.core.utils.StringUtils; -import buildcraft.energy.Engine; import buildcraft.energy.TileEngine; public abstract class GuiEngine extends GuiBuildCraft { protected class EngineLedger extends Ledger { - Engine engine; + TileEngine engine; int headerColour = 0xe1c92f; int subheaderColour = 0xaaafb8; int textColour = 0x000000; - public EngineLedger(Engine engine) { + public EngineLedger(TileEngine engine) { this.engine = engine; maxHeight = 94; overlayColor = 0xd46c1f; @@ -40,17 +39,17 @@ public abstract class GuiEngine extends GuiBuildCraft { fontRenderer.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.currentOutput") + ":", x + 22, y + 20, subheaderColour); - fontRenderer.drawString(String.format("%.1f MJ/t", engine.getCurrentOutput()), x + 22, y + 32, textColour); + fontRenderer.drawString(String.format("%.1f MJ/t", engine.currentOutput), x + 22, y + 32, textColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour); fontRenderer.drawString(String.format("%.1f MJ", engine.getEnergyStored()), x + 22, y + 56, textColour); fontRenderer.drawStringWithShadow(StringUtils.localize("gui.heat") + ":", x + 22, y + 68, subheaderColour); - fontRenderer.drawString(String.format("%.2f \u00B0C", (engine.getHeat() / 100.0) + 20.0), x + 22, y + 80, textColour); + fontRenderer.drawString(String.format("%.2f \u00B0C", engine.getHeat()), x + 22, y + 80, textColour); } @Override public String getTooltip() { - return engine.getCurrentOutput() + " MJ/t"; + return String.format("%.1f MJ/t", engine.currentOutput); } } @@ -61,6 +60,6 @@ public abstract class GuiEngine extends GuiBuildCraft { @Override protected void initLedgers(IInventory inventory) { super.initLedgers(inventory); - ledgerManager.add(new EngineLedger(((TileEngine) tile).engine)); + ledgerManager.add(new EngineLedger((TileEngine) tile)); } } diff --git a/common/buildcraft/energy/render/RenderEngine.java b/common/buildcraft/energy/render/RenderEngine.java index 973bc21d..f17bfd7a 100644 --- a/common/buildcraft/energy/render/RenderEngine.java +++ b/common/buildcraft/energy/render/RenderEngine.java @@ -26,9 +26,8 @@ import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore.RenderMode; import buildcraft.core.DefaultProps; import buildcraft.core.IInventoryRenderer; -import buildcraft.energy.Engine; -import buildcraft.energy.Engine.EnergyStage; -import buildcraft.energy.IEngineProvider; +import buildcraft.energy.TileEngine; +import buildcraft.energy.TileEngine.EnergyStage; public class RenderEngine extends TileEntitySpecialRenderer implements IInventoryRenderer { @@ -86,13 +85,13 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IInventor @Override public void inventoryRender(double x, double y, double z, float f, float f1) { - render(EnergyStage.Blue, 0.25F, ForgeDirection.UP, baseTexture, x, y, z); + render(EnergyStage.BLUE, 0.25F, ForgeDirection.UP, baseTexture, x, y, z); } @Override public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { - Engine engine = ((IEngineProvider) tileentity).getEngine(); + TileEngine engine = ((TileEngine) tileentity); if (engine != null) { render(engine.getEnergyStage(), engine.progress, engine.orientation, engine.getTextureFile(), x, y, z); @@ -181,13 +180,13 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IInventor String texture = ""; switch (energy) { - case Blue: + case BLUE: texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_blue.png"; break; - case Green: + case GREEN: texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_green.png"; break; - case Yellow: + case YELLOW: texture = DefaultProps.TEXTURE_PATH_BLOCKS + "/trunk_yellow.png"; break; default: diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index 76b3f3ec..f133b5fa 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -38,14 +38,14 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction private int nextLaserUpdate = 10; private int nextLaserSearch = 100; private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown; - + public TileLaser() { powerProvider = new PowerProvider(this); initPowerProvider(); } private void initPowerProvider() { - powerProvider.configure(25, 25, 25, 1000); + powerProvider.configure(25, 150, 25, 1000); powerProvider.configurePowerPerdition(1, 1); } diff --git a/common/buildcraft/transport/IPipeTransportPowerHook.java b/common/buildcraft/transport/IPipeTransportPowerHook.java index 48cae72e..26e6e88b 100644 --- a/common/buildcraft/transport/IPipeTransportPowerHook.java +++ b/common/buildcraft/transport/IPipeTransportPowerHook.java @@ -13,7 +13,7 @@ import net.minecraftforge.common.ForgeDirection; public interface IPipeTransportPowerHook { - public double receiveEnergy(ForgeDirection from, double val); + public float receiveEnergy(ForgeDirection from, float val); public void requestEnergy(ForgeDirection from, float amount); } diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 9b094529..6fae0d2c 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -16,7 +16,6 @@ import buildcraft.api.gates.ITrigger; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerProvider; import buildcraft.core.DefaultProps; -import buildcraft.core.IMachine; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; import buildcraft.transport.network.PacketPowerUpdate; @@ -42,15 +41,15 @@ public class PipeTransportPower extends PipeTransport { } private boolean needsInit = true; private TileEntity[] tiles = new TileEntity[6]; - public double[] displayPower = new double[6]; - public double[] prevDisplayPower = new double[6]; + public float[] displayPower = new float[6]; + public float[] prevDisplayPower = new float[6]; public short[] clientDisplayPower = new short[6]; public int overload; public int[] powerQuery = new int[6]; public int[] nextPowerQuery = new int[6]; public long currentDate; - public double[] internalPower = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - public double[] internalNextPower = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + public float[] internalPower = new float[6]; + public float[] internalNextPower = new float[6]; public int maxPower = 8; public PipeTransportPower() { @@ -124,11 +123,11 @@ public class PipeTransportPower extends PipeTransport { // Send the power to nearby pipes who requested it System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6); - Arrays.fill(displayPower, 0.0); + Arrays.fill(displayPower, 0.0F); for (int i = 0; i < 6; ++i) { if (internalPower[i] > 0) { - double totalPowerQuery = 0; + float totalPowerQuery = 0; for (int j = 0; j < 6; ++j) { if (j != i && powerQuery[j] > 0) @@ -139,10 +138,10 @@ public class PipeTransportPower extends PipeTransport { for (int j = 0; j < 6; ++j) { if (j != i && powerQuery[j] > 0) { - double watts = 0.0; + float watts = 0.0F; if (tiles[j] instanceof TileGenericPipe) { - watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); + watts = (internalPower[i] / totalPowerQuery) * powerQuery[j]; TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j]; PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport; @@ -154,8 +153,8 @@ public class PipeTransportPower extends PipeTransport { PowerProvider prov = pow.getPowerProvider(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); if (prov != null && prov.canAcceptPowerFromPipes && prov.powerRequest() > 0) { - watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); - prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); + watts = (internalPower[i] / totalPowerQuery) * powerQuery[j]; + watts = prov.receiveEnergy(watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); internalPower[i] -= watts; } } @@ -169,7 +168,7 @@ public class PipeTransportPower extends PipeTransport { double highestPower = 0; for (int i = 0; i < 6; i++) { - displayPower[i] = (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0) + displayPower[i]) / DISPLAY_SMOOTHING; + displayPower[i] = (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING; if (displayPower[i] > highestPower) { highestPower = displayPower[i]; } @@ -262,7 +261,7 @@ public class PipeTransportPower extends PipeTransport { powerQuery = nextPowerQuery; nextPowerQuery = new int[6]; - double[] next = internalPower; + float[] next = internalPower; internalPower = internalNextPower; internalNextPower = next; // for (int i = 0; i < powerQuery.length; i++) { @@ -279,7 +278,7 @@ public class PipeTransportPower extends PipeTransport { } } - public double receiveEnergy(ForgeDirection from, double val) { + public float receiveEnergy(ForgeDirection from, float val) { step(); if (this.container.pipe instanceof IPipeTransportPowerHook) { return ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val); @@ -315,8 +314,8 @@ public class PipeTransportPower extends PipeTransport { for (int i = 0; i < 6; ++i) { powerQuery[i] = nbttagcompound.getInteger("powerQuery[" + i + "]"); nextPowerQuery[i] = nbttagcompound.getInteger("nextPowerQuery[" + i + "]"); - internalPower[i] = nbttagcompound.getDouble("internalPower[" + i + "]"); - internalNextPower[i] = nbttagcompound.getDouble("internalNextPower[" + i + "]"); + internalPower[i] = (float) nbttagcompound.getDouble("internalPower[" + i + "]"); + internalNextPower[i] = (float) nbttagcompound.getDouble("internalNextPower[" + i + "]"); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 3ab253a5..698d8306 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -82,19 +82,22 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { if (powerProvider.getEnergyStored() <= 0) return; - World w = worldObj; + extractItems(); + powerProvider.setEnergy(0); + } - int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); + private void extractItems() { + int meta = container.getBlockMetadata(); if (meta > 5) return; - + Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.getOrientation(meta)); pos.moveForwards(1); - TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); + TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (tile instanceof IInventory) { - if (!PipeManager.canExtractItems(this, w, (int) pos.x, (int) pos.y, (int) pos.z)) + if (!PipeManager.canExtractItems(this, worldObj, (int) pos.x, (int) pos.y, (int) pos.z)) return; IInventory inventory = (IInventory) tile; @@ -113,12 +116,11 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor { entityPos.moveForwards(0.6); - IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, stack); + IPipedItem entity = new EntityPassiveItem(worldObj, entityPos.x, entityPos.y, entityPos.z, stack); ((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation); } } - powerProvider.setEnergy(0); } /** diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index bcdcc74a..277a9a7c 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -113,11 +113,11 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { if (!powerSources[o.ordinal()]) continue; - float energyUsable = powerProvider.useEnergy(1, energyToRemove, false); + float energyUsable = powerProvider.useEnergy(0, energyToRemove, false); - float energySend = (float) trans.receiveEnergy(o, energyUsable); + float energySend = trans.receiveEnergy(o, energyUsable); if (energySend > 0) { - powerProvider.useEnergy(1, energySend, true); + powerProvider.useEnergy(0, energySend, true); } } } From f92576ed36837eaff1f751ee4a96a9ee8df107a1 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sat, 29 Jun 2013 01:37:41 -0700 Subject: [PATCH 18/29] Forgot a minor bit the alt impl --- common/buildcraft/energy/TileEngine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 11dc8e18..46e6fc1a 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -223,7 +223,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto if (extracted > 0) { float needed = receptor.receiveEnergy(extracted, orientation.getOpposite(), true); extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power -// extractEnergy(0, needed, true); // Uncomment for constant power +// currentOutput = extractEnergy(0, needed, true); // Uncomment for constant power } } } From 593d88946814b735a0fd0195a88fcf7f85d75ca5 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sat, 29 Jun 2013 02:21:54 -0700 Subject: [PATCH 19/29] Fixed Legacy code --- common/buildcraft/energy/TileEngine.java | 10 +++++++--- .../buildcraft/energy/TileEngineLegacy.java | 20 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 46e6fc1a..d46a7b43 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -30,6 +30,8 @@ import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; import buildcraft.energy.gui.ContainerEngine; import net.minecraft.inventory.ICrafting; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagFloat; public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, IOverrideDefaultTriggers, IPipeConnection { @@ -227,13 +229,12 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto } } } - + // Uncomment out for constant power // public float getActualOutput() { // float heatLevel = getIdealHeatLevel(); // return getCurrentOutput() * heatLevel; // } - protected void burn() { } @@ -284,7 +285,10 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto orientation = ForgeDirection.getOrientation(data.getInteger("orientation")); progress = data.getFloat("progress"); energy = data.getFloat("energyF"); - heat = data.getFloat("heat"); + NBTBase tag = data.getTag("heat"); + if (tag instanceof NBTTagFloat) { + heat = data.getFloat("heat"); + } inv.readFromNBT(data); } diff --git a/common/buildcraft/energy/TileEngineLegacy.java b/common/buildcraft/energy/TileEngineLegacy.java index 21883cf4..f25aa5c7 100644 --- a/common/buildcraft/energy/TileEngineLegacy.java +++ b/common/buildcraft/energy/TileEngineLegacy.java @@ -7,7 +7,6 @@ */ package buildcraft.energy; -import buildcraft.BuildCraftEnergy; import buildcraft.core.DefaultProps; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -21,18 +20,27 @@ import net.minecraft.tileentity.TileEntity; */ public class TileEngineLegacy extends TileEngine { + private NBTTagCompound nbt; + public TileEngineLegacy() { super(0); } @Override public void updateEntity() { - int meta = getBlockMetadata(); - NBTTagCompound nbt = new NBTTagCompound(); - writeToNBT(nbt); - TileEntity newTile = BuildCraftEnergy.engineBlock.createTileEntity(worldObj, meta); + worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord); + TileEntity newTile = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); newTile.readFromNBT(nbt); - worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, newTile); + sendNetworkUpdate(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + @Override + public void readFromNBT(NBTTagCompound data) { + nbt = (NBTTagCompound) data.copy(); + this.xCoord = data.getInteger("x"); + this.yCoord = data.getInteger("y"); + this.zCoord = data.getInteger("z"); } @Override From b1041e19d6270cf6deb3b848aea828e4e4652d37 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sat, 29 Jun 2013 03:22:55 -0700 Subject: [PATCH 20/29] Some minor bits --- common/buildcraft/api/power/PowerProvider.java | 3 +-- common/buildcraft/energy/TileEngineLegacy.java | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/common/buildcraft/api/power/PowerProvider.java b/common/buildcraft/api/power/PowerProvider.java index b8cbfa8d..ccbec7e9 100644 --- a/common/buildcraft/api/power/PowerProvider.java +++ b/common/buildcraft/api/power/PowerProvider.java @@ -227,8 +227,7 @@ public final class PowerProvider { if (boundsCheck) { if (quantity < minEnergyReceived) { quantity = minEnergyReceived; - } - if (quantity > maxEnergyReceived) { + } else if (quantity > maxEnergyReceived) { quantity = maxEnergyReceived; } } diff --git a/common/buildcraft/energy/TileEngineLegacy.java b/common/buildcraft/energy/TileEngineLegacy.java index f25aa5c7..7882e768 100644 --- a/common/buildcraft/energy/TileEngineLegacy.java +++ b/common/buildcraft/energy/TileEngineLegacy.java @@ -30,9 +30,11 @@ public class TileEngineLegacy extends TileEngine { public void updateEntity() { worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord); TileEntity newTile = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); - newTile.readFromNBT(nbt); - sendNetworkUpdate(); - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + if (newTile instanceof TileEngine) { + newTile.readFromNBT(nbt); + sendNetworkUpdate(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } } @Override From 670c2684e72a166f6e67e5589886461b8b59c1a6 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sun, 30 Jun 2013 17:52:57 -0700 Subject: [PATCH 21/29] Fix Iron Engine heat issues --- common/buildcraft/BuildCraftEnergy.java | 2 +- common/buildcraft/energy/TileEngineIron.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 50937ba9..85bf64ba 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -177,7 +177,7 @@ public class BuildCraftEnergy { IronEngineFuel.fuels.add(new IronEngineFuel(LiquidDictionary.getLiquid("Fuel", LiquidContainerRegistry.BUCKET_VOLUME), 6, 100000)); // Iron Engine Coolants - IronEngineCoolant.addCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 0.0025F); + IronEngineCoolant.addCoolant(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), 0.0023F); IronEngineCoolant.addCoolant(Block.ice.blockID, 0, new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME * 2)); LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getLiquid("Oil", LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack( diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index 2964f0e9..cbc98052 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -43,7 +43,7 @@ import net.minecraftforge.liquids.ITankContainer; public class TileEngineIron extends TileEngine implements ITankContainer { public static int MAX_LIQUID = LiquidContainerRegistry.BUCKET_VOLUME * 10; - public static float HEAT_PER_MJ = 0.01F; + public static float HEAT_PER_MJ = 0.0023F; public static float COOLDOWN_RATE = 0.005F; int burnTime = 0; private LiquidTank fuelTank; @@ -199,7 +199,7 @@ public class TileEngineIron extends TileEngine implements ITankContainer { } } - if (heat > 0 && (penaltyCooling > 0 || !isRedstonePowered)) { + if (heat > MIN_HEAT && (penaltyCooling > 0 || !isRedstonePowered)) { heat -= COOLDOWN_RATE; } From af89a9470b5c6262900f65be96ca398257e7e4f6 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Mon, 1 Jul 2013 14:21:51 -0700 Subject: [PATCH 22/29] Power API Take 3 --- .../buildcraft/api/core/SafeTimeTracker.java | 6 + .../buildcraft/api/power/IPowerReceptor.java | 5 +- .../{PowerProvider.java => PowerHandler.java} | 204 +++++++++++------- common/buildcraft/builders/TileBuilder.java | 75 +++---- common/buildcraft/builders/TileFiller.java | 26 +-- common/buildcraft/core/TileBuildCraft.java | 5 - common/buildcraft/energy/TileEngine.java | 30 +-- common/buildcraft/factory/TileMiningWell.java | 20 +- common/buildcraft/factory/TilePump.java | 24 ++- common/buildcraft/factory/TileQuarry.java | 33 +-- common/buildcraft/factory/TileRefinery.java | 26 +-- common/buildcraft/silicon/TileLaser.java | 31 +-- common/buildcraft/transport/EnergyPulser.java | 3 +- .../transport/PipeTransportPower.java | 19 +- .../buildcraft/transport/TileGenericPipe.java | 16 +- .../transport/pipes/PipeItemsEmerald.java | 12 +- .../transport/pipes/PipeItemsObsidian.java | 30 +-- .../transport/pipes/PipeItemsWood.java | 31 +-- .../transport/pipes/PipeLiquidsWood.java | 24 ++- .../transport/pipes/PipePowerWood.java | 43 ++-- 20 files changed, 363 insertions(+), 300 deletions(-) rename common/buildcraft/api/power/{PowerProvider.java => PowerHandler.java} (61%) 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(); } } From 9daec45638cd16c0f598a5d9d1c95f8acfa4d4cb Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Mon, 1 Jul 2013 15:26:57 -0700 Subject: [PATCH 23/29] Fixed perdition issues --- .../buildcraft/api/core/SafeTimeTracker.java | 6 +- common/buildcraft/api/power/PowerHandler.java | 61 +++++++++++++------ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/common/buildcraft/api/core/SafeTimeTracker.java b/common/buildcraft/api/core/SafeTimeTracker.java index 2da2cb60..30df49b7 100644 --- a/common/buildcraft/api/core/SafeTimeTracker.java +++ b/common/buildcraft/api/core/SafeTimeTracker.java @@ -13,8 +13,9 @@ import net.minecraft.world.World; public class SafeTimeTracker { - private long lastMark = 0; + private long lastMark = Long.MIN_VALUE; private long duration = 0; + private boolean marked; /** * Return true if a given delay has passed since last time marked was called successfully. @@ -31,6 +32,7 @@ public class SafeTimeTracker { } else if (lastMark + delay <= currentTime) { duration = currentTime - lastMark; lastMark = world.getWorldTime(); + marked = true; return true; } else return false; @@ -38,7 +40,7 @@ public class SafeTimeTracker { } public long durationOfLastDelay(){ - return duration; + return marked ? duration : 0; } public void markTime(World world) { diff --git a/common/buildcraft/api/power/PowerHandler.java b/common/buildcraft/api/power/PowerHandler.java index 98f7470c..58f54952 100644 --- a/common/buildcraft/api/power/PowerHandler.java +++ b/common/buildcraft/api/power/PowerHandler.java @@ -53,8 +53,18 @@ public final class PowerHandler { this.powerLoss = powerLoss; } - public float applyPerdition(PowerHandler provider, float current) { - current -= powerLoss; + /** + * Apply the perdition algorithm to the current stored energy. This + * function can only be called once per tick, but it might not be called + * every tick. It is triggered by any manipulation of the stored energy. + * + * @param powerHandler the PowerHandler requesting the perdition update + * @param current the current stored energy + * @param ticksPassed ticks since the last time this function was called + * @return + */ + public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) { + current -= powerLoss * ticksPassed; if (current < 0) { current = 0; } @@ -139,9 +149,18 @@ public final class PowerHandler { perdition = new PerditionCalculator(0); return; } - perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity * 10.0F); + perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity); } + /** + * Allows you to define a new PerditionCalculator class to handler perdition + * calculations. + * + * For example if you want exponentially increasing loss bases on amount + * stored. + * + * @param perdition + */ public void setPerdition(PerditionCalculator perdition) { this.perdition = perdition; } @@ -153,17 +172,14 @@ public final class PowerHandler { } private void applyPerdition() { - if (energyStored > 0) { - 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); - } - } + if (perditionTracker.markTimeIfDelay(receptor.getWorldObj(), 1) && energyStored > 0) { + float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); + if (newEnergy == 0 || newEnergy < energyStored) { + energyStored = newEnergy; + } else { + energyStored = DEFUALT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); } + validateEnergy(); } } @@ -199,6 +215,8 @@ public final class PowerHandler { * @return amount used */ public float useEnergy(float min, float max, boolean doUse) { + applyPerdition(); + float result = 0; if (energyStored >= min) { @@ -215,6 +233,8 @@ public final class PowerHandler { } } + validateEnergy(); + return result; } @@ -328,14 +348,19 @@ public final class PowerHandler { public void setEnergy(float quantity) { this.energyStored = quantity; - if (energyStored > maxEnergyStored) { - energyStored = maxEnergyStored; - } else if (energyStored < 0) { - energyStored = 0; - } + validateEnergy(); } public boolean isPowerSource(ForgeDirection from) { return powerSources[from.ordinal()] != 0; } + + private void validateEnergy() { + if (energyStored < 0) { + energyStored = 0; + } + if (energyStored > maxEnergyStored) { + energyStored = maxEnergyStored; + } + } } From 499b6f342db15364f57778d8cf12d7b0ee86d9c2 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Mon, 1 Jul 2013 15:53:05 -0700 Subject: [PATCH 24/29] Re-add update function Some weirdness occurs with some applications without it unfortunately. --- common/buildcraft/api/power/PowerHandler.java | 19 +++++++++++++ common/buildcraft/core/TileBuildCraft.java | 27 +++++++++---------- .../buildcraft/transport/TileGenericPipe.java | 7 +++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/common/buildcraft/api/power/PowerHandler.java b/common/buildcraft/api/power/PowerHandler.java index 58f54952..f3762833 100644 --- a/common/buildcraft/api/power/PowerHandler.java +++ b/common/buildcraft/api/power/PowerHandler.java @@ -171,6 +171,21 @@ public final class PowerHandler { return perdition; } + /** + * Ticks the power handler. You should call this if you can, but its not + * required. + * + * If you don't call it, the possibility exists for some weirdness with the + * perdition algorithm and work callback as its possible they will not be + * called on every tick they otherwise would be. You should be able to + * design around this though if you are aware of the limitations. + */ + public void update() { + applyPerdition(); + applyWork(); + validateEnergy(); + } + private void applyPerdition() { if (perditionTracker.markTimeIfDelay(receptor.getWorldObj(), 1) && energyStored > 0) { float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); @@ -286,6 +301,10 @@ public final class PowerHandler { return type; } + public void update() { + PowerHandler.this.update(); + } + /** * The amount of power that this PowerHandler currently needs. * diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 3d563dc4..6db37aba 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -1,12 +1,10 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.core; import java.util.HashMap; @@ -30,10 +28,8 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized private static Map updateWrappers = new HashMap(); @SuppressWarnings("rawtypes") private static Map descriptionWrappers = new HashMap(); - private final TilePacketWrapper descriptionPacket; private final TilePacketWrapper updatePacket; - private boolean init = false; public TileBuildCraft() { @@ -56,6 +52,11 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized initialize(); init = true; } + + if (this instanceof IPowerReceptor) { + IPowerReceptor receptor = ((IPowerReceptor) this); + receptor.getPowerReceiver(null).update(); + } } @Override @@ -69,7 +70,6 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized } public void destroy() { - } public void sendNetworkUpdate() { @@ -105,13 +105,10 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized @Override public void postPacketHandling(PacketUpdate packet) { - } - public boolean isInvNameLocalized() - { - // TODO Auto-generated method stub - return false; - } - + public boolean isInvNameLocalized() { + // TODO Auto-generated method stub + return false; + } } diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index a9562931..0029534c 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -33,6 +33,7 @@ import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeEntry; @@ -189,6 +190,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank refreshRenderState = false; } + PowerReceiver provider = getPowerReceiver(null); + + if (provider != null) { + provider.update(); + } + if (pipe != null) { pipe.updateEntity(); } From 5492f83a3119abb6b32ff7ad80044876a0acb747 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 2 Jul 2013 07:11:57 -0700 Subject: [PATCH 25/29] Should fix Wooden Power Pipe power sources issues --- common/buildcraft/transport/pipes/PipePowerWood.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 0cc28d78..063054e1 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -94,8 +94,10 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { } } - if (sources <= 0) + if (sources <= 0) { + powerHandler.useEnergy(5, 5, true); return; + } float energyToRemove; @@ -139,6 +141,9 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { public void writeToNBT(NBTTagCompound data) { super.writeToNBT(data); powerHandler.writeToNBT(data); + for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { + data.setBoolean("powerSources[" + i + "]", powerSources[i]); + } } @Override @@ -146,5 +151,8 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { super.readFromNBT(data); powerHandler.readFromNBT(data); initPowerProvider(); + for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { + powerSources[i] = data.getBoolean("powerSources[" + i + "]"); + } } } From c3a54f2a24f2a2e7446fb9c065464f838923b44d Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 2 Jul 2013 07:56:36 -0700 Subject: [PATCH 26/29] Added IPowerEmitter --- .../buildcraft/api/power/IPowerEmitter.java | 24 ++++++++++++++++ .../buildcraft/api/power/IPowerReceptor.java | 28 ++++++++++++++++++- common/buildcraft/api/power/PowerHandler.java | 3 +- common/buildcraft/energy/TileEngine.java | 8 +++++- .../transport/PipeTransportPower.java | 11 ++++++-- .../transport/pipes/PipePowerWood.java | 11 +------- 6 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 common/buildcraft/api/power/IPowerEmitter.java diff --git a/common/buildcraft/api/power/IPowerEmitter.java b/common/buildcraft/api/power/IPowerEmitter.java new file mode 100644 index 00000000..7ccf62b9 --- /dev/null +++ b/common/buildcraft/api/power/IPowerEmitter.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.power; + +import net.minecraftforge.common.ForgeDirection; + +/** + * Essentially only used for Wooden Power Pipe connection rules. + * + * This Tile Entity interface allows you to indicate that a block can emit power + * from a specific side. + * + * @author CovertJaguar + */ +public interface IPowerEmitter { + + public boolean canEmitPowerFrom(ForgeDirection side); +} diff --git a/common/buildcraft/api/power/IPowerReceptor.java b/common/buildcraft/api/power/IPowerReceptor.java index 8effb816..64dc1aff 100644 --- a/common/buildcraft/api/power/IPowerReceptor.java +++ b/common/buildcraft/api/power/IPowerReceptor.java @@ -11,11 +11,37 @@ import buildcraft.api.power.PowerHandler.PowerReceiver; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +/** + * This interface should be implemented by any Tile Entity that wishes to be + * able to receive power. + * + * @author CovertJaguar + */ public interface IPowerReceptor { + /** + * Get the PowerReceiver for this side of the block. You can return the same + * PowerReceiver for all sides or one for each side. + * + * You should NOT return null to this method unless you mean to NEVER + * receive power from that side. Returning null, after previous returning a + * PowerReceiver, will most likely cause pipe connections to derp out and + * engines to eventually explode. + * + * @param side + * @return + */ public PowerReceiver getPowerReceiver(ForgeDirection side); + /** + * Call back from the PowerHandler that is called when the store power + * exceeds the activation power. + * + * It can be triggered by update() calls or power modification calls. + * + * @param workProvider + */ public void doWork(PowerHandler workProvider); - + public World getWorldObj(); } diff --git a/common/buildcraft/api/power/PowerHandler.java b/common/buildcraft/api/power/PowerHandler.java index f3762833..aa13cd91 100644 --- a/common/buildcraft/api/power/PowerHandler.java +++ b/common/buildcraft/api/power/PowerHandler.java @@ -10,6 +10,7 @@ package buildcraft.api.power; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; +import java.util.EnumSet; public final class PowerHandler { @@ -80,7 +81,7 @@ public final class PowerHandler { 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 int[] powerSources = new int[6]; public final IPowerReceptor receptor; private PerditionCalculator perdition; private final PowerReceiver receiver; diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 40a13592..0c89487f 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -19,6 +19,7 @@ import buildcraft.BuildCraftEnergy; import buildcraft.api.core.Position; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; +import buildcraft.api.power.IPowerEmitter; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; @@ -35,7 +36,7 @@ import net.minecraft.inventory.ICrafting; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagFloat; -public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, IOverrideDefaultTriggers, IPipeConnection { +public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IInventory, IOverrideDefaultTriggers, IPipeConnection { public enum EnergyStage { @@ -495,6 +496,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto return with != orientation; } + @Override + public boolean canEmitPowerFrom(ForgeDirection side) { + return side == orientation; + } + public void checkRedstonePower() { isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); } diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 4d271155..01408091 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -13,6 +13,7 @@ import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftCore; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.gates.ITrigger; +import buildcraft.api.power.IPowerEmitter; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.Type; @@ -76,9 +77,13 @@ public class PipeTransportPower extends PipeTransport { if (tile instanceof IPowerReceptor) { IPowerReceptor receptor = (IPowerReceptor) tile; PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite()); - if (receiver == null) - return false; - if (container.pipe instanceof PipePowerWood || receiver.getType().canReceiveFromPipes()) + if (receiver != null && receiver.getType().canReceiveFromPipes()) + return true; + } + + if (container.pipe instanceof PipePowerWood && tile instanceof IPowerEmitter) { + IPowerEmitter emitter = (IPowerEmitter) tile; + if (emitter.canEmitPowerFrom(side.getOpposite())) return true; } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 063054e1..009169c8 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -50,16 +50,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { @Override public int getIconIndex(ForgeDirection direction) { - if (direction == ForgeDirection.UNKNOWN) - return standardIconIndex; - else { - int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); - - if (metadata == direction.ordinal()) - return solidIconIndex; - else - return standardIconIndex; - } + return standardIconIndex; } @Override From 71c79606c0f22cacdbe7ee6756fb55e106d2240a Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 2 Jul 2013 08:01:09 -0700 Subject: [PATCH 27/29] Fix typo in javadocs --- common/buildcraft/api/power/IPowerReceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/buildcraft/api/power/IPowerReceptor.java b/common/buildcraft/api/power/IPowerReceptor.java index 64dc1aff..6c9aae36 100644 --- a/common/buildcraft/api/power/IPowerReceptor.java +++ b/common/buildcraft/api/power/IPowerReceptor.java @@ -34,7 +34,7 @@ public interface IPowerReceptor { public PowerReceiver getPowerReceiver(ForgeDirection side); /** - * Call back from the PowerHandler that is called when the store power + * Call back from the PowerHandler that is called when the stored power * exceeds the activation power. * * It can be triggered by update() calls or power modification calls. From 599afc578eb3469b3f884cd1466ccd4024a480ef Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Thu, 4 Jul 2013 00:30:15 -0700 Subject: [PATCH 28/29] Cleaned up some code. --- common/buildcraft/api/power/PowerHandler.java | 1 - .../transport/PipeTransportPower.java | 49 ++++++++++++------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/common/buildcraft/api/power/PowerHandler.java b/common/buildcraft/api/power/PowerHandler.java index aa13cd91..1b408238 100644 --- a/common/buildcraft/api/power/PowerHandler.java +++ b/common/buildcraft/api/power/PowerHandler.java @@ -10,7 +10,6 @@ package buildcraft.api.power; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.core.SafeTimeTracker; -import java.util.EnumSet; public final class PowerHandler { diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 01408091..59d4f45e 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -146,7 +146,12 @@ public class PipeTransportPower extends PipeTransport { if (j != i && powerQuery[j] > 0) { float watts = 0.0F; - if (tiles[j] instanceof TileGenericPipe) { + PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]); + if (prov != null && prov.powerRequest() > 0) { + watts = (internalPower[i] / totalPowerQuery) * powerQuery[j]; + watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); + internalPower[i] -= watts; + } else if (tiles[j] instanceof TileGenericPipe) { watts = (internalPower[i] / totalPowerQuery) * powerQuery[j]; TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j]; @@ -154,15 +159,6 @@ public class PipeTransportPower extends PipeTransport { watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts); internalPower[i] -= watts; - } else if (tiles[j] instanceof IPowerReceptor) { - IPowerReceptor pow = (IPowerReceptor) tiles[j]; - PowerReceiver prov = pow.getPowerReceiver(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); - - if (prov != null && prov.getType().canReceiveFromPipes() && prov.powerRequest() > 0) { - watts = (internalPower[i] / totalPowerQuery) * powerQuery[j]; - watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); - internalPower[i] -= watts; - } } displayPower[j] += watts; @@ -188,18 +184,15 @@ public class PipeTransportPower extends PipeTransport { overload = OVERLOAD_TICKS; } - // Compute the tiles requesting energy that are not pipes + // Compute the tiles requesting energy that are not power pipes for (int i = 0; i < 6; ++i) { - if (tiles[i] instanceof IPowerReceptor && !(tiles[i] instanceof TileGenericPipe)) { - IPowerReceptor receptor = (IPowerReceptor) tiles[i]; - PowerReceiver prov = receptor.getPowerReceiver(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); - if (prov != null && prov.getType().canReceiveFromPipes()) { - float request = prov.powerRequest(); + PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[i]); + if (prov != null) { + float request = prov.powerRequest(); - if (request > 0) { - requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request); - } + if (request > 0) { + requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request); } } } @@ -256,6 +249,19 @@ public class PipeTransportPower extends PipeTransport { } + private PowerReceiver getReceiverOnSide(ForgeDirection side) { + TileEntity tile = tiles[side.ordinal()]; + if (!(tile instanceof IPowerReceptor)) + return null; + IPowerReceptor receptor = (IPowerReceptor) tile; + PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite()); + if (receiver == null) + return null; + if (!receiver.getType().canReceiveFromPipes()) + return null; + return receiver; + } + public boolean isOverloaded() { return overload >= OVERLOAD_TICKS; } @@ -284,6 +290,11 @@ public class PipeTransportPower extends PipeTransport { } } + /** + * Do NOT ever call this from outside Buildcraft unless you are a pipe mod. + * It is NOT part of the API. All power input MUST go through designated + * input pipes, such as Wooden Power Pipes. + */ public float receiveEnergy(ForgeDirection from, float val) { step(); if (this.container.pipe instanceof IPipeTransportPowerHook) { From d0a7a64505b6fbea3eab3a498f5aff0b5299f5fc Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Thu, 4 Jul 2013 03:37:36 -0700 Subject: [PATCH 29/29] Exploding Engines should kill themselves Added because someone decided turning off explosions was a good idea. --- common/buildcraft/energy/TileEngine.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 0c89487f..fc635f94 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -406,6 +406,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto if (getEnergyStage() == EnergyStage.OVERHEAT) { worldObj.createExplosion(null, xCoord, yCoord, zCoord, explosionRange(), true); + worldObj.setBlockToAir(xCoord, yCoord, zCoord); } if (energy > getMaxEnergy()) {