Skip to content

Commit

Permalink
Entirely fix all future cases of tool stack adding empty NBT to items
Browse files Browse the repository at this point in the history
Now instead of doing so, it will log a warning. Said warning can print a stack trace if enabled in config. Don't want to always stack trace as sometimes tool stacks are created in frequent contexts
  • Loading branch information
KnightMiner committed Jan 19, 2023
1 parent abc51f3 commit 9f58e91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public static class Common {
public final BooleanValue showAllAnvilVariants;
public final BooleanValue showAllSmelteryVariants;

// debug
public final BooleanValue forceIntegrationMaterials;
public final BooleanValue logInvalidToolStackTrace;

Common(ForgeConfigSpec.Builder builder) {
builder.comment("Everything to do with gameplay").push("gameplay");
Expand Down Expand Up @@ -259,6 +261,9 @@ public static class Common {
"Does not provide recipes for any of them, they will only be available to cheat in creative.")
.worldRestart()
.define("forceIntegrationMaterials", false);
this.logInvalidToolStackTrace = builder
.comment("If true, logs the stacktrace whenever a tool stack is created from a non-modifiable item. The stacktrace helps debug which mod is causing it, but is rather expensive on the chance they are doing it a lot.")
.define("logInvalidToolStackTrace", true);
builder.pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.common.config.Config;
import slimeknights.tconstruct.library.materials.MaterialRegistry;
import slimeknights.tconstruct.library.materials.definition.MaterialVariantId;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
Expand Down Expand Up @@ -136,7 +138,15 @@ private static ToolStack from(ItemStack stack, boolean copyNbt) {
if (!copyNbt) {
// bypass the setter as vanilla insists on setting damage values there, along with verifying the tag
// both are things we will do later, doing so now causes us to recursively call this method (though not infinite)
stack.tag = nbt;
if (stack.is(TinkerTags.Items.MODIFIABLE)) {
stack.tag = nbt;
} else {
if (Config.COMMON.logInvalidToolStackTrace.get()) {
TConstruct.LOG.warn("Tool stack constructed using non-modifiable tool, this may cause issues as it has no NBT. Stacktrace can be disabled in config.", new Exception("Stack trace"));
} else {
TConstruct.LOG.warn("Tool stack constructed using non-modifiable tool, this may cause issues as it has no NBT. To debug this issue, enable logInvalidToolStackTrace in the config.");
}
}
}
} else if (copyNbt) {
nbt = nbt.copy();
Expand Down

0 comments on commit 9f58e91

Please sign in to comment.