From a499ab2cf0b8996551f57281394aab93a0366571 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Fri, 8 Feb 2013 19:29:13 +0100 Subject: [PATCH] "Light Blue Wool" now works Awesome. More performance, better item recognition. Less spaghetti in the code. --- com/Acrobot/Breeze/Utils/MaterialUtil.java | 50 ++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/com/Acrobot/Breeze/Utils/MaterialUtil.java b/com/Acrobot/Breeze/Utils/MaterialUtil.java index 71cd470..1833904 100644 --- a/com/Acrobot/Breeze/Utils/MaterialUtil.java +++ b/com/Acrobot/Breeze/Utils/MaterialUtil.java @@ -144,54 +144,50 @@ public class MaterialUtil { String[] split = Iterables.toArray(Splitter.onPattern(":|-|#").trimResults().split(itemName), String.class); Material material = getMaterial(split[0]); - - boolean onlyPartiallyChecked = false; + short durability = getDurability(itemName); if (material == null) { if (!split[0].contains(" ")) { return null; } - int index = split[0].indexOf(' '); + for (int index = split[0].indexOf(' '); index >= 0; index = split[0].indexOf(' ', index + 1)) { + material = getMaterial(split[0].substring(index)); - material = getMaterial(split[0].substring(index + 1)); + if (material != null) { + if (durability == 0) { + durability = DataValue.get(split[0].substring(0, index), material); + } + + break; + } + } if (material == null) { return null; } - - onlyPartiallyChecked = true; - } - - itemStack = new ItemStack(material, 1); - - short durability = getDurability(itemName); - - if (durability == 0 && onlyPartiallyChecked) { - String[] spaces = itemName.split(" "); - if (spaces.length != 0) { - durability = DataValue.get(spaces[0], material); - } } + itemStack = new ItemStack(material); itemStack.setDurability(durability); - Map enchantments = getEnchantments(itemName); //TODO - it's obsolete, left only for backward compatibility - - if (!enchantments.isEmpty()) { - try { - itemStack.addEnchantments(enchantments); - } catch (IllegalArgumentException exception) { - //Do nothing, because the enchantment can't be applied - } - } - ItemMeta meta = getMetadata(itemName); if (meta != null) { itemStack.setItemMeta(meta); + } else { + Map enchantments = getEnchantments(itemName); //TODO - it's obsolete, left only for backward compatibility + + if (!enchantments.isEmpty()) { + try { + itemStack.addEnchantments(enchantments); + } catch (IllegalArgumentException exception) { + //Do nothing, because the enchantment can't be applied + } + } } + return itemStack; }