Last active
August 29, 2015 14:10
-
-
Save maxov/f05bb86b625231267d55 to your computer and use it in GitHub Desktop.
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
// 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