Skip to content

Commit

Permalink
Fix collect debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed May 14, 2024
1 parent 24d6b27 commit 8bf3d6d
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 29 deletions.
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
Expand Up @@ -73,7 +73,7 @@ public LootConditionList getConditions() {

@Override
public void collectDebugInfo(DebugInfo info) {
info.add(getType().toString());
info.add("% Composite: " + getType());
info.push();
entries(entries -> entries.collectDebugInfo(info));
when(conditions -> conditions.collectDebugInfo(info));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.almostreliable.lootjs.core.entry;

import com.almostreliable.lootjs.loot.LootConditionList;
import com.almostreliable.lootjs.loot.LootFunctionList;
import com.almostreliable.lootjs.util.DebugInfo;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.entries.EmptyLootItem;
Expand Down Expand Up @@ -36,4 +35,10 @@ public ItemStack create(LootContext context) {

return ItemStack.EMPTY;
}

@Override
public void collectDebugInfo(DebugInfo info) {
info.add("% Empty");
super.collectDebugInfo(info);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.almostreliable.lootjs.core.entry;

import com.almostreliable.lootjs.core.filters.ItemFilter;
import com.almostreliable.lootjs.loot.LootConditionList;
import com.almostreliable.lootjs.loot.LootFunctionList;
import com.almostreliable.lootjs.util.DebugInfo;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -95,4 +95,10 @@ public ItemStack create(LootContext context) {
public boolean test(ItemFilter filter) {
return filter.test(new ItemStack(getItem()));
}

@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
Expand Up @@ -140,7 +140,6 @@ default void collectDebugInfo(DebugInfo info) {

}


default boolean isItem() {
return getVanillaType() == LootPoolEntries.ITEM;
}
Expand Down
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.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.entries.LootPoolSingletonContainer;
import net.minecraft.world.level.storage.loot.entries.LootTableReference;
Expand All @@ -24,4 +25,10 @@ public ResourceLocation getLocation() {
public void setLocation(ResourceLocation reference) {
vanillaEntry.name = reference;
}

@Override
public void collectDebugInfo(DebugInfo info) {
info.add("% Table: " + vanillaEntry.name);
super.collectDebugInfo(info);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.almostreliable.lootjs.core.entry;

import com.almostreliable.lootjs.loot.LootConditionList;
import com.almostreliable.lootjs.loot.LootFunctionList;
import com.almostreliable.lootjs.util.DebugInfo;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -87,4 +86,10 @@ public ItemStack create(LootContext context) {

return null;
}

@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 @@ -63,10 +63,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
26 changes: 5 additions & 21 deletions src/main/java/com/almostreliable/lootjs/loot/LootFunctionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import com.almostreliable.lootjs.util.DebugInfo;
import com.almostreliable.lootjs.util.ListHolder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;
import net.minecraft.world.level.storage.loot.functions.LootItemFunctions;
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;

import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -49,31 +46,18 @@ public LootFunctionList addFunction(LootItemFunction function) {
return this;
}

@Override
public LootFunctionList setCount(NumberProvider numberProvider) {
LootItemFunction sc = LootFunction.setCount(numberProvider);
replace(LootItemFunctions.SET_COUNT, sc);
return this;
}

public LootFunctionList setNbt(CompoundTag nbt) {
LootItemFunction sc = LootFunction.setNbt(nbt);
replace(LootItemFunctions.SET_NBT, sc);
return this;
}

public LootFunctionList setNBT(CompoundTag nbt) {
return setNbt(nbt);
}

public void collectDebugInfo(DebugInfo info) {
if (this.isEmpty()) return;

info.add("% Functions: [");
info.push();
for (var entry : this) {
ResourceLocation key = BuiltInRegistries.LOOT_FUNCTION_TYPE.getKey(entry.getType());
if (key == null) continue;
if (key == null) {
info.add(entry.getClass().getSimpleName());
continue;
}

info.add(key.toString());
}

Expand Down

0 comments on commit 8bf3d6d

Please sign in to comment.