Skip to content

Commit

Permalink
Fix referencing tags during a method possibly called on item init
Browse files Browse the repository at this point in the history
Using the interface is cleaner here anyways
Prevents log spam with farmers delight (#5065)
  • Loading branch information
KnightMiner committed Jan 21, 2023
1 parent 0b70ad4 commit 520ceeb
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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;
Expand Down Expand Up @@ -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) {
// 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)) {
// 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)
stack.tag = nbt;
} else {
if (Config.COMMON.logInvalidToolStackTrace.get()) {
Expand Down

0 comments on commit 520ceeb

Please sign in to comment.