diff --git a/CHANGELOG.md b/CHANGELOG.md index 7057e47..37867b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. +# Unreleased + +- Fix `print` method for loot tables. Will now print the entries correctly. + ## [3.1.0] - 2024-08-03 - Remove `addItem` for loot pools. Prefer to use `addEntry` diff --git a/example_scripts/print.js b/example_scripts/print.js new file mode 100644 index 0000000..f376f32 --- /dev/null +++ b/example_scripts/print.js @@ -0,0 +1,3 @@ +LootJS.lootTables(event => { + event.getLootTable("minecraft:chests/simple_dungeon").print() +}) diff --git a/src/main/java/com/almostreliable/lootjs/core/entry/AbstractSimpleLootEntry.java b/src/main/java/com/almostreliable/lootjs/core/entry/AbstractSimpleLootEntry.java index 66fba10..421b583 100644 --- a/src/main/java/com/almostreliable/lootjs/core/entry/AbstractSimpleLootEntry.java +++ b/src/main/java/com/almostreliable/lootjs/core/entry/AbstractSimpleLootEntry.java @@ -2,6 +2,7 @@ import com.almostreliable.lootjs.loot.LootConditionList; import com.almostreliable.lootjs.loot.LootFunctionList; +import com.almostreliable.lootjs.util.DebugInfo; import net.minecraft.world.level.storage.loot.entries.LootPoolEntryType; import net.minecraft.world.level.storage.loot.entries.LootPoolSingletonContainer; @@ -71,4 +72,12 @@ public void setQuality(int quality) { public int getQuality() { return vanillaEntry.quality; } + + @Override + public void collectDebugInfo(DebugInfo info) { + info.push(); + when(conditions -> conditions.collectDebugInfo(info)); + getFunctions().collectDebugInfo(info); + info.pop(); + } } diff --git a/src/main/java/com/almostreliable/lootjs/core/entry/EmptyLootEntry.java b/src/main/java/com/almostreliable/lootjs/core/entry/EmptyLootEntry.java index 97d8c94..d62d36d 100644 --- a/src/main/java/com/almostreliable/lootjs/core/entry/EmptyLootEntry.java +++ b/src/main/java/com/almostreliable/lootjs/core/entry/EmptyLootEntry.java @@ -1,5 +1,6 @@ package com.almostreliable.lootjs.core.entry; +import com.almostreliable.lootjs.util.DebugInfo; import net.minecraft.world.level.storage.loot.entries.EmptyLootItem; import net.minecraft.world.level.storage.loot.entries.LootPoolSingletonContainer; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; @@ -22,4 +23,10 @@ public EmptyLootEntry addCondition(LootItemCondition condition) { getConditions().add(condition); return this; } + + @Override + public void collectDebugInfo(DebugInfo info) { + info.add("% Empty"); + super.collectDebugInfo(info); + } } 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 201a8b3..ce88090 100644 --- a/src/main/java/com/almostreliable/lootjs/core/entry/ItemLootEntry.java +++ b/src/main/java/com/almostreliable/lootjs/core/entry/ItemLootEntry.java @@ -1,9 +1,11 @@ package com.almostreliable.lootjs.core.entry; import com.almostreliable.lootjs.core.filters.ItemFilter; +import com.almostreliable.lootjs.util.DebugInfo; import com.almostreliable.lootjs.util.Utils; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.TypedDataComponent; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -103,4 +105,10 @@ public ItemLootEntry addCondition(LootItemCondition condition) { getConditions().add(condition); return this; } + + @Override + public void collectDebugInfo(DebugInfo info) { + info.add("% Item: " + BuiltInRegistries.ITEM.getKey(getItem())); + super.collectDebugInfo(info); + } } diff --git a/src/main/java/com/almostreliable/lootjs/core/entry/TableReferenceLootEntry.java b/src/main/java/com/almostreliable/lootjs/core/entry/TableReferenceLootEntry.java index 0b707f7..d750cc6 100644 --- a/src/main/java/com/almostreliable/lootjs/core/entry/TableReferenceLootEntry.java +++ b/src/main/java/com/almostreliable/lootjs/core/entry/TableReferenceLootEntry.java @@ -1,5 +1,6 @@ package com.almostreliable.lootjs.core.entry; +import com.almostreliable.lootjs.util.DebugInfo; import com.mojang.datafixers.util.Either; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -35,4 +36,10 @@ public TableReferenceLootEntry addCondition(LootItemCondition condition) { getConditions().add(condition); return this; } + + @Override + public void collectDebugInfo(DebugInfo info) { + info.add("% Table: " + getLocation()); + super.collectDebugInfo(info); + } } diff --git a/src/main/java/com/almostreliable/lootjs/core/entry/TagLootEntry.java b/src/main/java/com/almostreliable/lootjs/core/entry/TagLootEntry.java index aa6b0e2..72068cf 100644 --- a/src/main/java/com/almostreliable/lootjs/core/entry/TagLootEntry.java +++ b/src/main/java/com/almostreliable/lootjs/core/entry/TagLootEntry.java @@ -1,5 +1,6 @@ package com.almostreliable.lootjs.core.entry; +import com.almostreliable.lootjs.util.DebugInfo; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -56,4 +57,10 @@ public TagLootEntry addCondition(LootItemCondition condition) { getConditions().add(condition); return this; } + + @Override + public void collectDebugInfo(DebugInfo info) { + info.add("% Tag: " + getTag()); + super.collectDebugInfo(info); + } } diff --git a/src/main/java/com/almostreliable/lootjs/loot/LootEntryList.java b/src/main/java/com/almostreliable/lootjs/loot/LootEntryList.java index 3392ba2..ecc87ef 100644 --- a/src/main/java/com/almostreliable/lootjs/loot/LootEntryList.java +++ b/src/main/java/com/almostreliable/lootjs/loot/LootEntryList.java @@ -66,9 +66,14 @@ public void collectDebugInfo(DebugInfo info) { info.add("% Entries: ["); info.push(); + info.add("{"); + info.push(); for (LootEntry entry : this) { entry.collectDebugInfo(info); } + + info.pop(); + info.add("}"); info.pop(); info.add("]"); }