diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 11:53:57 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 11:53:57 -0500 |
| commit | b09f774d422263ce15b97d6d0804beddf856176d (patch) | |
| tree | e542258481d7496b15679f3c329ef9e087c7d8fc /src/main/java/io/github/moulberry/notenoughupdates/recipes | |
| parent | 22cb02adbeb24b7ec98f843bcaba99cebe3e4f03 (diff) | |
| download | notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.gz notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.tar.bz2 notenoughupdates-b09f774d422263ce15b97d6d0804beddf856176d.zip | |
feat: improve formating :)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/recipes')
8 files changed, 891 insertions, 823 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java index 21823792..d0b464f6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingOverlay.java @@ -20,121 +20,131 @@ import java.util.function.BiConsumer; public class CraftingOverlay { - private final NEUManager manager; - private CraftingRecipe currentRecipe = null; - - public CraftingOverlay(NEUManager manager) { - this.manager = manager; - MinecraftForge.EVENT_BUS.register(this); - } - - public void setShownRecipe(CraftingRecipe recipe) { - currentRecipe = recipe; - } - - private void forEachSlot(ContainerChest chest, BiConsumer<Ingredient, Slot> block) { - for (int i = 0; i < 9; i++) { - Ingredient recipeIngredient = currentRecipe.getInputs()[i]; - Slot slot = chest.inventorySlots.get(10 + 9 * (i / 3) + (i % 3)); - block.accept(recipeIngredient, slot); - } - } - - private void forEachHoveredSlot(GuiChest gui, ContainerChest chest, int mouseX, int mouseY, BiConsumer<Ingredient, Slot> block) { - forEachSlot(chest, (recipeIngredient, slot) -> { - if (Utils.isWithinRect( - mouseX, mouseY, - slot.xDisplayPosition + gui.guiLeft, - slot.yDisplayPosition + gui.guiTop, - 16, 16)) - block.accept(recipeIngredient, slot); - }); - } - - private void runIfCraftingOverlayIsPresent(Gui gui, BiConsumer<GuiChest, ContainerChest> block) { - if (currentRecipe == null) return; - if (!(gui instanceof GuiChest)) return; - GuiChest guiChest = (GuiChest) gui; - ContainerChest chest = (ContainerChest) guiChest.inventorySlots; - IInventory chestInventory = chest.getLowerChestInventory(); - if (!"Craft Item".equals(chestInventory.getDisplayName().getUnformattedText())) return; - block.accept(guiChest, chest); - } - - @SubscribeEvent - public void onGuiOpen(GuiOpenEvent event) { - currentRecipe = null; - } - - @SubscribeEvent - public void onRender(GuiScreenEvent.DrawScreenEvent.Post event) { - runIfCraftingOverlayIsPresent(event.gui, (guiChest, chest) -> { - renderSlots(guiChest, chest); - if (currentRecipe.getCraftText() != null) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - fontRenderer.drawStringWithShadow( - currentRecipe.getCraftText(), - Utils.peekGuiScale().getScaledWidth() / 2f - fontRenderer.getStringWidth(currentRecipe.getCraftText()) / 2f, - guiChest.guiTop - 15f, 0x808080); - } - renderTooltip(guiChest, chest); - }); - } - - @SubscribeEvent - public void onKeyDown(GuiScreenEvent.KeyboardInputEvent.Pre event) { - if (!Keyboard.getEventKeyState() || (Keyboard.getEventKey() != Keyboard.KEY_U && Keyboard.getEventKey() != Keyboard.KEY_R)) - return; - runIfCraftingOverlayIsPresent(event.gui, (guiChest, chest) -> { - int mouseX = Utils.getMouseX(); - int mouseY = Utils.getMouseY(); - - forEachHoveredSlot(guiChest, chest, mouseX, mouseY, (recipeIngredient, slot) -> { - if (slot.getStack() == null && recipeIngredient != null) { - if (Keyboard.getEventKey() == Keyboard.KEY_R) - manager.showRecipe(recipeIngredient.getInternalItemId()); - if (Keyboard.getEventKey() == Keyboard.KEY_U) - manager.displayGuiItemRecipe(recipeIngredient.getInternalItemId(), null); - } - }); - }); - } - - private void renderTooltip(GuiChest guiChest, ContainerChest chest) { - int mouseX = Utils.getMouseX(); - int mouseY = Utils.getMouseY(); - forEachHoveredSlot(guiChest, chest, mouseX, mouseY, (recipeIngredient, slot) -> { - ItemStack actualItem = slot.getStack(); - if (actualItem == null && recipeIngredient != null) { - Utils.drawHoveringText( - recipeIngredient.getItemStack().getTooltip(Minecraft.getMinecraft().thePlayer, false), - mouseX, mouseY, - Utils.peekGuiScale().getScaledWidth(), Utils.peekGuiScale().getScaledHeight(), -1, - Minecraft.getMinecraft().fontRendererObj); - } - }); - } - - private void renderSlots(GuiChest guiChest, ContainerChest chest) { - forEachSlot(chest, (recipeIngredient, slot) -> { - ItemStack actualItem = slot.getStack(); - if (actualItem != null && (recipeIngredient == null || - !recipeIngredient.getInternalItemId().equals(manager.getInternalNameForItem(actualItem)) || - actualItem.stackSize < recipeIngredient.getCount())) { - drawItemStack(guiChest, slot, actualItem); - } - if (recipeIngredient != null && actualItem == null) { - drawItemStack(guiChest, slot, recipeIngredient.getItemStack()); - } - }); - } - - private void drawItemStack(GuiChest gui, Slot slot, ItemStack item) { - int slotX = slot.xDisplayPosition + gui.guiLeft; - int slotY = slot.yDisplayPosition + gui.guiTop; - Gui.drawRect(slotX, slotY, slotX + 16, slotY + 16, 0x64ff0000); - if (item != null) - Utils.drawItemStack(item, slotX, slotY); - } + private final NEUManager manager; + private CraftingRecipe currentRecipe = null; + + public CraftingOverlay(NEUManager manager) { + this.manager = manager; + MinecraftForge.EVENT_BUS.register(this); + } + + public void setShownRecipe(CraftingRecipe recipe) { + currentRecipe = recipe; + } + + private void forEachSlot(ContainerChest chest, BiConsumer<Ingredient, Slot> block) { + for (int i = 0; i < 9; i++) { + Ingredient recipeIngredient = currentRecipe.getInputs()[i]; + Slot slot = chest.inventorySlots.get(10 + 9 * (i / 3) + (i % 3)); + block.accept(recipeIngredient, slot); + } + } + + private void forEachHoveredSlot( + GuiChest gui, + ContainerChest chest, + int mouseX, + int mouseY, + BiConsumer<Ingredient, Slot> block + ) { + forEachSlot(chest, (recipeIngredient, slot) -> { + if (Utils.isWithinRect( + mouseX, mouseY, + slot.xDisplayPosition + gui.guiLeft, + slot.yDisplayPosition + gui.guiTop, + 16, 16 + )) + block.accept(recipeIngredient, slot); + }); + } + + private void runIfCraftingOverlayIsPresent(Gui gui, BiConsumer<GuiChest, ContainerChest> block) { + if (currentRecipe == null) return; + if (!(gui instanceof GuiChest)) return; + GuiChest guiChest = (GuiChest) gui; + ContainerChest chest = (ContainerChest) guiChest.inventorySlots; + IInventory chestInventory = chest.getLowerChestInventory(); + if (!"Craft Item".equals(chestInventory.getDisplayName().getUnformattedText())) return; + block.accept(guiChest, chest); + } + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + currentRecipe = null; + } + + @SubscribeEvent + public void onRender(GuiScreenEvent.DrawScreenEvent.Post event) { + runIfCraftingOverlayIsPresent(event.gui, (guiChest, chest) -> { + renderSlots(guiChest, chest); + if (currentRecipe.getCraftText() != null) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + fontRenderer.drawStringWithShadow( + currentRecipe.getCraftText(), + Utils.peekGuiScale().getScaledWidth() / 2f - fontRenderer.getStringWidth(currentRecipe.getCraftText()) / 2f, + guiChest.guiTop - 15f, 0x808080 + ); + } + renderTooltip(guiChest, chest); + }); + } + + @SubscribeEvent + public void onKeyDown(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if (!Keyboard.getEventKeyState() || + (Keyboard.getEventKey() != Keyboard.KEY_U && Keyboard.getEventKey() != Keyboard.KEY_R)) + return; + runIfCraftingOverlayIsPresent(event.gui, (guiChest, chest) -> { + int mouseX = Utils.getMouseX(); + int mouseY = Utils.getMouseY(); + + forEachHoveredSlot(guiChest, chest, mouseX, mouseY, (recipeIngredient, slot) -> { + if (slot.getStack() == null && recipeIngredient != null) { + if (Keyboard.getEventKey() == Keyboard.KEY_R) + manager.showRecipe(recipeIngredient.getInternalItemId()); + if (Keyboard.getEventKey() == Keyboard.KEY_U) + manager.displayGuiItemRecipe(recipeIngredient.getInternalItemId(), null); + } + }); + }); + } + + private void renderTooltip(GuiChest guiChest, ContainerChest chest) { + int mouseX = Utils.getMouseX(); + int mouseY = Utils.getMouseY(); + forEachHoveredSlot(guiChest, chest, mouseX, mouseY, (recipeIngredient, slot) -> { + ItemStack actualItem = slot.getStack(); + if (actualItem == null && recipeIngredient != null) { + Utils.drawHoveringText( + recipeIngredient.getItemStack().getTooltip(Minecraft.getMinecraft().thePlayer, false), + mouseX, mouseY, + Utils.peekGuiScale().getScaledWidth(), Utils.peekGuiScale().getScaledHeight(), -1, + Minecraft.getMinecraft().fontRendererObj + ); + } + }); + } + + private void renderSlots(GuiChest guiChest, ContainerChest chest) { + forEachSlot(chest, (recipeIngredient, slot) -> { + ItemStack actualItem = slot.getStack(); + if (actualItem != null && (recipeIngredient == null || + !recipeIngredient.getInternalItemId().equals(manager.getInternalNameForItem(actualItem)) || + actualItem.stackSize < recipeIngredient.getCount())) { + drawItemStack(guiChest, slot, actualItem); + } + if (recipeIngredient != null && actualItem == null) { + drawItemStack(guiChest, slot, recipeIngredient.getItemStack()); + } + }); + } + + private void drawItemStack(GuiChest gui, Slot slot, ItemStack item) { + int slotX = slot.xDisplayPosition + gui.guiLeft; + int slotY = slot.yDisplayPosition + gui.guiTop; + Gui.drawRect(slotX, slotY, slotX + 16, slotY + 16, 0x64ff0000); + if (item != null) + Utils.drawItemStack(item, slotX, slotY); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java index 082c1ad8..576cbbd4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/CraftingRecipe.java @@ -17,130 +17,130 @@ import java.util.Set; public class CraftingRecipe implements NeuRecipe { - public static final ResourceLocation BACKGROUND = new ResourceLocation("textures/gui/container/crafting_table.png"); - - private static final int EXTRA_STRING_X = 132; - private static final int EXTRA_STRING_Y = 25; - - private final NEUManager manager; - private final Ingredient[] inputs; - private final String extraText; - private final Ingredient outputIngredient; - private List<RecipeSlot> slots; - - public CraftingRecipe(NEUManager manager, Ingredient[] inputs, Ingredient output, String extra) { - this.manager = manager; - this.inputs = inputs; - this.outputIngredient = output; - this.extraText = extra; - if (inputs.length != 9) - throw new IllegalArgumentException("Cannot construct crafting recipe with non standard crafting grid size"); - } - - @Override - public Set<Ingredient> getIngredients() { - Set<Ingredient> ingredients = Sets.newHashSet(inputs); - ingredients.remove(null); - return ingredients; - } - - @Override - public boolean hasVariableCost() { - return false; - } - - @Override - public Set<Ingredient> getOutputs() { - return Collections.singleton(getOutput()); - } - - public Ingredient getOutput() { - return outputIngredient; - } - - public Ingredient[] getInputs() { - return inputs; - } - - - @Override - public List<RecipeSlot> getSlots() { - if (slots != null) return slots; - slots = new ArrayList<>(); - for (int x = 0; x < 3; x++) { - for (int y = 0; y < 3; y++) { - Ingredient input = inputs[x + y * 3]; - if (input == null) continue; - ItemStack item = input.getItemStack(); - if (item == null) continue; - slots.add(new RecipeSlot(30 + x * GuiItemRecipe.SLOT_SPACING, 17 + y * GuiItemRecipe.SLOT_SPACING, item)); - } - } - slots.add(new RecipeSlot(124, 35, outputIngredient.getItemStack())); - return slots; - } - - public String getCraftText() { - return extraText; - } - - @Override - public ResourceLocation getBackground() { - return BACKGROUND; - } - - @Override - public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - - String craftingText = getCraftText(); - if (craftingText != null) - Utils.drawStringCenteredScaledMaxWidth(craftingText, fontRenderer, - gui.guiLeft + EXTRA_STRING_X, gui.guiTop + EXTRA_STRING_Y, false, 75, 0x404040); - } - - @Override - public JsonObject serialize() { - JsonObject object = new JsonObject(); - object.addProperty("type", "crafting"); - object.addProperty("count", outputIngredient.getCount()); - object.addProperty("overrideOutputId", outputIngredient.getInternalItemId()); - for (int i = 0; i < 9; i++) { - Ingredient ingredient = inputs[i]; - if (ingredient == null) continue; - String[] x = {"1", "2", "3"}; - String[] y = {"A", "B", "C"}; - String name = x[i / 3] + y[i % 3]; - object.addProperty(name, ingredient.serialize()); - } - if(extraText != null) - object.addProperty("crafttext", extraText); - return object; - } - - public static CraftingRecipe parseCraftingRecipe(NEUManager manager, JsonObject recipe, JsonObject outputItem) { - Ingredient[] craftMatrix = new Ingredient[9]; - - String[] x = {"1", "2", "3"}; - String[] y = {"A", "B", "C"}; - for (int i = 0; i < 9; i++) { - String name = y[i / 3] + x[i % 3]; - if (!recipe.has(name)) continue; - String item = recipe.get(name).getAsString(); - if (item == null || item.isEmpty()) continue; - craftMatrix[i] = new Ingredient(manager, item); - } - int resultCount = 1; - if (recipe.has("count")) - resultCount = recipe.get("count").getAsInt(); - String extra = null; - if (outputItem.has("crafttext")) - extra = outputItem.get("crafttext").getAsString(); - if (recipe.has("crafttext")) - extra = recipe.get("crafttext").getAsString(); - String outputItemId = outputItem.get("internalname").getAsString(); - if (recipe.has("overrideOutputId")) - outputItemId = recipe.get("overrideOutputId").getAsString(); - return new CraftingRecipe(manager, craftMatrix, new Ingredient(manager, outputItemId, resultCount), extra); - } + public static final ResourceLocation BACKGROUND = new ResourceLocation("textures/gui/container/crafting_table.png"); + + private static final int EXTRA_STRING_X = 132; + private static final int EXTRA_STRING_Y = 25; + + private final NEUManager manager; + private final Ingredient[] inputs; + private final String extraText; + private final Ingredient outputIngredient; + private List<RecipeSlot> slots; + + public CraftingRecipe(NEUManager manager, Ingredient[] inputs, Ingredient output, String extra) { + this.manager = manager; + this.inputs = inputs; + this.outputIngredient = output; + this.extraText = extra; + if (inputs.length != 9) + throw new IllegalArgumentException("Cannot construct crafting recipe with non standard crafting grid size"); + } + + @Override + public Set<Ingredient> getIngredients() { + Set<Ingredient> ingredients = Sets.newHashSet(inputs); + ingredients.remove(null); + return ingredients; + } + + @Override + public boolean hasVariableCost() { + return false; + } + + @Override + public Set<Ingredient> getOutputs() { + return Collections.singleton(getOutput()); + } + + public Ingredient getOutput() { + return outputIngredient; + } + + public Ingredient[] getInputs() { + return inputs; + } + + @Override + public List<RecipeSlot> getSlots() { + if (slots != null) return slots; + slots = new ArrayList<>(); + for (int x = 0; x < 3; x++) { + for (int y = 0; y < 3; y++) { + Ingredient input = inputs[x + y * 3]; + if (input == null) continue; + ItemStack item = input.getItemStack(); + if (item == null) continue; + slots.add(new RecipeSlot(30 + x * GuiItemRecipe.SLOT_SPACING, 17 + y * GuiItemRecipe.SLOT_SPACING, item)); + } + } + slots.add(new RecipeSlot(124, 35, outputIngredient.getItemStack())); + return slots; + } + + public String getCraftText() { + return extraText; + } + + @Override + public ResourceLocation getBackground() { + return BACKGROUND; + } + + @Override + public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + + String craftingText = getCraftText(); + if (craftingText != null) + Utils.drawStringCenteredScaledMaxWidth(craftingText, fontRenderer, + gui.guiLeft + EXTRA_STRING_X, gui.guiTop + EXTRA_STRING_Y, false, 75, 0x404040 + ); + } + + @Override + public JsonObject serialize() { + JsonObject object = new JsonObject(); + object.addProperty("type", "crafting"); + object.addProperty("count", outputIngredient.getCount()); + object.addProperty("overrideOutputId", outputIngredient.getInternalItemId()); + for (int i = 0; i < 9; i++) { + Ingredient ingredient = inputs[i]; + if (ingredient == null) continue; + String[] x = {"1", "2", "3"}; + String[] y = {"A", "B", "C"}; + String name = x[i / 3] + y[i % 3]; + object.addProperty(name, ingredient.serialize()); + } + if (extraText != null) + object.addProperty("crafttext", extraText); + return object; + } + + public static CraftingRecipe parseCraftingRecipe(NEUManager manager, JsonObject recipe, JsonObject outputItem) { + Ingredient[] craftMatrix = new Ingredient[9]; + + String[] x = {"1", "2", "3"}; + String[] y = {"A", "B", "C"}; + for (int i = 0; i < 9; i++) { + String name = y[i / 3] + x[i % 3]; + if (!recipe.has(name)) continue; + String item = recipe.get(name).getAsString(); + if (item == null || item.isEmpty()) continue; + craftMatrix[i] = new Ingredient(manager, item); + } + int resultCount = 1; + if (recipe.has("count")) + resultCount = recipe.get("count").getAsInt(); + String extra = null; + if (outputItem.has("crafttext")) + extra = outputItem.get("crafttext").getAsString(); + if (recipe.has("crafttext")) + extra = recipe.get("crafttext").getAsString(); + String outputItemId = outputItem.get("internalname").getAsString(); + if (recipe.has("overrideOutputId")) + outputItemId = recipe.get("overrideOutputId").getAsString(); + return new CraftingRecipe(manager, craftMatrix, new Ingredient(manager, outputItemId, resultCount), extra); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java index 2870a54e..c971d82a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/ForgeRecipe.java @@ -19,207 +19,238 @@ import java.util.*; public class ForgeRecipe implements NeuRecipe { - private static final ResourceLocation BACKGROUND = new ResourceLocation("notenoughupdates", "textures/gui/forge_recipe.png"); - - private static final int SLOT_IMAGE_U = 176; - private static final int SLOT_IMAGE_V = 0; - private static final int SLOT_IMAGE_SIZE = 18; - private static final int SLOT_PADDING = 1; - private static final int EXTRA_INFO_MAX_WIDTH = 75; - public static final int EXTRA_INFO_X = 132; - public static final int EXTRA_INFO_Y = 25; - - public enum ForgeType { - REFINING, ITEM_FORGING - } - - private final NEUManager manager; - private final List<Ingredient> inputs; - private final Ingredient output; - private final int hotmLevel; - private final int timeInSeconds; // TODO: quick forge - private List<RecipeSlot> slots; - - public ForgeRecipe(NEUManager manager, List<Ingredient> inputs, Ingredient output, int durationInSeconds, int hotmLevel) { - this.manager = manager; - this.inputs = inputs; - this.output = output; - this.hotmLevel = hotmLevel; - this.timeInSeconds = durationInSeconds; - } - - public List<Ingredient> getInputs() { - return inputs; - } - - public Ingredient getOutput() { - return output; - } - - public int getHotmLevel() { - return hotmLevel; - } - - public int getTimeInSeconds() { - return timeInSeconds; - } - - @Override - public ResourceLocation getBackground() { - return BACKGROUND; - } - - @Override - public Set<Ingredient> getIngredients() { - return Sets.newHashSet(inputs); - } - - @Override - public boolean hasVariableCost() { - return false; - } - - @Override - public Set<Ingredient> getOutputs() { - return Collections.singleton(output); - } - - @Override - public List<RecipeSlot> getSlots() { - if (slots != null) return slots; - slots = new ArrayList<>(); - for (int i = 0; i < inputs.size(); i++) { - Ingredient input = inputs.get(i); - ItemStack itemStack = input.getItemStack(); - if (itemStack == null) continue; - int[] slotCoordinates = getSlotCoordinates(i, inputs.size()); - slots.add(new RecipeSlot(slotCoordinates[0], slotCoordinates[1], itemStack)); - } - slots.add(new RecipeSlot(124, 35, output.getItemStack())); - return slots; - } - - @Override - public void drawExtraBackground(GuiItemRecipe gui, int mouseX, int mouseY) { - Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); - for (int i = 0; i < inputs.size(); i++) { - int[] slotCoordinates = getSlotCoordinates(i, inputs.size()); - gui.drawTexturedModalRect( - gui.guiLeft + slotCoordinates[0] - SLOT_PADDING, gui.guiTop + slotCoordinates[1] - SLOT_PADDING, - SLOT_IMAGE_U, SLOT_IMAGE_V, - SLOT_IMAGE_SIZE, SLOT_IMAGE_SIZE); - } - } - - @Override - public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - if (timeInSeconds > 0) - Utils.drawStringCenteredScaledMaxWidth(formatDuration(timeInSeconds), fontRenderer, gui.guiLeft + EXTRA_INFO_X, gui.guiTop + EXTRA_INFO_Y, false, EXTRA_INFO_MAX_WIDTH, 0xff00ff); - } - - @Override - public void drawHoverInformation(GuiItemRecipe gui, int mouseX, int mouseY) { - manager.hotm.getInformationOnCurrentProfile().ifPresent(hotmTree -> { - if (timeInSeconds > 0 && gui.isWithinRect( - mouseX, mouseY, - gui.guiLeft + EXTRA_INFO_X - EXTRA_INFO_MAX_WIDTH / 2, - gui.guiTop + EXTRA_INFO_Y - 8, - EXTRA_INFO_MAX_WIDTH, 16 - )) { - int qf = hotmTree.getLevel("forge_time"); - int reducedTime = getReducedTime(qf); - if (qf > 0) { - - Utils.drawHoveringText(Arrays.asList(EnumChatFormatting.YELLOW + formatDuration(reducedTime) + " with Quick Forge (Level " + qf + ")"), mouseX, mouseY, gui.width, gui.height, 500, Minecraft.getMinecraft().fontRendererObj); - } - } - }); - } - - public int getReducedTime(int quickForgeUpgradeLevel) { - return HotmInformation.getQuickForgeMultiplier(quickForgeUpgradeLevel) * timeInSeconds / 1000; - } - - @Override - public JsonObject serialize() { - JsonObject object = new JsonObject(); - JsonArray ingredients = new JsonArray(); - for (Ingredient input : inputs) { - ingredients.add(new JsonPrimitive(input.serialize())); - } - object.addProperty("type", "forge"); - object.add("inputs", ingredients); - object.addProperty("count", output.getCount()); - object.addProperty("overrideOutputId", output.getInternalItemId()); - if (hotmLevel >= 0) - object.addProperty("hotmLevel", hotmLevel); - if (timeInSeconds >= 0) - object.addProperty("duration", timeInSeconds); - return object; - } - - static ForgeRecipe parseForgeRecipe(NEUManager manager, JsonObject recipe, JsonObject output) { - List<Ingredient> ingredients = new ArrayList<>(); - for (JsonElement element : recipe.getAsJsonArray("inputs")) { - String ingredientString = element.getAsString(); - ingredients.add(new Ingredient(manager, ingredientString)); - } - String internalItemId = output.get("internalname").getAsString(); - if (recipe.has("overrideOutputId")) - internalItemId = recipe.get("overrideOutputId").getAsString(); - int resultCount = 1; - if (recipe.has("count")) { - resultCount = recipe.get("count").getAsInt(); - } - int duration = -1; - if (recipe.has("duration")) { - duration = recipe.get("duration").getAsInt(); - } - int hotmLevel = -1; - if (recipe.has("hotmLevel")) { - hotmLevel = recipe.get("hotmLevel").getAsInt(); - } - return new ForgeRecipe(manager, ingredients, new Ingredient(manager, internalItemId, resultCount), duration, hotmLevel); - } - - private static final int RECIPE_CENTER_X = 40; - private static final int RECIPE_CENTER_Y = 34; - private static final int SLOT_DISTANCE_FROM_CENTER = 22; - private static final int RECIPE_FALLBACK_X = 20; - private static final int RECIPE_FALLBACK_Y = 15; - - static int[] getSlotCoordinates(int slotNumber, int totalSlotCount) { - if (totalSlotCount > 6) { - return new int[]{ - RECIPE_FALLBACK_X + (slotNumber % 4) * GuiItemRecipe.SLOT_SPACING, - RECIPE_FALLBACK_Y + (slotNumber / 4) * GuiItemRecipe.SLOT_SPACING, - }; - } - if (totalSlotCount == 1) { - return new int[] { - RECIPE_CENTER_X - GuiItemRecipe.SLOT_SIZE / 2, - RECIPE_CENTER_Y - GuiItemRecipe.SLOT_SIZE / 2 - }; - } - double rad = Math.PI * 2 * slotNumber / totalSlotCount; - int x = (int) (Math.cos(rad) * SLOT_DISTANCE_FROM_CENTER); - int y = (int) (Math.sin(rad) * SLOT_DISTANCE_FROM_CENTER); - return new int[]{RECIPE_CENTER_X + x, RECIPE_CENTER_Y + y}; - } - - static String formatDuration(int seconds) { - int minutes = seconds / 60; - seconds %= 60; - int hours = minutes / 60; - minutes %= 60; - int days = hours / 24; - hours %= 24; - StringBuilder sB = new StringBuilder(); - if (days != 0) sB.append(days).append("d "); - if (hours != 0) sB.append(hours).append("h "); - if (minutes != 0) sB.append(minutes).append("m "); - if (seconds != 0) sB.append(seconds).append("s "); - return sB.substring(0, sB.length() - 1); - } + private static final ResourceLocation BACKGROUND = + new ResourceLocation("notenoughupdates", "textures/gui/forge_recipe.png"); + + private static final int SLOT_IMAGE_U = 176; + private static final int SLOT_IMAGE_V = 0; + private static final int SLOT_IMAGE_SIZE = 18; + private static final int SLOT_PADDING = 1; + private static final int EXTRA_INFO_MAX_WIDTH = 75; + public static final int EXTRA_INFO_X = 132; + public static final int EXTRA_INFO_Y = 25; + + public enum ForgeType { + REFINING, ITEM_FORGING + } + + private final NEUManager manager; + private final List<Ingredient> inputs; + private final Ingredient output; + private final int hotmLevel; + private final int timeInSeconds; // TODO: quick forge + private List<RecipeSlot> slots; + + public ForgeRecipe( + NEUManager manager, + List<Ingredient> inputs, + Ingredient output, + int durationInSeconds, + int hotmLevel + ) { + this.manager = manager; + this.inputs = inputs; + this.output = output; + this.hotmLevel = hotmLevel; + this.timeInSeconds = durationInSeconds; + } + + public List<Ingredient> getInputs() { + return inputs; + } + + public Ingredient getOutput() { + return output; + } + + public int getHotmLevel() { + return hotmLevel; + } + + public int getTimeInSeconds() { + return timeInSeconds; + } + + @Override + public ResourceLocation getBackground() { + return BACKGROUND; + } + + @Override + public Set<Ingredient> getIngredients() { + return Sets.newHashSet(inputs); + } + + @Override + public boolean hasVariableCost() { + return false; + } + + @Override + public Set<Ingredient> getOutputs() { + return Collections.singleton(output); + } + + @Override + public List<RecipeSlot> getSlots() { + if (slots != null) return slots; + slots = new ArrayList<>(); + for (int i = 0; i < inputs.size(); i++) { + Ingredient input = inputs.get(i); + ItemStack itemStack = input.getItemStack(); + if (itemStack == null) continue; + int[] slotCoordinates = getSlotCoordinates(i, inputs.size()); + slots.add(new RecipeSlot(slotCoordinates[0], slotCoordinates[1], itemStack)); + } + slots.add(new RecipeSlot(124, 35, output.getItemStack())); + return slots; + } + + @Override + public void drawExtraBackground(GuiItemRecipe gui, int mouseX, int mouseY) { + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + for (int i = 0; i < inputs.size(); i++) { + int[] slotCoordinates = getSlotCoordinates(i, inputs.size()); + gui.drawTexturedModalRect( + gui.guiLeft + slotCoordinates[0] - SLOT_PADDING, gui.guiTop + slotCoordinates[1] - SLOT_PADDING, + SLOT_IMAGE_U, SLOT_IMAGE_V, + SLOT_IMAGE_SIZE, SLOT_IMAGE_SIZE + ); + } + } + + @Override + public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + if (timeInSeconds > 0) + Utils.drawStringCenteredScaledMaxWidth( + formatDuration(timeInSeconds), + fontRenderer, + gui.guiLeft + EXTRA_INFO_X, + gui.guiTop + EXTRA_INFO_Y, + false, + EXTRA_INFO_MAX_WIDTH, + 0xff00ff + ); + } + + @Override + public void drawHoverInformation(GuiItemRecipe gui, int mouseX, int mouseY) { + manager.hotm.getInformationOnCurrentProfile().ifPresent(hotmTree -> { + if (timeInSeconds > 0 && gui.isWithinRect( + mouseX, mouseY, + gui.guiLeft + EXTRA_INFO_X - EXTRA_INFO_MAX_WIDTH / 2, + gui.guiTop + EXTRA_INFO_Y - 8, + EXTRA_INFO_MAX_WIDTH, 16 + )) { + int qf = hotmTree.getLevel("forge_time"); + int reducedTime = getReducedTime(qf); + if (qf > 0) { + + Utils.drawHoveringText( + Arrays.asList( + EnumChatFormatting.YELLOW + formatDuration(reducedTime) + " with Quick Forge (Level " + qf + ")"), + mouseX, + mouseY, + gui.width, + gui.height, + 500, + Minecraft.getMinecraft().fontRendererObj + ); + } + } + }); + } + + public int getReducedTime(int quickForgeUpgradeLevel) { + return HotmInformation.getQuickForgeMultiplier(quickForgeUpgradeLevel) * timeInSeconds / 1000; + } + + @Override + public JsonObject serialize() { + JsonObject object = new JsonObject(); + JsonArray ingredients = new JsonArray(); + for (Ingredient input : inputs) { + ingredients.add(new JsonPrimitive(input.serialize())); + } + object.addProperty("type", "forge"); + object.add("inputs", ingredients); + object.addProperty("count", output.getCount()); + object.addProperty("overrideOutputId", output.getInternalItemId()); + if (hotmLevel >= 0) + object.addProperty("hotmLevel", hotmLevel); |
