Skip to content

Instantly share code, notes, and snippets.

@copygirl
Last active December 14, 2015 05:29
Show Gist options
  • Save copygirl/5035630 to your computer and use it in GitHub Desktop.
Save copygirl/5035630 to your computer and use it in GitHub Desktop.
package net.mcft.copy.betterstorage.api;
import net.minecraft.item.ItemStack;
public interface IItemFilter {
/**
* Checks to see if the filter accepts the ItemStack.
* Returns how many items to accept. The ItemStack may
* have a stack size above its usual limit.
* <p>
* In the case of a ICrateStorage's extractItems
* function, returning more than 0 but less than the
* supplied ItemStack stack size should cause accept()
* to be called again with the remaining items.
* Returning -1 signalizes that the filter is done and
* doesn't want any more items.
*
* @param stack
* The ItemStack to check.
* @return
* Number if items to accept from the ItemStack.
*/
public int accept(ItemStack stack);
}
package net.mcft.copy.betterstorage.api;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
public interface ICrateStorage {
/**
* Returns a unique inventory identifier for that side.
* When this identifier matches another inventory's or
* side's identifier, they should be considered the same.
*
* @param side
* The global side. UNKNOWN to get the identifier for
* the whole inventory.
*
* @return
* The unique identifier for that side.
*/
public Object getInventoryIdentifier(ForgeDirection side);
/*
* Sample implementation for simple inventory:
* return this;
*
* Sample implementation for sided inventory:
* private Object[] sidedIdentifiers;
* private void setupIdentifiers() { // Called in constructor
* Object bottom = new Object();
* Object top = new Object();
* Object side = new Object();
* sidedIdentifiers = { bottom, top, side, side, side, side };
* }
* public Object getInventoryIdentifier(ForgeDirection side) {
* if (side == ForgeDirection.UNKNOWN) return this;
* return sidedIdentifiers[side.ordinal()];
* }
*/
/**
* Returns all items in the inventory, accessible or not.
* The returned list may contain null values and
* ItemStacks with stack sizes above their usual limit.
* <p>
* Do not directly modify the items in the list returned.
* <p>
* Note that if the inventory is modified, the list may
* or may not change as well.
*
* @param side
* The global side. UNKNOWN if the whole inventory
* is requested.
*
* @return
* A list of items in the inventory.
*/
public List<ItemStack> getContents(ForgeDirection side);
/*
* Sample implementation for simple inventory:
* return Arrays.asList(contents);
*
* Sample implementation for sided inventory:
* List<ItemStack> items = Arrays.asList(contents);
* if (side == ForgeDirection.UNKNOWN) return items;
* int start = getStartInventorySide(side);
* int size = getSizeInventorySide(side);
* return items.subList(start, size - start);
*/
/**
* Returns the number of items of a specific type (damage
* and NBT data sensitive) in the inventory.
*
* @param side
* The global side. UNKNOWN if it should check the
* whole inventory.
* @param identifier
* The type of item to count. Stack size doesn't
* matter.
*
* @return Number of items of that type.
*/
public int getItemCount(ForgeDirection side, ItemStack identifier);
/*
* Sample implementation for simple and sided inventory:
* int count = 0;
* for (ItemStack item : getContents(side))
* if (item != null && item.isItemEqual(identifier) &&
* Item.areItemStackTagsEqual(item, identifier))
* count += item.stackSize;
* return count;
*/
/**
* Returns the space left for a specific type of item
* (damage and NBT data sensitive) in this inventory.
* When there's space for the item, a machine should also
* be able to insert them using insertItems().
*
* @param side
* The global side. UNKNOWN if it should check for
* space in the whole inventory, but sided
* inventories may not accept this.
* @param identifier
* The type of item for which to check space. Stack
* size doesn't matter.
*
* @return
* The space left for the item type.
*/
public int spaceForItem(ForgeDirection side, ItemStack identifier);
/**
* Tries to insert items to the inventory, returns how
* many items couldn't be added. The stack may have a
* size above its usual limit.
* <p>
* The implementation mustn't modify or keep a reference
* to the supplied stack, so the caller can still use it.
*
* @param side
* The global side. UNKNOWN is unspecified, sided
* inventories might not accept it, use a default sub
* inventory or the whole inventory.
* @param stack
* The items to be inserted.
*
* @return
* The number of items rejected, 0 if successful.
*/
public int insertItems(ForgeDirection side, ItemStack stack);
/**
* Tries to extract items which match a specific filter,
* returns the items extracted.
* <p>
* When the ItemFilter accepts more than 0 but less than
* the supplied ItemStack stack size, the implementation
* should rerun the filter on the remaining items.
* When the ItemFilter returns -1, it's signalizes that
* it's done and doesn't want any more items.
*
* @param side
* The global side. UNKNOWN is unspecified, sided
* inventories might not accept it, use a default sub
* inventory or the whole inventory.
* @param filter
* The item filter.
* @param amount
* The amount of items to extract.
*
* @return
* The items extracted.
*/
public List<ItemStack> extractItems(ForgeDirection side, IItemFilter filter);
}
package net.mcft.copy.betterstorage.api;
import net.minecraft.item.ItemStack;
public interface IItemFilter {
/**
* Checks to see if the filter accepts the ItemStack.
* Returns how many items to accept. The ItemStack may
* have a stack size above its usual limit.
* <p>
* In the case of a ICrateStorage's extractItems
* function, returning more than 0 but less than the
* supplied ItemStack stack size should cause accept()
* to be called again with the remaining items.
* Returning -1 signalizes that the filter is done and
* doesn't want any more items.
*
* @param stack
* The ItemStack to check.
* @return
* Number if items to accept from the ItemStack.
*/
public int accept(ItemStack stack);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment