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.
This commit is contained in:
CovertJaguar 2013-06-25 01:00:24 -07:00
parent d7fb14b8a8
commit 1f8c9f78ee
27 changed files with 175 additions and 620 deletions

View file

@ -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");

View file

@ -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();
}

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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<BlockIndex> 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() {

View file

@ -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;
}

View file

@ -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();
}
}

View file

@ -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) {
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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));
}
}

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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]);

View file

@ -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

View file

@ -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;
}
}

View file

@ -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);
}
}
}
}

View file

@ -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<ITrigger> getTriggers() {
LinkedList<ITrigger> result = new LinkedList<ITrigger>();

View file

@ -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;
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}