#1156 Updated CoFH API

This commit is contained in:
CrazyPants committed 2014-10-27 13:05:41 +08:00
1 parent 73f9ab553f
commit e1a6ad9942
30 files changed
+998 -19

No files matched your search

@@ -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);
}
@@ -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<IChatComponent> info, boolean debug);
}
@@ -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 -&gt; client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
* are guaranteed to have it.
*
* @param energy
*/
@@ -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.
*
* <p>
* Note that {@link IEnergyHandler} is an extension of this.
*
* @author King Lemming
@@ -4,7 +4,7 @@ import net.minecraft.item.ItemStack;
/**
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
*
* <p>
* A reference implementation is provided {@link ItemEnergyContainer}.
*
* @author King Lemming
@@ -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.
*
* <p>
* 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);
}
@@ -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.
* <p>
* 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);
}
@@ -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.
* <p>
* 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);
}
@@ -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.<br>
* This is not to be implemented on TileEntities. This is for internal use only.
* <p>
* A reference implementation can be found at {@link EnergyStorage}.
*
* @author King Lemming
@@ -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) {
@@ -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<String> getAugmentTypes(ItemStack stack);
}
@@ -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);
}
@@ -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);
}
@@ -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();
}
@@ -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();
}
@@ -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();
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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<IChatComponent> info, ForgeDirection side, EntityPlayer player, boolean debug);
}
@@ -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;
@@ -0,0 +1,13 @@
package cofh.api.transport;
interface IEnderAttuned {
public String getChannelString();
public int getFrequency();
public boolean setFrequency(int frequency);
public boolean clearFrequency();
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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<String, Map<Integer, List<IEnderItemHandler>>> inputItem = new THashMap<String, Map<Integer, List<IEnderItemHandler>>>();
public static Map<String, Map<Integer, List<IEnderFluidHandler>>> inputFluid = new THashMap<String, Map<Integer, List<IEnderFluidHandler>>>();
public static Map<String, Map<Integer, List<IEnderEnergyHandler>>> inputEnergy = new THashMap<String, Map<Integer, List<IEnderEnergyHandler>>>();
public static Map<String, Map<Integer, List<IEnderItemHandler>>> outputItem = new THashMap<String, Map<Integer, List<IEnderItemHandler>>>();
public static Map<String, Map<Integer, List<IEnderFluidHandler>>> outputFluid = new THashMap<String, Map<Integer, List<IEnderFluidHandler>>>();
public static Map<String, Map<Integer, List<IEnderEnergyHandler>>> outputEnergy = new THashMap<String, Map<Integer, List<IEnderEnergyHandler>>>();
public static Configuration linkConf;
public static Map<String, String> clientFrequencyNames = new LinkedHashMap<String, String>();
public static Map<String, String> clientFrequencyNamesReversed = new LinkedHashMap<String, String>();
public static void clear() {
inputItem.clear();
inputFluid.clear();
inputEnergy.clear();
outputItem.clear();
outputFluid.clear();
outputEnergy.clear();
}
public static List<IEnderItemHandler> getLinkedItemInputs(IEnderItemHandler theAttuned) {
if (inputItem.get(theAttuned.getChannelString()) == null) {
return null;
}
return inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency());
}
public static List<IEnderItemHandler> getLinkedItemOutputs(IEnderItemHandler theAttuned) {
if (outputItem.get(theAttuned.getChannelString()) == null) {
return null;
}
return outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency());
}
public static List<IEnderFluidHandler> getLinkedFluidInputs(IEnderFluidHandler theAttuned) {
if (inputFluid.get(theAttuned.getChannelString()) == null) {
return null;
}
return inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency());
}
public static List<IEnderFluidHandler> getLinkedFluidOutputs(IEnderFluidHandler theAttuned) {
if (outputFluid.get(theAttuned.getChannelString()) == null) {
return null;
}
return outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency());
}
public static List<IEnderEnergyHandler> getLinkedEnergyInputs(IEnderEnergyHandler theAttuned) {
if (inputEnergy.get(theAttuned.getChannelString()) == null) {
return null;
}
return inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency());
}
public static List<IEnderEnergyHandler> 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<Integer, List<IEnderItemHandler>>());
}
if (inputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) {
inputItem.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList<IEnderItemHandler>());
}
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<Integer, List<IEnderItemHandler>>());
}
if (outputItem.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) {
outputItem.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList<IEnderItemHandler>());
}
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<Integer, List<IEnderFluidHandler>>());
}
if (inputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) {
inputFluid.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList<IEnderFluidHandler>());
}
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<Integer, List<IEnderFluidHandler>>());
}
if (outputFluid.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) {
outputFluid.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList<IEnderFluidHandler>());
}
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<Integer, List<IEnderEnergyHandler>>());
}
if (inputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) {
inputEnergy.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList<IEnderEnergyHandler>());
}
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<Integer, List<IEnderEnergyHandler>>());
}
if (outputEnergy.get(theAttuned.getChannelString()).get(theAttuned.getFrequency()) == null) {
outputEnergy.get(theAttuned.getChannelString()).put(theAttuned.getFrequency(), new ArrayList<IEnderEnergyHandler>());
}
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<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(clientFrequencyNames.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
@Override
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> 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<String, String> result = new LinkedHashMap<String, String>();
for (Map.Entry<String, String> 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);
}
}
}
@@ -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;