From 2b662d8ea73ccca560777e369f1e31f333aec5db Mon Sep 17 00:00:00 2001 From: LLytho Date: Thu, 25 Jul 2024 11:19:17 +0200 Subject: [PATCH] Fix a crash & `create` in `LootTableEvent` --- CHANGELOG.md | 4 ++++ example_scripts/create_loot_table.js | 5 +++++ .../com/almostreliable/lootjs/core/entry/ItemLootEntry.java | 2 +- .../lootjs/mixin/ReloadableServerRegistriesMixin.java | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 example_scripts/create_loot_table.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa33b9..52a06b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning]. - / +## [3.0.4] - 2024-07-25 + +- Fix `.create` in loot tables event + ## [3.0.3] - 2024-07-22 - Bump kubejs version diff --git a/example_scripts/create_loot_table.js b/example_scripts/create_loot_table.js new file mode 100644 index 0000000..bbb7296 --- /dev/null +++ b/example_scripts/create_loot_table.js @@ -0,0 +1,5 @@ +LootJS.lootTables(e => { + e.create("lootjs:blocks/test_table", "block").createPool((pool) => { + pool.addEntry(LootEntry.of("minecraft:stick").limitCount(10, 32)); + }); +}); diff --git a/src/main/java/com/almostreliable/lootjs/core/entry/ItemLootEntry.java b/src/main/java/com/almostreliable/lootjs/core/entry/ItemLootEntry.java index 792132a..201a8b3 100644 --- a/src/main/java/com/almostreliable/lootjs/core/entry/ItemLootEntry.java +++ b/src/main/java/com/almostreliable/lootjs/core/entry/ItemLootEntry.java @@ -38,7 +38,7 @@ public ItemLootEntry(ItemStack itemStack) { getFunctions().setCount(ConstantValue.exactly(itemStack.getCount())); } - if (!itemStack.getComponents().isEmpty()) { + if (!itemStack.isComponentsPatchEmpty()) { DataComponentPatch.Builder builder = DataComponentPatch.builder(); for (TypedDataComponent component : itemStack.getComponents()) { builder.set(Utils.cast(component.type()), component.value()); diff --git a/src/main/java/com/almostreliable/lootjs/mixin/ReloadableServerRegistriesMixin.java b/src/main/java/com/almostreliable/lootjs/mixin/ReloadableServerRegistriesMixin.java index 63068db..f8d8589 100644 --- a/src/main/java/com/almostreliable/lootjs/mixin/ReloadableServerRegistriesMixin.java +++ b/src/main/java/com/almostreliable/lootjs/mixin/ReloadableServerRegistriesMixin.java @@ -18,7 +18,7 @@ @Mixin(value = ReloadableServerRegistries.class, priority = 1337) public class ReloadableServerRegistriesMixin { - @Inject(method = "apply", at = @At("RETURN")) + @Inject(method = "apply", at = @At("HEAD")) private static void lootjs$runLootTableEventJS(LayeredRegistryAccess arg, List> list, CallbackInfoReturnable> cir) { WritableRegistry registry = null; try {