From 5e878d75bcfd12790cf8670b05598bb636491e45 Mon Sep 17 00:00:00 2001 From: WolfyScript Date: Thu, 10 Feb 2022 21:23:48 +0100 Subject: [PATCH 1/2] Fixed EliteWorkbenchCondition always returning false. --- .../recipes/conditions/EliteWorkbenchCondition.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/wolfyscript/customcrafting/recipes/conditions/EliteWorkbenchCondition.java b/src/main/java/me/wolfyscript/customcrafting/recipes/conditions/EliteWorkbenchCondition.java index e15fe8ca0..5260513d5 100644 --- a/src/main/java/me/wolfyscript/customcrafting/recipes/conditions/EliteWorkbenchCondition.java +++ b/src/main/java/me/wolfyscript/customcrafting/recipes/conditions/EliteWorkbenchCondition.java @@ -22,6 +22,7 @@ package me.wolfyscript.customcrafting.recipes.conditions; +import me.wolfyscript.customcrafting.data.CCCache; import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonAlias; import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonIgnore; import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonProperty; @@ -74,8 +75,11 @@ public boolean check(CustomRecipe recipe, Conditions.Data data) { if (RecipeType.Container.ELITE_CRAFTING.isInstance(recipe)) { if (data.getBlock() != null) { CustomItem customItem = NamespacedKeyUtils.getCustomItem(data.getBlock()); - if (customItem != null && customItem.getApiReference() instanceof WolfyUtilitiesRef wolfyUtilsRef) { - return eliteWorkbenches.contains(wolfyUtilsRef.getNamespacedKey()) && ((EliteWorkbenchData) customItem.getCustomData(CustomCrafting.ELITE_CRAFTING_TABLE_DATA)).isEnabled(); + if (customItem != null) { + EliteWorkbenchData eliteWorkbench = (EliteWorkbenchData) customItem.getCustomData(CustomCrafting.ELITE_CRAFTING_TABLE_DATA); + if (eliteWorkbench != null && eliteWorkbench.isEnabled()) { + return eliteWorkbenches.contains(customItem.getNamespacedKey()) && ((EliteWorkbenchData) customItem.getCustomData(CustomCrafting.ELITE_CRAFTING_TABLE_DATA)).isEnabled(); + } } } return false; From 5cff677146c86e1b30a156c18d249b6691494bd5 Mon Sep 17 00:00:00 2001 From: WolfyScript Date: Thu, 10 Feb 2022 21:55:16 +0100 Subject: [PATCH 2/2] Fixed EliteCraftingRecipes not showing up inside the recipe menu of the EliteCraftingTable. --- .../configs/recipebook/RecipeContainer.java | 12 ++++++------ .../data/cache/EliteWorkbench.java | 17 ++++++++++++----- .../gui/elite_crafting/ButtonSlotCrafting.java | 2 +- .../gui/elite_crafting/ButtonSlotResult.java | 2 +- .../gui/elite_crafting/CraftingWindow.java | 2 +- .../listeners/EliteWorkbenchListener.java | 10 ++++++---- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/wolfyscript/customcrafting/configs/recipebook/RecipeContainer.java b/src/main/java/me/wolfyscript/customcrafting/configs/recipebook/RecipeContainer.java index c3ca77546..6840c1519 100644 --- a/src/main/java/me/wolfyscript/customcrafting/configs/recipebook/RecipeContainer.java +++ b/src/main/java/me/wolfyscript/customcrafting/configs/recipebook/RecipeContainer.java @@ -103,20 +103,20 @@ public boolean isValid(Set materials) { return materials.isEmpty() || cachedRecipes.stream().anyMatch(recipe1 -> recipe1.getResult().getChoices().stream().anyMatch(customItem -> materials.contains(customItem.getItemStack().getType()))); } - public boolean isValid(EliteWorkbench cache) { - var data = cache.getEliteWorkbenchData(); + public boolean isValid(EliteWorkbench eliteWorkbench) { + var data = eliteWorkbench.getData(); return cachedRecipes.parallelStream().anyMatch(cachedRecipe -> { if (cachedRecipe instanceof CraftingRecipe && (RecipeType.Container.ELITE_CRAFTING.isInstance(cachedRecipe) || data.isAdvancedRecipes())) { if (RecipeType.Container.ELITE_CRAFTING.isInstance(cachedRecipe)) { - EliteWorkbenchCondition condition = cachedRecipe.getConditions().getEliteCraftingTableCondition(); - if (condition != null && !condition.getEliteWorkbenches().contains(data.getNamespacedKey())) { + Conditions conditions = cachedRecipe.getConditions(); + if (conditions.has(EliteWorkbenchCondition.KEY) && !conditions.getByType(EliteWorkbenchCondition.class).getEliteWorkbenches().contains(eliteWorkbench.getCustomItem().getNamespacedKey())) { return false; } if (cachedRecipe instanceof AbstractRecipeShapeless shapeless) { - return shapeless.getIngredients().size() <= cache.getCurrentGridSize() * cache.getCurrentGridSize(); + return shapeless.getIngredients().size() <= eliteWorkbench.getCurrentGridSize() * eliteWorkbench.getCurrentGridSize(); } else { CraftingRecipeEliteShaped recipe1 = (CraftingRecipeEliteShaped) cachedRecipe; - return recipe1.getShape().length <= cache.getCurrentGridSize() && recipe1.getShape()[0].length() <= cache.getCurrentGridSize(); + return recipe1.getShape().length <= eliteWorkbench.getCurrentGridSize() && recipe1.getShape()[0].length() <= eliteWorkbench.getCurrentGridSize(); } } return true; diff --git a/src/main/java/me/wolfyscript/customcrafting/data/cache/EliteWorkbench.java b/src/main/java/me/wolfyscript/customcrafting/data/cache/EliteWorkbench.java index 19492f43c..138b0e52e 100644 --- a/src/main/java/me/wolfyscript/customcrafting/data/cache/EliteWorkbench.java +++ b/src/main/java/me/wolfyscript/customcrafting/data/cache/EliteWorkbench.java @@ -23,13 +23,15 @@ package me.wolfyscript.customcrafting.data.cache; import me.wolfyscript.customcrafting.configs.custom_data.EliteWorkbenchData; +import me.wolfyscript.utilities.api.inventory.custom_items.CustomItem; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class EliteWorkbench { private byte currentGridSize; - private EliteWorkbenchData eliteWorkbench; + private EliteWorkbenchData data; + private CustomItem customItem; private ItemStack result; private ItemStack[] contents; @@ -63,11 +65,16 @@ public void setResult(ItemStack result) { this.result = result; } - public EliteWorkbenchData getEliteWorkbenchData() { - return eliteWorkbench; + public EliteWorkbenchData getData() { + return data; } - public void setEliteWorkbenchData(EliteWorkbenchData eliteWorkbench) { - this.eliteWorkbench = eliteWorkbench; + public CustomItem getCustomItem() { + return customItem; + } + + public void setCustomItemAndData(CustomItem customItem, EliteWorkbenchData eliteWorkbench) { + this.customItem = customItem; + this.data = eliteWorkbench; } } diff --git a/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotCrafting.java b/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotCrafting.java index 330be92e7..76400e0d4 100644 --- a/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotCrafting.java +++ b/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotCrafting.java @@ -39,7 +39,7 @@ class ButtonSlotCrafting extends ItemInputButton { (cache, guiHandler, player, inventory, itemStack, slot, b) -> { EliteWorkbench eliteWorkbench = cache.getEliteWorkbench(); eliteWorkbench.getContents()[recipeSlot] = inventory.getItem(slot); - ItemStack result = customCrafting.getCraftManager().preCheckRecipe(eliteWorkbench.getContents(), player, inventory, true, eliteWorkbench.getEliteWorkbenchData().isAdvancedRecipes()); + ItemStack result = customCrafting.getCraftManager().preCheckRecipe(eliteWorkbench.getContents(), player, inventory, true, eliteWorkbench.getData().isAdvancedRecipes()); eliteWorkbench.setResult(result); }, null, (hashMap, cache, guiHandler, player, inventory, itemStack, slot, help) -> { diff --git a/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotResult.java b/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotResult.java index afa61fb58..bc3d377da 100644 --- a/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotResult.java +++ b/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/ButtonSlotResult.java @@ -82,7 +82,7 @@ class ButtonSlotResult extends ItemInputButton { } }, (cache, guiHandler, player, inventory, itemStack, slot, b) -> { EliteWorkbench eliteWorkbench = cache.getEliteWorkbench(); - EliteWorkbenchData eliteWorkbenchData = eliteWorkbench.getEliteWorkbenchData(); + EliteWorkbenchData eliteWorkbenchData = eliteWorkbench.getData(); ItemStack result = customCrafting.getCraftManager().preCheckRecipe(eliteWorkbench.getContents(), player, inventory, true, eliteWorkbenchData.isAdvancedRecipes()); eliteWorkbench.setResult(result); }, (hashMap, cache, guiHandler, player, inventory, itemStack, slot, help) -> { diff --git a/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/CraftingWindow.java b/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/CraftingWindow.java index 0b9d107e5..b924ee46d 100644 --- a/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/CraftingWindow.java +++ b/src/main/java/me/wolfyscript/customcrafting/gui/elite_crafting/CraftingWindow.java @@ -99,7 +99,7 @@ public boolean onClose(GuiHandler guiHandler, GUIInventory gui } } } - eliteWorkbench.setEliteWorkbenchData(null); + eliteWorkbench.setCustomItemAndData(null, null); eliteWorkbench.setResult(new ItemStack(Material.AIR)); eliteWorkbench.setContents(null); eliteWorkbench.setCurrentGridSize((byte) 0); diff --git a/src/main/java/me/wolfyscript/customcrafting/listeners/EliteWorkbenchListener.java b/src/main/java/me/wolfyscript/customcrafting/listeners/EliteWorkbenchListener.java index 6f0ace1bd..c701377aa 100644 --- a/src/main/java/me/wolfyscript/customcrafting/listeners/EliteWorkbenchListener.java +++ b/src/main/java/me/wolfyscript/customcrafting/listeners/EliteWorkbenchListener.java @@ -27,6 +27,7 @@ import me.wolfyscript.customcrafting.data.CCCache; import me.wolfyscript.customcrafting.utils.NamespacedKeyUtils; import me.wolfyscript.utilities.api.WolfyUtilities; +import me.wolfyscript.utilities.api.inventory.gui.GuiHandler; import me.wolfyscript.utilities.util.NamespacedKey; import me.wolfyscript.utilities.util.world.WorldUtils; import org.bukkit.event.Event; @@ -50,11 +51,12 @@ public void onInteract(PlayerInteractEvent event) { if (block != null && WorldUtils.getWorldCustomItemStore().isStored(block.getLocation())) { var customItem = NamespacedKeyUtils.getCustomItem(block); if (customItem != null) { - EliteWorkbenchData eliteWorkbench = (EliteWorkbenchData) customItem.getCustomData(CustomCrafting.ELITE_CRAFTING_TABLE_DATA); - if (eliteWorkbench != null && eliteWorkbench.isEnabled()) { + var eliteCraftingTableData = (EliteWorkbenchData) customItem.getCustomData(CustomCrafting.ELITE_CRAFTING_TABLE_DATA); + if (eliteCraftingTableData != null && eliteCraftingTableData.isEnabled()) { event.setCancelled(true); - ((CCCache) api.getInventoryAPI().getGuiHandler(event.getPlayer()).getCustomCache()).getEliteWorkbench().setEliteWorkbenchData(eliteWorkbench.clone()); - api.getInventoryAPI().getGuiHandler(event.getPlayer()).openWindow(new NamespacedKey("crafting", "crafting_grid" + eliteWorkbench.getGridSize())); + GuiHandler guiHandler = api.getInventoryAPI(CCCache.class).getGuiHandler(event.getPlayer()); + guiHandler.getCustomCache().getEliteWorkbench().setCustomItemAndData(customItem, eliteCraftingTableData.clone()); + guiHandler.openWindow(new NamespacedKey("crafting", "crafting_grid" + eliteCraftingTableData.getGridSize())); } } }