superb-warfare/src/main/java/com/atsuishio/superbwarfare/tools/NBTTool.java
2025-04-05 17:50:49 +08:00

26 lines
No EOL
927 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.atsuishio.superbwarfare.tools;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
// From Botania
public final class NBTTool {
public static CompoundTag getTag(ItemStack stack) {
var data = stack.get(DataComponents.CUSTOM_DATA);
if (data != null) return data.copyTag();
return new CompoundTag();
}
/**
* 警告请勿使用该方法保存任何枪械NBT数据请统一使用GunData.save()保存枪械数据
*/
public static void saveTag(ItemStack stack, CompoundTag tag) {
var data = stack.get(DataComponents.CUSTOM_DATA);
var oldTag = data != null ? data.copyTag() : new CompoundTag();
var newTag = oldTag.merge(tag);
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(newTag));
}
}