Skip to content

Commit

Permalink
fixed concurrently modifying the client item properties (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathing authored Nov 7, 2024
1 parent f7a2d65 commit 3de00ca
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ private void doClientStuff(final FMLClientSetupEvent event) {
Type type = new TypeToken<Map<String, Float>>(){}.getType();
enchantmentMap = new Gson().fromJson(new BufferedReader(input), type);

ItemModelsProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity) -> {
Map<Enchantment, Integer> 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<Enchantment, Integer> 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);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ private void doClientStuff (final FMLClientSetupEvent event) {
Type type = new TypeToken<Map<String, Float>>(){}.getType();
enchantmentMap = new Gson().fromJson(new BufferedReader(input), type);

ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> {
Map<Enchantment, Integer> 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<Enchantment, Integer> 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);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ private void doClientStuff (final FMLClientSetupEvent event) {
Type type = new TypeToken<Map<String, Float>>(){}.getType();
enchantmentMap = new Gson().fromJson(new BufferedReader(input), type);

ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> {
Map<Enchantment, Integer> 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<Enchantment, Integer> 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);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ private void doClientStuff (final FMLClientSetupEvent event) {
Type type = new TypeToken<Map<String, Float>>(){}.getType();
enchantmentMap = new Gson().fromJson(new BufferedReader(input), type);

ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> {
Map<Enchantment, Integer> 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<Enchantment, Integer> 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);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ private void doClientStuff (final FMLClientSetupEvent event) {
Type type = new TypeToken<Map<String, Float>>(){}.getType();
enchantmentMap = new Gson().fromJson(new BufferedReader(input), type);

ItemProperties.register(Items.ENCHANTED_BOOK, new ResourceLocation("nebs:enchant"), (stack, world, entity, i) -> {
Map<Enchantment, Integer> 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<Enchantment, Integer> 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();

Expand Down

0 comments on commit 3de00ca

Please sign in to comment.