diff --git a/src/projectzombie/init/Models.java b/src/projectzombie/init/Models.java index b6df280..2096cf6 100755 --- a/src/projectzombie/init/Models.java +++ b/src/projectzombie/init/Models.java @@ -116,6 +116,7 @@ public class Models public static final ModelGui UI_TEMPERATURE = new ModelGui(Resources.ATLAS.get("/gui/temperature.png"), new Vec2d(0.75, 0.75)); public static final ModelGui UI_WATER = new ModelGui(Resources.ATLAS.get("/gui/water.png"), new Vec2d(0.75, 0.75)); public static final ModelGui UI_ITEM_HOVER = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png")).setOpacity(0.25); + public static final ModelGui UI_TEXT_BG = new ModelGui(Resources.ATLAS.get("/gui/pixel_white.png")).setColor(0.5f, 0.5f, 0.5f); public static final ModelItem UI_SLOT_ARMOR_HELMET = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_helmet.png")); public static final ModelItem UI_SLOT_ARMOR_CHEST = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_chest.png")); diff --git a/src/projectzombie/inventory/recipe/Recipe.java b/src/projectzombie/inventory/recipe/Recipe.java index 4c6ce78..e1d2e10 100644 --- a/src/projectzombie/inventory/recipe/Recipe.java +++ b/src/projectzombie/inventory/recipe/Recipe.java @@ -4,10 +4,11 @@ import projectzombie.inventory.Inventory; import projectzombie.inventory.Crafting; import projectzombie.util.math.ItemStack; -public abstract class Recipe +public interface Recipe { - public abstract ItemStack getResult(); - public abstract boolean canCraft(Crafting tool); - public abstract boolean hasResourcesToCraft(Inventory inventory); - public abstract ItemStack craftResult(Inventory inventory); + public ItemStack getResult(); + public boolean canCraft(Crafting tool); + public boolean hasResourcesToCraft(Inventory inventory); + public ItemStack craftResult(Inventory inventory); + public ItemStack[] getIngredients(); } diff --git a/src/projectzombie/inventory/recipe/RecipeBasic.java b/src/projectzombie/inventory/recipe/RecipeBasic.java index e34c030..193011e 100644 --- a/src/projectzombie/inventory/recipe/RecipeBasic.java +++ b/src/projectzombie/inventory/recipe/RecipeBasic.java @@ -4,7 +4,7 @@ import projectzombie.inventory.Crafting; import projectzombie.inventory.Inventory; import projectzombie.util.math.ItemStack; -public class RecipeBasic extends Recipe +public class RecipeBasic implements Recipe { protected ItemStack[] stacks_required; protected Crafting[] tools_required; @@ -55,4 +55,9 @@ public class RecipeBasic extends Recipe return result.copy(); } + + @Override + public ItemStack[] getIngredients() { + return stacks_required; + } } diff --git a/src/projectzombie/menu/MenuInventoryBasic.java b/src/projectzombie/menu/MenuInventoryBasic.java index 3f27e4e..183ea91 100644 --- a/src/projectzombie/menu/MenuInventoryBasic.java +++ b/src/projectzombie/menu/MenuInventoryBasic.java @@ -19,13 +19,10 @@ public class MenuInventoryBasic extends MenuInventory { private GUIContainerSlider slider; private Inventory inventory; - private Crafting tool; public MenuInventoryBasic(Menu parent, Crafting tool) { super(parent); - this.tool = tool; - Recipe[] recipies = Recipies.getCraftableRecipies(tool); inventory = Main.player.getInventory(); @@ -39,7 +36,9 @@ public class MenuInventoryBasic extends MenuInventory { Recipe recipe = recipies[i]; - GUIRecipeCard slot = new GUIRecipeCard(inventory, slider, recipe, tool, new Vec2d(0, i*1.5)); + GUIRecipeCard slot = new GUIRecipeCard(inventory, slider, recipe, tool, new Vec2d(0, + Models.UI_SELECTION_BOX_BIG.getHeight() / 2 - + (i + 1) * Models.UI_LABEL_RECIPE.getHeight() * 36 / 34.0)); slider.add(slot); diff --git a/src/projectzombie/menu/gui/GUIItemHolder.java b/src/projectzombie/menu/gui/GUIItemHolder.java index 1a7bda0..813fa1e 100644 --- a/src/projectzombie/menu/gui/GUIItemHolder.java +++ b/src/projectzombie/menu/gui/GUIItemHolder.java @@ -5,6 +5,7 @@ import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.entity.EntityItem; +import projectzombie.init.Models; import projectzombie.model.Model; import projectzombie.text.Text; import projectzombie.util.math.ItemStack; @@ -23,22 +24,58 @@ public class GUIItemHolder implements GUIComponent @Override public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover) { + matrix = Matrix4.translate(mousePos.x, mousePos.y, 0); + if(!holding.isEmpty()) { - Model model = holding.item.getModel(holding.meta).getGuiModel(); - matrix = Matrix4.multiply(Matrix4.translate(mousePos.x - 0.425, mousePos.y - 0.425, 0), matrix); + Matrix4 holding_matrix = Matrix4.multiply(matrix, Matrix4.translate(-0.425, -0.425, 0)); - model.setModel(matrix); + Model model = holding.item.getModel(holding.meta).getGuiModel(); + + model.setModel(holding_matrix); model.render(); if(holding.count > 1) { - Matrix4 text_matrix = Matrix4.multiply(matrix, Matrix4.translate(-0.75 / 4, -0.75 / 4, 0)); + Matrix4 text_matrix = Matrix4.multiply(holding_matrix, Matrix4.translate(-0.75 / 4, -0.75 / 4, 0)); text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), text_matrix); Text.render("" + holding.count, text_matrix); } } + + if(hover != null || !holding.isEmpty()) + { + ItemStack stack; + + if(!holding.isEmpty()) { + stack = holding; + } else { + stack = hover.getItemStack(); + } + + if(!stack.isEmpty()) + { + String name = stack.item.getName(stack.meta); + + Matrix4 container_matrix = matrix; + + container_matrix = Matrix4.multiply(container_matrix, Matrix4.translate( + -0.4 * name.length() / 2, -1, 0)); + + Matrix4 text_matrix = container_matrix; + + text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), text_matrix); + container_matrix = Matrix4.multiply(container_matrix, Matrix4.translate(-0.2, -0.2, 0)); + container_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d( + (0.4 * (name.length() + 1)), 0.8, 0)), container_matrix); + + Models.UI_TEXT_BG.setModel(container_matrix); + Models.UI_TEXT_BG.render(); + + Text.render(name, text_matrix); + } + } } @Override @@ -73,7 +110,7 @@ public class GUIItemHolder implements GUIComponent public void onRightClick(Vec2d pos) { // Drop part of the holding item if the hover item doesn't exist - if(hover == null) + if(hover == null || this.hover.getter.isReadOnly()) { if(!holding.isEmpty()) { @@ -141,7 +178,7 @@ public class GUIItemHolder implements GUIComponent public void onMouseClick(Vec2d pos) { // Drop the holding item if the hover item doesn't exist - if(hover == null) + if(hover == null || this.hover.getter.isReadOnly()) { if(!holding.isEmpty()) { diff --git a/src/projectzombie/menu/gui/GUIItemSlot.java b/src/projectzombie/menu/gui/GUIItemSlot.java index b8f6cbb..4dff3f1 100644 --- a/src/projectzombie/menu/gui/GUIItemSlot.java +++ b/src/projectzombie/menu/gui/GUIItemSlot.java @@ -27,6 +27,10 @@ public class GUIItemSlot implements GUIComponent this.pos = pos; } + public Vec2d getPos() { + return pos; + } + public boolean isItemAllowed(ItemStack stack) { return getter.isAllowed(stack); } @@ -61,7 +65,7 @@ public class GUIItemSlot implements GUIComponent model.render(); } - if(checkMouseHover(mousePos) && canHover) + if(!getter.isReadOnly() && checkMouseHover(mousePos) && canHover) { double offset = (0.85 - hitboxSize) / 2; Matrix4 hover_matrix = Matrix4.multiply(matrix, Matrix4.translate(offset, offset, 0)); diff --git a/src/projectzombie/menu/gui/GUIItemSlotGetter.java b/src/projectzombie/menu/gui/GUIItemSlotGetter.java index bd3fa95..76ac25f 100644 --- a/src/projectzombie/menu/gui/GUIItemSlotGetter.java +++ b/src/projectzombie/menu/gui/GUIItemSlotGetter.java @@ -14,4 +14,8 @@ public interface GUIItemSlotGetter { public default boolean mustTakeAll() { return false; } + + public default boolean isReadOnly() { + return false; + } } diff --git a/src/projectzombie/menu/gui/GUIRecipeCard.java b/src/projectzombie/menu/gui/GUIRecipeCard.java index e48814e..ae6735e 100644 --- a/src/projectzombie/menu/gui/GUIRecipeCard.java +++ b/src/projectzombie/menu/gui/GUIRecipeCard.java @@ -9,7 +9,7 @@ import projectzombie.inventory.recipe.Recipe; import projectzombie.model.ModelGui; import projectzombie.util.math.ItemStack; -public class GUIRecipeCard implements GUIContainer, GUIItemSlotGetter +public class GUIRecipeCard implements GUIContainer { private static final ModelGui LABEL = Models.UI_LABEL_RECIPE; @@ -17,6 +17,7 @@ public class GUIRecipeCard implements GUIContainer, GUIItemSlotGetter private Recipe recipe; private GUIContainer gui; private GUIItemSlot result_slot; + private GUIItemSlot[] ingredients; private Inventory inventory; private Crafting tool; @@ -28,10 +29,77 @@ public class GUIRecipeCard implements GUIContainer, GUIItemSlotGetter this.inventory = inventory; this.tool = tool; - result_slot = new GUIItemSlot(1.5, true, this); + 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() * 102 / 128.0, - Models.UI_LABEL_RECIPE.getHeight() * 8 / 32.0))); + Models.UI_LABEL_RECIPE.getWidth() * 103 / 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