修复一个可能导致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;
|
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.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
|
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||||
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
import com.atsuishio.superbwarfare.network.message.GunsDataMessage;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.packs.resources.ResourceManager;
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
@ -196,14 +196,27 @@ public class GunsTool {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setGunIntTag(ItemStack stack, String name, int num) {
|
public static void setGunIntTag(ItemStack stack, String name, int num) {
|
||||||
CompoundTag tag = stack.getOrCreateTag().getCompound("GunData");
|
if (stack == null) return;
|
||||||
tag.putInt(name, num);
|
|
||||||
stack.addTagElement("GunData", tag);
|
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) {
|
public static int getGunIntTag(ItemStack stack, String name) {
|
||||||
CompoundTag tag = stack.getOrCreateTag().getCompound("GunData");
|
if (stack == null) return 0;
|
||||||
return tag.getInt(name);
|
|
||||||
|
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