From 3de00ca97a673c56ef58fd3d9c651f1b11174a54 Mon Sep 17 00:00:00 2001 From: Jonathing Date: Thu, 7 Nov 2024 17:12:59 -0500 Subject: [PATCH] fixed concurrently modifying the client item properties (#57) --- .../nebs/NekosEnchantedBooks.java | 17 ++++++++++------- .../nebs/NekosEnchantedBooks.java | 17 ++++++++++------- .../nebs/NekosEnchantedBooks.java | 17 ++++++++++------- .../nebs/NekosEnchantedBooks.java | 17 ++++++++++------- .../nebs/NekosEnchantedBooks.java | 19 +++++++++++-------- 5 files changed, 51 insertions(+), 36 deletions(-) diff --git a/1.16/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java b/1.16/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java index 033f4e6..74d167a 100644 --- a/1.16/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java +++ b/1.16/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java @@ -53,14 +53,17 @@ private void doClientStuff(final FMLClientSetupEvent event) { Type type = new TypeToken>(){}.getType(); enchantmentMap = new Gson().fromJson(new BufferedReader(input), type); - ItemModelsProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity) -> { - Map map = EnchantmentHelper.getEnchantments(stack); - if (map.isEmpty() || enchantmentMap == null) { - return 0.0F; - } + // enqueue this part so we don't concurrently modify the client item properties + event.enqueueWork(() -> { + ItemModelsProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity) -> { + Map map = EnchantmentHelper.getEnchantments(stack); + if (map.isEmpty() || enchantmentMap == null) { + return 0.0F; + } - String key = map.entrySet().iterator().next().getKey().getDescriptionId(); - return enchantmentMap.getOrDefault(key, 0.0F); + String key = map.entrySet().iterator().next().getKey().getDescriptionId(); + return enchantmentMap.getOrDefault(key, 0.0F); + }); }); } diff --git a/1.17/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java b/1.17/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java index 933698d..aa29bf9 100644 --- a/1.17/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java +++ b/1.17/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java @@ -52,14 +52,17 @@ private void doClientStuff (final FMLClientSetupEvent event) { Type type = new TypeToken>(){}.getType(); enchantmentMap = new Gson().fromJson(new BufferedReader(input), type); - ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { - Map map = EnchantmentHelper.getEnchantments(stack); - if (map.isEmpty() || enchantmentMap == null) { - return 0.0F; - } + // enqueue this part so we don't concurrently modify the client item properties + event.enqueueWork(() -> { + ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { + Map map = EnchantmentHelper.getEnchantments(stack); + if (map.isEmpty() || enchantmentMap == null) { + return 0.0F; + } - String key = map.entrySet().iterator().next().getKey().getDescriptionId(); - return enchantmentMap.getOrDefault(key, 0.0F); + String key = map.entrySet().iterator().next().getKey().getDescriptionId(); + return enchantmentMap.getOrDefault(key, 0.0F); + }); }); } diff --git a/1.18/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java b/1.18/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java index cf39f12..7d99284 100644 --- a/1.18/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java +++ b/1.18/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java @@ -52,14 +52,17 @@ private void doClientStuff (final FMLClientSetupEvent event) { Type type = new TypeToken>(){}.getType(); enchantmentMap = new Gson().fromJson(new BufferedReader(input), type); - ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { - Map map = EnchantmentHelper.getEnchantments(stack); - if (map.isEmpty() || enchantmentMap == null) { - return 0.0F; - } + // enqueue this part so we don't concurrently modify the client item properties + event.enqueueWork(() -> { + ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { + Map map = EnchantmentHelper.getEnchantments(stack); + if (map.isEmpty() || enchantmentMap == null) { + return 0.0F; + } - String key = map.entrySet().iterator().next().getKey().getDescriptionId(); - return enchantmentMap.getOrDefault(key, 0.0F); + String key = map.entrySet().iterator().next().getKey().getDescriptionId(); + return enchantmentMap.getOrDefault(key, 0.0F); + }); }); } diff --git a/1.19/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java b/1.19/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java index 43d22bd..98efcdf 100644 --- a/1.19/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java +++ b/1.19/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java @@ -52,14 +52,17 @@ private void doClientStuff (final FMLClientSetupEvent event) { Type type = new TypeToken>(){}.getType(); enchantmentMap = new Gson().fromJson(new BufferedReader(input), type); - ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { - Map map = EnchantmentHelper.getEnchantments(stack); - if (map.isEmpty() || enchantmentMap == null) { - return 0.0F; - } + // enqueue this part so we don't concurrently modify the client item properties + event.enqueueWork(() -> { + ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { + Map map = EnchantmentHelper.getEnchantments(stack); + if (map.isEmpty() || enchantmentMap == null) { + return 0.0F; + } - String key = map.entrySet().iterator().next().getKey().getDescriptionId(); - return enchantmentMap.getOrDefault(key, 0.0F); + String key = map.entrySet().iterator().next().getKey().getDescriptionId(); + return enchantmentMap.getOrDefault(key, 0.0F); + }); }); } diff --git a/1.20/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java b/1.20/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java index 0723823..98efcdf 100755 --- a/1.20/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java +++ b/1.20/src/main/java/org/infernalstudios/nebs/NekosEnchantedBooks.java @@ -52,17 +52,20 @@ private void doClientStuff (final FMLClientSetupEvent event) { Type type = new TypeToken>(){}.getType(); enchantmentMap = new Gson().fromJson(new BufferedReader(input), type); - ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { - Map map = EnchantmentHelper.getEnchantments(stack); - if (map.isEmpty() || enchantmentMap == null) { - return 0.0F; - } + // enqueue this part so we don't concurrently modify the client item properties + event.enqueueWork(() -> { + ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> { + Map map = EnchantmentHelper.getEnchantments(stack); + if (map.isEmpty() || enchantmentMap == null) { + return 0.0F; + } - String key = map.entrySet().iterator().next().getKey().getDescriptionId(); - return enchantmentMap.getOrDefault(key, 0.0F); + String key = map.entrySet().iterator().next().getKey().getDescriptionId(); + return enchantmentMap.getOrDefault(key, 0.0F); + }); }); } - + private void gatherData(GatherDataEvent event) { DataGenerator gen = event.getGenerator();