diff options
author | Linnea Gräf <nea@nea.moe> | 2024-06-12 20:57:55 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-06-12 20:57:55 +0200 |
commit | c897a31cd3d2d0045b1555e307b1fd30643e0c3b (patch) | |
tree | 3e6ffc6d2f767769f29c679eefff150b5bbcfdb4 | |
parent | fc45d59ebdb7ed846ad5be2ddb077de4c6b779fe (diff) | |
download | NotEnoughUpdates-c897a31cd3d2d0045b1555e307b1fd30643e0c3b.tar.gz NotEnoughUpdates-c897a31cd3d2d0045b1555e307b1fd30643e0c3b.tar.bz2 NotEnoughUpdates-c897a31cd3d2d0045b1555e307b1fd30643e0c3b.zip |
Add extra check before modifying custom armorfeat/lessarmorstuff
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java index afb63dff..59e5a610 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java @@ -72,6 +72,7 @@ public class ItemCustomizeManager { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static ItemDataMap itemDataMap = new ItemDataMap(); + public static class ItemDataMap { public HashMap<String, ItemData> itemData = new HashMap<>(); } @@ -304,7 +305,8 @@ public class ItemCustomizeManager { public static Item getCustomItem(ItemStack stack) { ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0 || data.customItem.split(":").length == 0) return stack.getItem(); + if (data == null || data.customItem == null || data.customItem.length() == 0 || + data.customItem.split(":").length == 0) return stack.getItem(); Item newItem = Item.getByNameOrId(data.customItem.split(":")[0]); if (newItem == null) return stack.getItem(); return newItem; @@ -329,7 +331,8 @@ public class ItemCustomizeManager { if (damageString.equals("?")) { ArrayList<ItemStack> list = new ArrayList<>(); getCustomItem(stack).getSubItems(getCustomItem(stack), null, list); - if (damageMap.get(stack.getTagCompound().hashCode()) == null || System.currentTimeMillis() - lastUpdate.get(stack.getTagCompound().hashCode()) > 250) { + if (damageMap.get(stack.getTagCompound().hashCode()) == null || System.currentTimeMillis() - lastUpdate.get( + stack.getTagCompound().hashCode()) > 250) { damageMap.put(stack.getTagCompound().hashCode(), random.nextInt(list.size())); lastUpdate.put(stack.getTagCompound().hashCode(), System.currentTimeMillis()); @@ -351,8 +354,9 @@ public class ItemCustomizeManager { public static boolean shouldRenderLeatherColour(ItemStack stack) { ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0) return stack.getItem() instanceof ItemArmor && - ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; + if (data == null || data.customItem == null || data.customItem.length() == 0) + return stack.getItem() instanceof ItemArmor && + ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; Item item = Item.getByNameOrId(data.customItem); if (item == null) return stack.getItem() instanceof ItemArmor && ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; @@ -362,7 +366,8 @@ public class ItemCustomizeManager { public static boolean hasCustomItem(ItemStack stack) { ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0 || data.defaultItem == null || data.customItem.equals(data.defaultItem) || data.customItem.split(":").length == 0) return false; + if (data == null || data.customItem == null || data.customItem.length() == 0 || data.defaultItem == null || + data.customItem.equals(data.defaultItem) || data.customItem.split(":").length == 0) return false; Item item = Item.getByNameOrId(data.customItem.split(":")[0]); Item defaultItem = Item.getByNameOrId(data.defaultItem); if (item == null) { @@ -372,16 +377,24 @@ public class ItemCustomizeManager { return defaultItem != item; } - public static ItemStack useCustomArmour(LayerArmorBase<?> instance, EntityLivingBase entitylivingbaseIn, int armorSlot) { + public static ItemStack useCustomArmour( + LayerArmorBase<?> instance, + EntityLivingBase entitylivingbaseIn, + int armorSlot + ) { ItemStack stack = instance.getCurrentArmor(entitylivingbaseIn, armorSlot); - if (stack == null) return stack; + if (stack == null || getDataForItem(stack) == null) return stack; ItemStack newStack = stack.copy(); newStack.setItem(ItemCustomizeManager.getCustomItem(newStack)); newStack.setItemDamage(ItemCustomizeManager.getCustomItemDamage(newStack)); - if (armorSlot != 4) { - if (newStack.getItem() instanceof ItemArmor) return newStack; - else return stack; - } + + if (armorSlot != 4 && newStack.getItem() instanceof ItemArmor) + // Remove non armor from any slot except heads + newStack = stack; + + if (newStack.getItem() == stack.getItem() + && newStack.getItemDamage() == stack.getItemDamage()) + return stack; return newStack; } |