diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index db2e600b..66d288fa 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -140,14 +140,15 @@ public class PipeTransportPower extends PipeTransport { watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts); internalPower[i] -= watts; } else if (tiles[j] instanceof IPowerReceptor) { - watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); IPowerReceptor pow = (IPowerReceptor) tiles[j]; + if (pow.powerRequest(ForgeDirection.VALID_DIRECTIONS[j].getOpposite()) > 0) { + watts = (internalPower[i] / totalPowerQuery * powerQuery[j]); + IPowerProvider prov = pow.getPowerProvider(); - IPowerProvider prov = pow.getPowerProvider(); - - if (prov != null) { - prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); - internalPower[i] -= watts; + if (prov != null) { + prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); + internalPower[i] -= watts; + } } } diff --git a/common/buildcraft/transport/PipeTriggerProvider.java b/common/buildcraft/transport/PipeTriggerProvider.java index 9bf8021f..3dedaf98 100644 --- a/common/buildcraft/transport/PipeTriggerProvider.java +++ b/common/buildcraft/transport/PipeTriggerProvider.java @@ -9,6 +9,7 @@ import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerProvider; import buildcraft.api.transport.IPipe; +import buildcraft.transport.pipes.PipePowerWood; public class PipeTriggerProvider implements ITriggerProvider { @@ -31,8 +32,10 @@ public class PipeTriggerProvider implements ITriggerProvider { } else if (pipe.transport instanceof PipeTransportPower) { result.add(BuildCraftTransport.triggerPipeEmpty); result.add(BuildCraftTransport.triggerPipeContainsEnergy); - result.add(BuildCraftTransport.triggerPipeRequestsEnergy); result.add(BuildCraftTransport.triggerPipeTooMuchEnergy); + if (pipe instanceof PipePowerWood) { + result.add(BuildCraftTransport.triggerPipeRequestsEnergy); + } } else if (pipe.transport instanceof PipeTransportLiquids) { result.add(BuildCraftTransport.triggerPipeEmpty); result.add(BuildCraftTransport.triggerPipeLiquids); @@ -45,5 +48,4 @@ public class PipeTriggerProvider implements ITriggerProvider { public LinkedList getNeighborTriggers(Block block, TileEntity tile) { return null; } - } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 116b77b3..a75465c6 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -13,26 +13,35 @@ import buildcraft.api.core.IIconProvider; import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerFramework; +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 { private IPowerProvider powerProvider; protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard; protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; - private int[] powerSources = new int[6]; + private boolean[] powerSources = new boolean[6]; + private boolean full; public PipePowerWood(int itemID) { super(new PipeTransportPower(), new PipeLogicWood(), itemID); powerProvider = PowerFramework.currentFramework.createPowerProvider(); + initPowerProvider(); + ((PipeTransportPower) transport).initFromPipe(getClass()); + } + + private void initPowerProvider() { powerProvider.configure(50, 2, 1000, 1, 1500); powerProvider.configurePowerPerdition(1, 10); - ((PipeTransportPower) transport).initFromPipe(getClass()); } @Override @@ -76,26 +85,26 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { if (worldObj.isRemote) return; + if (powerProvider.getEnergyStored() <= 0) + return; + int sources = 0; for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { if (!container.isPipeConnected(o)) { - powerSources[o.ordinal()] = 0; + powerSources[o.ordinal()] = false; continue; } - if (powerSources[o.ordinal()] > 0) { - powerSources[o.ordinal()]--; - } if (powerProvider.isPowerSource(o)) { - powerSources[o.ordinal()] = 40; + powerSources[o.ordinal()] = true; } - if (powerSources[o.ordinal()] > 0) { + if (powerSources[o.ordinal()]) { sources++; } } - + if (sources <= 0) return; - + float energyToRemove; if (powerProvider.getEnergyStored() > 40) { @@ -110,7 +119,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { PipeTransportPower trans = (PipeTransportPower) transport; for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { - if (powerSources[o.ordinal()] <= 0) + if (!powerSources[o.ordinal()]) continue; float energyUsable = powerProvider.useEnergy(1, energyToRemove, false); @@ -122,8 +131,33 @@ public class PipePowerWood extends Pipe implements IPowerReceptor { } } + public boolean requestsPower() { + if (full) { + boolean request = powerProvider.getEnergyStored() < powerProvider.getMaxEnergyStored() / 2; + if (request) { + full = false; + } + return request; + } + full = powerProvider.getEnergyStored() >= powerProvider.getMaxEnergyStored() - 10; + return !full; + } + @Override public int powerRequest(ForgeDirection from) { return getPowerProvider().getMaxEnergyReceived(); } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + powerProvider.writeToNBT(data); + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + PowerFramework.currentFramework.loadPowerProvider(this, data); + initPowerProvider(); + } } diff --git a/common/buildcraft/transport/triggers/TriggerPipeContents.java b/common/buildcraft/transport/triggers/TriggerPipeContents.java index 26503f4f..d039f2f1 100644 --- a/common/buildcraft/transport/triggers/TriggerPipeContents.java +++ b/common/buildcraft/transport/triggers/TriggerPipeContents.java @@ -21,6 +21,7 @@ import buildcraft.transport.Pipe; import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportLiquids; import buildcraft.transport.PipeTransportPower; +import buildcraft.transport.pipes.PipePowerWood; public class TriggerPipeContents extends BCTrigger implements ITriggerPipe { @@ -127,12 +128,8 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe { return false; case RequestsEnergy: - for (double s : transportPower.powerQuery) { - if (s > 0) - return true; - } - - return false; + PipePowerWood wood = (PipePowerWood) pipe; + return wood.requestsPower(); case TooMuchEnergy: return transportPower.isOverloaded(); }