package projectzombie.menu.gui; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec2d; import projectzombie.init.Models; import projectzombie.inventory.Crafting; import projectzombie.inventory.Inventory; import projectzombie.inventory.recipe.Recipe; import projectzombie.model.ModelGui; import projectzombie.util.math.ItemStack; public class GUIRecipeCard implements GUIContainer { private static final ModelGui LABEL = Models.UI_LABEL_RECIPE; private Vec2d pos; private Recipe recipe; private GUIContainer gui; private GUIItemSlot result_display_slot; private GUIItemSlot result_slot; private GUIItemSlot[] ingredients; private Inventory inventory; private Crafting tool; public GUIRecipeCard(Inventory inventory, GUIContainer gui, Recipe recipe, Crafting tool, Vec2d pos) { this.gui = gui; this.recipe = recipe; this.pos = pos; this.inventory = inventory; this.tool = tool; result_slot = new GUIItemSlot(1.5, true, new GUIItemSlotGetter() { @Override public void setItemStack(ItemStack stack) { } @Override public boolean isAllowed(ItemStack stack) { return false; } @Override public ItemStack getItemStack() { return (recipe.canCraft(tool) && recipe.hasResourcesToCraft(inventory)) ? recipe.getResult().copy() : ItemStack.getEmpty(); } @Override public boolean mustTakeAll() { return true; } @Override public void onRemoveItemStack() { if(recipe.canCraft(tool) && recipe.hasResourcesToCraft(inventory)) { recipe.craftResult(inventory); } } }); result_slot.setPos(pos.add(new Vec2d( Models.UI_LABEL_RECIPE.getWidth() * 103 / 128.0 + 0.25, Models.UI_LABEL_RECIPE.getHeight() * 9 / 32.0 + 0.25))); result_display_slot = new GUIItemSlotReadonly(1, true, recipe.getResult()); result_display_slot.setPos(pos.add(new Vec2d( Models.UI_LABEL_RECIPE.getWidth() * 87 / 128.0 + 0.25, Models.UI_LABEL_RECIPE.getHeight() * 9 / 32.0 + 0.25))); ItemStack[] ingredients = recipe.getIngredients(); this.ingredients = new GUIItemSlot[ingredients.length]; for(int i=0;i