package com.xfestudio.mydimensionlord.platform;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import java.util.function.Consumer;
/** Copy-on-write item data: changing a component must also invalidate stack equality. */
public final class ItemData {
private ItemData() {}
public static CompoundTag read(ItemStack stack) {
CustomData data = stack.get(DataComponents.CUSTOM_DATA);
return data == null ? null : data.copyTag();
}
public static CompoundTag readOrEmpty(ItemStack stack) {
CompoundTag tag = read(stack);
return tag == null ? new CompoundTag() : tag;
}
public static void update(ItemStack stack, Consumer<CompoundTag> change) {
CustomData.update(DataComponents.CUSTOM_DATA, stack, change);
}
public static void write(ItemStack stack, CompoundTag tag) {
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
}
}
package com.xfestudio.mydimensionlord.platform;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import java.util.function.Consumer;
/** Copy-on-write item data: changing a component must also invalidate stack equality. */
public final class ItemData {
private ItemData() {}
public static CompoundTag read(ItemStack stack) {
CustomData data = stack.get(DataComponents.CUSTOM_DATA);
return data == null ? null : data.copyTag();
}
public static CompoundTag readOrEmpty(ItemStack stack) {
CompoundTag tag = read(stack);
return tag == null ? new CompoundTag() : tag;
}
public static void update(ItemStack stack, Consumer<CompoundTag> change) {
CustomData.update(DataComponents.CUSTOM_DATA, stack, change);
}
public static void write(ItemStack stack, CompoundTag tag) {
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
}
}