From c09be6f465f62b325076bce674233bf6ac875f7f Mon Sep 17 00:00:00 2001 From: asie Date: Tue, 9 Apr 2019 21:59:14 +0200 Subject: [PATCH] update energy API, Gradle wrapper version --- api/cofh/api/CoFHAPIProps.java | 2 +- api/cofh/api/energy/EnergyStorage.java | 8 +- api/cofh/api/energy/IEnergyConnection.java | 4 +- api/cofh/api/energy/IEnergyContainerItem.java | 8 +- api/cofh/api/energy/IEnergyHandler.java | 1 - api/cofh/api/energy/IEnergyStorage.java | 8 +- api/cofh/api/energy/IEnergyTransport.java | 109 ++++++++++++++++++ api/cofh/api/energy/ItemEnergyContainer.java | 4 +- api/cofh/api/energy/package-info.java | 5 +- api/cofh/api/package-info.java | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 11 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 api/cofh/api/energy/IEnergyTransport.java diff --git a/api/cofh/api/CoFHAPIProps.java b/api/cofh/api/CoFHAPIProps.java index 9b528304..5d21f636 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.2"; + public static final String VERSION = "1.7.10R1.3.1"; } diff --git a/api/cofh/api/energy/EnergyStorage.java b/api/cofh/api/energy/EnergyStorage.java index 1674c189..25e0126a 100644 --- a/api/cofh/api/energy/EnergyStorage.java +++ b/api/cofh/api/energy/EnergyStorage.java @@ -4,9 +4,9 @@ import net.minecraft.nbt.NBTTagCompound; /** * Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. - * + * * @author King Lemming - * + * */ public class EnergyStorage implements IEnergyStorage { @@ -89,7 +89,7 @@ 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. - * + * * @param energy */ public void setEnergyStored(int energy) { @@ -106,7 +106,7 @@ public class EnergyStorage implements IEnergyStorage { /** * This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this * externally, as not all IEnergyHandlers are guaranteed to have it. - * + * * @param energy */ public void modifyEnergyStored(int energy) { diff --git a/api/cofh/api/energy/IEnergyConnection.java b/api/cofh/api/energy/IEnergyConnection.java index 79bdf77a..301271e5 100644 --- a/api/cofh/api/energy/IEnergyConnection.java +++ b/api/cofh/api/energy/IEnergyConnection.java @@ -7,9 +7,9 @@ import net.minecraftforge.common.util.ForgeDirection; * accept it; otherwise just use IEnergyHandler. *

