diff --git a/common/buildcraft/BCCompatHooks.java b/common/buildcraft/BCCompatHooks.java deleted file mode 100644 index 21befcd2..00000000 --- a/common/buildcraft/BCCompatHooks.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package buildcraft; - -import net.minecraft.tileentity.TileEntity; - -import cpw.mods.fml.common.Loader; - -import buildcraft.transport.BlockGenericPipe; -import buildcraft.transport.TileGenericPipe; - -public final class BCCompatHooks { - private BCCompatHooks() { - - } - - public static BlockGenericPipe createPipeBlock() { - BlockGenericPipe genericPipeBlock; - - if (Loader.isModLoaded("BuildCraft|Compat")) { - try { - genericPipeBlock = (BlockGenericPipe) BCCompatHooks.class.getClassLoader().loadClass("buildcraft.transport.BlockGenericPipeCompat").newInstance(); - } catch (Exception e) { - e.printStackTrace(); - genericPipeBlock = new BlockGenericPipe(); - } - } else { - genericPipeBlock = new BlockGenericPipe(); - } - - return genericPipeBlock; - } - - public static Class getPipeTile() { - Class tileClass; - - if (Loader.isModLoaded("BuildCraft|Compat")) { - try { - tileClass = (Class) BCCompatHooks.class.getClassLoader().loadClass("buildcraft.transport.TileGenericPipeCompat"); - } catch (Exception e) { - e.printStackTrace(); - tileClass = TileGenericPipe.class; - } - } else { - tileClass = TileGenericPipe.class; - } - - return tileClass; - } -} diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index e12b8241..0525a560 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -46,6 +46,7 @@ import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.StatementManager; import buildcraft.api.transport.PipeManager; import buildcraft.api.transport.PipeWire; +import buildcraft.compat.CompatHooks; import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; @@ -119,7 +120,6 @@ import buildcraft.transport.pipes.PipePowerWood; import buildcraft.transport.pipes.PipeStructureCobblestone; import buildcraft.transport.pluggable.ItemLens; import buildcraft.transport.pluggable.ItemPlug; -import buildcraft.transport.pluggable.ItemPowerAdapter; import buildcraft.transport.pluggable.ItemRobotStation; import buildcraft.transport.pluggable.LensPluggable; import buildcraft.transport.pluggable.PlugPluggable; @@ -314,7 +314,7 @@ public class BuildCraftTransport extends BuildCraftMod { pipeWaterproof.setUnlocalizedName("pipeWaterproof"); CoreProxy.proxy.registerItem(pipeWaterproof); - genericPipeBlock = BCCompatHooks.createPipeBlock(); + genericPipeBlock = CompatHooks.INSTANCE.createPipeBlock(); CoreProxy.proxy.registerBlock(genericPipeBlock.setBlockName("pipeBlock"), ItemBlock.class); diff --git a/common/buildcraft/compat/CompatHooks.java b/common/buildcraft/compat/CompatHooks.java new file mode 100644 index 00000000..985815c3 --- /dev/null +++ b/common/buildcraft/compat/CompatHooks.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.compat; + +import net.minecraft.tileentity.TileEntity; + +import cpw.mods.fml.common.Loader; + +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.transport.IInjectable; +import buildcraft.transport.BlockGenericPipe; +import buildcraft.transport.TileGenericPipe; + +public final class CompatHooks { + public static final CompatHooks INSTANCE; + + static { + CompatHooks i = null; + if (Loader.isModLoaded("BuildCraft|Compat")) { + try { + i = (CompatHooks) CompatHooks.class.getClassLoader().loadClass("buildcraft.compat.CompatHooksImpl").newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (i == null) { + i = new CompatHooks(); + } + + INSTANCE = i; + } + + public CompatHooks() { + + } + + public IInjectable getInjectableWrapper(TileEntity tile, ForgeDirection side) { + return null; + } + + public BlockGenericPipe createPipeBlock() { + BlockGenericPipe genericPipeBlock; + + if (Loader.isModLoaded("BuildCraft|Compat")) { + try { + genericPipeBlock = (BlockGenericPipe) CompatHooks.class.getClassLoader().loadClass("buildcraft.transport.BlockGenericPipeCompat").newInstance(); + } catch (Exception e) { + e.printStackTrace(); + genericPipeBlock = new BlockGenericPipe(); + } + } else { + genericPipeBlock = new BlockGenericPipe(); + } + + return genericPipeBlock; + } + + public Class getPipeTile() { + Class tileClass; + + if (Loader.isModLoaded("BuildCraft|Compat")) { + try { + tileClass = (Class) CompatHooks.class.getClassLoader().loadClass("buildcraft.transport.TileGenericPipeCompat"); + } catch (Exception e) { + e.printStackTrace(); + tileClass = TileGenericPipe.class; + } + } else { + tileClass = TileGenericPipe.class; + } + + return tileClass; + } +} diff --git a/common/buildcraft/core/utils/Utils.java b/common/buildcraft/core/utils/Utils.java index 2790e046..47ae78a9 100644 --- a/common/buildcraft/core/utils/Utils.java +++ b/common/buildcraft/core/utils/Utils.java @@ -40,7 +40,9 @@ import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.Position; +import buildcraft.api.transport.IInjectable; import buildcraft.api.transport.IPipeTile; +import buildcraft.compat.CompatHooks; import buildcraft.core.DefaultProps; import buildcraft.core.EntityBlock; import buildcraft.core.IDropControlInventory; @@ -141,13 +143,13 @@ public final class Utils { /** * Look around the tile given in parameter in all 6 position, tries to add - * the items to a random pipe entry around. Will make sure that the location + * the items to a random injectable tile around. Will make sure that the location * from which the items are coming from (identified by the from parameter) * isn't used again so that entities doesn't go backwards. Returns true if * successful, false otherwise. */ - public static int addToRandomPipeAround(World world, int x, int y, int z, ForgeDirection from, ItemStack stack) { - List possiblePipes = new ArrayList(); + public static int addToRandomInjectableAround(World world, int x, int y, int z, ForgeDirection from, ItemStack stack) { + List possiblePipes = new ArrayList(); List pipeDirections = new ArrayList(); for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { @@ -161,24 +163,26 @@ public final class Utils { TileEntity tile = BlockUtils.getTileEntity(world, (int) pos.x, (int) pos.y, (int) pos.z); - if (tile instanceof IPipeTile) { - IPipeTile pipe = (IPipeTile) tile; - if (pipe.getPipeType() != IPipeTile.PipeType.ITEM) { - continue; - } - if (!pipe.isPipeConnected(side.getOpposite())) { + if (tile instanceof IInjectable) { + if (!((IInjectable) tile).canInjectItems(side.getOpposite())) { continue; } - possiblePipes.add(pipe); + possiblePipes.add((IInjectable) tile); pipeDirections.add(side.getOpposite()); + } else { + IInjectable wrapper = CompatHooks.INSTANCE.getInjectableWrapper(tile, side); + if (wrapper != null) { + possiblePipes.add(wrapper); + pipeDirections.add(side.getOpposite()); + } } } if (possiblePipes.size() > 0) { int choice = RANDOM.nextInt(possiblePipes.size()); - IPipeTile pipeEntry = possiblePipes.get(choice); + IInjectable pipeEntry = possiblePipes.get(choice); return pipeEntry.injectItem(stack, true, pipeDirections.get(choice)); } diff --git a/common/buildcraft/energy/TileEngineWood.java b/common/buildcraft/energy/TileEngineWood.java index dffb2caf..42f94f95 100644 --- a/common/buildcraft/energy/TileEngineWood.java +++ b/common/buildcraft/energy/TileEngineWood.java @@ -13,10 +13,11 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.power.IRedstoneEngine; import buildcraft.api.power.IRedstoneEngineReceiver; import buildcraft.api.transport.IPipeTile; -public class TileEngineWood extends TileEngine { +public class TileEngineWood extends TileEngine implements IRedstoneEngine { private boolean hasSent = false; @@ -126,9 +127,7 @@ public class TileEngineWood extends TileEngine { TileEntity tile = getTile(orientation); - // TODO: Make a proper API out of this - if ((tile instanceof IRedstoneEngineReceiver && ((IRedstoneEngineReceiver) tile).canConnectRedstoneEngine(orientation.getOpposite())) || - (tile instanceof IPipeTile && ((IPipeTile) tile).getPipeType() != IPipeTile.PipeType.POWER)) { + if (tile instanceof IRedstoneEngineReceiver && ((IRedstoneEngineReceiver) tile).canConnectRedstoneEngine(orientation.getOpposite())) { super.sendPower(); } else { this.energy = 0; diff --git a/common/buildcraft/factory/BlockMiner.java b/common/buildcraft/factory/BlockMiner.java index 8e76f66c..4cf925ab 100644 --- a/common/buildcraft/factory/BlockMiner.java +++ b/common/buildcraft/factory/BlockMiner.java @@ -50,7 +50,7 @@ public class BlockMiner { // Second, try to add to adjacent pipes if (stack.stackSize > 0) { - stack.stackSize -= Utils.addToRandomPipeAround(owner.getWorldObj(), owner.xCoord, owner.yCoord, owner.zCoord, ForgeDirection.UNKNOWN, stack); + stack.stackSize -= Utils.addToRandomInjectableAround(owner.getWorldObj(), owner.xCoord, owner.yCoord, owner.zCoord, ForgeDirection.UNKNOWN, stack); } // Lastly, throw the object away diff --git a/common/buildcraft/silicon/TileAssemblyTable.java b/common/buildcraft/silicon/TileAssemblyTable.java index cdc9e077..b571bf15 100644 --- a/common/buildcraft/silicon/TileAssemblyTable.java +++ b/common/buildcraft/silicon/TileAssemblyTable.java @@ -101,7 +101,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IInventory, } if (remaining != null && remaining.stackSize > 0) { - remaining.stackSize -= Utils.addToRandomPipeAround(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN, remaining); + remaining.stackSize -= Utils.addToRandomInjectableAround(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN, remaining); } if (remaining != null && remaining.stackSize > 0) { diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index eaccac17..590dc627 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -25,9 +25,11 @@ import buildcraft.BuildCraftCore; import buildcraft.BuildCraftTransport; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.power.IEngine; +import buildcraft.api.power.IRedstoneEngine; import buildcraft.api.transport.IPipeTile; import buildcraft.core.DefaultProps; import buildcraft.core.TileBuildCraft; +import buildcraft.energy.TileEngineWood; import buildcraft.transport.network.PacketPowerUpdate; import buildcraft.transport.pipes.PipePowerCobblestone; import buildcraft.transport.pipes.PipePowerDiamond; @@ -123,6 +125,12 @@ public class PipeTransportPower extends PipeTransport { return false; } + if (tile instanceof IRedstoneEngine) { + // Do not render wooden pipe connections to match the look of transport/fluid pipes + // for kinesis. + return false; + } + return tile instanceof IEnergyConnection && ((IEnergyConnection) tile).canConnectEnergy(side.getOpposite()); // TODO: Look into this code again when the new RF API is out. /* diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 98aa1e4e..f797a896 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -43,6 +43,8 @@ import buildcraft.api.core.IIconProvider; import buildcraft.api.core.ISerializable; import buildcraft.api.core.Position; import buildcraft.api.gates.IGateExpansion; +import buildcraft.api.power.IRedstoneEngine; +import buildcraft.api.power.IRedstoneEngineReceiver; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeTile; @@ -63,12 +65,13 @@ import buildcraft.core.utils.Utils; import buildcraft.transport.ItemFacade.FacadeState; import buildcraft.transport.gates.GateFactory; import buildcraft.transport.gates.GatePluggable; +import buildcraft.transport.pipes.PipePowerWood; import buildcraft.transport.pluggable.PlugPluggable; import buildcraft.transport.pluggable.RobotStationPluggable; public class TileGenericPipe extends TileEntity implements IFluidHandler, IPipeTile, ITileBufferHolder, IEnergyHandler, IDropControlInventory, - ISyncedTile, ISolidSideTile, IGuiReturnHandler { + ISyncedTile, ISolidSideTile, IGuiReturnHandler, IRedstoneEngineReceiver { public boolean initialized = false; public final PipeRenderState renderState = new PipeRenderState(); @@ -589,7 +592,14 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, blockNeighborChange = true; } - /* IPIPEENTRY */ + @Override + public boolean canInjectItems(ForgeDirection from) { + if (getPipeType() != IPipeTile.PipeType.ITEM) { + return false; + } + return isPipeConnected(from); + } + @Override public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from, EnumColor color) { if (!pipe.inputOpen(from)) { @@ -1201,4 +1211,13 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, public IPipe getPipe() { return pipe; } + + @Override + public boolean canConnectRedstoneEngine(ForgeDirection side) { + if (pipe instanceof IRedstoneEngineReceiver) { + return ((IRedstoneEngineReceiver) pipe).canConnectRedstoneEngine(side); + } else { + return ((getPipeType() != PipeType.POWER) && (getPipeType() != PipeType.STRUCTURE)); + } + } } diff --git a/common/buildcraft/transport/TransportProxy.java b/common/buildcraft/transport/TransportProxy.java index 7b52eaeb..9b9080cf 100644 --- a/common/buildcraft/transport/TransportProxy.java +++ b/common/buildcraft/transport/TransportProxy.java @@ -11,7 +11,7 @@ package buildcraft.transport; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.registry.GameRegistry; -import buildcraft.BCCompatHooks; +import buildcraft.compat.CompatHooks; import buildcraft.BuildCraftTransport; public class TransportProxy { @@ -22,7 +22,7 @@ public class TransportProxy { public void registerTileEntities() { // The first name here is the current TE name; the remaining names are old names used for backwards compatibility - GameRegistry.registerTileEntityWithAlternatives(BCCompatHooks.getPipeTile(), "net.minecraft.src.buildcraft.transport.GenericPipe", "net.minecraft.src.buildcraft.GenericPipe", "net.minecraft.src.buildcraft.transport.TileGenericPipe"); + GameRegistry.registerTileEntityWithAlternatives(CompatHooks.INSTANCE.getPipeTile(), "net.minecraft.src.buildcraft.transport.GenericPipe", "net.minecraft.src.buildcraft.GenericPipe", "net.minecraft.src.buildcraft.transport.TileGenericPipe"); GameRegistry.registerTileEntity(TileFilteredBuffer.class, "net.minecraft.src.buildcraft.transport.TileFilteredBuffer"); } diff --git a/common/buildcraft/transport/pipes/PipePowerWood.java b/common/buildcraft/transport/pipes/PipePowerWood.java index f058003f..46da8b48 100644 --- a/common/buildcraft/transport/pipes/PipePowerWood.java +++ b/common/buildcraft/transport/pipes/PipePowerWood.java @@ -18,9 +18,11 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.common.util.ForgeDirection; import cofh.api.energy.IEnergyHandler; +import cofh.api.energy.IEnergyProvider; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; +import buildcraft.api.power.IRedstoneEngineReceiver; import buildcraft.api.transport.IPipeTile; import buildcraft.core.RFBattery; import buildcraft.transport.IPipeTransportPowerHook; @@ -28,7 +30,7 @@ import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportPower; -public class PipePowerWood extends Pipe implements IPipeTransportPowerHook, IEnergyHandler { +public class PipePowerWood extends Pipe implements IPipeTransportPowerHook, IEnergyHandler, IRedstoneEngineReceiver { public final boolean[] powerSources = new boolean[6]; @@ -39,6 +41,8 @@ public class PipePowerWood extends Pipe implements IPipeTran private boolean full; private int requestedEnergy, sources, lastRequestedEnergy; + private boolean allowExtraction = false; + public PipePowerWood(Item item) { super(new PipeTransportPower(), item); @@ -101,6 +105,32 @@ public class PipePowerWood extends Pipe implements IPipeTran return; } + if (allowExtraction) { + allowExtraction = false; + + int energyMaxExtract = Math.min(battery.getMaxEnergyExtract(), battery.getMaxEnergyStored() - battery.getEnergyStored()); + energyMaxExtract /= sources; + + for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { + if (!powerSources[o.ordinal()]) { + continue; + } + + TileEntity source = container.getNeighborTile(o); + if (source instanceof IEnergyProvider) { + int energyExtracted = battery.addEnergy(0, + ((IEnergyProvider) source).extractEnergy(o.getOpposite(), energyMaxExtract, true), + false); + ((IEnergyProvider) source).extractEnergy(o.getOpposite(), energyExtracted, true); + } else if (source instanceof IEnergyHandler) { + int energyExtracted = battery.addEnergy(0, + ((IEnergyHandler) source).extractEnergy(o.getOpposite(), energyMaxExtract, true), + false); + ((IEnergyHandler) source).extractEnergy(o.getOpposite(), energyExtracted, true); + } + } + } + int energyToRemove = Math.min(battery.getEnergyStored(), requestedEnergy); // TODO: Have energyToRemove be precalculated @@ -178,6 +208,10 @@ public class PipePowerWood extends Pipe implements IPipeTran @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { + if (from.ordinal() < 6 && container.getNeighborTile(from) instanceof IRedstoneEngineReceiver) { + allowExtraction = true; + return maxReceive; + } if (from.ordinal() < 6 && powerSources[from.ordinal()]) { return battery.receiveEnergy(simulate ? Math.min(maxReceive, lastRequestedEnergy) : maxReceive, simulate); } else { @@ -200,4 +234,9 @@ public class PipePowerWood extends Pipe implements IPipeTran public int getMaxEnergyStored(ForgeDirection from) { return battery.getMaxEnergyStored(); } + + @Override + public boolean canConnectRedstoneEngine(ForgeDirection side) { + return true; + } }