diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 2ab0ae01..a929bd09 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -4,8 +4,10 @@ Version 2.1.7 Changes - Added EnderRail +- #1145 Added RedNet support to insulated redstone conduits (fnuecke) - #1133 Update zh_CN.lang (Mrkwtkr) - #1138 Created cs_CZ.lang (nalimleinad) +- #1156 Updated CoFH API Bugs - Fixed Transceivers losing items when single player worlds reloaded without restarting MC diff --git a/src/main/java/cofh/api/block/IBlockDebug.java b/src/main/java/cofh/api/block/IBlockDebug.java new file mode 100644 index 00000000..091831c9 --- /dev/null +++ b/src/main/java/cofh/api/block/IBlockDebug.java @@ -0,0 +1,33 @@ +package cofh.api.block; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on blocks which have some debug method which can be activated via a tool or other means. + * + * @author King Lemming + * + */ +public interface IBlockDebug { + + /** + * This function debugs a block. + * + * @param world + * Reference to the world. + * @param x + * X coordinate of the block. + * @param y + * Y coordinate of the block. + * @param z + * Z coordinate of the block. + * @param side + * The side of the block. + * @param player + * Player doing the debugging. + */ + void debugBlock(IBlockAccess world, int x, int y, int z, ForgeDirection side, EntityPlayer player); + +} diff --git a/src/main/java/cofh/api/block/IBlockInfo.java b/src/main/java/cofh/api/block/IBlockInfo.java new file mode 100644 index 00000000..12d96f0b --- /dev/null +++ b/src/main/java/cofh/api/block/IBlockInfo.java @@ -0,0 +1,43 @@ +package cofh.api.block; + +import cofh.api.tileentity.ITileInfo; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on blocks which can provide information about themselves. If the block contains Tile Entities, then it is recommended that this + * function serve as a passthrough for {@link ITileInfo}. + * + * @author King Lemming + * + */ +public interface IBlockInfo { + + /** + * This function appends information to a list provided to it. + * + * @param world + * Reference to the world. + * @param x + * X coordinate of the block. + * @param y + * Y coordinate of the block. + * @param z + * Z coordinate of the block. + * @param side + * The side of the block that is being queried. + * @param player + * Player doing the querying - this can be NULL. + * @param info + * The list that the information should be appended to. + * @param debug + * If true, the block should return "debug" information. + */ + void getBlockInfo(IBlockAccess world, int x, int y, int z, ForgeDirection side, EntityPlayer player, List info, boolean debug); + +} diff --git a/src/main/java/cofh/api/energy/EnergyStorage.java b/src/main/java/cofh/api/energy/EnergyStorage.java index b3383aeb..1674c189 100644 --- a/src/main/java/cofh/api/energy/EnergyStorage.java +++ b/src/main/java/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/src/main/java/cofh/api/energy/IEnergyConnection.java b/src/main/java/cofh/api/energy/IEnergyConnection.java index 63faffb9..79bdf77a 100644 --- a/src/main/java/cofh/api/energy/IEnergyConnection.java +++ b/src/main/java/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/src/main/java/cofh/api/energy/IEnergyContainerItem.java b/src/main/java/cofh/api/energy/IEnergyContainerItem.java index 0bcfda60..c28455b1 100644 --- a/src/main/java/cofh/api/energy/IEnergyContainerItem.java +++ b/src/main/java/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/src/main/java/cofh/api/energy/IEnergyHandler.java b/src/main/java/cofh/api/energy/IEnergyHandler.java index 3df31234..22f2dbc6 100644 --- a/src/main/java/cofh/api/energy/IEnergyHandler.java +++ b/src/main/java/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/src/main/java/cofh/api/energy/IEnergyProvider.java b/src/main/java/cofh/api/energy/IEnergyProvider.java new file mode 100644 index 00000000..05287b35 --- /dev/null +++ b/src/main/java/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/src/main/java/cofh/api/energy/IEnergyReceiver.java b/src/main/java/cofh/api/energy/IEnergyReceiver.java new file mode 100644 index 00000000..c726e09e --- /dev/null +++ b/src/main/java/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/src/main/java/cofh/api/energy/IEnergyStorage.java b/src/main/java/cofh/api/energy/IEnergyStorage.java index 1e84bc22..bc206560 100644 --- a/src/main/java/cofh/api/energy/IEnergyStorage.java +++ b/src/main/java/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/src/main/java/cofh/api/energy/TileEnergyHandler.java b/src/main/java/cofh/api/energy/TileEnergyHandler.java index a7fabeb7..7cc655e9 100644 --- a/src/main/java/cofh/api/energy/TileEnergyHandler.java +++ b/src/main/java/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/src/main/java/cofh/api/item/IAugmentItem.java b/src/main/java/cofh/api/item/IAugmentItem.java new file mode 100644 index 00000000..497bace9 --- /dev/null +++ b/src/main/java/cofh/api/item/IAugmentItem.java @@ -0,0 +1,29 @@ +package cofh.api.item; + +import java.util.Set; + +import net.minecraft.item.ItemStack; + +public interface IAugmentItem { + + /** + * Get the augmentation level for a given Augment and Augment Type. + * + * @param stack + * ItemStack representing the Augment. + * @param type + * String containing the Augment type name. + * @return The Augment level of the stack for the requested type - 0 if it does not affect that attribute. + */ + int getAugmentLevel(ItemStack stack, String type); + + /** + * Get the Augment Types for a given Augment. Set ensure that there are no duplicates. + * + * @param stack + * ItemStack representing the Augment. + * @return Set of the Augmentation Types. Should return an empty set if there are none (but this would be really stupid to make). DO NOT RETURN NULL. + */ + Set getAugmentTypes(ItemStack stack); + +} diff --git a/src/main/java/cofh/api/item/IEmpowerableItem.java b/src/main/java/cofh/api/item/IEmpowerableItem.java new file mode 100644 index 00000000..f77c71f6 --- /dev/null +++ b/src/main/java/cofh/api/item/IEmpowerableItem.java @@ -0,0 +1,41 @@ +package cofh.api.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +/** + * Implement this interface on Item classes which may be "Empowered" - what that means is completely up to you. This just provides a uniform way of dealing with + * them. + * + * @author King Lemming + * + */ +public interface IEmpowerableItem { + + /** + * Check whether or not a given item is currently in an empowered state. + */ + boolean isEmpowered(ItemStack stack); + + /** + * Attempt to set the empowered state of the item. + * + * @param stack + * ItemStack to be empowered/disempowered. + * @param state + * Desired state. + * @return TRUE if the operation was successful, FALSE if it was not. + */ + boolean setEmpoweredState(ItemStack stack, boolean state); + + /** + * Callback method for reacting to a state change. Useful in KeyBinding handlers. + * + * @param player + * Player holding the item, if applicable. + * @param stack + * The item being held. + */ + void onStateChange(EntityPlayer player, ItemStack stack); + +} diff --git a/src/main/java/cofh/api/item/IInventoryContainerItem.java b/src/main/java/cofh/api/item/IInventoryContainerItem.java new file mode 100644 index 00000000..b87896cc --- /dev/null +++ b/src/main/java/cofh/api/item/IInventoryContainerItem.java @@ -0,0 +1,20 @@ +package cofh.api.item; + +import net.minecraft.item.ItemStack; + +/** + * Implement this interface on Item classes that are themselves inventories. + * + * A reference implementation is provided {@link ItemInventoryContainer}. + * + * @author King Lemming + * + */ +public interface IInventoryContainerItem { + + /** + * Get the size of this inventory of this container item. + */ + int getSizeInventory(ItemStack container); + +} diff --git a/src/main/java/cofh/api/tileentity/IAugmentable.java b/src/main/java/cofh/api/tileentity/IAugmentable.java new file mode 100644 index 00000000..735ade14 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IAugmentable.java @@ -0,0 +1,28 @@ +package cofh.api.tileentity; + +import net.minecraft.item.ItemStack; + +/** + * Implemented on objects which support Augments. + * + * @author King Lemming + * + */ +public interface IAugmentable { + + /** + * Attempt to reconfigure the tile based on the Augmentations present. + */ + void installAugments(); + + /** + * Returns an array of the Augment slots for this Tile Entity. + */ + ItemStack[] getAugmentSlots(); + + /** + * Returns a status array for the Augmentations installed in the Tile Entity. + */ + boolean[] getAugmentStatus(); + +} diff --git a/src/main/java/cofh/api/tileentity/IEnergyInfo.java b/src/main/java/cofh/api/tileentity/IEnergyInfo.java new file mode 100644 index 00000000..72d553b3 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IEnergyInfo.java @@ -0,0 +1,33 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on objects which can report information about their energy usage. + * + * This is used for reporting purposes - Energy transactions are handled through IEnergyHandler! + * + * @author King Lemming + * + */ +public interface IEnergyInfo { + + /** + * Returns energy usage/generation per tick (RF/t). + */ + int getInfoEnergyPerTick(); + + /** + * Returns maximum energy usage/generation per tick (RF/t). + */ + int getInfoMaxEnergyPerTick(); + + /** + * Returns energy stored (RF). + */ + int getInfoEnergyStored(); + + /** + * Returns maximum energy stored (RF). + */ + int getInfoMaxEnergyStored(); + +} diff --git a/src/main/java/cofh/api/tileentity/IPlacedTile.java b/src/main/java/cofh/api/tileentity/IPlacedTile.java new file mode 100644 index 00000000..df54a969 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IPlacedTile.java @@ -0,0 +1,13 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which need to know when they are placed into the world. + * + * @author Zeldo + * + */ +public interface IPlacedTile { + + public void tilePlaced(); + +} diff --git a/src/main/java/cofh/api/tileentity/IPortableData.java b/src/main/java/cofh/api/tileentity/IPortableData.java new file mode 100644 index 00000000..13134dbd --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IPortableData.java @@ -0,0 +1,33 @@ +package cofh.api.tileentity; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; + +/** + * Implement this interface on Tile Entities which can write a limited amount of data about themselves. + * + * This is typically for the purposes of being transferred to a similar tile entity. + * + * @author King Lemming + * + */ +public interface IPortableData { + + /** + * Data identifier of the Tile Entity/Block. Used for display as well as verification purposes. Tiles with completely interchangeable data should return the + * same type. + * + * @return + */ + String getDataType(); + + /** + * Read the data from a tag. The player object exists because this should always be called via player interaction! + */ + void readPortableData(EntityPlayer player, NBTTagCompound tag); + + /** + * Write the data to a tag. The player object exists because this should always be called via player interaction! + */ + void writePortableData(EntityPlayer player, NBTTagCompound tag); +} diff --git a/src/main/java/cofh/api/tileentity/IReconfigurableFacing.java b/src/main/java/cofh/api/tileentity/IReconfigurableFacing.java new file mode 100644 index 00000000..40efe7c3 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IReconfigurableFacing.java @@ -0,0 +1,39 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which allow for reconfiguration of their facing. + * + * Coordination with the containing block is required. + * + * @author King Lemming + * + */ +public interface IReconfigurableFacing { + + /** + * Returns the current facing of the block. + */ + int getFacing(); + + /** + * Returns whether or not the block's face can be aligned with the Y Axis. + */ + boolean allowYAxisFacing(); + + /** + * Attempt to rotate the block. Arbitrary based on implementation. + * + * @return True if rotation was successful, false otherwise. + */ + boolean rotateBlock(); + + /** + * Set the facing of the block. + * + * @param side + * The side to set the facing to. + * @return True if the facing was set, false otherwise. + */ + boolean setFacing(int side); + +} diff --git a/src/main/java/cofh/api/tileentity/IReconfigurableSides.java b/src/main/java/cofh/api/tileentity/IReconfigurableSides.java new file mode 100644 index 00000000..79c0f5bc --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IReconfigurableSides.java @@ -0,0 +1,54 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which allow for reconfiguration of their sides. + * + * Coordination with the containing block is required. + * + * @author King Lemming + * + */ +public interface IReconfigurableSides { + + /** + * Decrement the config for a given side. + * + * @param side + * The side to decrement. + * @return True if config was changed, false otherwise. + */ + boolean decrSide(int side); + + /** + * Increment the config for a given side. + * + * @param side + * The side to decrement. + * @return True if config was changed, false otherwise. + */ + boolean incrSide(int side); + + /** + * Set the config for a given side. + * + * @param side + * The side to set. + * @param config + * The config value to use. + * @return True of config was set, false otherwise. + */ + boolean setSide(int side, int config); + + /** + * Reset configs on all sides to their base values. + * + * @return True if reset was successful, false otherwise. + */ + boolean resetSides(); + + /** + * Returns the number of possible config settings for a given side. + */ + int getNumConfig(int side); + +} diff --git a/src/main/java/cofh/api/tileentity/ISecurable.java b/src/main/java/cofh/api/tileentity/ISecurable.java new file mode 100644 index 00000000..06018fa6 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ISecurable.java @@ -0,0 +1,56 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which can have access restrictions. + * + * @author King Lemming + * + */ +public interface ISecurable { + + /** + * Enum for Access Modes - Restricted is Friends Only, Private is Owner only. + * + * @author King Lemming + * + */ + public static enum AccessMode { + PUBLIC, RESTRICTED, PRIVATE; + + public boolean isPublic() { + + return this == PUBLIC; + } + + public boolean isRestricted() { + + return this == RESTRICTED; + } + + public boolean isPrivate() { + + return this == PRIVATE; + } + + public static AccessMode stepForward(AccessMode curAccess) { + + return curAccess == PUBLIC ? RESTRICTED : curAccess == PRIVATE ? PUBLIC : PRIVATE; + } + + public static AccessMode stepBackward(AccessMode curAccess) { + + return curAccess == PUBLIC ? PRIVATE : curAccess == PRIVATE ? RESTRICTED : PUBLIC; + } + } + + boolean setAccess(AccessMode access); + + boolean setOwnerName(String name); + + AccessMode getAccess(); + + String getOwnerName(); + + boolean canPlayerAccess(String name); + +} diff --git a/src/main/java/cofh/api/tileentity/ISidedTexture.java b/src/main/java/cofh/api/tileentity/ISidedTexture.java new file mode 100644 index 00000000..1d5884f4 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ISidedTexture.java @@ -0,0 +1,25 @@ +package cofh.api.tileentity; + +import net.minecraft.util.IIcon; + +/** + * Implement this interface on Tile Entities which can change their block's texture based on the current render pass. The block must defer the call to its Tile + * Entity. + * + * @author Zeldo Kavira + * + */ +public interface ISidedTexture { + + /** + * Returns the icon to use for a given side and render pass. + * + * @param side + * Block side to get the texture for. + * @param pass + * Render pass. + * @return The icon to use. + */ + IIcon getTexture(int side, int pass); + +} diff --git a/src/main/java/cofh/api/tileentity/ITileInfo.java b/src/main/java/cofh/api/tileentity/ITileInfo.java new file mode 100644 index 00000000..f040694a --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ITileInfo.java @@ -0,0 +1,31 @@ +package cofh.api.tileentity; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which can provide information about themselves. + * + * @author King Lemming + * + */ +public interface ITileInfo { + + /** + * This function appends information to a list provided to it. + * + * @param info + * The list that the information should be appended to. + * @param side + * The side of the block that is being queried. + * @param player + * Player doing the querying - this can be NULL. + * @param debug + * If true, the tile should return "debug" information. + */ + void getTileInfo(List info, ForgeDirection side, EntityPlayer player, boolean debug); + +} diff --git a/src/main/java/cofh/api/tileentity/package-info.java b/src/main/java/cofh/api/tileentity/package-info.java index f8396866..eae5967b 100644 --- a/src/main/java/cofh/api/tileentity/package-info.java +++ b/src/main/java/cofh/api/tileentity/package-info.java @@ -2,8 +2,9 @@ * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub * http://www.teamcofh.com */ -@API(apiVersion = "1.7.10R1.0.0", owner = "CoFHAPI", provides = "CoFHAPI|tileentity") +@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|tileentity") package cofh.api.tileentity; +import cofh.api.CoFHAPIProps; import cpw.mods.fml.common.API; diff --git a/src/main/java/cofh/api/transport/IEnderAttuned.java b/src/main/java/cofh/api/transport/IEnderAttuned.java new file mode 100644 index 00000000..4a453f52 --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderAttuned.java @@ -0,0 +1,13 @@ +package cofh.api.transport; + +interface IEnderAttuned { + + public String getChannelString(); + + public int getFrequency(); + + public boolean setFrequency(int frequency); + + public boolean clearFrequency(); + +} diff --git a/src/main/java/cofh/api/transport/IEnderEnergyHandler.java b/src/main/java/cofh/api/transport/IEnderEnergyHandler.java new file mode 100644 index 00000000..0886be76 --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderEnergyHandler.java @@ -0,0 +1,35 @@ +package cofh.api.transport; + +/** + * This interface is implemented on Ender Attuned objects which can receive Energy (Redstone Flux). + * + * @author King Lemming + * + */ +public interface IEnderEnergyHandler extends IEnderAttuned { + + /** + * Return whether or not the Ender Attuned object can currently send energy (Redstone Flux). + */ + boolean canSendEnergy(); + + /** + * This should be checked to see if the Ender Attuned object can currently receive energy (Redstone Flux). + * + * Note: In practice, this can (and should) be used to ensure that something does not send to itself. + */ + boolean canReceiveEnergy(); + + /** + * This tells the Ender Attuned object to receive energy. This returns the amount remaining, *not* the amount received - a return of 0 means that all energy + * was received! + * + * @param energy + * Amount of energy to be received. + * @param simulate + * If TRUE, the result will only be simulated. + * @return Amount of energy that is remaining (or would be remaining, if simulated). + */ + int receiveEnergy(int energy, boolean simulate); + +} diff --git a/src/main/java/cofh/api/transport/IEnderFluidHandler.java b/src/main/java/cofh/api/transport/IEnderFluidHandler.java new file mode 100644 index 00000000..3927fe1b --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderFluidHandler.java @@ -0,0 +1,37 @@ +package cofh.api.transport; + +import net.minecraftforge.fluids.FluidStack; + +/** + * This interface is implemented on Ender Attuned objects which can receive Fluid. + * + * @author King Lemming + * + */ +public interface IEnderFluidHandler extends IEnderAttuned { + + /** + * Return whether or not the Ender Attuned object can currently send FluidStacks. + */ + boolean canSendFluid(); + + /** + * This should be checked to see if the Ender Attuned object can currently receive a FluidStack. + * + * Note: In practice, this can (and should) be used to ensure that something does not send to itself. + */ + boolean canReceiveFluid(); + + /** + * This tells the Ender Attuned object to receive a FluidStack. This returns what remains of the original stack, *not* the amount received - a null return + * means that the entire stack was received! + * + * @param fluid + * FluidStack to be received. + * @param simulate + * If TRUE, the result will only be simulated. + * @return FluidStack representing how much fluid is remaining (or would be remaining, if simulated). + */ + FluidStack receiveFluid(FluidStack fluid, boolean simulate); + +} diff --git a/src/main/java/cofh/api/transport/IEnderItemHandler.java b/src/main/java/cofh/api/transport/IEnderItemHandler.java new file mode 100644 index 00000000..2944a001 --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderItemHandler.java @@ -0,0 +1,38 @@ +package cofh.api.transport; + +import net.minecraft.item.ItemStack; + +/** + * This interface is implemented on Ender Attuned objects which can receive Items. + * + * @author King Lemming + * + */ +public interface IEnderItemHandler extends IEnderAttuned { + + /** + * Return whether or not the Ender Attuned object can currently send ItemStacks. + */ + boolean canSendItems(); + + /** + * This should be checked to see if the Ender Attuned object can currently receive an ItemStack. + * + * Note: In practice, this can (and should) be used to ensure that something does not send to itself. + */ + boolean canReceiveItems(); + + /** + * This tells the Ender Attuned object to receive an ItemStack. This returns what remains of the original stack, *not* the amount received - a null return + * means that the entire stack was received! + * + * This function does not support simulation because Inventory manipulation in Minecraft is an absolute mess and it would be a computational liability to do + * so. + * + * @param item + * ItemStack to be received. + * @return An ItemStack representing how much is remaining. + */ + ItemStack receiveItem(ItemStack item); + +} diff --git a/src/main/java/cofh/api/transport/RegistryEnderAttuned.java b/src/main/java/cofh/api/transport/RegistryEnderAttuned.java new file mode 100644 index 00000000..0f91b215 --- /dev/null +++ b/src/main/java/cofh/api/transport/RegistryEnderAttuned.java @@ -0,0 +1,287 @@ +package cofh.api.transport; + +import gnu.trove.map.hash.THashMap; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.minecraftforge.common.config.Configuration; + +public final class RegistryEnderAttuned { + + public static Map>> inputItem = new THashMap>>(); + public static Map>> inputFluid = new THashMap>>(); + public static Map>> inputEnergy = new THashMap>>(); + + public static Map>> outputItem = new THashMap>>(); + public static Map>> outputFluid = new THashMap>>(); + public static Map>> outputEnergy = new THashMap>>(); + + public static Configuration linkConf; + + public static Map clientFrequencyNames = new LinkedHashMap(); + public static Map clientFrequencyNamesReversed = new LinkedHashMap(); + + public static void clear() { + + inputItem.clear(); + inputFluid.clear(); + inputEnergy.clear(); + outputItem.clear(); + outputFluid.clear(); + outputEnergy.clear(); + } + + public static List getLinkedItemInputs(IEnderItemHandler theAttuned) { + + if (inputItem.get(theAttuned.getChannelString()) == null) { + return null; + } + return inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); + } + + public static List getLinkedItemOutputs(IEnderItemHandler theAttuned) { + + if (outputItem.get(theAttuned.getChannelString()) == null) { + return null; + } + return outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); + } + + public static List getLinkedFluidInputs(IEnderFluidHandler theAttuned) { + + if (inputFluid.get(theAttuned.getChannelString()) == null) { + return null; + } + return inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); + } + + public static List getLinkedFluidOutputs(IEnderFluidHandler theAttuned) { + + if (outputFluid.get(theAttuned.getChannelString()) == null) { + return null; + } + return outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); + } + + public static List getLinkedEnergyInputs(IEnderEnergyHandler theAttuned) { + + if (inputEnergy.get(theAttuned.getChannelString()) == null) { + return null; + } + return inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); + } + + public static List getLinkedEnergyOutputs(IEnderEnergyHandler theAttuned) { + + if (outputEnergy.get(theAttuned.getChannelString()) == null) { + return null; + } + return outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()); + } + + /* HELPER FUNCTIONS */ + public static void addItemHandler(IEnderItemHandler theAttuned) { + + if (theAttuned.canSendItems()) { + if (inputItem.get(theAttuned.getChannelString()) == null) { + inputItem.put(theAttuned.getChannelString(), new HashMap>()); + } + if (inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) { + inputItem.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList()); + } + if (!inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).contains(theAttuned)) { + inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).add(theAttuned); + } + } + if (theAttuned.canReceiveItems()) { + if (outputItem.get(theAttuned.getChannelString()) == null) { + outputItem.put(theAttuned.getChannelString(), new HashMap>()); + } + if (outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) { + outputItem.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList()); + } + if (!outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).contains(theAttuned)) { + outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).add(theAttuned); + } + } + } + + public static void addFluidHandler(IEnderFluidHandler theAttuned) { + + if (theAttuned.canSendFluid()) { + if (inputFluid.get(theAttuned.getChannelString()) == null) { + inputFluid.put(theAttuned.getChannelString(), new HashMap>()); + } + if (inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) { + inputFluid.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList()); + } + if (!inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).contains(theAttuned)) { + inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).add(theAttuned); + } + } + if (theAttuned.canReceiveFluid()) { + if (outputFluid.get(theAttuned.getChannelString()) == null) { + outputFluid.put(theAttuned.getChannelString(), new HashMap>()); + } + if (outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) { + outputFluid.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList()); + } + if (!outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).contains(theAttuned)) { + outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).add(theAttuned); + } + } + } + + public static void addEnergyHandler(IEnderEnergyHandler theAttuned) { + + if (theAttuned.canSendEnergy()) { + if (inputEnergy.get(theAttuned.getChannelString()) == null) { + inputEnergy.put(theAttuned.getChannelString(), new HashMap>()); + } + if (inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) { + inputEnergy.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList()); + } + if (!inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).contains(theAttuned)) { + inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).add(theAttuned); + } + } + if (theAttuned.canReceiveEnergy()) { + if (outputEnergy.get(theAttuned.getChannelString()) == null) { + outputEnergy.put(theAttuned.getChannelString(), new HashMap>()); + } + if (outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) { + outputEnergy.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList()); + } + if (!outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).contains(theAttuned)) { + outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).add(theAttuned); + } + } + } + + public static void removeItemHandler(IEnderItemHandler theAttuned) { + + if (inputItem.get(theAttuned.getChannelString()) != null) { + if (inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) != null) { + inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).remove(theAttuned); + if (inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).size() == 0) { + inputItem.get(theAttuned.getChannelString()).remove(theAttuned.getFrequency()); + } + } + } + if (outputItem.get(theAttuned.getChannelString()) != null) { + if (outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) != null) { + outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).remove(theAttuned); + if (outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).size() == 0) { + outputItem.get(theAttuned.getChannelString()).remove(theAttuned.getFrequency()); + } + } + } + } + + public static void removeFluidHandler(IEnderFluidHandler theAttuned) { + + if (inputFluid.get(theAttuned.getChannelString()) != null) { + if (inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) != null) { + inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).remove(theAttuned); + if (inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).size() == 0) { + inputFluid.get(theAttuned.getChannelString()).remove(theAttuned.getFrequency()); + } + } + } + if (outputFluid.get(theAttuned.getChannelString()) != null) { + if (outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) != null) { + outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).remove(theAttuned); + if (outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).size() == 0) { + outputFluid.get(theAttuned.getChannelString()).remove(theAttuned.getFrequency()); + } + } + } + } + + public static void removeEnergyHandler(IEnderEnergyHandler theAttuned) { + + if (inputEnergy.get(theAttuned.getChannelString()) != null) { + if (inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) != null) { + inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).remove(theAttuned); + if (inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).size() == 0) { + inputEnergy.get(theAttuned.getChannelString()).remove(theAttuned.getFrequency()); + } + } + } + if (outputEnergy.get(theAttuned.getChannelString()) != null) { + if (outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) != null) { + outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).remove(theAttuned); + if (outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()).size() == 0) { + outputEnergy.get(theAttuned.getChannelString()).remove(theAttuned.getFrequency()); + } + } + } + } + + public static void add(IEnderAttuned theAttuned) { + + if (theAttuned instanceof IEnderItemHandler) { + addItemHandler((IEnderItemHandler) theAttuned); + } + if (theAttuned instanceof IEnderFluidHandler) { + addFluidHandler((IEnderFluidHandler) theAttuned); + } + if (theAttuned instanceof IEnderEnergyHandler) { + addEnergyHandler((IEnderEnergyHandler) theAttuned); + } + } + + public static void remove(IEnderAttuned theAttuned) { + + if (theAttuned instanceof IEnderItemHandler) { + removeItemHandler((IEnderItemHandler) theAttuned); + } + if (theAttuned instanceof IEnderFluidHandler) { + removeFluidHandler((IEnderFluidHandler) theAttuned); + } + if (theAttuned instanceof IEnderEnergyHandler) { + removeEnergyHandler((IEnderEnergyHandler) theAttuned); + } + } + + public static void sortClientNames() { + + List> list = new ArrayList>(clientFrequencyNames.entrySet()); + Collections.sort(list, new Comparator>() { + + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + + int int1 = Integer.valueOf(clientFrequencyNamesReversed.get(o1.getValue())); + int int2 = Integer.valueOf(clientFrequencyNamesReversed.get(o2.getValue())); + return int1 > int2 ? 1 : int1 == int2 ? 0 : -1; + } + }); + Map result = new LinkedHashMap(); + for (Map.Entry entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + clientFrequencyNames = result; + } + + public static void clearClientNames() { + + clientFrequencyNames.clear(); + clientFrequencyNamesReversed.clear(); + } + + public static void addClientNames(String owner, String name) { + + if (!owner.isEmpty()) { + clientFrequencyNames.put(owner, name); + clientFrequencyNamesReversed.put(name, owner); + } + } + +} diff --git a/src/main/java/cofh/api/transport/package-info.java b/src/main/java/cofh/api/transport/package-info.java index 1f960da1..fae0150f 100644 --- a/src/main/java/cofh/api/transport/package-info.java +++ b/src/main/java/cofh/api/transport/package-info.java @@ -2,8 +2,9 @@ * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub * http://www.teamcofh.com */ -@API(apiVersion = "1.7.10R1.0.0", owner = "CoFHAPI", provides = "CoFHAPI|transport") +@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|transport") package cofh.api.transport; +import cofh.api.CoFHAPIProps; import cpw.mods.fml.common.API;