From 4c97f71e42f75e27e5d709ea28d8295eae869af1 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Thu, 8 Aug 2024 01:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0PerkItem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/perk/PerkHelper.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/net/mcreator/superbwarfare/perk/PerkHelper.java diff --git a/src/main/java/net/mcreator/superbwarfare/perk/PerkHelper.java b/src/main/java/net/mcreator/superbwarfare/perk/PerkHelper.java new file mode 100644 index 000000000..e053192a6 --- /dev/null +++ b/src/main/java/net/mcreator/superbwarfare/perk/PerkHelper.java @@ -0,0 +1,66 @@ +package net.mcreator.superbwarfare.perk; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; + +import javax.annotation.Nullable; + +public class PerkHelper { + private static final String TAG_PERK_ID = "id"; + private static final String TAG_PERK_LEVEL = "level"; + + public static CompoundTag makePerk(@Nullable ResourceLocation pId, int pLevel) { + CompoundTag compoundtag = new CompoundTag(); + compoundtag.putString(TAG_PERK_ID, String.valueOf(pId)); + compoundtag.putShort(TAG_PERK_LEVEL, (short) pLevel); + return compoundtag; + } + + public static CompoundTag setPerkLevel(CompoundTag pCompound, int pLevel) { + pCompound.putShort(TAG_PERK_LEVEL, (short) pLevel); + return pCompound; + } + + public static int getPerkLevel(CompoundTag pCompound) { + return Mth.clamp(pCompound.getInt(TAG_PERK_LEVEL), 0, 255); + } + + @Nullable + public static ResourceLocation getPerkId(CompoundTag pCompoundTag) { + return ResourceLocation.tryParse(pCompoundTag.getString("id")); + } + + // TODO 实现通过注册表找到对应perk并返回对应的resourcelocation +// @Nullable +// public static ResourceLocation getPerkId(Perk perk) { +// return +// } + + public static int getItemPerkLevel(Perk perk, ItemStack stack) { + if (stack.isEmpty()) { + return 0; + } else { +// ResourceLocation resourcelocation = getEnchantmentId(pEnchantment); +// ListTag listtag = getPerkTags(stack); +// +// for(int i = 0; i < listtag.size(); ++i) { +// CompoundTag compoundtag = listtag.getCompound(i); +// ResourceLocation resourcelocation1 = getEnchantmentId(compoundtag); +// if (resourcelocation1 != null && resourcelocation1.equals(resourcelocation)) { +// return getEnchantmentLevel(compoundtag); +// } +// } + + return 0; + } + } + + public static ListTag getPerkTags(ItemStack stack) { + return stack.getTag() != null ? stack.getTag().getList("Perks", 10) : new ListTag(); + } + + +}