优化NBT#UUID
This commit is contained in:
parent
4eb52372b1
commit
fdaa4c48d6
3 changed files with 13 additions and 5 deletions
|
@ -319,8 +319,8 @@ public class LivingEventHandler {
|
|||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
if (newStack.getItem() != oldStack.getItem()
|
||||
|| newStack.getTag() == null || oldStack.getTag() == null
|
||||
|| !newStack.getTag().hasUUID("gun_uuid") || !oldStack.getTag().hasUUID("gun_uuid")
|
||||
|| !newStack.getTag().getUUID("gun_uuid").equals(oldStack.getTag().getUUID("gun_uuid"))
|
||||
|| !GunsTool.getGunData(newStack).hasUUID("UUID") || !GunsTool.getGunData(oldStack).hasUUID("UUID")
|
||||
|| !GunsTool.getGunData(newStack).getUUID("UUID").equals(GunsTool.getGunData(oldStack).getUUID("UUID"))
|
||||
) {
|
||||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||
stopGunReloadSound(serverPlayer, oldGun);
|
||||
|
|
|
@ -57,7 +57,7 @@ public abstract class GunItem extends Item {
|
|||
|
||||
if (!ItemNBTTool.getBoolean(itemstack, "init", false)) {
|
||||
GunsTool.initGun(level, itemstack, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1));
|
||||
GunsTool.genUUID(itemstack);
|
||||
GunsTool.generateAndSetUUID(itemstack);
|
||||
ItemNBTTool.setBoolean(itemstack, "init", true);
|
||||
}
|
||||
|
||||
|
|
|
@ -87,9 +87,12 @@ public class GunsTool {
|
|||
}
|
||||
}
|
||||
|
||||
public static void genUUID(ItemStack stack) {
|
||||
public static void generateAndSetUUID(ItemStack stack) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
stack.getOrCreateTag().putUUID("gun_uuid", uuid);
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
var data = tag.getCompound("GunData");
|
||||
data.putUUID("UUID", uuid);
|
||||
stack.addTagElement("GunData", data);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -205,6 +208,11 @@ public class GunsTool {
|
|||
}
|
||||
|
||||
/* GunData */
|
||||
public static CompoundTag getGunData(ItemStack stack) {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
return tag.getCompound("GunData");
|
||||
}
|
||||
|
||||
public static void setGunIntTag(ItemStack stack, String name, int num) {
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
var data = tag.getCompound("GunData");
|
||||
|
|
Loading…
Add table
Reference in a new issue