From 89f71c515be93b98af16da4ac146e6c5e2924b7f Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sun, 18 May 2014 15:55:19 +0200 Subject: [PATCH] Added to wood pipes the ability to interact with all BC energy APIs. Close #1824 --- .../buildcraft/transport/TileGenericPipe.java | 21 ++++++++++++++++- .../transport/pipes/PipePowerWood.java | 23 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 02443ad0..19786b5d 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -46,6 +46,9 @@ import buildcraft.api.gates.IGateExpansion; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; import buildcraft.api.mj.MjBattery; +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeTile; import buildcraft.api.transport.PipeWire; @@ -63,7 +66,7 @@ import buildcraft.core.utils.Utils; import buildcraft.transport.gates.GateDefinition; import buildcraft.transport.gates.GateFactory; -public class TileGenericPipe extends TileEntity implements IFluidHandler, +public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler { @@ -1030,4 +1033,20 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, ((IGuiReturnHandler) pipe).readGuiData(data, sender); } } + + @Override + public PowerReceiver getPowerReceiver(ForgeDirection side) { + if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { + return ((IPowerReceptor) pipe).getPowerReceiver(null); + } else { + return null; + } + } + + @Override + public void doWork(PowerHandler workProvider) { + if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { + ((IPowerReceptor) pipe).doWork(workProvider); + } + } } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index 3d2eb219..2fd36715 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -19,15 +19,20 @@ import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.SafeTimeTracker; +import buildcraft.api.mj.MjAPILegacy; import buildcraft.api.mj.MjBattery; import buildcraft.api.power.IPowerEmitter; +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; -public class PipePowerWood extends Pipe implements IPipeTransportPowerHook { +public class PipePowerWood extends Pipe implements IPowerReceptor, IPipeTransportPowerHook { public final boolean[] powerSources = new boolean[6]; @@ -39,6 +44,8 @@ public class PipePowerWood extends Pipe implements IPipeTran private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(1); private boolean full; + private MjAPILegacy powerHandler; + public PipePowerWood(Item item) { super(new PipeTransportPower(), item); transport.initFromPipe(getClass()); @@ -165,4 +172,18 @@ public class PipePowerWood extends Pipe implements IPipeTran public boolean isPowerSource(ForgeDirection from) { return container.getTile(from) instanceof IPowerEmitter; } + + @Override + public PowerReceiver getPowerReceiver(ForgeDirection side) { + if (powerHandler == null) { + powerHandler = MjAPILegacy.from(container, Type.PIPE); + } + + return powerHandler.getPowerReceiver(ForgeDirection.UNKNOWN); + } + + @Override + public void doWork(PowerHandler workProvider) { + + } }