diff --git a/src/main/java/cofh/api/block/IBlockDebug.java b/src/main/java/cofh/api/block/IBlockDebug.java index 9805f7f06..03254b2ed 100644 --- a/src/main/java/cofh/api/block/IBlockDebug.java +++ b/src/main/java/cofh/api/block/IBlockDebug.java @@ -1,11 +1,14 @@ package cofh.api.block; +import cofh.api.tileentity.ITileDebug; + 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. + * Implement this interface on blocks which have some debug method which can be activated via a tool or other means. If the block contains Tile Entities, then + * it is recommended that this function serve as a passthrough for {@link ITileDebug}. * * @author King Lemming * @@ -28,6 +31,6 @@ public interface IBlockDebug { * @param player * Player doing the debugging. */ - public void debugBlock(IBlockAccess world, int x, int y, int z, ForgeDirection side, EntityPlayer player); + 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 index 8b263533c..0c102f552 100644 --- a/src/main/java/cofh/api/block/IBlockInfo.java +++ b/src/main/java/cofh/api/block/IBlockInfo.java @@ -1,5 +1,7 @@ package cofh.api.block; +import cofh.api.tileentity.ITileInfo; + import java.util.List; import net.minecraft.entity.player.EntityPlayer; @@ -7,7 +9,8 @@ import net.minecraft.world.IBlockAccess; import net.minecraftforge.common.util.ForgeDirection; /** - * Implement this interface on blocks which can provide information about themselves. + * 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 * @@ -32,8 +35,8 @@ public interface IBlockInfo { * @param info * The list that the information should be appended to. * @param debug - * If true, the Block should return "debug" information. + * If true, the block should return "debug" information. */ - public void getBlockInfo(IBlockAccess world, int x, int y, int z, ForgeDirection side, EntityPlayer player, List info, boolean debug); + 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/block/IDismantleable.java b/src/main/java/cofh/api/block/IDismantleable.java index fd7943782..70f888a44 100644 --- a/src/main/java/cofh/api/block/IDismantleable.java +++ b/src/main/java/cofh/api/block/IDismantleable.java @@ -15,11 +15,11 @@ public interface IDismantleable { /** * Dismantles the block. If returnBlock is true, the drop(s) should be placed into the player's inventory. */ - public ItemStack dismantleBlock(EntityPlayer player, World world, int x, int y, int z, boolean returnBlock); + ItemStack dismantleBlock(EntityPlayer player, World world, int x, int y, int z, boolean returnBlock); /** * Return true if the block can be dismantled. The criteria for this is entirely up to the block. */ - public boolean canDismantle(EntityPlayer player, World world, int x, int y, int z); + boolean canDismantle(EntityPlayer player, World world, int x, int y, int z); } diff --git a/src/main/java/cofh/api/core/IInitializer.java b/src/main/java/cofh/api/core/IInitializer.java new file mode 100644 index 000000000..87b64b02a --- /dev/null +++ b/src/main/java/cofh/api/core/IInitializer.java @@ -0,0 +1,17 @@ +package cofh.api.core; + +/** + * Interface which can be put on just about anything to allow for iteration during initialization. + * + * @author King Lemming + * + */ +public interface IInitializer { + + boolean preInit(); + + boolean initialize(); + + boolean postInit(); + +} diff --git a/src/main/java/cofh/api/energy/IEnergyConnection.java b/src/main/java/cofh/api/energy/IEnergyConnection.java new file mode 100644 index 000000000..63faffb9f --- /dev/null +++ b/src/main/java/cofh/api/energy/IEnergyConnection.java @@ -0,0 +1,21 @@ +package cofh.api.energy; + +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 + * + */ +public interface IEnergyConnection { + + /** + * Returns TRUE if the TileEntity can connect on a given side. + */ + boolean canConnectEnergy(ForgeDirection from); + +} diff --git a/src/main/java/cofh/api/energy/IEnergyHandler.java b/src/main/java/cofh/api/energy/IEnergyHandler.java index ec6236fe3..3df312346 100644 --- a/src/main/java/cofh/api/energy/IEnergyHandler.java +++ b/src/main/java/cofh/api/energy/IEnergyHandler.java @@ -3,14 +3,14 @@ package cofh.api.energy; import net.minecraftforge.common.util.ForgeDirection; /** - * Implement this interface on TileEntities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + * 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 { +public interface IEnergyHandler extends IEnergyConnection { /** * Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. @@ -38,11 +38,6 @@ public interface IEnergyHandler { */ int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); - /** - * Returns true if the Handler functions on a given side - if a Tile Entity can receive or send energy on a given side, this should return true. - */ - boolean canInterface(ForgeDirection from); - /** * Returns the amount of energy currently stored. */ diff --git a/src/main/java/cofh/api/energy/ItemEnergyContainer.java b/src/main/java/cofh/api/energy/ItemEnergyContainer.java new file mode 100644 index 000000000..055ae45bc --- /dev/null +++ b/src/main/java/cofh/api/energy/ItemEnergyContainer.java @@ -0,0 +1,110 @@ +package cofh.api.energy; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +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 { + + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public ItemEnergyContainer() { + + } + + public ItemEnergyContainer(int capacity) { + + this(capacity, capacity, capacity); + } + + public ItemEnergyContainer(int capacity, int maxTransfer) { + + this(capacity, maxTransfer, maxTransfer); + } + + public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) { + + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } + + public ItemEnergyContainer setCapacity(int capacity) { + + this.capacity = capacity; + return this; + } + + public void setMaxTransfer(int maxTransfer) { + + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + } + + public void setMaxReceive(int maxReceive) { + + this.maxReceive = maxReceive; + } + + public void setMaxExtract(int maxExtract) { + + this.maxExtract = maxExtract; + } + + /* IEnergyContainerItem */ + @Override + public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { + + if (container.stackTagCompound == null) { + container.stackTagCompound = new NBTTagCompound(); + } + int energy = container.stackTagCompound.getInteger("Energy"); + int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + + if (!simulate) { + energy += energyReceived; + container.stackTagCompound.setInteger("Energy", energy); + } + return energyReceived; + } + + @Override + public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { + + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) { + return 0; + } + int energy = container.stackTagCompound.getInteger("Energy"); + int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + + if (!simulate) { + energy -= energyExtracted; + container.stackTagCompound.setInteger("Energy", energy); + } + return energyExtracted; + } + + @Override + public int getEnergyStored(ItemStack container) { + + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) { + return 0; + } + return container.stackTagCompound.getInteger("Energy"); + } + + @Override + public int getMaxEnergyStored(ItemStack container) { + + return capacity; + } + +} diff --git a/src/main/java/cofh/api/energy/TileEnergyHandler.java b/src/main/java/cofh/api/energy/TileEnergyHandler.java index c2d021613..a7fabeb77 100644 --- a/src/main/java/cofh/api/energy/TileEnergyHandler.java +++ b/src/main/java/cofh/api/energy/TileEnergyHandler.java @@ -29,6 +29,12 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler { } /* IEnergyHandler */ + @Override + public boolean canConnectEnergy(ForgeDirection from) { + + return true; + } + @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { @@ -41,12 +47,6 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler { return storage.extractEnergy(maxExtract, simulate); } - @Override - public boolean canInterface(ForgeDirection from) { - - return true; - } - @Override public int getEnergyStored(ForgeDirection from) { 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 000000000..f77c71f6a --- /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/IInventoryConnection.java b/src/main/java/cofh/api/item/IInventoryConnection.java new file mode 100644 index 000000000..d0ad117b3 --- /dev/null +++ b/src/main/java/cofh/api/item/IInventoryConnection.java @@ -0,0 +1,20 @@ +package cofh.api.item; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on TileEntities which should connect to item transportation blocks. + * + * Note that {@link IInventoryHandler} is an extension of this. + * + * @author King Lemming + * + */ +public interface IInventoryConnection { + + /** + * Returns TRUE if the TileEntity can connect on a given side. + */ + boolean canConnectInventory(ForgeDirection from); + +} 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 000000000..91c051083 --- /dev/null +++ b/src/main/java/cofh/api/item/IInventoryContainerItem.java @@ -0,0 +1,78 @@ +package cofh.api.item; + +import java.util.List; + +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 { + + /** + * Add an ItemStack to the inventory of this container item. This returns what is remaining of the original stack - a null return means that the entire + * stack was accepted! + * + * @param container + * ItemStack with the inventory. + * @param item + * ItemStack to be inserted. The size of this stack corresponds to the maximum amount to insert. + * @param simulate + * If TRUE, the insertion will only be simulated. + * @return An ItemStack representing how much is remaining after the item was inserted (or would have been, if simulated) into the container inventory. + */ + ItemStack insertItem(ItemStack container, ItemStack item, boolean simulate); + + /** + * Extract an ItemStack from the inventory of this container item. This returns the resulting stack - a null return means that nothing was extracted! + * + * @param container + * ItemStack with the inventory. + * @param item + * ItemStack to be extracted. The size of this stack corresponds to the maximum amount to extract. If this is null, then a null ItemStack should + * immediately be returned. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return An ItemStack representing how much was extracted (or would have been, if simulated) from the container inventory. + */ + ItemStack extractItem(ItemStack container, ItemStack item, boolean simulate); + + /** + * Extract an ItemStack from the inventory of this container item. This returns the resulting stack - a null return means that nothing was extracted! + * + * @param container + * ItemStack with the inventory. + * @param maxExtract + * Maximum number of items to extract. (The returned ItemStack should have a stackSize no higher than this.) + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return An ItemStack representing how much was extracted (or would have been, if simulated) from the container inventory. + */ + ItemStack extractItem(ItemStack container, int maxExtract, boolean simulate); + + /** + * Get the contents of the container item's inventory. This should only return non-null ItemStacks, and an empty List if the inventory has nothing. + */ + List getInventoryContents(ItemStack container); + + /** + * Get the size of this inventory of this container item. + */ + int getSizeInventory(ItemStack container); + + /** + * Returns whether or not the container item's inventory is empty. + */ + boolean isEmpty(ItemStack container); + + /** + * Returns whether or not the container item's inventory is full. + */ + boolean isFull(ItemStack container); + +} diff --git a/src/main/java/cofh/api/item/IInventoryHandler.java b/src/main/java/cofh/api/item/IInventoryHandler.java new file mode 100644 index 000000000..4340e5f36 --- /dev/null +++ b/src/main/java/cofh/api/item/IInventoryHandler.java @@ -0,0 +1,82 @@ +package cofh.api.item; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on TileEntities which should handle items. + * + * A reference implementation is provided {@link TileInventoryHandler}. + * + * @author King Lemming + * + */ +public interface IInventoryHandler extends IInventoryConnection { + + /** + * Insert an ItemStack into the IInventoryHandler, internal distribution is left entirely to the IInventoryHandler. This returns what is remaining of the + * original stack - a null return means that the entire stack was accepted! + * + * @param from + * Orientation the item is inserted from. + * @param item + * ItemStack to be inserted. The size of this stack corresponds to the maximum amount to insert. + * @param simulate + * If TRUE, the insertion will only be simulated. + * @return An ItemStack representing how much is remaining after the item was inserted (or would have been, if simulated) into the container inventory. + */ + ItemStack insertItem(ForgeDirection from, ItemStack item, boolean simulate); + + /** + * Extract an ItemStack from an IInventoryHandler, internal distribution is left entirely to the IInventoryHandler. This returns the resulting stack - a + * null return means that nothing was extracted! + * + * @param from + * Orientation the item is extracted from. + * @param item + * ItemStack to be extracted. The size of this stack corresponds to the maximum amount to extract. If this is null, then a null ItemStack should + * immediately be returned. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return An ItemStack representing how much was extracted (or would have been, if simulated) from the container inventory. + */ + ItemStack extractItem(ForgeDirection from, ItemStack item, boolean simulate); + + /** + * Extract an ItemStack from an IInventoryHandler, internal distribution is left entirely to the IInventoryHandler. This returns the resulting stack - a + * null return means that nothing was extracted! + * + * @param from + * Orientation the item is extracted from. + * @param maxExtract + * Maximum number of items to extract. (The returned ItemStack should have a stackSize no higher than this.) + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return An ItemStack representing how much was extracted (or would have been, if simulated) from the container inventory. + */ + ItemStack extractItem(ForgeDirection from, int maxExtract, boolean simulate); + + /** + * Get the contents of the IInventoryHandler's inventory. This returns a COPY. This should only return non-null ItemStacks, and an empty List if the + * inventory has nothing. + */ + List getInventoryContents(ForgeDirection from); + + /** + * Get the size (number of internal slots) of the IInventoryHandler's inventory. + */ + int getSizeInventory(ForgeDirection from); + + /** + * Returns whether or not the IInventoryHandler's inventory is empty (for a given side). + */ + boolean isEmpty(ForgeDirection from); + + /** + * Returns whether or not the IInventoryHandler's inventory is full (for a given side). + */ + boolean isFull(ForgeDirection from); + +} diff --git a/src/main/java/cofh/api/item/ISecureItem.java b/src/main/java/cofh/api/item/ISecureItem.java new file mode 100644 index 000000000..6e4731afb --- /dev/null +++ b/src/main/java/cofh/api/item/ISecureItem.java @@ -0,0 +1,26 @@ +package cofh.api.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +/** + * Implement this interface on Item classes which are Secure - linked to a specific player or group of players. + * + * Obviously, this relies on people using this interface properly. The Wheaton Rule is in effect here - don't be a jerk. + * + * @author King Lemming + * + */ +public interface ISecureItem { + + /** + * Check whether or not a given player can use this item. + */ + boolean canPlayerAccess(ItemStack stack, EntityPlayer player); + + /** + * Get the Owner of this item. This function is intentionally nebulous and is not guaranteed to be a player name. + */ + String getOwnerString(); + +} diff --git a/src/main/java/cofh/api/item/ITinkerableItem.java b/src/main/java/cofh/api/item/ITinkerableItem.java new file mode 100644 index 000000000..cb1185daf --- /dev/null +++ b/src/main/java/cofh/api/item/ITinkerableItem.java @@ -0,0 +1,33 @@ +package cofh.api.item; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +/** + * Implement this interface on Item classes which can be externally modified through tinkering. + * + * Basically a catch all for "upgrading" a given ItemStack, which may represent an Item or a Block. + * + * @author King Lemming + * + */ +public interface ITinkerableItem { + + /** + * Returns a list of valid ItemStacks which may be used to upgrade this Tinkerable. + */ + List getValidTinkers(ItemStack container); + + /** + * Applies a tinker to this item. + * + * @param container + * The ItemStack (Tinkerable) to which the tinker is being applied. + * @param tinker + * The ItemStack representing the upgrade. + * @return True if the application was successful, false if it was not. + */ + boolean applyTinker(ItemStack container, ItemStack tinker); + +} diff --git a/src/main/java/cofh/api/tileentity/IAugmentableTile.java b/src/main/java/cofh/api/tileentity/IAugmentableTile.java new file mode 100644 index 000000000..8e4431de4 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IAugmentableTile.java @@ -0,0 +1,28 @@ +package cofh.api.tileentity; + +import net.minecraft.item.ItemStack; + +/** + * Implemented on TileEntities which support Augments. + * + * @author King Lemming + * + */ +public interface IAugmentableTile { + + /** + * Attempt to reconfigure the tile based on the Augmentations present. Return TRUE if it was successful; FALSE if a condition was not met. + */ + boolean augmentTile(); + + /** + * 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 000000000..9648de39b --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IEnergyInfo.java @@ -0,0 +1,33 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities 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/IReconfigurableFacing.java b/src/main/java/cofh/api/tileentity/IReconfigurableFacing.java new file mode 100644 index 000000000..40efe7c35 --- /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 000000000..79c0f5bcc --- /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/IRedstoneCache.java b/src/main/java/cofh/api/tileentity/IRedstoneCache.java new file mode 100644 index 000000000..f1254d8dc --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IRedstoneCache.java @@ -0,0 +1,17 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which cache their redstone status. + * + * Note that {@link IRedstoneControl} is an extension of this. + * + * @author King Lemming + * + */ +public interface IRedstoneCache { + + void setPowered(boolean isPowered); + + boolean isPowered(); + +} diff --git a/src/main/java/cofh/api/tileentity/IRedstoneControl.java b/src/main/java/cofh/api/tileentity/IRedstoneControl.java new file mode 100644 index 000000000..11060325d --- /dev/null +++ b/src/main/java/cofh/api/tileentity/IRedstoneControl.java @@ -0,0 +1,57 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which have Redstone Control functionality. This means that a tile can be set to ignore redstone entirely, or + * respond to a low or high redstone state. + * + * @author King Lemming + * + */ +public interface IRedstoneControl extends IRedstoneCache { + + public static enum ControlMode { + DISABLED(true), LOW(false), HIGH(true); + + private final boolean state; + + private ControlMode(boolean state) { + + this.state = state; + } + + public boolean isDisabled() { + + return this == DISABLED; + } + + public boolean isLow() { + + return this == LOW; + } + + public boolean isHigh() { + + return this == HIGH; + } + + public boolean getState() { + + return state; + } + + public static ControlMode stepForward(ControlMode curControl) { + + return curControl == DISABLED ? LOW : curControl == HIGH ? DISABLED : HIGH; + } + + public static ControlMode stepBackward(ControlMode curControl) { + + return curControl == DISABLED ? HIGH : curControl == HIGH ? LOW : DISABLED; + } + } + + void setControl(ControlMode control); + + ControlMode getControl(); + +} diff --git a/src/main/java/cofh/api/tileentity/ISecureTile.java b/src/main/java/cofh/api/tileentity/ISecureTile.java new file mode 100644 index 000000000..4d4c4d260 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ISecureTile.java @@ -0,0 +1,56 @@ +package cofh.api.tileentity; + +/** + * Implement this interface on Tile Entities which have access restrictions. + * + * @author King Lemming + * + */ +public interface ISecureTile { + + /** + * 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 000000000..1d5884f4a --- /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/ITileDebug.java b/src/main/java/cofh/api/tileentity/ITileDebug.java new file mode 100644 index 000000000..62faa22c4 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ITileDebug.java @@ -0,0 +1,27 @@ +package cofh.api.tileentity; + +import cofh.api.block.IBlockDebug; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which can be debugged via some in-game method, such as a tool. The containing block should be an instance of + * {@link IBlockDebug} and defer the call to the tile. + * + * @author King Lemming + * + */ +public interface ITileDebug { + + /** + * This function debugs a tile entity. + * + * @param side + * The side of the block. + * @param player + * Player doing the debugging. + */ + void debugTile(ForgeDirection side, EntityPlayer player); + +} 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 000000000..a0b4b8770 --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ITileInfo.java @@ -0,0 +1,33 @@ +package cofh.api.tileentity; + +import cofh.api.block.IBlockInfo; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which can provide information about themselves. The containing block should be an instance of {@link IBlockInfo} + * and defer the call to the tile. + * + * @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/transport/IEnderAttuned.java b/src/main/java/cofh/api/transport/IEnderAttuned.java index 60da71ea1..744943876 100644 --- a/src/main/java/cofh/api/transport/IEnderAttuned.java +++ b/src/main/java/cofh/api/transport/IEnderAttuned.java @@ -1,50 +1,13 @@ package cofh.api.transport; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; +interface IEnderAttuned { -public interface IEnderAttuned { + public String getOwnerString(); - public enum EnderTypes { - ITEM, FLUID, REDSTONE_FLUX - } - - String getOwnerString(); - - int getFrequency(); + public int getFrequency(); public boolean setFrequency(int frequency); public boolean clearFrequency(); - boolean canSendItems(); - - boolean canSendFluid(); - - boolean canSendEnergy(); - - boolean canReceiveItems(); - - boolean canReceiveFluid(); - - boolean canReceiveEnergy(); - - boolean currentlyValidToReceiveItems(IEnderAttuned asker); - - boolean currentlyValidToReceiveFluid(IEnderAttuned asker); - - boolean currentlyValidToReceiveEnergy(IEnderAttuned asker); - - boolean currentlyValidToSendItems(IEnderAttuned asker); - - boolean currentlyValidToSendFluid(IEnderAttuned asker); - - boolean currentlyValidToSendEnergy(IEnderAttuned asker); - - ItemStack receiveItem(ItemStack item); - - FluidStack receiveFluid(FluidStack fluid, boolean doFill); - - int receiveEnergy(int energy, boolean simulate); - } 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 000000000..0886be766 --- /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 000000000..3927fe1bc --- /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 000000000..2944a0016 --- /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/IItemConduit.java b/src/main/java/cofh/api/transport/IItemConduit.java deleted file mode 100644 index 7efc516b6..000000000 --- a/src/main/java/cofh/api/transport/IItemConduit.java +++ /dev/null @@ -1,32 +0,0 @@ -package cofh.api.transport; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -/** - * This interface is implemented on Item Conduits. Use it to attempt to eject items into an entry point. - * - * @author Zeldo Kavira, King Lemming - * - */ -public interface IItemConduit { - - /** - * Insert an ItemStack into the IItemConduit. Will only accept items if there is a valid destination. This returns what is remaining of the original stack - - * a null return means that the entire stack was accepted/routed! - * - * @param from - * Orientation the item is inserted from. - * @param item - * ItemStack to be inserted. The size of this stack corresponds to the maximum amount to insert. - * @return An ItemStack representing how much is remaining after the item was inserted (or would have been, if simulated) into the Conduit. - */ - public ItemStack insertItem(ForgeDirection from, ItemStack item); - - /* THE FOLLOWING WILL BE REMOVED IN 3.0.1.X */ - @Deprecated - public ItemStack insertItem(ForgeDirection from, ItemStack item, boolean simulate); - - @Deprecated - public ItemStack sendItems(ItemStack item, ForgeDirection from); -} diff --git a/src/main/java/cofh/api/transport/IItemDuct.java b/src/main/java/cofh/api/transport/IItemDuct.java new file mode 100644 index 000000000..4c50c8560 --- /dev/null +++ b/src/main/java/cofh/api/transport/IItemDuct.java @@ -0,0 +1,26 @@ +package cofh.api.transport; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * This interface is implemented on ItemDucts. Use it to attempt to eject items into an entry point. + * + * @author Zeldo Kavira, King Lemming + * + */ +public interface IItemDuct { + + /** + * Insert an ItemStack into the IItemDuct. Will only accept items if there is a valid destination. This returns what is remaining of the original stack - a + * null return means that the entire stack was accepted/routed! + * + * @param from + * Orientation the item is inserted from. + * @param item + * ItemStack to be inserted. The size of this stack corresponds to the maximum amount to insert. + * @return An ItemStack representing how much is remaining after the item was inserted into the Duct. + */ + public ItemStack insertItem(ForgeDirection from, ItemStack item); + +} diff --git a/src/main/java/cofh/api/world/IFeatureGenerator.java b/src/main/java/cofh/api/world/IFeatureGenerator.java new file mode 100644 index 000000000..f0d732f33 --- /dev/null +++ b/src/main/java/cofh/api/world/IFeatureGenerator.java @@ -0,0 +1,39 @@ +package cofh.api.world; + +import java.util.Random; + +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; + +/** + * This interface should be implemented on classes which define a world feature to be generated in a {@link IFeatureHandler}. It is essentially a more robust + * version of {@link WorldGenerator}, and may include one or more WorldGenerators should you wish. + * + * @author King Lemming + * + */ +public interface IFeatureGenerator { + + /** + * Returns the name of the feature, used for displaying in the World.cfg file. + */ + public String getFeatureName(); + + /** + * Generates the world feature. + * + * @param random + * Random derived from the world seed. + * @param chunkX + * Minimum X chunk-coordinate of the chunk. (x16 for block coordinate) + * @param chunkZ + * Minimum Z chunk-coordinate of the chunk. (x16 for block coordinate) + * @param world + * The world to generate in. + * @param newGen + * True on initial generation, false on retrogen. + * @return True if generation happened, false otherwise. + */ + public boolean generateFeature(Random random, int chunkX, int chunkZ, World world, boolean newGen); + +} diff --git a/src/main/java/cofh/api/world/IFeatureHandler.java b/src/main/java/cofh/api/world/IFeatureHandler.java new file mode 100644 index 000000000..eea078ce8 --- /dev/null +++ b/src/main/java/cofh/api/world/IFeatureHandler.java @@ -0,0 +1,22 @@ +package cofh.api.world; + +/** + * Provides an interface to allow for the addition of Features to world generation. + * + * See {@link IFeatureGenerator}. + * + * @author King Lemming + * + */ +public interface IFeatureHandler { + + /** + * Register a feature with an IFeatureHandler. + * + * @param feature + * The feature to register. + * @return True if the registration was successful, false if a feature with that name existed. + */ + public boolean registerFeature(IFeatureGenerator feature); + +} diff --git a/src/main/java/mekanism/common/EnergyNetwork.java b/src/main/java/mekanism/common/EnergyNetwork.java index 85138a5c2..6190fb0e5 100644 --- a/src/main/java/mekanism/common/EnergyNetwork.java +++ b/src/main/java/mekanism/common/EnergyNetwork.java @@ -267,7 +267,7 @@ public class EnergyNetwork extends DynamicNetwork { IEnergyHandler handler = (IEnergyHandler)acceptor; - if(handler.canInterface(side.getOpposite())) + if(handler.canConnectEnergy(side.getOpposite())) { if(handler.getMaxEnergyStored(side.getOpposite()) - handler.getEnergyStored(side.getOpposite()) > 0 || handler.receiveEnergy(side.getOpposite(), 1, true) > 0) { diff --git a/src/main/java/mekanism/common/multipart/PartUniversalCable.java b/src/main/java/mekanism/common/multipart/PartUniversalCable.java index f4aec49d0..35b57f940 100644 --- a/src/main/java/mekanism/common/multipart/PartUniversalCable.java +++ b/src/main/java/mekanism/common/multipart/PartUniversalCable.java @@ -269,7 +269,7 @@ public class PartUniversalCable extends PartTransmitter implement } @Override - public boolean canInterface(ForgeDirection from) + public boolean canConnectEnergy(ForgeDirection from) { return true; } diff --git a/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java b/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java index b125a231e..48ec9e66c 100644 --- a/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java @@ -219,14 +219,14 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp } @Override - public boolean canInterface(ForgeDirection from) + public boolean canConnectEnergy(ForgeDirection from) { if(getInv() == null) { return false; } - return getInv().canInterface(from); + return getInv().canConnectEnergy(from); } @Override diff --git a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java index 96e9d5dc2..fdc8a13d9 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java @@ -258,7 +258,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i } @Override - public boolean canInterface(ForgeDirection from) + public boolean canConnectEnergy(ForgeDirection from) { return getConsumingSides().contains(from) || getOutputtingSides().contains(from); } diff --git a/src/main/java/mekanism/common/util/CableUtils.java b/src/main/java/mekanism/common/util/CableUtils.java index c337b5ff8..efeb0d223 100644 --- a/src/main/java/mekanism/common/util/CableUtils.java +++ b/src/main/java/mekanism/common/util/CableUtils.java @@ -150,7 +150,7 @@ public final class CableUtils { return (tileEntity instanceof ICableOutputter && ((ICableOutputter)tileEntity).canOutputTo(side.getOpposite())) || (tileEntity instanceof IEnergySource && ((IEnergySource)tileEntity).emitsEnergyTo(tileEntity, side.getOpposite())) || - (tileEntity instanceof IEnergyHandler && ((IEnergyHandler)tileEntity).canInterface(side.getOpposite())) || + (tileEntity instanceof IEnergyHandler && ((IEnergyHandler)tileEntity).canConnectEnergy(side.getOpposite())) || (tileEntity instanceof IPowerEmitter && ((IPowerEmitter)tileEntity).canEmitPowerFrom(side.getOpposite())); } @@ -202,7 +202,7 @@ public final class CableUtils } else if(tileEntity instanceof IEnergyHandler) { - if(((IEnergyHandler)tileEntity).canInterface(side.getOpposite())) + if(((IEnergyHandler)tileEntity).canConnectEnergy(side.getOpposite())) { return true; } @@ -309,7 +309,7 @@ public final class CableUtils { IEnergyHandler handler = (IEnergyHandler)tileEntity; - if(handler.canInterface(side.getOpposite())) + if(handler.canConnectEnergy(side.getOpposite())) { int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(sendingEnergy*Mekanism.TO_TE), false); sent += used*Mekanism.FROM_TE;