Skip to content

Commit

Permalink
Fixes for item stackability when removing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Oct 7, 2023
1 parent 74031a6 commit 6bdbf09
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit 6bdbf09

Please sign in to comment.