Skip to content

Commit

Permalink
Fix matchCustomCondition and jsonFunction using wrong codec.
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Aug 24, 2024
1 parent 29ac487 commit 52d1039
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning].
# Unreleased

- Fix `print` method for loot tables. Will now print the entries correctly.
- Fix `matchCustomCondition` and `jsonFunction` using wrong codec.

## [3.1.0] - 2024-08-03

Expand Down
18 changes: 18 additions & 0 deletions example_scripts/custom_condition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LootJS.lootTables((event) => {
event.getBlockTable('minecraft:coal_ore')
.clear()
.firstPool()
.addEntry(LootEntry.of('minecraft:diamond').matchCustomCondition({
condition: "minecraft:match_tool",
predicate: {
enchantments: [
{
enchantment: "minecraft:silk_touch",
levels: {
min: 1,
},
},
],
},
}));
})
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ default C matchAllOf(LootItemCondition... conditions) {

default C matchCustomCondition(JsonObject json) {
var regOps = RegistryOps.create(JsonOps.INSTANCE, LootJS.lookup());
var condition = LootItemCondition.CODEC.parse(regOps, json).getOrThrow().value();
var condition = LootItemCondition.DIRECT_CODEC.parse(regOps, json).getOrThrow();
return addCondition(condition);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ default F toggleTooltips(Map<String, Boolean> toggles) {

default F jsonFunction(JsonObject json) {
var regOps = RegistryOps.create(JsonOps.INSTANCE, LootJS.lookup());
LootItemFunction function = LootItemFunctions.CODEC.parse(regOps, json).getOrThrow().value();
LootItemFunction function = LootItemFunctions.ROOT_CODEC.parse(regOps, json).getOrThrow();
return addFunction(function);
}

Expand Down

0 comments on commit 52d1039

Please sign in to comment.