From b06b4e7156fd9981d62d435f65b96856d8b00654 Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:16:20 +0100 Subject: [PATCH] fix: fix issue with templates --- .../gui/impl/SmithingTable_V1_20.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java b/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java index 959bd0d..413a410 100644 --- a/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java +++ b/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java @@ -238,10 +238,16 @@ private void updateGui(Inventory inv) { } if (template == null || template.getType().isAir()) { - if (!needNetheriteTemplate) { + template = new ItemStack(Material.AIR); + } + + if (!needNetheriteTemplate && !hasTemplate(addition, base, template)) { + if (template.getType().isAir()) { template = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE); - } else { - template = new ItemStack(Material.AIR); + } else if (base.getType().isAir()) { + base = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE); + } else if (addition.getType().isAir()) { + addition = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);; } } @@ -275,6 +281,30 @@ private boolean checkRecipes(Inventory inv, ItemStack finalTemplate, ItemStack f return successful; } + private boolean hasTemplate(ItemStack item1, ItemStack item2, ItemStack item3) { + if (isTemplate(item1)) { + return true; + } else if (isTemplate(item2)) { + return true; + } else { + return isTemplate(item3); + } + } + + private boolean isTemplate(ItemStack item) { + return switch (item.getType()) { + case COAST_ARMOR_TRIM_SMITHING_TEMPLATE, SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE, + DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, EYE_ARMOR_TRIM_SMITHING_TEMPLATE, + SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, HOST_ARMOR_TRIM_SMITHING_TEMPLATE, + RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE, + RIB_ARMOR_TRIM_SMITHING_TEMPLATE, SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE, + SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, TIDE_ARMOR_TRIM_SMITHING_TEMPLATE, + VEX_ARMOR_TRIM_SMITHING_TEMPLATE, WARD_ARMOR_TRIM_SMITHING_TEMPLATE, + WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE -> true; + default -> false; + }; + } + private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) { Iterator recipeIterator = Bukkit.getServer().recipeIterator(); while (recipeIterator.hasNext()) {