Fix referencing tags during a method possibly called on item init
Using the interface is cleaner here anyways
Prevents log spam with farmers delight
@@ -14,7 +14,6 @@ import net.minecraft.world.item.Item;
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;
@@ -129,16 +128,17 @@ public class ToolStack implements IToolStackView {
*/
private static ToolStack from(ItemStack stack, boolean copyNbt) {
Item item = stack.getItem();
- ToolDefinition definition = item instanceof IModifiable
- ? ((IModifiable)item).getToolDefinition()
+ ToolDefinition definition = item instanceof IModifiable mod
+ ? mod.getToolDefinition()
: ToolDefinition.EMPTY;
CompoundTag nbt = stack.getTag();
if (nbt == null) {
nbt = new CompoundTag();
if (!copyNbt) {
+ // only a wrongly made tool will have an empty definition. check preferred to a tag check as tags may not be loaded when this is first called
+ if (definition != ToolDefinition.EMPTY) {
// 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)
- if (stack.is(TinkerTags.Items.MODIFIABLE)) {
stack.tag = nbt;
} else {
if (Config.COMMON.logInvalidToolStackTrace.get()) {