* Note that {@link IEnergyHandler} is an extension of this. - * + * * @author King Lemming - * + * */ public interface IEnergyConnection { diff --git a/api/cofh/api/energy/IEnergyContainerItem.java b/api/cofh/api/energy/IEnergyContainerItem.java index c28455b1..3ef72576 100644 --- a/api/cofh/api/energy/IEnergyContainerItem.java +++ b/api/cofh/api/energy/IEnergyContainerItem.java @@ -6,15 +6,15 @@ 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 - * + * */ public interface IEnergyContainerItem { /** * Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. - * + * * @param container * ItemStack to be charged. * @param maxReceive @@ -28,7 +28,7 @@ public interface IEnergyContainerItem { /** * Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally * discharged. - * + * * @param container * ItemStack to be discharged. * @param maxExtract diff --git a/api/cofh/api/energy/IEnergyHandler.java b/api/cofh/api/energy/IEnergyHandler.java index 22f2dbc6..6a4600a4 100644 --- a/api/cofh/api/energy/IEnergyHandler.java +++ b/api/cofh/api/energy/IEnergyHandler.java @@ -42,7 +42,6 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver { @Override int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); - /** * Returns the amount of energy currently stored. */ diff --git a/api/cofh/api/energy/IEnergyStorage.java b/api/cofh/api/energy/IEnergyStorage.java index bc206560..414b2656 100644 --- a/api/cofh/api/energy/IEnergyStorage.java +++ b/api/cofh/api/energy/IEnergyStorage.java @@ -5,15 +5,15 @@ package cofh.api.energy; * 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 - * + * */ public interface IEnergyStorage { /** * Adds energy to the storage. Returns quantity of energy that was accepted. - * + * * @param maxReceive * Maximum amount of energy to be inserted. * @param simulate @@ -24,7 +24,7 @@ public interface IEnergyStorage { /** * Removes energy from the storage. Returns quantity of energy that was removed. - * + * * @param maxExtract * Maximum amount of energy to be extracted. * @param simulate diff --git a/api/cofh/api/energy/IEnergyTransport.java b/api/cofh/api/energy/IEnergyTransport.java new file mode 100644 index 00000000..ab45e04f --- /dev/null +++ b/api/cofh/api/energy/IEnergyTransport.java @@ -0,0 +1,109 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which transport energy. + *

+ * This is used to "negotiate" connection types between two separate IEnergyTransports, allowing users to set flow direction and allowing for networks Of + * IEnergyTransports to intelligently transfer energy to other networks. + */ +public interface IEnergyTransport extends IEnergyProvider, IEnergyReceiver { + + /** + * The type of interface for a given side of a {@link IEnergyTransport}. + *

+ * Values are:
+ * {@link SEND} for sending only
+ * {@link RECEIVE} for receiving only
+ * {@link BALANCE} for sending and receiving, and the default state + */ + public enum InterfaceType { + /** + * Indicates that this {@link IEnergyTransport} is only sending power on this side. + */ + SEND, + /** + * Indicates that this {@link IEnergyTransport} is only receiving power on this side. + */ + RECEIVE, + /** + * Indicates that this {@link IEnergyTransport} wants to balance power between itself and the + * senders/receivers on this side. This is the default state.
+ * To block any connection, use {@link IEnergyConnection#canConnectEnergy} + *

+ * IEnergyTransport based senders should check that the total power in the destination IEnergyTransport is less than the power in themselves before sending. + *
+ * Active IEnergyTransport receivers (i.e., those that call {@link IEnergyProvider#extractEnergy}) should check that they contain less power than the + * source IEnergyTransport. + */ + BALANCE; + + /** + * Returns the opposite state to this InterfaceType. + *

+ * {@link #BALANCE} is considered its own opposite.
+ * {@link #SEND} is the opposite of {@link #RECEIVE} and visa versa. + */ + public InterfaceType getOpposite() { + + return this == BALANCE ? BALANCE : this == SEND ? RECEIVE : SEND; + } + + /** + * Returns the next InterfaceType as described in {@link IEnergyTransport#getTransportState} + */ + public InterfaceType rotate() { + + return rotate(true); + } + + /** + * Returns the next InterfaceType as described in {@link IEnergyTransport#getTransportState} + * + * @param forward + * Whether to step in the order specified by {@link IEnergyTransport#getTransportState} (true) or to step in the opposite direction + */ + public InterfaceType rotate(boolean forward) { + + if (forward) { + return this == BALANCE ? RECEIVE : this == RECEIVE ? SEND : BALANCE; + } else { + return this == BALANCE ? SEND : this == SEND ? RECEIVE : BALANCE; + } + } + } + + /** + * {@inheritDoc}
+ * This method cannot be a no-op for IEnergyTransport. + */ + @Override + int getEnergyStored(ForgeDirection from); + + /** + * Indicates to other IEnergyTransports the state of the given side. See {@link #InterfaceType} for details. + *

+ * For clarity of state tracking, on a tile update from another IEnergyTransport, if its mode has changed from the opposite of your own mode on that side, you + * should change your mode to the opposite of its mode. + *

+ * When the user alters your mode and your state is:
+ * BALANCE, your mode should change to {@link InterFaceType#RECEIVE}.
+ * RECEIVE, your mode should change to {@link InterFaceType#SEND}.
+ * SEND, your mode should change to {@link InterFaceType#BALANCE}.
+ * This is not required, but will be easier for users. + * + * @return The type of connection to establish on this side. null is NOT a valid value + */ + InterfaceType getTransportState(ForgeDirection from); + + /** + * This method is provided primarily for the purposes of automation tools, and should not need to be called by another IEnergyTransport. + *

+ * Calls to this method may fail if this IEnergyTransport has been secured by a user. + * + * @return Whether or not state was successfully altered. + */ + boolean setTransportState(InterfaceType state, ForgeDirection from); + +} diff --git a/api/cofh/api/energy/ItemEnergyContainer.java b/api/cofh/api/energy/ItemEnergyContainer.java index 055ae45b..2d3659cb 100644 --- a/api/cofh/api/energy/ItemEnergyContainer.java +++ b/api/cofh/api/energy/ItemEnergyContainer.java @@ -6,9 +6,9 @@ import net.minecraft.nbt.NBTTagCompound; /** * Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own. - * + * * @author King Lemming - * + * */ public class ItemEnergyContainer extends Item implements IEnergyContainerItem { diff --git a/api/cofh/api/energy/package-info.java b/api/cofh/api/energy/package-info.java index b31e5249..7379702b 100644 --- a/api/cofh/api/energy/package-info.java +++ b/api/cofh/api/energy/package-info.java @@ -1,11 +1,10 @@ /** - * (C) 2015 Team CoFH / CoFH / Cult of the Full Hub + * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub * http://www.teamcofh.com */ @API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy") package cofh.api.energy; +import cofh.api.CoFHAPIProps; import cpw.mods.fml.common.API; -import cofh.api.CoFHAPIProps; - diff --git a/api/cofh/api/package-info.java b/api/cofh/api/package-info.java index e811c33f..08ff5fcb 100644 --- a/api/cofh/api/package-info.java +++ b/api/cofh/api/package-info.java @@ -1,5 +1,5 @@ /** - * (C) 2015 Team CoFH / CoFH / Cult of the Full Hub + * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub * http://www.teamcofh.com */ @API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5cec17b9..4fd89293 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip