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,9 +140,9 @@ 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();
if (prov != null) {
@ -150,6 +150,7 @@ public class PipeTransportPower extends PipeTransport {
internalPower[i] -= watts;
}
}
}
displayPower[j] += watts;
displayPower[i] += watts;

View file

@ -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<ITrigger> getNeighborTriggers(Block block, TileEntity tile) {
return null;
}
}

View file

@ -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,19 +85,19 @@ 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++;
}
}
@ -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();
}
}

View file

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