Update Storage Drawers API

This commit is contained in:
Raoul Van den Berge
2016-12-03 20:24:41 +01:00
parent 9ab9a2f56f
commit 89f41485d3
20 changed files with 52 additions and 119 deletions

View File

@@ -2,7 +2,7 @@
### 1.3
- Port to Minecraft 1.11 (raoulvdberge, way2muchnoise)
- Removed RF support (raoulvdberge)
- Removed RF support, use Forge Energy instead (raoulvdberge)
- Removed IC2 support (raoulvdberge)
- Removed MCMultiPart support (will be re-added as soon as MCMultiPart for MC 1.11 is available) (raoulvdberge)

View File

@@ -6,7 +6,7 @@ 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.
* <p>
*
* This event is also called when the drawer is changed to empty.
*/
public class DrawerPopulatedEvent extends Event {

View File

@@ -1,34 +0,0 @@
package com.jaquadro.minecraft.storagedrawers.api.inventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
public interface IDrawerInventory extends ISidedInventory {
/**
* Gets a drawer's group slot index from an IInventory slot index.
*
* @param inventorySlot An IInventory slot index returned from getInventorySlot.
*/
int getDrawerSlot(int inventorySlot);
/**
* Gets an IInventory slot index suitable for operations for the given type.
*
* @param drawerSlot The index of the drawer within its group.
* @param type The type of IInventory slot to return an index for.
*/
int getInventorySlot(int drawerSlot, SlotType type);
/**
* Gets the type associated with a given IInventory slot index.
*
* @param inventorySlot An IInventory slot index returned from getInventorySlot.
*/
SlotType getInventorySlotType(int inventorySlot);
boolean canInsertItem(int slot, ItemStack stack);
boolean canExtractItem(int slot, ItemStack stack);
boolean syncInventoryIfNeeded();
}

View File

@@ -1,15 +0,0 @@
package com.jaquadro.minecraft.storagedrawers.api.inventory;
import net.minecraft.item.ItemStack;
public interface IInventoryAdapter {
ItemStack getInventoryStack(SlotType slotType);
void setInStack(ItemStack stack);
void setOutStack(ItemStack stack);
void syncInventory();
boolean syncInventoryIfNeeded();
}

View File

@@ -1,18 +0,0 @@
package com.jaquadro.minecraft.storagedrawers.api.inventory;
/**
* Classifies different IInventory slots according to how they should be used.
*/
public enum SlotType {
/**
* An inventory slot for input-only operations; stack sizes artificially held low.
*/
INPUT,
/**
* An inventory slot for output-only operations; stack sizes artificially held high.
*/
OUTPUT;
public static final SlotType[] values = values();
}

View File

@@ -1,5 +0,0 @@
@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|inventory", apiVersion = StorageDrawersApi.VERSION)
package com.jaquadro.minecraft.storagedrawers.api.inventory;
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
import net.minecraftforge.fml.common.API;

View File

@@ -23,6 +23,8 @@ public interface IPackBlockFactory
/**
* Hides block from NEI if NEI is active.
* <p>
* Registers block metadata from an initialized DataResolver with Storage Drawers.
*/
//void hideBlock (String blockID);

View File

@@ -2,6 +2,8 @@ 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
@@ -14,5 +16,6 @@ public interface IIngredientHandler {
* @param object An ingredient object.
* @return An ItemStack for the given ingredient.
*/
@Nonnull
ItemStack getItemStack(Object object);
}

View File

@@ -13,7 +13,7 @@ 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.
* <p>
*
* 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}.
@@ -25,7 +25,7 @@ public interface IRecipeHandler {
* 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.
* <p>
*
* 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}.

View File

@@ -2,6 +2,8 @@ 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"),
@@ -55,6 +57,7 @@ public enum EnumBasicDrawer implements IDrawerGeometry, IStringSerializable {
}
@Override
@Nonnull
public String getName() {
return name;
}

View File

