diff --git a/api/cofh/api/CoFHAPIProps.java b/api/cofh/api/CoFHAPIProps.java index be48ec3d..22096377 100644 --- a/api/cofh/api/CoFHAPIProps.java +++ b/api/cofh/api/CoFHAPIProps.java @@ -6,6 +6,6 @@ public class CoFHAPIProps { } - public static final String VERSION = "1.7.10R1.0.0"; + public static final String VERSION = "1.7.10R1.0.1"; } diff --git a/api/cofh/api/energy/EnergyStorage.java b/api/cofh/api/energy/EnergyStorage.java index b3383aeb..1674c189 100644 --- a/api/cofh/api/energy/EnergyStorage.java +++ b/api/cofh/api/energy/EnergyStorage.java @@ -87,8 +87,8 @@ public class EnergyStorage implements IEnergyStorage { } /** - * This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are - * guaranteed to have it. + * This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers + * are guaranteed to have it. * * @param energy */ diff --git a/api/cofh/api/energy/IEnergyConnection.java b/api/cofh/api/energy/IEnergyConnection.java index 63faffb9..79bdf77a 100644 --- a/api/cofh/api/energy/IEnergyConnection.java +++ b/api/cofh/api/energy/IEnergyConnection.java @@ -5,7 +5,7 @@ import net.minecraftforge.common.util.ForgeDirection; /** * Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not * accept it; otherwise just use IEnergyHandler. - * + *
* Note that {@link IEnergyHandler} is an extension of this. * * @author King Lemming diff --git a/api/cofh/api/energy/IEnergyContainerItem.java b/api/cofh/api/energy/IEnergyContainerItem.java index 0bcfda60..c28455b1 100644 --- a/api/cofh/api/energy/IEnergyContainerItem.java +++ b/api/cofh/api/energy/IEnergyContainerItem.java @@ -4,7 +4,7 @@ import net.minecraft.item.ItemStack; /** * Implement this interface on Item classes that support external manipulation of their internal energy storages. - * + *
* A reference implementation is provided {@link ItemEnergyContainer}. * * @author King Lemming diff --git a/api/cofh/api/energy/IEnergyHandler.java b/api/cofh/api/energy/IEnergyHandler.java index 3df31234..22f2dbc6 100644 --- a/api/cofh/api/energy/IEnergyHandler.java +++ b/api/cofh/api/energy/IEnergyHandler.java @@ -4,17 +4,19 @@ import net.minecraftforge.common.util.ForgeDirection; /** * Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects. - * + *
* A reference implementation is provided {@link TileEnergyHandler}. - * + * * @author King Lemming - * + * */ -public interface IEnergyHandler extends IEnergyConnection { +public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver { + + // merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things) /** - * Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. - * + * Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver. + * * @param from * Orientation the energy is received from. * @param maxReceive @@ -23,11 +25,12 @@ public interface IEnergyHandler extends IEnergyConnection { * If TRUE, the charge will only be simulated. * @return Amount of energy that was (or would have been, if simulated) received. */ + @Override int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate); /** - * Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. - * + * Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider. + * * @param from * Orientation the energy is extracted from. * @param maxExtract @@ -36,16 +39,20 @@ public interface IEnergyHandler extends IEnergyConnection { * If TRUE, the extraction will only be simulated. * @return Amount of energy that was (or would have been, if simulated) extracted. */ + @Override int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); + /** * Returns the amount of energy currently stored. */ + @Override int getEnergyStored(ForgeDirection from); /** * Returns the maximum amount of energy that can be stored. */ + @Override int getMaxEnergyStored(ForgeDirection from); } diff --git a/api/cofh/api/energy/IEnergyProvider.java b/api/cofh/api/energy/IEnergyProvider.java new file mode 100644 index 00000000..05287b35 --- /dev/null +++ b/api/cofh/api/energy/IEnergyProvider.java @@ -0,0 +1,38 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + *
+ * A reference implementation is provided {@link TileEnergyHandler}. + * + * @author King Lemming + * + */ +public interface IEnergyProvider extends IEnergyConnection { + + /** + * Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider. + * + * @param from + * Orientation the energy is extracted from. + * @param maxExtract + * Maximum amount of energy to extract. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted. + */ + int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); + + /** + * Returns the amount of energy currently stored. + */ + int getEnergyStored(ForgeDirection from); + + /** + * Returns the maximum amount of energy that can be stored. + */ + int getMaxEnergyStored(ForgeDirection from); + +} diff --git a/api/cofh/api/energy/IEnergyReceiver.java b/api/cofh/api/energy/IEnergyReceiver.java new file mode 100644 index 00000000..c726e09e --- /dev/null +++ b/api/cofh/api/energy/IEnergyReceiver.java @@ -0,0 +1,38 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + *
+ * A reference implementation is provided {@link TileEnergyHandler}.
+ *
+ * @author King Lemming
+ *
+ */
+public interface IEnergyReceiver extends IEnergyConnection {
+
+ /**
+ * Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
+ *
+ * @param from
+ * Orientation the energy is received from.
+ * @param maxReceive
+ * Maximum amount of energy to receive.
+ * @param simulate
+ * If TRUE, the charge will only be simulated.
+ * @return Amount of energy that was (or would have been, if simulated) received.
+ */
+ int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
+
+ /**
+ * Returns the amount of energy currently stored.
+ */
+ int getEnergyStored(ForgeDirection from);
+
+ /**
+ * Returns the maximum amount of energy that can be stored.
+ */
+ int getMaxEnergyStored(ForgeDirection from);
+
+}
diff --git a/api/cofh/api/energy/IEnergyStorage.java b/api/cofh/api/energy/IEnergyStorage.java
index 1e84bc22..bc206560 100644
--- a/api/cofh/api/energy/IEnergyStorage.java
+++ b/api/cofh/api/energy/IEnergyStorage.java
@@ -1,8 +1,9 @@
package cofh.api.energy;
/**
- * An energy storage is the unit of interaction with Energy inventories.
- *
+ * An energy storage is the unit of interaction with Energy inventories.
+ * This is not to be implemented on TileEntities. This is for internal use only.
+ *
* A reference implementation can be found at {@link EnergyStorage}. * * @author King Lemming diff --git a/api/cofh/api/energy/TileEnergyHandler.java b/api/cofh/api/energy/TileEnergyHandler.java index a7fabeb7..7cc655e9 100644 --- a/api/cofh/api/energy/TileEnergyHandler.java +++ b/api/cofh/api/energy/TileEnergyHandler.java @@ -6,9 +6,9 @@ import net.minecraftforge.common.util.ForgeDirection; /** * Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own. - * + * * @author King Lemming - * + * */ public class TileEnergyHandler extends TileEntity implements IEnergyHandler { @@ -28,25 +28,28 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler { storage.writeToNBT(nbt); } - /* IEnergyHandler */ + /* IEnergyConnection */ @Override public boolean canConnectEnergy(ForgeDirection from) { return true; } + /* IEnergyReceiver */ @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { return storage.receiveEnergy(maxReceive, simulate); } + /* IEnergyProvider */ @Override public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { return storage.extractEnergy(maxExtract, simulate); } + /* IEnergyReceiver and IEnergyProvider */ @Override public int getEnergyStored(ForgeDirection from) { diff --git a/build.gradle b/build.gradle index 3428b8c5..3207f5bb 100755 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ apply plugin: 'forge' // adds the forge dependency apply plugin: 'maven' // for uploading to a maven repo apply plugin: 'checkstyle' -version = "6.2.5" +version = "6.2.6" group= "com.mod-buildcraft" archivesBaseName = "buildcraft" // the name that all artifacts will use as a base. artifacts names follow this pattern: [baseName]-[appendix]-[version]-[classifier].[extension] diff --git a/common/buildcraft/core/statements/DefaultTriggerProvider.java b/common/buildcraft/core/statements/DefaultTriggerProvider.java index 8d581f3a..d1640eda 100644 --- a/common/buildcraft/core/statements/DefaultTriggerProvider.java +++ b/common/buildcraft/core/statements/DefaultTriggerProvider.java @@ -15,7 +15,10 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import cofh.api.energy.IEnergyConnection; import cofh.api.energy.IEnergyHandler; +import cofh.api.energy.IEnergyProvider; +import cofh.api.energy.IEnergyReceiver; import buildcraft.BuildCraftCore; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.ITriggerExternal; @@ -57,9 +60,13 @@ public class DefaultTriggerProvider implements ITriggerProvider { res.add(BuildCraftCore.triggerMachineInactive); } - if (tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(side.getOpposite()) > 0) { - res.add((ITriggerExternal) BuildCraftCore.triggerEnergyHigh); - res.add((ITriggerExternal) BuildCraftCore.triggerEnergyLow); + if (tile instanceof IEnergyConnection && ((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())) { + if ((tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(side.getOpposite()) > 0) + || (tile instanceof IEnergyReceiver && ((IEnergyReceiver) tile).getMaxEnergyStored(side.getOpposite()) > 0) + || (tile instanceof IEnergyProvider && ((IEnergyProvider) tile).getMaxEnergyStored(side.getOpposite()) > 0)) { + res.add((ITriggerExternal) BuildCraftCore.triggerEnergyHigh); + res.add((ITriggerExternal) BuildCraftCore.triggerEnergyLow); + } } return res; diff --git a/common/buildcraft/core/statements/TriggerEnergy.java b/common/buildcraft/core/statements/TriggerEnergy.java index 50d9f487..a4527679 100644 --- a/common/buildcraft/core/statements/TriggerEnergy.java +++ b/common/buildcraft/core/statements/TriggerEnergy.java @@ -13,7 +13,10 @@ import net.minecraft.tileentity.TileEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.common.util.ForgeDirection; +import cofh.api.energy.IEnergyConnection; import cofh.api.energy.IEnergyHandler; +import cofh.api.energy.IEnergyProvider; +import cofh.api.energy.IEnergyReceiver; import buildcraft.api.gates.IGate; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; @@ -36,13 +39,21 @@ public class TriggerEnergy extends BCStatement implements ITriggerInternal, ITri return StringUtils.localize("gate.trigger.machine.energyStored" + (high ? "High" : "Low")); } - private boolean isValidEnergyHandler(IEnergyHandler handler) { - return handler != null; - } + private boolean isTriggeredEnergyHandler(IEnergyConnection connection, ForgeDirection side) { + int energyStored, energyMaxStored; - private boolean isTriggeredEnergyHandler(IEnergyHandler handler, ForgeDirection side) { - int energyStored = handler.getEnergyStored(side); - int energyMaxStored = handler.getMaxEnergyStored(side); + if (connection instanceof IEnergyHandler) { + energyStored = ((IEnergyHandler) connection).getEnergyStored(side); + energyMaxStored = ((IEnergyHandler) connection).getMaxEnergyStored(side); + } else if (connection instanceof IEnergyProvider) { + energyStored = ((IEnergyProvider) connection).getEnergyStored(side); + energyMaxStored = ((IEnergyProvider) connection).getMaxEnergyStored(side); + } else if (connection instanceof IEnergyReceiver) { + energyStored = ((IEnergyReceiver) connection).getEnergyStored(side); + energyMaxStored = ((IEnergyReceiver) connection).getMaxEnergyStored(side); + } else { + return false; + } if (energyMaxStored > 0) { if (high) { @@ -58,9 +69,7 @@ public class TriggerEnergy extends BCStatement implements ITriggerInternal, ITri if (container instanceof IGate) { IGate gate = (IGate) container; if (gate.getPipe() instanceof IEnergyHandler) { - if (isValidEnergyHandler((IEnergyHandler) gate.getPipe())) { - return isTriggeredEnergyHandler((IEnergyHandler) gate.getPipe(), ForgeDirection.UNKNOWN); - } + return isTriggeredEnergyHandler((IEnergyHandler) gate.getPipe(), ForgeDirection.UNKNOWN); } } @@ -70,10 +79,10 @@ public class TriggerEnergy extends BCStatement implements ITriggerInternal, ITri @Override public boolean isTriggerActive(TileEntity tile, ForgeDirection side, IStatementContainer container, IStatementParameter[] parameters) { - if (tile instanceof IEnergyHandler) { - // Since we return false upon the trigger being invalid anyway, - // we can skip the isValidEnergyHandler(...) check. - return isTriggeredEnergyHandler((IEnergyHandler) tile, side.getOpposite()); + if (tile instanceof IEnergyHandler || tile instanceof IEnergyProvider || tile instanceof IEnergyReceiver) { + if (((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())) { + return isTriggeredEnergyHandler((IEnergyConnection) tile, side.getOpposite()); + } } return false; diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 97ca8233..fbc59c6e 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -17,6 +17,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import cofh.api.energy.IEnergyConnection; import cofh.api.energy.IEnergyHandler; +import cofh.api.energy.IEnergyReceiver; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftTransport; import buildcraft.api.core.SafeTimeTracker; @@ -99,7 +100,7 @@ public class PipeTransportPower extends PipeTransport { // Disregard engines for this. return false; } - if (tile instanceof IEnergyHandler) { + if (tile instanceof IEnergyHandler || tile instanceof IEnergyReceiver) { IEnergyConnection handler = (IEnergyConnection) tile; if (handler.canConnectEnergy(side.getOpposite())) { return true; @@ -230,6 +231,16 @@ public class PipeTransportPower extends PipeTransport { } else if (tiles[out] instanceof IEnergyHandler) { IEnergyHandler handler = (IEnergyHandler) tiles[out]; + if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite())) { + // Transmit power to an RF energy handler + + powerConsumed = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite(), + powerConsumed, false); + tilePowered = true; + } + } else if (tiles[out] instanceof IEnergyReceiver) { + IEnergyReceiver handler = (IEnergyReceiver) tiles[out]; + if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite())) { // Transmit power to an RF energy handler @@ -300,6 +311,15 @@ public class PipeTransportPower extends PipeTransport { if (handler.canConnectEnergy(dir.getOpposite())) { int request = handler.receiveEnergy(dir.getOpposite(), this.maxPower, true); + if (request > 0) { + requestEnergy(dir, request); + } + } + } else if (tile instanceof IEnergyReceiver) { + IEnergyReceiver handler = (IEnergyReceiver) tile; + if (handler.canConnectEnergy(dir.getOpposite())) { + int request = handler.receiveEnergy(dir.getOpposite(), this.maxPower, true); + if (request > 0) { requestEnergy(dir, request); }