Skip to content

Instantly share code, notes, and snippets.

@maxov
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxov/f05bb86b625231267d55 to your computer and use it in GitHub Desktop.
Save maxov/f05bb86b625231267d55 to your computer and use it in GitHub Desktop.
// simply a marker
interface Carrier {
Inventory getInventory();
}
interface Inventory {
Collection<ItemStack> getItems();
}
interface ItemList extends Inventory, List<ItemStack> {
}
interface ItemGrid extends Inventory, Map<Integer, ItemStack> {
ItemStack get(Vector2i pos);
void set(Vector2i pos, ItemStack stack)
}
// simple getter/setter, no fluff
interface ItemSlot extends Inventory {
ItemStack get();
void set(ItemStack newItem);
ItemStack split(int count);
}
interface View<I, O> {
List<O> get(I input);
List<O> get(List<I> input);
<P> View<I, P> andThen(View<O, P> that);
}
interface InventoryView<O> extends View<Inventory, O> { }
interface ViewFuel extends InventoryView<ItemSlot> { }
interface ViewCraftingInput extends InventoryView<Inventory> {}
interface ViewResult extends InventoryView<ItemSlot> {}
interface ViewMatrix extends InventoryView<ItemGrid> {}
class MyPlugin {
@Inject ViewFuel fuel;
// or
ViewCraftingInput crafting = Views.of(ViewCraftingInput.class);
ViewMatrix matrix = Views.of(ViewMatrix.class);
InventoryView<ItemGrid> comp = crafting.andThen(matrix);
{
Inventory myInventory = myCarrier.getInventory();
List<ItemGrid> invfuel = comp.get(myInventory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment