Skip to content

Commit

Permalink
Fix print method for loot tables
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Aug 24, 2024
1 parent 3f2fb86 commit 29ac487
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions example_scripts/print.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LootJS.lootTables(event => {
event.getLootTable("minecraft:chests/simple_dungeon").print()
})
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("]");
}
Expand Down

0 comments on commit 29ac487

Please sign in to comment.