From ab886e10cd290a8acb47394940964b696582d783 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Fri, 11 Apr 2025 20:18:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4subtype=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compat/jei/SbwJEIPlugin.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java b/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java index c3de433b3..b04f4e838 100644 --- a/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java +++ b/src/main/java/com/atsuishio/superbwarfare/compat/jei/SbwJEIPlugin.java @@ -18,8 +18,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.alchemy.PotionContents; import org.jetbrains.annotations.NotNull; - -import javax.annotation.ParametersAreNonnullByDefault; +import org.jetbrains.annotations.Nullable; @JeiPlugin public class SbwJEIPlugin implements IModPlugin { @@ -43,8 +42,7 @@ public class SbwJEIPlugin implements IModPlugin { public void registerItemSubtypes(ISubtypeRegistration registration) { registration.registerSubtypeInterpreter(ModItems.CONTAINER.get(), new ISubtypeInterpreter<>() { @Override - @ParametersAreNonnullByDefault - public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) { + public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) { var data = ingredient.get(DataComponents.BLOCK_ENTITY_DATA); var tag = data != null ? data.copyTag() : new CompoundTag(); if (tag.contains("EntityType")) { @@ -54,38 +52,41 @@ public class SbwJEIPlugin implements IModPlugin { } @Override - @ParametersAreNonnullByDefault - public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { + public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { return (String) getSubtypeData(ingredient, context); } }); - registration.registerSubtypeInterpreter(ModItems.POTION_MORTAR_SHELL.get(), new ISubtypeInterpreter<>() { @Override - @ParametersAreNonnullByDefault - public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) { - var potion = ingredient.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY); - return potion.potion().map(Holder::getRegisteredName); + public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) { + PotionContents contents = ingredient.get(DataComponents.POTION_CONTENTS); + if (contents == null) { + return null; + } + return contents.potion().orElse(null); } @Override - @ParametersAreNonnullByDefault - public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { - return (String) getSubtypeData(ingredient, context); + public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { + if (ingredient.getComponentsPatch().isEmpty()) { + return ""; + } + PotionContents contents = ingredient.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY); + String itemDescriptionId = ingredient.getItem().getDescriptionId(); + String potionEffectId = contents.potion().map(Holder::getRegisteredName).orElse("none"); + return itemDescriptionId + ".effect_id." + potionEffectId; } }); registration.registerSubtypeInterpreter(ModItems.C4_BOMB.get(), new ISubtypeInterpreter<>() { @Override - @ParametersAreNonnullByDefault - public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) { + public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) { return NBTTool.getTag(ingredient).getBoolean("Control"); } @Override - @ParametersAreNonnullByDefault - public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { + public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) { return (String) getSubtypeData(ingredient, context); } });