From e7c19b07abfa97199be706a302d1556f238d789d Mon Sep 17 00:00:00 2001 From: Cola Date: Mon, 22 Aug 2022 14:27:38 +0100 Subject: [PATCH 1/4] Just need to fix gui --- paper/build.gradle.kts | 2 +- .../igotyou/FactoryMod/ConfigParser.java | 20 +++ .../FactoryMod/recipes/LoreRemoveRecipe.java | 118 ++++++++++++++++++ paper/src/main/resources/config.yml | 17 +++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts index 8a2b52f6..ef0cebe6 100644 --- a/paper/build.gradle.kts +++ b/paper/build.gradle.kts @@ -13,7 +13,7 @@ civGradle { dependencies { paperDevBundle("1.18.2-R0.1-SNAPSHOT") - compileOnly("net.civmc.civmodcore:paper:2.0.0-SNAPSHOT:dev-all") + compileOnly("net.civmc.civmodcore:civmodcore-paper:2.3.3:dev-all") compileOnly("net.civmc.namelayer:paper:3.0.0-SNAPSHOT:dev") compileOnly("net.civmc.citadel:paper:5.0.0-SNAPSHOT:dev") } diff --git a/paper/src/main/java/com/github/igotyou/FactoryMod/ConfigParser.java b/paper/src/main/java/com/github/igotyou/FactoryMod/ConfigParser.java index 2f3f3f6c..b068c3ff 100644 --- a/paper/src/main/java/com/github/igotyou/FactoryMod/ConfigParser.java +++ b/paper/src/main/java/com/github/igotyou/FactoryMod/ConfigParser.java @@ -18,6 +18,7 @@ import com.github.igotyou.FactoryMod.recipes.IRecipe; import com.github.igotyou.FactoryMod.recipes.InputRecipe; import com.github.igotyou.FactoryMod.recipes.LoreEnchantRecipe; +import com.github.igotyou.FactoryMod.recipes.LoreRemoveRecipe; import com.github.igotyou.FactoryMod.recipes.PlayerHeadRecipe; import com.github.igotyou.FactoryMod.recipes.PrintBookRecipe; import com.github.igotyou.FactoryMod.recipes.PrintNoteRecipe; @@ -791,6 +792,25 @@ private IRecipe parseRecipe(ConfigurationSection config) { result = new LoreEnchantRecipe(identifier, name, productionTime, input, toolMap, appliedLore, overwrittenLore); break; + case "REMOVELORE": + ConfigurationSection loreItem = config.getConfigurationSection("removeLore"); + ItemMap materials; + if (loreItem == null) { + if (!(parentRecipe instanceof LoreRemoveRecipe)) { + materials = new ItemMap(); + } else { + materials = ((LoreRemoveRecipe) parentRecipe).getItemToCleanse().clone(); + } + } else { + materials = ConfigHelper.parseItemMap(loreItem); + } + if (materials.getTotalItemAmount() == 0) { + plugin.warning("Lore removing recipe " + name + " had no item specified, it was skipped"); + result = null; + break; + } + result = new LoreRemoveRecipe(identifier, name, productionTime, input, materials); + break; case "RECIPEMODIFIERUPGRADE": int rank = config.getInt("rank"); String toUpgrade = config.getString("recipeUpgraded"); diff --git a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java new file mode 100644 index 00000000..b60da96d --- /dev/null +++ b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java @@ -0,0 +1,118 @@ +package com.github.igotyou.FactoryMod.recipes; + +import com.github.igotyou.FactoryMod.factories.FurnCraftChestFactory; +import com.github.igotyou.FactoryMod.utility.MultiInventoryWrapper; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import vg.civcraft.mc.civmodcore.inventory.items.ItemMap; +import vg.civcraft.mc.civmodcore.inventory.items.ItemUtils; + +public class LoreRemoveRecipe extends InputRecipe{ + + private Component infoComponent = Component.text("This item has lore that will be removed!", NamedTextColor.GOLD).decoration( + TextDecoration.ITALIC, false); + private ItemMap itemToCleanse; + private ItemStack exampleInput; + private ItemStack exampleOutput; + + public LoreRemoveRecipe(String identifier, String name, int productionTime, ItemMap input, ItemMap itemToCleanse) { + super(identifier, name, productionTime, input); + this.itemToCleanse = itemToCleanse; + this.exampleInput = itemToCleanse.getItemStackRepresentation().get(0); + this.exampleOutput = itemToCleanse.getItemStackRepresentation().get(0); + ItemUtils.addComponentLore(exampleInput, infoComponent); + } + + @Override + public boolean applyEffect(Inventory inputInv, Inventory outputInv, FurnCraftChestFactory fccf) { + MultiInventoryWrapper combo = new MultiInventoryWrapper(inputInv, outputInv); + logBeforeRecipeRun(combo, fccf); + ItemStack toolio = itemToCleanse.getItemStackRepresentation().get(0); + for (ItemStack is : inputInv.getContents()) { + if (is != null && toolio.getType() == is.getType() && checkIfHasLore(is)) { + if (input.removeSafelyFrom(inputInv)) { + ItemMeta im = is.getItemMeta(); + if (im == null) { + im = Bukkit.getItemFactory().getItemMeta(is.getType()); + } + is.setItemMeta(Bukkit.getItemFactory().getItemMeta(is.getType())); + logAfterRecipeRun(combo, fccf); + return true; + } + } + } + logAfterRecipeRun(combo, fccf); + return false; + } + + @Override + public String getTypeIdentifier() { + return "REMOVELORE"; + } + + public ItemMap getItemToCleanse() { + return itemToCleanse; + } + + @Override + public List getInputRepresentation(Inventory i, FurnCraftChestFactory fccf) { + if (i == null) { + return Arrays.asList(exampleInput.clone()); + } + List returns = createLoredStacksForInfo(i); + ItemStack toSt = itemToCleanse.getItemStackRepresentation().get(0); + ItemUtils.addComponentLore(toSt, infoComponent); + ItemUtils.addLore(toSt, ChatColor.GREEN + "Enough materials for " + new ItemMap(toSt).getMultiplesContainedIn(i) + + " runs"); + returns.add(toSt); + return returns; + } + + @Override + public List getOutputRepresentation(Inventory i, FurnCraftChestFactory fccf) { + ItemStack is = exampleOutput.clone(); + if (i != null) { + ItemUtils.addLore( + is, + ChatColor.GREEN + + "Enough materials for " + + String.valueOf(Math.min(itemToCleanse.getMultiplesContainedIn(i), input.getMultiplesContainedIn(i))) + + " runs"); + } + List stacks = new LinkedList<>(); + stacks.add(is); + return stacks; + } + + private boolean checkIfHasLore(ItemStack itemStack) { + if (!itemStack.getItemMeta().hasLore()) { + return false; + } + return !itemStack.getItemMeta().lore().isEmpty(); + } + + @Override + public List getTextualInputRepresentation(Inventory i, FurnCraftChestFactory fccf) { + return Arrays.asList("1 " + ItemUtils.getItemName(exampleInput)); + } + + @Override + public List getTextualOutputRepresentation(Inventory i, FurnCraftChestFactory fccf) { + return Arrays.asList("1 " + ItemUtils.getItemName(exampleOutput)); + } + + @Override + public Material getRecipeRepresentationMaterial() { + return exampleOutput.getType(); + } +} diff --git a/paper/src/main/resources/config.yml b/paper/src/main/resources/config.yml index 8162c0e9..a1e6b1bf 100644 --- a/paper/src/main/resources/config.yml +++ b/paper/src/main/resources/config.yml @@ -693,6 +693,23 @@ factories: #appliedLore is the lore which is applied as replacement for the removed lore. This list may not be empty, but it may contain multiple entries + +#10. Remove Lore Recipe + +#This recipe is quite specific, We use it to get rid of the lore and PDC tag on an ItemStack that was placed by SimpleAdminHacks. + +#removeLore: +# type: REMOVELORE +# input: +# emeralds: +# material: EMERALD +# amount: 9 +# removeLore: +# chestplate: +# material: DIAMOND_CHESTPLATE + +# This will completely overwrite an items ItemMeta with a fresh copy + #GENERAL NOTE: # Every recipe type can include at the same level as "name: " the following, although only FCC's will respect it currently: From 24da31137c05e78df74b4b5050ca0f5d067bbd80 Mon Sep 17 00:00:00 2001 From: Cola Date: Mon, 22 Aug 2022 16:47:10 +0100 Subject: [PATCH 2/4] Fix GUI Thank you Okx for rubber ducking --- .../igotyou/FactoryMod/recipes/LoreRemoveRecipe.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java index b60da96d..6e8f5fd5 100644 --- a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java +++ b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java @@ -2,6 +2,7 @@ import com.github.igotyou.FactoryMod.factories.FurnCraftChestFactory; import com.github.igotyou.FactoryMod.utility.MultiInventoryWrapper; +import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -67,7 +68,11 @@ public ItemMap getItemToCleanse() { @Override public List getInputRepresentation(Inventory i, FurnCraftChestFactory fccf) { if (i == null) { - return Arrays.asList(exampleInput.clone()); + List itemStackRepresentation = input.getItemStackRepresentation(); + List inputs = new ArrayList<>(itemStackRepresentation.size() + 1); + inputs.addAll(itemStackRepresentation); + inputs.add(exampleInput.clone()); + return inputs; } List returns = createLoredStacksForInfo(i); ItemStack toSt = itemToCleanse.getItemStackRepresentation().get(0); From 4b0129ee90a3ad5b959a63c4cbb3c552f51d0884 Mon Sep 17 00:00:00 2001 From: Cola Date: Mon, 22 Aug 2022 16:54:24 +0100 Subject: [PATCH 3/4] Faster meta usage --- .../igotyou/FactoryMod/recipes/LoreRemoveRecipe.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java index 6e8f5fd5..93263fa9 100644 --- a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java +++ b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java @@ -17,6 +17,7 @@ import org.bukkit.inventory.meta.ItemMeta; import vg.civcraft.mc.civmodcore.inventory.items.ItemMap; import vg.civcraft.mc.civmodcore.inventory.items.ItemUtils; +import vg.civcraft.mc.civmodcore.inventory.items.MetaUtils; public class LoreRemoveRecipe extends InputRecipe{ @@ -76,9 +77,11 @@ public List getInputRepresentation(Inventory i, FurnCraftChestFactory } List returns = createLoredStacksForInfo(i); ItemStack toSt = itemToCleanse.getItemStackRepresentation().get(0); - ItemUtils.addComponentLore(toSt, infoComponent); - ItemUtils.addLore(toSt, ChatColor.GREEN + "Enough materials for " + new ItemMap(toSt).getMultiplesContainedIn(i) - + " runs"); + toSt.editMeta(meta -> { + MetaUtils.addComponentLore(meta, infoComponent); + MetaUtils.addLore(meta, ChatColor.GREEN + "Enough materials for " + new ItemMap(toSt).getMultiplesContainedIn(i) + + " runs"); + }); returns.add(toSt); return returns; } From a26b222a4b6b45cb89a15825aa80aaa165d4e613 Mon Sep 17 00:00:00 2001 From: Cola Date: Mon, 22 Aug 2022 17:15:31 +0100 Subject: [PATCH 4/4] Fix textual input --- .../FactoryMod/recipes/LoreRemoveRecipe.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java index 93263fa9..b3e00be4 100644 --- a/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java +++ b/paper/src/main/java/com/github/igotyou/FactoryMod/recipes/LoreRemoveRecipe.java @@ -9,12 +9,14 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; +import org.apache.commons.collections4.CollectionUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import vg.civcraft.mc.civmodcore.chat.ChatUtils; import vg.civcraft.mc.civmodcore.inventory.items.ItemMap; import vg.civcraft.mc.civmodcore.inventory.items.ItemUtils; import vg.civcraft.mc.civmodcore.inventory.items.MetaUtils; @@ -94,7 +96,7 @@ public List getOutputRepresentation(Inventory i, FurnCraftChestFactor is, ChatColor.GREEN + "Enough materials for " - + String.valueOf(Math.min(itemToCleanse.getMultiplesContainedIn(i), input.getMultiplesContainedIn(i))) + + Math.min(itemToCleanse.getMultiplesContainedIn(i), input.getMultiplesContainedIn(i)) + " runs"); } List stacks = new LinkedList<>(); @@ -103,15 +105,21 @@ public List getOutputRepresentation(Inventory i, FurnCraftChestFactor } private boolean checkIfHasLore(ItemStack itemStack) { - if (!itemStack.getItemMeta().hasLore()) { + ItemMeta meta = itemStack.getItemMeta(); + if (meta == null) { return false; } - return !itemStack.getItemMeta().lore().isEmpty(); + return CollectionUtils.isEmpty(meta.lore()); } @Override public List getTextualInputRepresentation(Inventory i, FurnCraftChestFactory fccf) { - return Arrays.asList("1 " + ItemUtils.getItemName(exampleInput)); + List inputNames = new ArrayList<>(); + inputNames.add(exampleInput.getAmount() + " " + ChatUtils.stringify(ItemUtils.asTranslatable(exampleInput))); + for (ItemStack is : input.getItemStackRepresentation()) { + inputNames.add(is.getAmount() + " " + ChatUtils.stringify(ItemUtils.asTranslatable(is))); + } + return inputNames; } @Override