forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of new inventory API.
- Loading branch information
Showing
7 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.minecraftforge.inventory; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
/** | ||
* An inventory with custom insert and extract methods, similar to Buildcraft's | ||
* ISpecialInventory. | ||
* | ||
* This is the most general interface. Any IInventory or ILinearInventory can be | ||
* wrapped as an ICustomInventory, but not vice versa. | ||
*/ | ||
public interface ICustomInventory extends IForgeInventory { | ||
|
||
/** | ||
* Attempts to insert some items into this inventory. | ||
* | ||
* @param item | ||
* The item to insert. The stack size is ignored. | ||
* @param amount | ||
* The number of items to insert. Must be at least 1. | ||
* @param simulate | ||
* If true, then the inventory will not be updated. The return | ||
* value must be the same as if simulate was false. | ||
* @throws IllegalArgumentException | ||
* If amount <= 0 | ||
* @throws NullPointerException | ||
* If item == null | ||
* @return The number of items that could not be inserted. | ||
*/ | ||
public int insert(ItemStack item, int amount, boolean simulate) throws IllegalArgumentException, NullPointerException; | ||
|
||
/** | ||
* Attempts to extract some items from this inventory. | ||
* | ||
* @param filter | ||
* A stack filter that defines which items can be extracted. | ||
* @param amount | ||
* The maximum number of items to extract. | ||
* @param simulate | ||
* If true, then the inventory will not be updated. The return | ||
* value must be the same as if simulate was false. | ||
* @throws IllegalArgumentException | ||
* If amount <= 0 | ||
* @throws NullPointerException | ||
* If filter == null | ||
* @return The stack extracted. If no items were extracted, this must be | ||
* null. The stack size must be less than or equal to amount. | ||
*/ | ||
public ItemStack extract(IStackFilter filter, int amount, boolean simulate) throws IllegalArgumentException, NullPointerException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.minecraftforge.inventory; | ||
|
||
/** | ||
* Marker interface for different types of inventories. Implementations of this | ||
* should implement either ICustomInventory or ILinearInventory or both. | ||
*/ | ||
public interface IForgeInventory { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
common/net/minecraftforge/inventory/IForgeInventoryTile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.minecraftforge.inventory; | ||
|
||
import net.minecraftforge.common.ForgeDirection; | ||
|
||
/** | ||
* This interface is implemented by tile entities that wish to use the new Forge | ||
* inventory system. | ||
*/ | ||
public interface IForgeInventoryTile { | ||
IForgeInventory getInventory(ForgeDirection side); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.minecraftforge.inventory; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
/** | ||
* A slot in an ILinearInventory. This is an interface as different slots may | ||
* have different properties. | ||
*/ | ||
public interface IInventorySlot { | ||
/** | ||
* Gets the item stack in the slot. | ||
* | ||
* It is not acceptable to edit the returned item stack while it is still | ||
* contained in this slot. Some implementations might return a defensive | ||
* copy, so this will have unpredictable results. | ||
* | ||
* @return The current contents of this slot. | ||
*/ | ||
ItemStack getStack(); | ||
|
||
/** | ||
* Sets the item stack in the slot. | ||
* | ||
* If the stack size is larger than the slot can hold, this method returns | ||
* false and doesn't update the slot's contents. The slot is not required to | ||
* check the item's maximum stack size, only the slot's maximum stack size. | ||
* | ||
* Slots can also refuse to accept stacks for any other reason - for example | ||
* they may only be able to hold certain items. | ||
* | ||
* If is == null, this method must return true. | ||
* | ||
* If this method returns false, the contents of the slot are unchanged. | ||
* | ||
* @param is | ||
* The new stack. | ||
* @param simulate | ||
* If true, then don't actually update the slot - just return | ||
* true or false depending on whether the set would've succeeded. | ||
* @return True if the slot now contains the stack (or it would've if | ||
* simulate was false). | ||
*/ | ||
boolean setStack(ItemStack is, boolean simulate); | ||
|
||
/** | ||
* Gets the maximum size of stacks that this slot can hold. | ||
* | ||
* @return The maximum stack size | ||
*/ | ||
int getMaximumStackSize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.minecraftforge.inventory; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
/** | ||
* An inventory that can be accessed as an array of slots, like a chest. This | ||
* doesn't make sense for all inventories, such as barrels. | ||
* | ||
* This is similar to vanilla's IInventory but allows slots to be completely | ||
* independent of each other - for example, they can have different maximum | ||
* stack sizes. | ||
*/ | ||
public interface ILinearInventory extends IForgeInventory { | ||
/** | ||
* @return The number of slots in this inventory. | ||
*/ | ||
int getNumSlots(); | ||
|
||
/** | ||
* @param index | ||
* The slot index. Valid slot indices are from 0 to | ||
* getNumSlots()-1 inclusive. | ||
* @return The slot in this inventory with the given index. | ||
* @throws IllegalArgumentException | ||
* If the slot index is out of range. | ||
*/ | ||
IInventorySlot getSlot(int index) throws IllegalArgumentException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.minecraftforge.inventory; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public interface IStackFilter { | ||
/** | ||
* Returns true if the given item matches this filter. The stack size is | ||
* ignored. | ||
* | ||
* @param item | ||
* The item to match. | ||
* @return True if the item matches the filter. | ||
*/ | ||
boolean matchesItem(ItemStack item); | ||
|
||
/** | ||
* A default filter that matches any item. | ||
*/ | ||
static final IStackFilter MATCH_ANY = new IStackFilter() { | ||
@Override | ||
public boolean matchesItem(ItemStack item) | ||
{ | ||
return true; | ||
} | ||
}; | ||
} |
Oops, something went wrong.