@@ -3,29 +3,16 @@ 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();
/**
* Gets an ItemStack initialized to the number of items stored in this drawer.
* The returned ItemStack is guaranteed to be a new copy and can be used for any purpose. Does not affect drawer contents.
*/
ItemStack getStoredItemCopy();
/**
* 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.
* @deprecated setStoredItem may redirect its set to another IDrawer, so use setStoredItemRedir instead.
*/
@Deprecated
void setStoredItem(ItemStack itemPrototype, int amount);
/**
* Sets the type of the stored item and initializes it to the given amount. Any existing item will be replaced.
*
@@ -33,7 +20,7 @@ public interface IDrawer {
* @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 setStoredItemRedir(ItemStack itemPrototype, int amount);
IDrawer setStoredItem(@Nonnull ItemStack itemPrototype, int amount);
/**
* Gets the number of items stored in this drawer.
@@ -59,7 +46,7 @@ public interface IDrawer {
*
* @param itemPrototype The item type to query.
*/
int getMaxCapacity(ItemStack itemPrototype);
int getMaxCapacity(@Nonnull ItemStack itemPrototype);
/**
* Gets the number of items that could still be added to this drawer before it is full.
@@ -73,7 +60,7 @@ public interface IDrawer {
/**
* Gets whether or not an item of the given type and data can be stored in this drawer.
* <p>
*
* 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.
@@ -81,17 +68,17 @@ public interface IDrawer {
*
* @param itemPrototype An ItemStack representing the type, metadata, and tags of an item.
*/
boolean canItemBeStored(ItemStack itemPrototype);
boolean canItemBeStored(@Nonnull ItemStack itemPrototype);
/**
* Gets whether or not an item of the given type and data can be extracted from this drawer.
* <p>
*
* 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(ItemStack itemPrototype);
boolean canItemBeExtracted(@Nonnull ItemStack itemPrototype);
/**
* Gets whether or not the drawer has items.
@@ -109,7 +96,6 @@ public interface IDrawer {
/**
* 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.
*/

View File

@@ -1,7 +1,5 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
public interface IDrawerGroup {
/**
* Gets the number of drawers contained within this group.
@@ -23,7 +21,5 @@ public interface IDrawerGroup {
*/
boolean isDrawerEnabled(int slot);
IDrawerInventory getDrawerInventory();
boolean markDirtyIfNeeded();
}

View File

@@ -3,10 +3,13 @@ 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, ItemStack stack, int count);
int putItemsIntoSlot(int slot, @Nonnull ItemStack stack, int count);
int interactPutCurrentItemIntoSlot(int slot, EntityPlayer player);

View File

@@ -7,7 +7,7 @@ package com.jaquadro.minecraft.storagedrawers.api.storage;
public interface IFractionalDrawer extends IDrawer {
/**
* Gets the storage ratio between the held item and the most compressed item within the drawer group.
* <p>
*
* 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.
*/

View File

@@ -2,16 +2,18 @@ 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<Integer> enumerateDrawersForInsertion(ItemStack stack, boolean strict);
Iterable<Integer> 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<Integer> enumerateDrawersForExtraction(ItemStack stack, boolean strict);
Iterable<Integer> enumerateDrawersForExtraction(@Nonnull ItemStack stack, boolean strict);
}

View File

@@ -13,28 +13,24 @@ public interface IProtectable {
/**
* 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);

View File

@@ -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);
}

View File

@@ -9,7 +9,6 @@ public interface ISealable {
/**
* Sets whether or not the drawer is currently sealed.
*
* @return false if the operation is not supported, true otherwise.
*/
boolean setIsSealed(boolean state);

View File

@@ -9,7 +9,6 @@ public interface IShroudable {
/**
* Sets whether or not the drawer is currently shrouded.
*
* @return false if the operation is not supported, true otherwise.
*/
boolean setIsShrouded(boolean state);

View File

@@ -58,7 +58,7 @@ public class StorageItemDrawer extends StorageItemExternal {
public static NonNullList<ItemStack> getStacks(IDrawer drawer) {
if (!drawer.isEmpty() && drawer.getStoredItemCount() > 0) {
return NonNullList.withSize(1, drawer.getStoredItemCopy());
return NonNullList.withSize(1, ItemHandlerHelper.copyStackWithSize(drawer.getStoredItemPrototype(), drawer.getStoredItemCount()));
}
return RSUtils.emptyNonNullList();
@@ -73,7 +73,7 @@ public class StorageItemDrawer extends StorageItemExternal {
if (!simulate && remainingSpace > 0) {
if (drawer.isEmpty()) {
drawer.setStoredItemRedir(stack, inserted);
drawer.setStoredItem(stack, inserted);
} else {
drawer.setStoredItemCount(stored + inserted);
}