add experimental code to power kinesis pipes with redstone engines for energy extraction, add proper IInjectable support, add more compat hooks (for IItemDuct)
This commit is contained in:
parent
fa001c4a24
commit
65a135123a
11 changed files with 174 additions and 80 deletions
|
@ -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<? extends TileEntity> getPipeTile() {
|
||||
Class<? extends TileEntity> tileClass;
|
||||
|
||||
if (Loader.isModLoaded("BuildCraft|Compat")) {
|
||||
try {
|
||||
tileClass = (Class<? extends TileEntity>) BCCompatHooks.class.getClassLoader().loadClass("buildcraft.transport.TileGenericPipeCompat");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
tileClass = TileGenericPipe.class;
|
||||
}
|
||||
} else {
|
||||
tileClass = TileGenericPipe.class;
|
||||
}
|
||||
|
||||
return tileClass;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
81
common/buildcraft/compat/CompatHooks.java
Normal file
81
common/buildcraft/compat/CompatHooks.java
Normal file
|
@ -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<? extends TileEntity> getPipeTile() {
|
||||
Class<? extends TileEntity> tileClass;
|
||||
|
||||
if (Loader.isModLoaded("BuildCraft|Compat")) {
|
||||
try {
|
||||
tileClass = (Class<? extends TileEntity>) CompatHooks.class.getClassLoader().loadClass("buildcraft.transport.TileGenericPipeCompat");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
tileClass = TileGenericPipe.class;
|
||||
}
|
||||
} else {
|
||||
tileClass = TileGenericPipe.class;
|
||||
}
|
||||
|
||||
return tileClass;
|
||||
}
|
||||
}
|
|
@ -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<IPipeTile> possiblePipes = new ArrayList<IPipeTile>();
|
||||
public static int addToRandomInjectableAround(World world, int x, int y, int z, ForgeDirection from, ItemStack stack) {
|
||||
List<IInjectable> possiblePipes = new ArrayList<IInjectable>();
|
||||
List<ForgeDirection> pipeDirections = new ArrayList<ForgeDirection>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
/*
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<PipeTransportPower> implements IPipeTransportPowerHook, IEnergyHandler {
|
||||
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPipeTransportPowerHook, IEnergyHandler, IRedstoneEngineReceiver {
|
||||
|
||||
public final boolean[] powerSources = new boolean[6];
|
||||
|
||||
|
@ -39,6 +41,8 @@ public class PipePowerWood extends Pipe<PipeTransportPower> 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<PipeTransportPower> 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<PipeTransportPower> 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<PipeTransportPower> implements IPipeTran
|
|||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
return battery.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstoneEngine(ForgeDirection side) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue