Skip to content

Commit b06b4e7

Browse files
committed
fix: fix issue with templates
1 parent 05c131c commit b06b4e7

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,16 @@ private void updateGui(Inventory inv) {
238238
}
239239

240240
if (template == null || template.getType().isAir()) {
241-
if (!needNetheriteTemplate) {
241+
template = new ItemStack(Material.AIR);
242+
}
243+
244+
if (!needNetheriteTemplate && !hasTemplate(addition, base, template)) {
245+
if (template.getType().isAir()) {
242246
template = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
243-
} else {
244-
template = new ItemStack(Material.AIR);
247+
} else if (base.getType().isAir()) {
248+
base = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
249+
} else if (addition.getType().isAir()) {
250+
addition = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);;
245251
}
246252
}
247253

@@ -275,6 +281,30 @@ private boolean checkRecipes(Inventory inv, ItemStack finalTemplate, ItemStack f
275281
return successful;
276282
}
277283

284+
private boolean hasTemplate(ItemStack item1, ItemStack item2, ItemStack item3) {
285+
if (isTemplate(item1)) {
286+
return true;
287+
} else if (isTemplate(item2)) {
288+
return true;
289+
} else {
290+
return isTemplate(item3);
291+
}
292+
}
293+
294+
private boolean isTemplate(ItemStack item) {
295+
return switch (item.getType()) {
296+
case COAST_ARMOR_TRIM_SMITHING_TEMPLATE, SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE,
297+
DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, EYE_ARMOR_TRIM_SMITHING_TEMPLATE,
298+
SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, HOST_ARMOR_TRIM_SMITHING_TEMPLATE,
299+
RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE,
300+
RIB_ARMOR_TRIM_SMITHING_TEMPLATE, SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE,
301+
SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, TIDE_ARMOR_TRIM_SMITHING_TEMPLATE,
302+
VEX_ARMOR_TRIM_SMITHING_TEMPLATE, WARD_ARMOR_TRIM_SMITHING_TEMPLATE,
303+
WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE -> true;
304+
default -> false;
305+
};
306+
}
307+
278308
private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
279309
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
280310
while (recipeIterator.hasNext()) {

0 commit comments

Comments
 (0)