diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/IStorageDrawersApi.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/IStorageDrawersApi.java new file mode 100644 index 000000000..7e0eb580e --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/IStorageDrawersApi.java @@ -0,0 +1,23 @@ +package com.jaquadro.minecraft.storagedrawers.api; + +import com.jaquadro.minecraft.storagedrawers.api.config.IUserConfig; +import com.jaquadro.minecraft.storagedrawers.api.registry.IRecipeHandlerRegistry; +import com.jaquadro.minecraft.storagedrawers.api.registry.IRenderRegistry; +import com.jaquadro.minecraft.storagedrawers.api.registry.IWailaRegistry; + +public interface IStorageDrawersApi +{ + /** + * Recipe handlers are used to make custom recipes compatible with compacting drawers. + */ + IRecipeHandlerRegistry recipeHandlerRegistry (); + + IRenderRegistry renderRegistry (); + + IWailaRegistry wailaRegistry (); + + /** + * User-managed configuration for the Storage Drawers mod. + */ + IUserConfig userConfig (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/StorageDrawersApi.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/StorageDrawersApi.java new file mode 100644 index 000000000..b078c8062 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/StorageDrawersApi.java @@ -0,0 +1,30 @@ +package com.jaquadro.minecraft.storagedrawers.api; + +/** + * Entry point for the public API. + */ +public class StorageDrawersApi +{ + private static IStorageDrawersApi instance; + + public static final String VERSION = "1.10.2-1.3.0"; + + /** + * API entry point. + * + * @return The {@link IStorageDrawersApi} instance or null if the API or Storage Drawers is unavailable. + */ + public static IStorageDrawersApi instance () { + if (instance == null) { + try { + Class classApi = Class.forName( "com.jaquadro.minecraft.storagedrawers.core.Api" ); + instance = (IStorageDrawersApi) classApi.getField("instance").get(null); + } + catch (Throwable t) { + return null; + } + } + + return instance; + } +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IAddonConfig.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IAddonConfig.java new file mode 100644 index 000000000..ca1757971 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IAddonConfig.java @@ -0,0 +1,21 @@ +package com.jaquadro.minecraft.storagedrawers.api.config; + +public interface IAddonConfig +{ + /** + * Gets whether the user has configured a preference for addon packs to hide their blocks and items from Vanilla + * creative tabs. + */ + boolean showAddonItemsNEI (); + + /** + * Gets whether the user has configured a preference for addon packs to hide their blocks and items from NEI. + */ + boolean showAddonItemsVanilla (); + + /** + * Gets whether the user has configured a preference for addon packs to provide their blocks and items through + * their own vanilla tab. + */ + boolean addonItemsUseSeparateTab (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IBlockConfig.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IBlockConfig.java new file mode 100644 index 000000000..f4101e790 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IBlockConfig.java @@ -0,0 +1,14 @@ +package com.jaquadro.minecraft.storagedrawers.api.config; + +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration; + +public interface IBlockConfig +{ + String getBlockConfigName (BlockConfiguration blockConfig); + + boolean isBlockEnabled (String blockConfigName); + + int getBlockRecipeOutput (String blockConfigName); + + int getBaseCapacity (String blockConfigName); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IIntegrationConfig.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IIntegrationConfig.java new file mode 100644 index 000000000..28d9f132c --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IIntegrationConfig.java @@ -0,0 +1,6 @@ +package com.jaquadro.minecraft.storagedrawers.api.config; + +public interface IIntegrationConfig +{ + boolean isRefinedRelocationEnabled (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IUserConfig.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IUserConfig.java new file mode 100644 index 000000000..f8aa5e538 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/IUserConfig.java @@ -0,0 +1,18 @@ +package com.jaquadro.minecraft.storagedrawers.api.config; + +/** + * The main hub for user-managed mod configuration. + */ +public interface IUserConfig +{ + /** + * Configuration options related to third party addon packs for Storage Drawers. + */ + @Deprecated + IAddonConfig addonConfig (); + + /** + * Configuration options related to individual blocks. + */ + IBlockConfig blockConfig (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/package-info.java new file mode 100644 index 000000000..4a83dca8e --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/config/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|config", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.config; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/event/DrawerPopulatedEvent.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/event/DrawerPopulatedEvent.java new file mode 100644 index 000000000..e82953e94 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/event/DrawerPopulatedEvent.java @@ -0,0 +1,19 @@ +package com.jaquadro.minecraft.storagedrawers.api.event; + +import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; +import net.minecraftforge.fml.common.eventhandler.Event; + +/** + * This event is called when a drawer has been bound to a new item. This is + * and opportunity for mods to cache extended data with the drawer. + * + * This event is also called when the drawer is changed to empty. + */ +public class DrawerPopulatedEvent extends Event +{ + public final IDrawer drawer; + + public DrawerPopulatedEvent (IDrawer drawer) { + this.drawer = drawer; + } +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/event/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/event/package-info.java new file mode 100644 index 000000000..517ce1760 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/event/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|event", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.event; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/BlockConfiguration.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/BlockConfiguration.java new file mode 100644 index 000000000..f0c121e2a --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/BlockConfiguration.java @@ -0,0 +1,42 @@ +package com.jaquadro.minecraft.storagedrawers.api.pack; + +import com.jaquadro.minecraft.storagedrawers.api.storage.EnumBasicDrawer; + +public enum BlockConfiguration +{ + BasicFull1(BlockType.Drawers, EnumBasicDrawer.FULL1), + BasicFull2(BlockType.Drawers, EnumBasicDrawer.FULL2), + BasicFull4(BlockType.Drawers, EnumBasicDrawer.FULL4), + BasicHalf2(BlockType.Drawers, EnumBasicDrawer.HALF2), + BasicHalf4(BlockType.Drawers, EnumBasicDrawer.HALF4), + Trim(BlockType.Trim, null); + + private final BlockType type; + private final EnumBasicDrawer drawer; + + BlockConfiguration (BlockType type, EnumBasicDrawer drawer) { + this.type = type; + this.drawer = drawer; + } + + public BlockType getBlockType () { + return type; + } + + public int getDrawerCount () { + return (drawer != null) ? drawer.getDrawerCount() : 0; + } + + public boolean isHalfDepth () { + return (drawer != null) && drawer.isHalfDepth(); + } + + public static BlockConfiguration by (BlockType type, EnumBasicDrawer drawer) { + for (BlockConfiguration config : values()) { + if (config.type == type && config.drawer == drawer) + return config; + } + + return null; + } +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/BlockType.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/BlockType.java new file mode 100644 index 000000000..f54d4ce8b --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/BlockType.java @@ -0,0 +1,7 @@ +package com.jaquadro.minecraft.storagedrawers.api.pack; + +public enum BlockType +{ + Drawers, + Trim +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/TextureType.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/TextureType.java new file mode 100644 index 000000000..92ca51df3 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/TextureType.java @@ -0,0 +1,13 @@ +package com.jaquadro.minecraft.storagedrawers.api.pack; + +public enum TextureType +{ + Front1, + Front2, + Front4, + Side, + SideVSplit, + SideHSplit, + TrimBorder, + TrimBlock +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/package-info.java new file mode 100644 index 000000000..2c7367e85 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/pack/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|pack", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.pack; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/package-info.java new file mode 100644 index 000000000..86d7280fa --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/package-info.java @@ -0,0 +1,4 @@ +@API(owner = "StorageDrawers", provides = "StorageDrawersAPI", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api; + +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IIngredientHandler.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IIngredientHandler.java new file mode 100644 index 000000000..0f33fd5c6 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IIngredientHandler.java @@ -0,0 +1,22 @@ +package com.jaquadro.minecraft.storagedrawers.api.registry; + +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +/** + * Ingredient handlers are used to get ItemStacks from ingredients in custom IRecipe implementations. If you have + * registered an IRecipeHandler that returns lists of objects that aren't ItemStacks, then you will need to + * implement an ingredient handler for those objects. + */ +public interface IIngredientHandler +{ + /** + * Gets an ItemStack from an object that represents an ingredient in an IRecipe. + * + * @param object An ingredient object. + * @return An ItemStack for the given ingredient. + */ + @Nonnull + ItemStack getItemStack (Object object); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRecipeHandler.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRecipeHandler.java new file mode 100644 index 000000000..d4311ea8a --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRecipeHandler.java @@ -0,0 +1,36 @@ +package com.jaquadro.minecraft.storagedrawers.api.registry; + +import net.minecraft.item.crafting.IRecipe; + +import java.util.List; + +/** + * Recipe handlers are used by compacting drawers to find more-compressed forms of blocks and items. If your recipe + * to craft compressed items is a custom IRecipe implementation, you will need to register a handler for it. + */ +public interface IRecipeHandler +{ + /** + * Get the recipe ingredient list as an array of objects (usually used for shaped recipes). + * If your array does not contain ItemStack objects, you will need to register an {@link IIngredientHandler} to + * get an ItemStack from them. + * + * If you would prefer to return a List, return null in this method and implement {@link #getInputAsList}. + * + * @param recipe An instance of a custom {@link IRecipe}. + * @return An array of ItemStacks or objects with a registered {@link IIngredientHandler}. + */ + Object[] getInputAsArray (IRecipe recipe); + + /** + * Get the recipe ingredient list as a list of objects (usually used for shapeless recipes). + * If your list does not contain ItemStack objects, you will need to register an {@link IIngredientHandler} to + * get an ItemStack from them. + * + * If you would prefer to return an array, return null in this method and implement {@link #getInputAsArray}. + * + * @param recipe An instance of a custom {@link IRecipe}. + * @return A list of ItemStacks or objects with a registered {@link IIngredientHandler}. + */ + List getInputAsList (IRecipe recipe); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRecipeHandlerRegistry.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRecipeHandlerRegistry.java new file mode 100644 index 000000000..b83d5347c --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRecipeHandlerRegistry.java @@ -0,0 +1,12 @@ +package com.jaquadro.minecraft.storagedrawers.api.registry; + +public interface IRecipeHandlerRegistry +{ + void registerRecipeHandler (Class clazz, IRecipeHandler handler); + + void registerIngredientHandler (Class clazz, IIngredientHandler handler); + + IRecipeHandler getRecipeHandler (Class clazz); + + IIngredientHandler getIngredientHandler (Class clazz); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRenderRegistry.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRenderRegistry.java new file mode 100644 index 000000000..cfa4543a1 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IRenderRegistry.java @@ -0,0 +1,8 @@ +package com.jaquadro.minecraft.storagedrawers.api.registry; + +import com.jaquadro.minecraft.storagedrawers.api.render.IRenderLabel; + +public interface IRenderRegistry +{ + void registerPreLabelRenderHandler (IRenderLabel renderHandler); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IWailaRegistry.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IWailaRegistry.java new file mode 100644 index 000000000..a4ee9874a --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IWailaRegistry.java @@ -0,0 +1,6 @@ +package com.jaquadro.minecraft.storagedrawers.api.registry; + +public interface IWailaRegistry +{ + void registerTooltipHandler (IWailaTooltipHandler handler); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IWailaTooltipHandler.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IWailaTooltipHandler.java new file mode 100644 index 000000000..d0f3328c6 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/IWailaTooltipHandler.java @@ -0,0 +1,8 @@ +package com.jaquadro.minecraft.storagedrawers.api.registry; + +import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; + +public interface IWailaTooltipHandler +{ + String transformItemName (IDrawer drawer, String defaultName); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/package-info.java new file mode 100644 index 000000000..75fe1f250 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/registry/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|registry", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.registry; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/render/IRenderLabel.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/render/IRenderLabel.java new file mode 100644 index 000000000..500030aa0 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/render/IRenderLabel.java @@ -0,0 +1,9 @@ +package com.jaquadro.minecraft.storagedrawers.api.render; + +import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; +import net.minecraft.tileentity.TileEntity; + +public interface IRenderLabel +{ + void render (TileEntity tileEntity, IDrawerGroup drawerGroup, int slot, float brightness, float partialTickTime); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/render/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/render/package-info.java new file mode 100644 index 000000000..76e937caa --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/render/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|render", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.render; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java new file mode 100644 index 000000000..66752c0c4 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java @@ -0,0 +1,13 @@ +package com.jaquadro.minecraft.storagedrawers.api.security; + +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; +import com.mojang.authlib.GameProfile; + +public interface ISecurityProvider +{ + String getProviderID (); + + boolean hasOwnership (GameProfile profile, IProtectable target); + + boolean hasAccess (GameProfile profile, IProtectable target); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/EnumBasicDrawer.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/EnumBasicDrawer.java new file mode 100644 index 000000000..93117ba7b --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/EnumBasicDrawer.java @@ -0,0 +1,72 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +import net.minecraft.util.IStringSerializable; + +import javax.annotation.Nonnull; + +public enum EnumBasicDrawer implements IDrawerGeometry, IStringSerializable +{ + FULL1(0, 1, false, "full1", "fulldrawers1"), + FULL2(1, 2, false, "full2", "fulldrawers2"), + FULL4(2, 4, false, "full4", "fulldrawers4"), + HALF2(3, 2, true, "half2", "halfdrawers2"), + HALF4(4, 4, true, "half4", "halfdrawers4"); + + private static final EnumBasicDrawer[] META_LOOKUP; + + private final int meta; + private final int drawerCount; + private final boolean halfDepth; + private final String name; + private final String unlocalizedName; + + EnumBasicDrawer (int meta, int drawerCount, boolean halfDepth, String name, String unlocalizedName) { + this.meta = meta; + this.name = name; + this.drawerCount = drawerCount; + this.halfDepth = halfDepth; + this.unlocalizedName = unlocalizedName; + } + + public int getMetadata () { + return meta; + } + + @Override + public int getDrawerCount () { + return drawerCount; + } + + @Override + public boolean isHalfDepth () { + return halfDepth; + } + + public String getUnlocalizedName () { + return unlocalizedName; + } + + public static EnumBasicDrawer byMetadata (int meta) { + if (meta < 0 || meta >= META_LOOKUP.length) + meta = 0; + return META_LOOKUP[meta]; + } + + @Override + public String toString () { + return getName(); + } + + @Override + @Nonnull + public String getName () { + return name; + } + + static { + META_LOOKUP = new EnumBasicDrawer[values().length]; + for (EnumBasicDrawer upgrade : values()) { + META_LOOKUP[upgrade.getMetadata()] = upgrade; + } + } +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawer.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawer.java new file mode 100644 index 000000000..851eb6f45 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawer.java @@ -0,0 +1,119 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import javax.annotation.Nonnull; + +public interface IDrawer +{ + /** + * Gets an ItemStack of size 1 representing the type, metadata, and tags of the stored items. + * The returned ItemStack should not be modified for any reason. Make a copy if you need to store or modify it. + */ + @Nonnull + ItemStack getStoredItemPrototype (); + + /** + * Sets the type of the stored item and initializes it to the given amount. Any existing item will be replaced. + * + * @param itemPrototype An ItemStack representing the type, metadata, and tags of the item to store. + * @param amount The amount to initialize the stored item count to. + * @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member. + */ + IDrawer setStoredItem (@Nonnull ItemStack itemPrototype, int amount); + + /** + * Gets the number of items stored in this drawer. + */ + int getStoredItemCount (); + + /** + * Sets the number of items stored in this drawer. Triggers syncing of inventories and client data. + * Setting a drawer's count to 0 may also result in the item type being cleared, depending in implementation. + * + * @param amount The new amount of items stored in this drawer. + */ + void setStoredItemCount (int amount); + + /** + * Gets the maximum number of items that can be stored in this drawer. + * This value will vary depending on the max stack size of the stored item type. + */ + int getMaxCapacity (); + + /** + * Gets the maximum number of items that could be stored in this drawer if it held the given item. + * + * @param itemPrototype The item type to query. + */ + int getMaxCapacity (@Nonnull ItemStack itemPrototype); + + /** + * Gets the maxmimum number of items that could be stored in this drawer for a standard item stack size + * of 64. + */ + int getDefaultMaxCapacity (); + + /** + * Gets the number of items that could still be added to this drawer before it is full. + */ + int getRemainingCapacity (); + + /** + * Gets the max stack size of the item type stored in this drawer. Convenience method. + */ + int getStoredItemStackSize (); + + /** + * Gets whether or not an item of the given type and data can be stored in this drawer. + * + * Stack size and available capacity are not considered. For drawers that are not empty, this + * method can allow ore-dictionary compatible items to be accepted into the drawer, as defined by what + * the drawer considers to be an equivalent item. + * For drawers that are empty, locking status is considered. + * + * @param itemPrototype An ItemStack representing the type, metadata, and tags of an item. + */ + boolean canItemBeStored (@Nonnull ItemStack itemPrototype); + + /** + * Gets whether or not an item of the given type and data can be extracted from this drawer. + * + * This is intended to allow outbound ore-dictionary conversions of compatible items, as defined by what + * the drawer considers to be an equivalent item. + * + * @param itemPrototype An ItemStack representing the type, metadata, and tags of an item. + */ + boolean canItemBeExtracted (@Nonnull ItemStack itemPrototype); + + /** + * Gets whether or not the drawer has items. + * A drawer set with an item type and 0 count is not considered empty. + */ + boolean isEmpty (); + + /** + * Gets auxiliary data that has been associated with this drawer. + * + * @param key The key used to identify the data. + * @return An opaque object that was previously stored. + */ + Object getExtendedData (String key); + + /** + * Stores auxiliary data with this drawer, mainly for use in integration. + * @param key The key to identify the data with. + * @param data The data to store. + */ + void setExtendedData (String key, Object data); + + /** + * Called when a component attribute of a drawer (such as lock or void) changes state. + */ + void attributeChanged (); + + void writeToNBT (NBTTagCompound tag); + + void readFromNBT (NBTTagCompound tag); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGeometry.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGeometry.java new file mode 100644 index 000000000..1dae92ad0 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGeometry.java @@ -0,0 +1,8 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +public interface IDrawerGeometry +{ + boolean isHalfDepth (); + + int getDrawerCount (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGroup.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGroup.java new file mode 100644 index 000000000..bc54eb6bf --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGroup.java @@ -0,0 +1,26 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +public interface IDrawerGroup +{ + /** + * Gets the number of drawers contained within this group. + */ + int getDrawerCount (); + + /** + * Gets the drawer at the given slot within this group. + */ + IDrawer getDrawer (int slot); + + /** + * Gets the drawer at the given slot within this group only if it is enabled. + */ + IDrawer getDrawerIfEnabled (int slot); + + /** + * Gets whether the drawer in the given slot is usable. + */ + boolean isDrawerEnabled (int slot); + + boolean markDirtyIfNeeded (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGroupInteractive.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGroupInteractive.java new file mode 100644 index 000000000..362b11b2b --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawerGroupInteractive.java @@ -0,0 +1,18 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public interface IDrawerGroupInteractive extends IDrawerGroup +{ + @Nonnull + ItemStack takeItemsFromSlot (int slot, int count); + + int putItemsIntoSlot (int slot, @Nonnull ItemStack stack, int count); + + int interactPutCurrentItemIntoSlot (int slot, EntityPlayer player); + + int interactPutCurrentInventoryIntoSlot (int slot, EntityPlayer player); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IFractionalDrawer.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IFractionalDrawer.java new file mode 100644 index 000000000..bd87a808b --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IFractionalDrawer.java @@ -0,0 +1,28 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +/** + * Represents a drawer with items that are a fractional component of another item within the drawer group. Compacting + * Drawers are a primary example of this drawer type. + */ +public interface IFractionalDrawer extends IDrawer +{ + /** + * Gets the storage ratio between the held item and the most compressed item within the drawer group. + * + * For example, most ingots have a conversion rate of 9 compared to metal blocks, and nuggets a rate of 81. + * Actual conversion rates are implementation-defined. + */ + int getConversionRate (); + + /** + * Gets the number of items left in the drawer if the maximum number of equivalent compressed items had been removed. + * The equivalency is determined by the next compression tier, and not necessarily the conversion rate. + */ + int getStoredItemRemainder (); + + /** + * Gets whether or not the stored item represents the smallest granularity of material that can be stored within + * the drawer group. + */ + boolean isSmallestUnit (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/INetworked.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/INetworked.java new file mode 100644 index 000000000..fba20d40a --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/INetworked.java @@ -0,0 +1,5 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +public interface INetworked +{ +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IPriorityGroup.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IPriorityGroup.java new file mode 100644 index 000000000..97b293e27 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/IPriorityGroup.java @@ -0,0 +1,10 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + + +public interface IPriorityGroup +{ + /** + * Gets the list of available drawer slots in priority order. + */ + int[] getAccessibleDrawerSlots (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java new file mode 100644 index 000000000..8795d77a8 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java @@ -0,0 +1,20 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public interface ISmartGroup +{ + /** + * Gets a lazy enumeration of all slots that will accept at least one item of the given stack, ordered by + * insertion preference. + */ + Iterable enumerateDrawersForInsertion (@Nonnull ItemStack stack, boolean strict); + + /** + * Gets a lazy enumeration of all slots that will provide at least one item of the given stack, ordered by + * extraction preference. + */ + Iterable enumerateDrawersForExtraction (@Nonnull ItemStack stack, boolean strict); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IItemLockable.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IItemLockable.java new file mode 100644 index 000000000..684822e65 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IItemLockable.java @@ -0,0 +1,21 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +public interface IItemLockable +{ + /** + * Gets whether or not a drawer or group is locked for the given lock attribute. + */ + boolean isItemLocked (LockAttribute attr); + + /** + * Gets whether or not the lock state can be changed for the given lock attribute. + * If this method returns false, isItemLocked may still return true. + */ + boolean canItemLock (LockAttribute attr); + + /** + * Sets the lock state of a drawer or group for the given lock attribute. + * If canItemLock returns false, this is a no-op. + */ + void setItemLocked (LockAttribute attr, boolean isLocked); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java new file mode 100644 index 000000000..c378c04a9 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java @@ -0,0 +1,38 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; +import net.minecraft.world.ILockableContainer; + +import java.util.UUID; + +public interface IProtectable +{ + /** + * Gets the owner of the drawer, or null if there is no owner. + */ + UUID getOwner (); + + /** + * Sets the owner of the drawer. Set to null to set no owner. + * @return false if the operation is not supported, true otherwise. + */ + boolean setOwner (UUID owner); + + /** + * Gets the provider managing security for the target. + * @return null to use the default provider, which enforces strict owner access. + */ + ISecurityProvider getSecurityProvider (); + + /** + * Gets the lockable interface if it exists on the protected drawer. + * @return A lockable interface, or null if lockable is not supported. + */ + ILockableContainer getLockableContainer (); + + /** + * Sets the provider managing security for the target. Set to null for default provider. + * @return false if the operation is not supported, true otherwise. + */ + boolean setSecurityProvider (ISecurityProvider provder); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IQuantifiable.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IQuantifiable.java new file mode 100644 index 000000000..1e37e82cb --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IQuantifiable.java @@ -0,0 +1,16 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +public interface IQuantifiable +{ + /** + * Gets whether or not the drawer has the quantified attribute. + * The quantified attribute instructs the drawer to render its numerical quantity. + */ + boolean isShowingQuantity (); + + /** + * Sets whether or not the drawer is currently quantified. + * @return false if the operation is not supported, true otherwise. + */ + boolean setIsShowingQuantity (boolean state); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/ISealable.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/ISealable.java new file mode 100644 index 000000000..7330780e1 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/ISealable.java @@ -0,0 +1,16 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +public interface ISealable +{ + /** + * Gets whether or not the drawer has the sealed attribute. + * A sealed drawer cannot be interacted with, and when broken will retain all of its items and upgrades. + */ + boolean isSealed (); + + /** + * Sets whether or not the drawer is currently sealed. + * @return false if the operation is not supported, true otherwise. + */ + boolean setIsSealed (boolean state); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IShroudable.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IShroudable.java new file mode 100644 index 000000000..b7f0bf035 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IShroudable.java @@ -0,0 +1,16 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +public interface IShroudable +{ + /** + * Gets whether or not the drawer has the shrouded attribute. + * The shrouded attribute instructs the drawer to not render its item label. + */ + boolean isShrouded (); + + /** + * Sets whether or not the drawer is currently shrouded. + * @return false if the operation is not supported, true otherwise. + */ + boolean setIsShrouded (boolean state); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IVoidable.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IVoidable.java new file mode 100644 index 000000000..9fc580635 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IVoidable.java @@ -0,0 +1,9 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +public interface IVoidable +{ + /** + * Gets whether or not the drawer has a voiding attribute. + */ + boolean isVoid (); +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/LockAttribute.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/LockAttribute.java new file mode 100644 index 000000000..cb726b411 --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/LockAttribute.java @@ -0,0 +1,37 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +import java.util.EnumSet; + +public enum LockAttribute +{ + LOCK_POPULATED, + LOCK_EMPTY; + + public int getFlagValue () { + return 1 << ordinal(); + } + + public static int getBitfield (EnumSet attributes) { + int value = 0; + if (attributes == null) + return value; + + for (LockAttribute attr : attributes) + value |= attr.getFlagValue(); + + return value; + } + + public static EnumSet getEnumSet (int bitfield) { + if (bitfield == 0) + return null; + + EnumSet set = EnumSet.noneOf(LockAttribute.class); + for (LockAttribute attr : values()) { + if ((bitfield & attr.getFlagValue()) != 0) + set.add(attr); + } + + return set; + } +} diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/package-info.java new file mode 100644 index 000000000..cbcb916aa --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|storage-attribute", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/package-info.java b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/package-info.java new file mode 100644 index 000000000..c9539a2ae --- /dev/null +++ b/src/api/java/com/jaquadro/minecraft/storagedrawers/api/storage/package-info.java @@ -0,0 +1,5 @@ +@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|storage", apiVersion = StorageDrawersApi.VERSION) +package com.jaquadro.minecraft.storagedrawers.api.storage; + +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/MekanismHooks.java b/src/main/java/mekanism/common/integration/MekanismHooks.java index 80756f125..1db17a590 100644 --- a/src/main/java/mekanism/common/integration/MekanismHooks.java +++ b/src/main/java/mekanism/common/integration/MekanismHooks.java @@ -16,6 +16,7 @@ import mekanism.common.Resource; import mekanism.common.block.states.BlockStateTransmitter.TransmitterType; import mekanism.common.integration.computer.CCPeripheral; import mekanism.common.integration.computer.OCDriver; +import mekanism.common.integration.storagedrawer.StorageDrawerRecipeHandler; import mekanism.common.recipe.RecipeHandler; import mekanism.common.util.MekanismUtils; import net.minecraft.init.Items; @@ -78,6 +79,11 @@ public final class MekanismHooks { //loadMettallurgy(); } + + if(Loader.isModLoaded("storagedrawers")) + { + StorageDrawerRecipeHandler.register(); + } } @Method(modid = "IC2") diff --git a/src/main/java/mekanism/common/integration/storagedrawer/StorageDrawerRecipeHandler.java b/src/main/java/mekanism/common/integration/storagedrawer/StorageDrawerRecipeHandler.java new file mode 100644 index 000000000..47b7d45be --- /dev/null +++ b/src/main/java/mekanism/common/integration/storagedrawer/StorageDrawerRecipeHandler.java @@ -0,0 +1,55 @@ +package mekanism.common.integration.storagedrawer; + +import com.jaquadro.minecraft.storagedrawers.api.IStorageDrawersApi; +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; +import com.jaquadro.minecraft.storagedrawers.api.registry.IRecipeHandler; +import com.jaquadro.minecraft.storagedrawers.api.registry.IRecipeHandlerRegistry; +import mekanism.common.recipe.ShapedMekanismRecipe; +import mekanism.common.recipe.ShapelessMekanismRecipe; + +import net.minecraft.item.crafting.IRecipe; + +import java.util.List; + +public class StorageDrawerRecipeHandler +{ + private StorageDrawerRecipeHandler(){} + + public static void register() + { + IStorageDrawersApi api = StorageDrawersApi.instance(); + if(api == null) + { + return; + } + IRecipeHandlerRegistry recipeHandlerRegistry = api.recipeHandlerRegistry(); + recipeHandlerRegistry.registerRecipeHandler(ShapedMekanismRecipe.class, new ShapedMekanismRecipeHandler()); + recipeHandlerRegistry.registerRecipeHandler(ShapelessMekanismRecipe.class, new ShapelessMekanismRecipeHandler()); + } + + private static class ShapedMekanismRecipeHandler implements IRecipeHandler + { + @Override + public Object[] getInputAsArray (IRecipe recipe) { + return ((ShapedMekanismRecipe) recipe).getInput(); + } + + @Override + public List getInputAsList (IRecipe recipe) { + return null; + } + } + + private static class ShapelessMekanismRecipeHandler implements IRecipeHandler + { + @Override + public Object[] getInputAsArray (IRecipe recipe) { + return null; + } + + @Override + public List getInputAsList (IRecipe recipe) { + return ((ShapelessMekanismRecipe) recipe).getInput(); + } + } +}