Skip to content

Commit

Permalink
implement new wood detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wStorm committed Nov 22, 2023
1 parent 217ca3f commit ba75403
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 27 deletions.
9 changes: 4 additions & 5 deletions src/com/dre/brewery/Barrel.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public Barrel(Block spigot, byte sign, BoundingBox bounds, Map<String, Object> i
/**
* Load from File
* <p>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<String, Object> items, float time, boolean async) {
this.spigot = spigot;
Expand Down Expand Up @@ -266,7 +265,7 @@ public static Barrel get(Block block) {
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);
Expand Down Expand Up @@ -375,8 +374,8 @@ public static boolean create(Block sign, Player player) {
/**
* 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) {
Expand Down Expand Up @@ -542,7 +541,7 @@ public static void save(ConfigurationSection config, ConfigurationSection oldDat
}
}
// 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));
Expand Down
16 changes: 9 additions & 7 deletions src/com/dre/brewery/recipe/BRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -140,7 +141,7 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri
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;
Expand All @@ -151,7 +152,7 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri
} 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};
}
}

Expand Down Expand Up @@ -181,7 +182,8 @@ public static List<RecipeItem> loadIngredients(ConfigurationSection cfg, String
return null;
}
List<RecipeItem> 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) {
Expand Down Expand Up @@ -325,7 +327,7 @@ public boolean isValid() {
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;
}
Expand Down Expand Up @@ -879,7 +881,7 @@ public Builder addLore(String line) {
* 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) {
Expand All @@ -897,7 +899,7 @@ public Builder addLore(int quality, String line) {
* Add Commands that are executed by the player on drinking
*/
public Builder addPlayerCmds(String... cmds) {
ArrayList<Tuple<Integer,String>> playercmds = new ArrayList<>(cmds.length);
ArrayList<Tuple<Integer, String>> playercmds = new ArrayList<>(cmds.length);

for (String cmd : cmds) {
playercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD));
Expand All @@ -914,7 +916,7 @@ public Builder addPlayerCmds(String... cmds) {
* Add Commands that are executed by the server on drinking
*/
public Builder addServerCmds(String... cmds) {
ArrayList<Tuple<Integer,String>> servercmds = new ArrayList<>(cmds.length);
ArrayList<Tuple<Integer, String>> servercmds = new ArrayList<>(cmds.length);

for (String cmd : cmds) {
servercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD));
Expand Down
81 changes: 66 additions & 15 deletions src/com/dre/brewery/utility/LegacyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

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;
Expand Down Expand Up @@ -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<Material> planks = new HashSet<>();
Set<String> allWoodTypes = new HashSet<>();
List<String> 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<Material> 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<Material> fences = new HashSet<>();
for (Material m : Material.values()) {
Expand All @@ -92,6 +134,8 @@ public class LegacyUtil {
public static final Set<Material> PLANKS;
public static final Set<Material> WOOD_STAIRS;
public static final Set<Material> FENCES;
public static final List<String> UNKNOWN_WOOD;
public static final int TOTAL_WOOD_TYPES;

// Materials removed in 1.13
public static final Material STATIONARY_LAVA = get("STATIONARY_LAVA");
Expand Down Expand Up @@ -197,6 +241,13 @@ public static byte getWoodType(Block wood) throws NoSuchFieldError, NoClassDefFo
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;
}
Expand Down

0 comments on commit ba75403

Please sign in to comment.