Fixed Power Request Trigger

Its now restricted to Wooden Power pipes.

Before:
The trigger was useless because it was triggering off the powerQuery
array which was always true so long as there was any device on the
network requesting power. This made it rather useless for scaling
production to demand.

After:
It now triggers whenever the Wooden Power Pipe's internal power buffer
drops below a certain point. This however required a modification of the
wooden pipe's internals because it was getting stuck in the "Off" state
due to how it handled transferring power from the buffer to the pipe
network.

Anyway, it works now and is somewhat useful.

Note: The Wooden Power Pipe's internal buffer stores 1500 MJ, this was
true even before this commit.
This commit is contained in:
CovertJaguar 2013-06-24 21:02:48 -07:00
parent 5f58280e5f
commit 8b6546a8bd
4 changed files with 59 additions and 25 deletions

View file

@ -140,14 +140,15 @@ public class PipeTransportPower extends PipeTransport {
watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts); watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);
internalPower[i] -= watts; internalPower[i] -= watts;
} else if (tiles[j] instanceof IPowerReceptor) { } else if (tiles[j] instanceof IPowerReceptor) {
watts = (internalPower[i] / totalPowerQuery * powerQuery[j]);
IPowerReceptor pow = (IPowerReceptor) tiles[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());
if (prov != null) { internalPower[i] -= watts;
prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()); }
internalPower[i] -= watts;
} }
} }

View file

@ -9,6 +9,7 @@ import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerProvider; import buildcraft.api.gates.ITriggerProvider;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.transport.pipes.PipePowerWood;
public class PipeTriggerProvider implements ITriggerProvider { public class PipeTriggerProvider implements ITriggerProvider {
@ -31,8 +32,10 @@ public class PipeTriggerProvider implements ITriggerProvider {
} else if (pipe.transport instanceof PipeTransportPower) { } else if (pipe.transport instanceof PipeTransportPower) {
result.add(BuildCraftTransport.triggerPipeEmpty); result.add(BuildCraftTransport.triggerPipeEmpty);
result.add(BuildCraftTransport.triggerPipeContainsEnergy); result.add(BuildCraftTransport.triggerPipeContainsEnergy);
result.add(BuildCraftTransport.triggerPipeRequestsEnergy);
result.add(BuildCraftTransport.triggerPipeTooMuchEnergy); result.add(BuildCraftTransport.triggerPipeTooMuchEnergy);
if (pipe instanceof PipePowerWood) {
result.add(BuildCraftTransport.triggerPipeRequestsEnergy);
}
} else if (pipe.transport instanceof PipeTransportLiquids) { } else if (pipe.transport instanceof PipeTransportLiquids) {
result.add(BuildCraftTransport.triggerPipeEmpty); result.add(BuildCraftTransport.triggerPipeEmpty);
result.add(BuildCraftTransport.triggerPipeLiquids); result.add(BuildCraftTransport.triggerPipeLiquids);
@ -45,5 +48,4 @@ public class PipeTriggerProvider implements ITriggerProvider {
public LinkedList<ITrigger> getNeighborTriggers(Block block, TileEntity tile) { public LinkedList<ITrigger> getNeighborTriggers(Block block, TileEntity tile) {
return null; return null;
} }
} }

View file

@ -13,26 +13,35 @@ import buildcraft.api.core.IIconProvider;
import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework; import buildcraft.api.power.PowerFramework;
import buildcraft.core.utils.Utils;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportPower; import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class PipePowerWood extends Pipe implements IPowerReceptor { public class PipePowerWood extends Pipe implements IPowerReceptor {
private IPowerProvider powerProvider; private IPowerProvider powerProvider;
protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard; protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard;
protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid; 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) { public PipePowerWood(int itemID) {
super(new PipeTransportPower(), new PipeLogicWood(), itemID); super(new PipeTransportPower(), new PipeLogicWood(), itemID);
powerProvider = PowerFramework.currentFramework.createPowerProvider(); powerProvider = PowerFramework.currentFramework.createPowerProvider();
initPowerProvider();
((PipeTransportPower) transport).initFromPipe(getClass());
}
private void initPowerProvider() {
powerProvider.configure(50, 2, 1000, 1, 1500); powerProvider.configure(50, 2, 1000, 1, 1500);
powerProvider.configurePowerPerdition(1, 10); powerProvider.configurePowerPerdition(1, 10);
((PipeTransportPower) transport).initFromPipe(getClass());
} }
@Override @Override
@ -76,26 +85,26 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
if (worldObj.isRemote) if (worldObj.isRemote)
return; return;
if (powerProvider.getEnergyStored() <= 0)
return;
int sources = 0; int sources = 0;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (!container.isPipeConnected(o)) { if (!container.isPipeConnected(o)) {
powerSources[o.ordinal()] = 0; powerSources[o.ordinal()] = false;
continue; continue;
} }
if (powerSources[o.ordinal()] > 0) {
powerSources[o.ordinal()]--;
}
if (powerProvider.isPowerSource(o)) { if (powerProvider.isPowerSource(o)) {
powerSources[o.ordinal()] = 40; powerSources[o.ordinal()] = true;
} }
if (powerSources[o.ordinal()] > 0) { if (powerSources[o.ordinal()]) {
sources++; sources++;
} }
} }
if (sources <= 0) if (sources <= 0)
return; return;
float energyToRemove; float energyToRemove;
if (powerProvider.getEnergyStored() > 40) { if (powerProvider.getEnergyStored() > 40) {
@ -110,7 +119,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
PipeTransportPower trans = (PipeTransportPower) transport; PipeTransportPower trans = (PipeTransportPower) transport;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (powerSources[o.ordinal()] <= 0) if (!powerSources[o.ordinal()])
continue; continue;
float energyUsable = powerProvider.useEnergy(1, energyToRemove, false); 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 @Override
public int powerRequest(ForgeDirection from) { public int powerRequest(ForgeDirection from) {
return getPowerProvider().getMaxEnergyReceived(); 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();
}
} }

View file

@ -21,6 +21,7 @@ import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportLiquids; import buildcraft.transport.PipeTransportLiquids;
import buildcraft.transport.PipeTransportPower; import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.pipes.PipePowerWood;
public class TriggerPipeContents extends BCTrigger implements ITriggerPipe { public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
@ -127,12 +128,8 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
return false; return false;
case RequestsEnergy: case RequestsEnergy:
for (double s : transportPower.powerQuery) { PipePowerWood wood = (PipePowerWood) pipe;
if (s > 0) return wood.requestsPower();
return true;
}
return false;
case TooMuchEnergy: case TooMuchEnergy:
return transportPower.isOverloaded(); return transportPower.isOverloaded();
} }