修复一个可能导致NPE的问题
This commit is contained in:
parent
5abcc7175f
commit
373427792e
1 changed files with 20 additions and 7 deletions
|
@ -1,10 +1,10 @@
|
|||
package com.atsuishio.superbwarfare.tools;
|
||||
|
||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.init.ModTags;
|
||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
@ -196,14 +196,27 @@ public class GunsTool {
|
|||
}
|
||||
|
||||
public static void setGunIntTag(ItemStack stack, String name, int num) {
|
||||
CompoundTag tag = stack.getOrCreateTag().getCompound("GunData");
|
||||
tag.putInt(name, num);
|
||||
if (stack == null) return;
|
||||
|
||||
var tag = stack.getTag();
|
||||
if (tag != null && tag.contains("GunData")) {
|
||||
tag.getCompound("GunData").putInt(name, num);
|
||||
stack.addTagElement("GunData", tag);
|
||||
} else {
|
||||
CompoundTag newTag = new CompoundTag();
|
||||
newTag.putInt(name, num);
|
||||
stack.addTagElement("GunData", newTag);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getGunIntTag(ItemStack stack, String name) {
|
||||
CompoundTag tag = stack.getOrCreateTag().getCompound("GunData");
|
||||
return tag.getInt(name);
|
||||
if (stack == null) return 0;
|
||||
|
||||
var tag = stack.getTag();
|
||||
if (tag != null && tag.contains("GunData")) {
|
||||
return tag.getCompound("GunData").getInt(name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue