Wooden Power Pipes can no longer output power
Prevents power loops when a machine both emits and accepts power. Closes #1202
This commit is contained in:
parent
f0c1e7467f
commit
56d46de1be
3 changed files with 35 additions and 12 deletions
|
@ -13,7 +13,15 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
|
||||
public interface IPipeTransportPowerHook {
|
||||
|
||||
/**
|
||||
* Override default behavior on receiving energy into the pipe.
|
||||
*
|
||||
* @return The amount of power used, or -1 for default behavior.
|
||||
*/
|
||||
public float receiveEnergy(ForgeDirection from, float val);
|
||||
|
||||
/**
|
||||
* Override default requested power.
|
||||
*/
|
||||
public float requestEnergy(ForgeDirection from, float amount);
|
||||
}
|
||||
|
|
|
@ -321,14 +321,15 @@ public class PipeTransportPower extends PipeTransport {
|
|||
|
||||
step();
|
||||
if (this.container.pipe instanceof IPipeTransportPowerHook) {
|
||||
return ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
|
||||
} else {
|
||||
internalNextPower[from.ordinal()] += val;
|
||||
float ret = ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
}
|
||||
internalNextPower[from.ordinal()] += val;
|
||||
|
||||
if (internalNextPower[from.ordinal()] > maxPower) {
|
||||
val -= internalNextPower[from.ordinal()] - maxPower;
|
||||
internalNextPower[from.ordinal()] = maxPower;
|
||||
}
|
||||
if (internalNextPower[from.ordinal()] > maxPower) {
|
||||
val -= internalNextPower[from.ordinal()] - maxPower;
|
||||
internalNextPower[from.ordinal()] = maxPower;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import buildcraft.api.power.IPowerReceptor;
|
|||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.transport.IPipeTransportPowerHook;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTransportPower;
|
||||
|
@ -21,8 +23,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
|
||||
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerReceptor {
|
||||
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerReceptor, IPipeTransportPowerHook {
|
||||
|
||||
private PowerHandler powerHandler;
|
||||
protected int standardIconIndex = PipeIconProvider.TYPE.PipePowerWood_Standard.ordinal();
|
||||
|
@ -108,9 +109,9 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
|
|||
|
||||
float energyUsable = powerHandler.useEnergy(0, energyToRemove, false);
|
||||
|
||||
float energySend = transport.receiveEnergy(o, energyUsable);
|
||||
if (energySend > 0) {
|
||||
powerHandler.useEnergy(0, energySend, true);
|
||||
float energySent = transport.receiveEnergy(o, energyUsable);
|
||||
if (energySent > 0) {
|
||||
powerHandler.useEnergy(0, energySent, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,4 +146,17 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
|
|||
powerSources[i] = data.getBoolean("powerSources[" + i + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ForgeDirection from, float val) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float requestEnergy(ForgeDirection from, float amount) {
|
||||
if (container.getTile(from) instanceof IPipeTile) {
|
||||
return amount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue