From ba75403f3b3fae391adfd7fcccd360365cae4757 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 22 Nov 2023 21:41:23 +0100 Subject: [PATCH] implement new wood detection --- src/com/dre/brewery/Barrel.java | 9 +-- src/com/dre/brewery/recipe/BRecipe.java | 16 ++-- src/com/dre/brewery/utility/LegacyUtil.java | 81 +++++++++++++++++---- 3 files changed, 79 insertions(+), 27 deletions(-) diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 0c880f1..0ffd696 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -66,7 +66,6 @@ public class Barrel implements InventoryHolder { /** * Load from File *

If async: true, The Barrel Bounds will not be recreated when missing/corrupt, getBody().getBounds() will be null if it needs recreating - * */ public Barrel(Block spigot, byte sign, BoundingBox bounds, Map items, float time, boolean async) { this.spigot = spigot; @@ -266,7 +265,7 @@ public class Barrel implements InventoryHolder { return null; } Material type = block.getType(); - if (LegacyUtil.isFence(type) || LegacyUtil.isSign(type) ) { + if (LegacyUtil.isFence(type) || LegacyUtil.isSign(type)) { return getBySpigot(block); } else { return getByWood(block); @@ -375,8 +374,8 @@ public class Barrel implements InventoryHolder { /** * Removes a barrel, throwing included potions to the ground * - * @param broken The Block that was broken - * @param breaker The Player that broke it, or null if not known + * @param broken The Block that was broken + * @param breaker The Player that broke it, or null if not known * @param dropItems If the items in the barrels inventory should drop to the ground */ public void remove(@Nullable Block broken, @Nullable Player breaker, boolean dropItems) { @@ -542,7 +541,7 @@ public class Barrel implements InventoryHolder { } } // also save barrels that are not loaded - if (oldData != null){ + if (oldData != null) { for (String uuid : oldData.getKeys(false)) { if (!config.contains(uuid)) { config.set(uuid, oldData.get(uuid)); diff --git a/src/com/dre/brewery/recipe/BRecipe.java b/src/com/dre/brewery/recipe/BRecipe.java index 85cd480..748f9ee 100644 --- a/src/com/dre/brewery/recipe/BRecipe.java +++ b/src/com/dre/brewery/recipe/BRecipe.java @@ -5,6 +5,7 @@ import com.dre.brewery.Brew; import com.dre.brewery.P; import com.dre.brewery.filedata.BConfig; import com.dre.brewery.utility.BUtil; +import com.dre.brewery.utility.LegacyUtil; import com.dre.brewery.utility.StringParser; import com.dre.brewery.utility.Tuple; import org.bukkit.Color; @@ -140,7 +141,7 @@ public class BRecipe { if (configSectionRecipes.isString(recipeId + ".customModelData")) { String[] cmdParts = configSectionRecipes.getString(recipeId + ".customModelData", "").split("/"); if (cmdParts.length == 3) { - recipe.cmData = new int[]{P.p.parseInt(cmdParts[0]), P.p.parseInt(cmdParts[1]), P.p.parseInt(cmdParts[2])}; + recipe.cmData = new int[] {P.p.parseInt(cmdParts[0]), P.p.parseInt(cmdParts[1]), P.p.parseInt(cmdParts[2])}; if (recipe.cmData[0] == 0 && recipe.cmData[1] == 0 && recipe.cmData[2] == 0) { P.p.errorLog("Invalid customModelData in Recipe: " + recipe.getRecipeName()); recipe.cmData = null; @@ -151,7 +152,7 @@ public class BRecipe { } else { int cmd = configSectionRecipes.getInt(recipeId + ".customModelData", 0); if (cmd != 0) { - recipe.cmData = new int[]{cmd, cmd, cmd}; + recipe.cmData = new int[] {cmd, cmd, cmd}; } } @@ -181,7 +182,8 @@ public class BRecipe { return null; } List ingredients = new ArrayList<>(ingredientsList.size()); - listLoop: for (String item : ingredientsList) { + listLoop: + for (String item : ingredientsList) { String[] ingredParts = item.split("/"); int amount = 1; if (ingredParts.length == 2) { @@ -325,7 +327,7 @@ public class BRecipe { P.p.errorLog("Invalid distilltime '" + distillTime + "' in Recipe: " + getRecipeName()); return false; } - if (wood < 0 || wood > 11) { + if (wood < 0 || wood > LegacyUtil.TOTAL_WOOD_TYPES) { P.p.errorLog("Invalid wood type '" + wood + "' in Recipe: " + getRecipeName()); return false; } @@ -879,7 +881,7 @@ public class BRecipe { * Add a Line of Lore * * @param quality 0 for any quality, 1: bad, 2: normal, 3: good - * @param line The Line for custom lore to add + * @param line The Line for custom lore to add * @return this */ public Builder addLore(int quality, String line) { @@ -897,7 +899,7 @@ public class BRecipe { * Add Commands that are executed by the player on drinking */ public Builder addPlayerCmds(String... cmds) { - ArrayList> playercmds = new ArrayList<>(cmds.length); + ArrayList> playercmds = new ArrayList<>(cmds.length); for (String cmd : cmds) { playercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD)); @@ -914,7 +916,7 @@ public class BRecipe { * Add Commands that are executed by the server on drinking */ public Builder addServerCmds(String... cmds) { - ArrayList> servercmds = new ArrayList<>(cmds.length); + ArrayList> servercmds = new ArrayList<>(cmds.length); for (String cmd : cmds) { servercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD)); diff --git a/src/com/dre/brewery/utility/LegacyUtil.java b/src/com/dre/brewery/utility/LegacyUtil.java index d15c952..f958e57 100644 --- a/src/com/dre/brewery/utility/LegacyUtil.java +++ b/src/com/dre/brewery/utility/LegacyUtil.java @@ -13,7 +13,9 @@ import org.bukkit.material.Wood; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import static com.dre.brewery.BCauldron.EMPTY; @@ -45,34 +47,74 @@ public class LegacyUtil { // EnumSet not supposed to be used anymore // See https://www.spigotmc.org/threads/spigot-bungeecord-1-19.559742/ Set planks = new HashSet<>(); + Set allWoodTypes = new HashSet<>(); + List unknownWoodTypes = new ArrayList<>(); for (Material m : Material.values()) { - if (m.name().endsWith("PLANKS")) { + String name = m.name(); + if (name.endsWith("PLANKS")) { + String woodName = name.substring(0, name.lastIndexOf("_")); planks.add(m); + allWoodTypes.add(woodName); + if (!name.startsWith("OAK") && + !name.startsWith("SPRUCE") && + !name.startsWith("BIRCH") && + !name.startsWith("JUNGLE") && + !name.startsWith("ACACIA") && + !name.startsWith("DARK_OAK") && + !name.startsWith("CRIMSON") && + !name.startsWith("WARPED") && + !name.startsWith("MANGROVE") && + !name.startsWith("CHERRY") && + !name.startsWith("BAMBOO")) { + + unknownWoodTypes.add(woodName); + } } } + unknownWoodTypes.sort(null); PLANKS = planks; + UNKNOWN_WOOD = unknownWoodTypes; + TOTAL_WOOD_TYPES = allWoodTypes.size(); + + if (!unknownWoodTypes.isEmpty()) { + P.p.log("New wood types detected. Assigning recipe numbers:"); + int lastKnownNumber = 12; + for (int i = 0; i < unknownWoodTypes.size(); i++) { + P.p.log(" " + unknownWoodTypes.get(i) + ": " + (i + lastKnownNumber)); + } + } + Set woodStairs = new HashSet<>(); - Material[] gotStairs = { - get("OAK_STAIRS", "WOOD_STAIRS"), - get("SPRUCE_STAIRS", "SPRUCE_WOOD_STAIRS"), - get("BIRCH_STAIRS", "BIRCH_WOOD_STAIRS"), - get("JUNGLE_STAIRS", "JUNGLE_WOOD_STAIRS"), - get("ACACIA_STAIRS"), - get("DARK_OAK_STAIRS"), - get("CRIMSON_STAIRS"), - get("WARPED_STAIRS"), - get("MANGROVE_STAIRS"), - get("CHERRY_STAIRS"), - get("BAMBOO_STAIRS"), - }; - for (Material stair : gotStairs) { + for (String wood : allWoodTypes) { + Material stair = get(wood + "_STAIRS"); if (stair != null) { woodStairs.add(stair); } } + if (!P.use1_13) { + Material[] legacyStairs = { + get("OAK_STAIRS", "WOOD_STAIRS"), + get("SPRUCE_STAIRS", "SPRUCE_WOOD_STAIRS"), + get("BIRCH_STAIRS", "BIRCH_WOOD_STAIRS"), + get("JUNGLE_STAIRS", "JUNGLE_WOOD_STAIRS"), + }; + for (Material stair : legacyStairs) { + if (stair != null) { + woodStairs.add(stair); + } + } + } WOOD_STAIRS = woodStairs; + // Special case for Bamboo mosaic, which simply counts as bamboo in recipes + if (get("BAMBOO_MOSAIC") != null) { + planks.add(get("BAMBOO_MOSAIC")); + } + if (get("BAMBOO_MOSAIC_STAIRS") != null) { + woodStairs.add(get("BAMBOO_MOSAIC_STAIRS")); + } + Set fences = new HashSet<>(); for (Material m : Material.values()) { @@ -92,6 +134,8 @@ public class LegacyUtil { public static final Set PLANKS; public static final Set WOOD_STAIRS; public static final Set FENCES; + public static final List UNKNOWN_WOOD; + public static final int TOTAL_WOOD_TYPES; // Materials removed in 1.13 public static final Material STATIONARY_LAVA = get("STATIONARY_LAVA"); @@ -197,6 +241,13 @@ public class LegacyUtil { return 10; } else if (material.startsWith("BAMBOO")) { return 11; + } else if (!UNKNOWN_WOOD.isEmpty()) { + for (int i = 0; i < UNKNOWN_WOOD.size(); i++) { + if (material.startsWith(UNKNOWN_WOOD.get(i))) { + return (byte) (i + 12); + } + } + return 0; } else { return 0; }