diff --git a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java index a490667397a..e2758d00a86 100644 --- a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java +++ b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java @@ -40,6 +40,7 @@ import net.minecraft.world.item.PickaxeItem; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; +import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.data.Keys; import org.spongepowered.api.effect.potion.PotionEffect; @@ -122,10 +123,7 @@ public static void register(final DataProviderRegistrator registrator) { tag.putInt(Constants.Item.CUSTOM_MODEL_DATA, v); }) .delete(h -> { - final CompoundTag tag = h.getTag(); - if (tag != null) { - tag.remove(Constants.Item.CUSTOM_MODEL_DATA); - } + h.removeTagKey(Constants.Item.CUSTOM_MODEL_DATA); }) .create(Keys.CUSTOM_NAME) .get(h -> { @@ -211,18 +209,21 @@ private static void setIsUnbrekable(final ItemStack stack, final Boolean value) if (value == null || (!value && !stack.hasTag())) { return; } - final CompoundTag tag = stack.getOrCreateTag(); if (value) { + final CompoundTag tag = stack.getOrCreateTag(); tag.putBoolean(Constants.Item.ITEM_UNBREAKABLE, true); } else { - tag.remove(Constants.Item.ITEM_UNBREAKABLE); + stack.removeTagKey(Constants.Item.ITEM_UNBREAKABLE); } } private static void deleteLore(final ItemStack stack) { - final CompoundTag tag = stack.getTag(); - if (tag != null && tag.contains(Constants.Item.ITEM_DISPLAY)) { - tag.getCompound(Constants.Item.ITEM_DISPLAY).remove(Constants.Item.ITEM_LORE); + final @Nullable CompoundTag tag = stack.getTagElement(Constants.Item.ITEM_DISPLAY); + if (tag != null) { + tag.remove(Constants.Item.ITEM_LORE); + if (tag.isEmpty()) { + stack.removeTagKey(Constants.Item.ITEM_DISPLAY); + } } } }