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..9805f7f0 --- /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. + */ + public 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..8b263533 --- /dev/null +++ b/src/main/java/cofh/api/block/IBlockInfo.java @@ -0,0 +1,39 @@ +package cofh.api.block; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on blocks which can provide information about themselves. + * + * @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. + */ + public 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 new file mode 100644 index 00000000..fd794378 --- /dev/null +++ b/src/main/java/cofh/api/block/IDismantleable.java @@ -0,0 +1,25 @@ +package cofh.api.block; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * Implemented on Blocks which have some method of being instantly dismantled. + * + * @author King Lemming + * + */ +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); + + /** + * 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); + +} 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 00000000..b507e6bc --- /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 { + + public boolean preInit(); + + public boolean initialize(); + + public boolean postInit(); + +} diff --git a/src/main/java/cofh/api/core/ISimpleRegistry.java b/src/main/java/cofh/api/core/ISimpleRegistry.java new file mode 100644 index 00000000..1ffe2cb7 --- /dev/null +++ b/src/main/java/cofh/api/core/ISimpleRegistry.java @@ -0,0 +1,22 @@ +package cofh.api.core; + +/** + * Basic interface for the Cape and Skin Registries. + * + * @author Zeldo Kavira + * + */ +public interface ISimpleRegistry { + + /** + * Register a new entry. + * + * @param playerName + * The player to register. + * @param URL + * Location of the cape/skin. + * @return True if registration was successful. + */ + public boolean register(String playerName, String URL); + +} diff --git a/src/main/java/cofh/api/core/NullSimpleRegistry.java b/src/main/java/cofh/api/core/NullSimpleRegistry.java new file mode 100644 index 00000000..df95dae5 --- /dev/null +++ b/src/main/java/cofh/api/core/NullSimpleRegistry.java @@ -0,0 +1,17 @@ +package cofh.api.core; + +/** + * Dummy class used to initialize Cape and Skin Registries to prevent accidental NPEs. + * + * @author Zeldo Kavira + * + */ +public class NullSimpleRegistry implements ISimpleRegistry { + + @Override + public boolean register(String playerName, String URL) { + + return false; + } + +} diff --git a/src/main/java/cofh/api/core/RegistryAccess.java b/src/main/java/cofh/api/core/RegistryAccess.java new file mode 100644 index 00000000..c1c04957 --- /dev/null +++ b/src/main/java/cofh/api/core/RegistryAccess.java @@ -0,0 +1,14 @@ +package cofh.api.core; + +/** + * Access to the Cape and Skin Registries of CoFH Core. + * + * @author Zeldo Kavira + * + */ +public class RegistryAccess { + + public static ISimpleRegistry capeRegistry = new NullSimpleRegistry(); + public static ISimpleRegistry skinRegistry = new NullSimpleRegistry(); + +} diff --git a/src/main/java/cofh/api/energy/EnergyStorage.java b/src/main/java/cofh/api/energy/EnergyStorage.java new file mode 100644 index 00000000..b3383aeb --- /dev/null +++ b/src/main/java/cofh/api/energy/EnergyStorage.java @@ -0,0 +1,158 @@ +package cofh.api.energy; + +import net.minecraft.nbt.NBTTagCompound; + +/** + * Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. + * + * @author King Lemming + * + */ +public class EnergyStorage implements IEnergyStorage { + + protected int energy; + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public EnergyStorage(int capacity) { + + this(capacity, capacity, capacity); + } + + public EnergyStorage(int capacity, int maxTransfer) { + + this(capacity, maxTransfer, maxTransfer); + } + + public EnergyStorage(int capacity, int maxReceive, int maxExtract) { + + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } + + public EnergyStorage readFromNBT(NBTTagCompound nbt) { + + this.energy = nbt.getInteger("Energy"); + + if (energy > capacity) { + energy = capacity; + } + return this; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + + if (energy < 0) { + energy = 0; + } + nbt.setInteger("Energy", energy); + return nbt; + } + + public void setCapacity(int capacity) { + + this.capacity = capacity; + + if (energy > capacity) { + energy = capacity; + } + } + + 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; + } + + public int getMaxReceive() { + + return maxReceive; + } + + public int getMaxExtract() { + + return maxExtract; + } + + /** + * This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are + * guaranteed to have it. + * + * @param energy + */ + public void setEnergyStored(int energy) { + + this.energy = energy; + + if (this.energy > capacity) { + this.energy = capacity; + } else if (this.energy < 0) { + this.energy = 0; + } + } + + /** + * This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this + * externally, as not all IEnergyHandlers are guaranteed to have it. + * + * @param energy + */ + public void modifyEnergyStored(int energy) { + + this.energy += energy; + + if (this.energy > capacity) { + this.energy = capacity; + } else if (this.energy < 0) { + this.energy = 0; + } + } + + /* IEnergyStorage */ + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { + + int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + + if (!simulate) { + energy += energyReceived; + } + return energyReceived; + } + + @Override + public int extractEnergy(int maxExtract, boolean simulate) { + + int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + + if (!simulate) { + energy -= energyExtracted; + } + return energyExtracted; + } + + @Override + public int getEnergyStored() { + + return energy; + } + + @Override + public int getMaxEnergyStored() { + + return capacity; + } + +} 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 00000000..63faffb9 --- /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/IEnergyContainerItem.java b/src/main/java/cofh/api/energy/IEnergyContainerItem.java index 41958293..0bcfda60 100644 --- a/src/main/java/cofh/api/energy/IEnergyContainerItem.java +++ b/src/main/java/cofh/api/energy/IEnergyContainerItem.java @@ -4,48 +4,49 @@ import net.minecraft.item.ItemStack; /** * Implement this interface on Item classes that support external manipulation of their internal energy storages. - * + * + * A reference implementation is provided {@link ItemEnergyContainer}. * * @author King Lemming * */ -public interface IEnergyContainerItem -{ +public interface IEnergyContainerItem { - /** - * Adds energy to an item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. - * - * @param container - * ItemStack to be charged. - * @param maxReceive - * Maximum amount of energy to be sent into the item. - * @param simulate - * If TRUE, the charge will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) received by the item. - */ - int receiveEnergy(ItemStack container, int maxReceive, boolean simulate); + /** + * Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. + * + * @param container + * ItemStack to be charged. + * @param maxReceive + * Maximum amount of energy to be sent into the item. + * @param simulate + * If TRUE, the charge will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) received by the item. + */ + int receiveEnergy(ItemStack container, int maxReceive, boolean simulate); - /** - * Removes energy from an item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally discharged. - * - * @param container - * ItemStack to be discharged. - * @param maxExtract - * Maximum amount of energy to be extracted from the item. - * @param simulate - * If TRUE, the discharge will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) extracted from the item. - */ - int extractEnergy(ItemStack container, int maxExtract, boolean simulate); + /** + * Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally + * discharged. + * + * @param container + * ItemStack to be discharged. + * @param maxExtract + * Maximum amount of energy to be extracted from the item. + * @param simulate + * If TRUE, the discharge will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted from the item. + */ + int extractEnergy(ItemStack container, int maxExtract, boolean simulate); - /** - * Get the amount of energy currently stored in the item. - */ - int getEnergyStored(ItemStack container); + /** + * Get the amount of energy currently stored in the container item. + */ + int getEnergyStored(ItemStack container); - /** - * Get the max amount of energy that can be stored in the item. - */ - int getMaxEnergyStored(ItemStack container); + /** + * Get the max amount of energy that can be stored in the container item. + */ + int getMaxEnergyStored(ItemStack container); -} \ No newline at end of file +} diff --git a/src/main/java/cofh/api/energy/IEnergyHandler.java b/src/main/java/cofh/api/energy/IEnergyHandler.java index bd14171d..3aaf81a7 100644 --- a/src/main/java/cofh/api/energy/IEnergyHandler.java +++ b/src/main/java/cofh/api/energy/IEnergyHandler.java @@ -1,23 +1,24 @@ 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. + * + * 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. - * + * * @param from * Orientation the energy is received from. * @param maxReceive - * Maximum amount of energy to received. + * 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. @@ -26,22 +27,17 @@ public interface IEnergyHandler { /** * Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. - * + * * @param from - * Orientation the energy is extracted to. + * Orientation the energy is extracted from. * @param maxExtract * Maximum amount of energy to extract. * @param simulate - * If TRUE, the discharge will only be simulated. + * 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 true if the Handler functions on a given side - if a Tile Entity can receive and/or send energy from 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/IEnergyStorage.java b/src/main/java/cofh/api/energy/IEnergyStorage.java new file mode 100644 index 00000000..1e84bc22 --- /dev/null +++ b/src/main/java/cofh/api/energy/IEnergyStorage.java @@ -0,0 +1,45 @@ +package cofh.api.energy; + +/** + * An energy storage is the unit of interaction with Energy inventories. + * + * A reference implementation can be found at {@link EnergyStorage}. + * + * @author King Lemming + * + */ +public interface IEnergyStorage { + + /** + * Adds energy to the storage. Returns quantity of energy that was accepted. + * + * @param maxReceive + * Maximum amount of energy to be inserted. + * @param simulate + * If TRUE, the insertion will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) accepted by the storage. + */ + int receiveEnergy(int maxReceive, boolean simulate); + + /** + * Removes energy from the storage. Returns quantity of energy that was removed. + * + * @param maxExtract + * Maximum amount of energy to be extracted. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted from the storage. + */ + int extractEnergy(int maxExtract, boolean simulate); + + /** + * Returns the amount of energy currently stored. + */ + int getEnergyStored(); + + /** + * Returns the maximum amount of energy that can be stored. + */ + int getMaxEnergyStored(); + +} 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 00000000..055ae45b --- /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 new file mode 100644 index 00000000..a7fabeb7 --- /dev/null +++ b/src/main/java/cofh/api/energy/TileEnergyHandler.java @@ -0,0 +1,62 @@ +package cofh.api.energy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +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 { + + protected EnergyStorage storage = new EnergyStorage(32000); + + @Override + public void readFromNBT(NBTTagCompound nbt) { + + super.readFromNBT(nbt); + storage.readFromNBT(nbt); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + + super.writeToNBT(nbt); + storage.writeToNBT(nbt); + } + + /* IEnergyHandler */ + @Override + public boolean canConnectEnergy(ForgeDirection from) { + + return true; + } + + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { + + return storage.receiveEnergy(maxReceive, simulate); + } + + @Override + public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { + + return storage.extractEnergy(maxExtract, simulate); + } + + @Override + public int getEnergyStored(ForgeDirection from) { + + return storage.getEnergyStored(); + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) { + + return storage.getMaxEnergyStored(); + } + +} 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 00000000..d0ad117b --- /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 00000000..91c05108 --- /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 00000000..4340e5f3 --- /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 00000000..e6191fbf --- /dev/null +++ b/src/main/java/cofh/api/item/ISecureItem.java @@ -0,0 +1,25 @@ +package cofh.api.item; + +import net.minecraft.entity.player.EntityPlayer; + +/** + * 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(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 00000000..cb1185da --- /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/IEnergyInfo.java b/src/main/java/cofh/api/tileentity/IEnergyInfo.java new file mode 100644 index 00000000..8337dbab --- /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). + */ + public int getInfoEnergyPerTick(); + + /** + * Returns maximum energy usage/generation per tick (RF/t). + */ + public int getInfoMaxEnergyPerTick(); + + /** + * Returns energy stored (RF). + */ + public int getInfoEnergy(); + + /** + * Returns maximum energy stored (RF). + */ + public int getInfoMaxEnergy(); + +} 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..df981096 --- /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. + */ + public int getFacing(); + + /** + * Returns whether or not the block's face can be aligned with the Y Axis. + */ + public boolean allowYAxisFacing(); + + /** + * Attempt to rotate the block. Arbitrary based on implementation. + * + * @return True if rotation was successful, false otherwise. + */ + public 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. + */ + public 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..354d58db --- /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. + */ + public 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. + */ + public 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. + */ + public boolean setSide(int side, int config); + + /** + * Reset configs on all sides to their base values. + * + * @return True if reset was successful, false otherwise. + */ + public boolean resetSides(); + + /** + * Returns the number of possible config settings for a given side. + */ + public 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 00000000..e7af8f8e --- /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 { + + public void setPowered(boolean isPowered); + + public 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 00000000..2dbeefc8 --- /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; + } + } + + public void setControl(ControlMode control); + + public 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 00000000..b7802d62 --- /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; + } + } + + public boolean setAccess(AccessMode access); + + public boolean setOwnerName(String name); + + public AccessMode getAccess(); + + public String getOwnerName(); + + public boolean canPlayerAccess(String name); + +} diff --git a/src/main/java/cofh/api/tileentity/ISidedBlockTexture.java b/src/main/java/cofh/api/tileentity/ISidedBlockTexture.java new file mode 100644 index 00000000..4f9fdf0c --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ISidedBlockTexture.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 ISidedBlockTexture { + + /** + * 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. + */ + public IIcon getBlockTexture(int side, int pass); + +} diff --git a/src/main/java/cofh/api/tileentity/ISubSelectionBoxProvider.java b/src/main/java/cofh/api/tileentity/ISubSelectionBoxProvider.java new file mode 100644 index 00000000..eff1e62b --- /dev/null +++ b/src/main/java/cofh/api/tileentity/ISubSelectionBoxProvider.java @@ -0,0 +1,11 @@ +package cofh.api.tileentity; + +import codechicken.lib.raytracer.IndexedCuboid6; + +import java.util.List; + +public interface ISubSelectionBoxProvider { + + public void addTraceableCuboids(List cuboids); + +} 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..e20fe17e --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderAttuned.java @@ -0,0 +1,50 @@ +package cofh.api.transport; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public interface IEnderAttuned { + + public enum EnderTypes { + ITEM, FLUID, REDSTONE_FLUX + } + + String getOwnerString(); + + int getFrequency(); + + boolean setFrequency(int frequency); + + 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/IEnderEnergyReceptor.java b/src/main/java/cofh/api/transport/IEnderEnergyReceptor.java new file mode 100644 index 00000000..b70fd712 --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderEnergyReceptor.java @@ -0,0 +1,30 @@ +package cofh.api.transport; + +/** + * This interface is implemented on Ender Attuned objects which can receive Energy (Redstone Flux). + * + * @author King Lemming + * + */ +public interface IEnderEnergyReceptor { + + /** + * This should be checked to see if the Ender Attuned object can currently receive energy. + * + * 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/IEnderFluidReceptor.java b/src/main/java/cofh/api/transport/IEnderFluidReceptor.java new file mode 100644 index 00000000..dd38846a --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderFluidReceptor.java @@ -0,0 +1,32 @@ +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 IEnderFluidReceptor { + + /** + * 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/IEnderItemReceptor.java b/src/main/java/cofh/api/transport/IEnderItemReceptor.java new file mode 100644 index 00000000..2f6cfbf2 --- /dev/null +++ b/src/main/java/cofh/api/transport/IEnderItemReceptor.java @@ -0,0 +1,33 @@ +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 IEnderItemReceptor { + + /** + * 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/IItemDuct.java b/src/main/java/cofh/api/transport/IItemDuct.java new file mode 100644 index 00000000..4c50c856 --- /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 00000000..f0d732f3 --- /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 00000000..eea078ce --- /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); + +}