添加JEI联动文件
This commit is contained in:
parent
ee17468332
commit
78f579d7d7
3 changed files with 142 additions and 1 deletions
|
@ -0,0 +1,45 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat.jei;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraft.world.item.alchemy.PotionContents;
|
||||||
|
import net.minecraft.world.item.crafting.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class PotionMortarShellRecipeMaker {
|
||||||
|
|
||||||
|
public static List<RecipeHolder<CraftingRecipe>> createRecipes() {
|
||||||
|
String group = "jei.potion_mortar_shell";
|
||||||
|
Ingredient ingredient = Ingredient.of(new ItemStack(ModItems.MORTAR_SHELL.get()));
|
||||||
|
|
||||||
|
return BuiltInRegistries.POTION.stream().map(potion -> {
|
||||||
|
ItemStack input = new ItemStack(Items.LINGERING_POTION);
|
||||||
|
input.set(DataComponents.POTION_CONTENTS, new PotionContents(Holder.direct(potion)));
|
||||||
|
|
||||||
|
ItemStack output = new ItemStack(ModItems.POTION_MORTAR_SHELL.get(), 4);
|
||||||
|
output.set(DataComponents.POTION_CONTENTS, new PotionContents(Holder.direct(potion)));
|
||||||
|
|
||||||
|
Ingredient potionIngredient = Ingredient.of(input);
|
||||||
|
NonNullList<Ingredient> inputs = NonNullList.of(Ingredient.EMPTY,
|
||||||
|
Ingredient.EMPTY, ingredient, Ingredient.EMPTY,
|
||||||
|
ingredient, potionIngredient, ingredient,
|
||||||
|
Ingredient.EMPTY, ingredient, Ingredient.EMPTY
|
||||||
|
);
|
||||||
|
|
||||||
|
ResourceLocation id = ResourceLocation.withDefaultNamespace(group + "." + output.getDescriptionId());
|
||||||
|
return new RecipeHolder<>(id, (CraftingRecipe) new ShapedRecipe(group,
|
||||||
|
CraftingBookCategory.MISC,
|
||||||
|
new ShapedRecipePattern(3, 3, inputs, Optional.empty()),
|
||||||
|
output
|
||||||
|
));
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat.jei;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
|
import mezz.jei.api.IModPlugin;
|
||||||
|
import mezz.jei.api.JeiPlugin;
|
||||||
|
import mezz.jei.api.constants.RecipeTypes;
|
||||||
|
import mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter;
|
||||||
|
import mezz.jei.api.ingredients.subtypes.UidContext;
|
||||||
|
import mezz.jei.api.registration.IRecipeRegistration;
|
||||||
|
import mezz.jei.api.registration.ISubtypeRegistration;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@JeiPlugin
|
||||||
|
public class SbwJEIPlugin implements IModPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ResourceLocation getPluginUid() {
|
||||||
|
return Mod.loc("jei_plugin");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 正确注册subtypes
|
||||||
|
@Override
|
||||||
|
public void registerRecipes(@NotNull IRecipeRegistration registration) {
|
||||||
|
registration.addItemStackInfo(new ItemStack(ModItems.ANCIENT_CPU.get()), Component.translatable("jei.superbwarfare.ancient_cpu"));
|
||||||
|
registration.addItemStackInfo(new ItemStack(ModItems.CHARGING_STATION.get()), Component.translatable("jei.superbwarfare.charging_station"));
|
||||||
|
|
||||||
|
var specialCraftingRecipes = PotionMortarShellRecipeMaker.createRecipes();
|
||||||
|
registration.addRecipes(RecipeTypes.CRAFTING, specialCraftingRecipes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerItemSubtypes(ISubtypeRegistration registration) {
|
||||||
|
registration.registerSubtypeInterpreter(ModItems.CONTAINER.get(), new ISubtypeInterpreter<>() {
|
||||||
|
@Override
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
public @NotNull 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")) {
|
||||||
|
return tag.getString("EntityType");
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
public @NotNull 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
|
return (String) getSubtypeData(ingredient, context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
registration.registerSubtypeInterpreter(ModItems.C4_BOMB.get(), new ISubtypeInterpreter<>() {
|
||||||
|
@Override
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
||||||
|
return NBTTool.getTag(ingredient).getBoolean("Control");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
|
return (String) getSubtypeData(ingredient, context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,9 @@ import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
|
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||||
|
@ -24,13 +26,14 @@ public class PotionMortarShell extends MortarShell {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getDefaultInstance() {
|
public @NotNull ItemStack getDefaultInstance() {
|
||||||
ItemStack itemstack = super.getDefaultInstance();
|
ItemStack itemstack = super.getDefaultInstance();
|
||||||
itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(Potions.POISON));
|
itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(Potions.POISON));
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||||
PotionContents potioncontents = stack.get(DataComponents.POTION_CONTENTS);
|
PotionContents potioncontents = stack.get(DataComponents.POTION_CONTENTS);
|
||||||
if (potioncontents != null) {
|
if (potioncontents != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue