实现JEI查询perk列表
This commit is contained in:
parent
b8ca6e69a2
commit
94fa60dc56
4 changed files with 105 additions and 3 deletions
|
@ -0,0 +1,87 @@
|
||||||
|
package com.atsuishio.superbwarfare.compat.jei;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
|
import com.atsuishio.superbwarfare.perk.Perk;
|
||||||
|
import mezz.jei.api.constants.VanillaTypes;
|
||||||
|
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
|
||||||
|
import mezz.jei.api.gui.drawable.IDrawable;
|
||||||
|
import mezz.jei.api.helpers.IGuiHelper;
|
||||||
|
import mezz.jei.api.recipe.IFocusGroup;
|
||||||
|
import mezz.jei.api.recipe.RecipeIngredientRole;
|
||||||
|
import mezz.jei.api.recipe.RecipeType;
|
||||||
|
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
// TODO 来个正常一点的背景
|
||||||
|
public class GunPerksCategory implements IRecipeCategory<ItemStack> {
|
||||||
|
|
||||||
|
public static final RecipeType<ItemStack> TYPE = RecipeType.create(Mod.MODID, "gun_perks", ItemStack.class);
|
||||||
|
|
||||||
|
private final IDrawable icon;
|
||||||
|
|
||||||
|
public GunPerksCategory(IGuiHelper helper) {
|
||||||
|
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModItems.AP_BULLET.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull RecipeType<ItemStack> getRecipeType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Component getTitle() {
|
||||||
|
return Component.translatable("jei.superbwarfare.gun_perks");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable IDrawable getIcon() {
|
||||||
|
return this.icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return 140;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return 128;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRecipe(@NotNull IRecipeLayoutBuilder builder, ItemStack stack, @NotNull IFocusGroup focuses) {
|
||||||
|
if (!(stack.getItem() instanceof GunItem)) return;
|
||||||
|
GunData data = GunData.from(stack);
|
||||||
|
var perks = data.availablePerks();
|
||||||
|
List<Perk> sortedPerks = new ArrayList<>(perks);
|
||||||
|
sortedPerks.sort((a, b) -> {
|
||||||
|
int aIndex = getIndex(a);
|
||||||
|
int bIndex = getIndex(b);
|
||||||
|
return (aIndex == bIndex) ? a.name.compareTo(b.name) : aIndex - bIndex;
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.addSlot(RecipeIngredientRole.INPUT, 5, 0).addItemStack(stack);
|
||||||
|
|
||||||
|
for (int i = 0; i < sortedPerks.size(); i++) {
|
||||||
|
var perkItem = sortedPerks.get(i).getItem().get();
|
||||||
|
builder.addSlot(RecipeIngredientRole.OUTPUT, 5 + (i % 7) * 18, 20 + i / 7 * 18).addItemStack(perkItem.getDefaultInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getIndex(Perk perk) {
|
||||||
|
return switch (perk.type) {
|
||||||
|
case AMMO -> 0;
|
||||||
|
case FUNCTIONAL -> 1;
|
||||||
|
case DAMAGE -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,8 @@ import mezz.jei.api.JeiPlugin;
|
||||||
import mezz.jei.api.constants.RecipeTypes;
|
import mezz.jei.api.constants.RecipeTypes;
|
||||||
import mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter;
|
import mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter;
|
||||||
import mezz.jei.api.ingredients.subtypes.UidContext;
|
import mezz.jei.api.ingredients.subtypes.UidContext;
|
||||||
|
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
||||||
|
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
||||||
import mezz.jei.api.registration.IRecipeRegistration;
|
import mezz.jei.api.registration.IRecipeRegistration;
|
||||||
import mezz.jei.api.registration.ISubtypeRegistration;
|
import mezz.jei.api.registration.ISubtypeRegistration;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
@ -30,6 +32,16 @@ public class SbwJEIPlugin implements IModPlugin {
|
||||||
return Mod.loc("jei_plugin");
|
return Mod.loc("jei_plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerCategories(IRecipeCategoryRegistration registration) {
|
||||||
|
registration.addRecipeCategories(new GunPerksCategory(registration.getJeiHelpers().getGuiHelper()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
|
||||||
|
registration.addRecipeCatalyst(new ItemStack(ModItems.REFORGING_TABLE.get()), GunPerksCategory.TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO 正确注册subtypes
|
// TODO 正确注册subtypes
|
||||||
@Override
|
@Override
|
||||||
public void registerRecipes(@NotNull IRecipeRegistration registration) {
|
public void registerRecipes(@NotNull IRecipeRegistration registration) {
|
||||||
|
@ -72,7 +84,7 @@ public class SbwJEIPlugin implements IModPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
if (ingredient.getComponentsPatch().isEmpty()) {
|
if (ingredient.getComponentsPatch().isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -85,12 +97,12 @@ public class SbwJEIPlugin implements IModPlugin {
|
||||||
|
|
||||||
registration.registerSubtypeInterpreter(ModItems.C4_BOMB.get(), new ISubtypeInterpreter<>() {
|
registration.registerSubtypeInterpreter(ModItems.C4_BOMB.get(), new ISubtypeInterpreter<>() {
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
public @NotNull Object getSubtypeData(ItemStack ingredient, UidContext context) {
|
||||||
return NBTTool.getTag(ingredient).getBoolean("Control");
|
return NBTTool.getTag(ingredient).getBoolean("Control");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
public @NotNull String getLegacyStringSubtypeInfo(ItemStack ingredient, UidContext context) {
|
||||||
return (String) getSubtypeData(ingredient, context);
|
return (String) getSubtypeData(ingredient, context);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"item.superbwarfare.ammo.rifle": "Rifle Ammo",
|
"item.superbwarfare.ammo.rifle": "Rifle Ammo",
|
||||||
"item.superbwarfare.ammo.sniper": "Sniper Ammo",
|
"item.superbwarfare.ammo.sniper": "Sniper Ammo",
|
||||||
"item.superbwarfare.ammo.heavy": "Heavy Ammo",
|
"item.superbwarfare.ammo.heavy": "Heavy Ammo",
|
||||||
|
|
||||||
"item.superbwarfare.sentinel": "Sentinel",
|
"item.superbwarfare.sentinel": "Sentinel",
|
||||||
"item.superbwarfare.rpk": "RPK",
|
"item.superbwarfare.rpk": "RPK",
|
||||||
"item.superbwarfare.m_870": "M870",
|
"item.superbwarfare.m_870": "M870",
|
||||||
|
@ -591,6 +592,7 @@
|
||||||
|
|
||||||
"jei.superbwarfare.ancient_cpu": "Mysterious ancient technology, can be found at ancient cities.",
|
"jei.superbwarfare.ancient_cpu": "Mysterious ancient technology, can be found at ancient cities.",
|
||||||
"jei.superbwarfare.charging_station": "Generates power by consuming fuel or food, and can also accept FE energy input. This block supplies FE energy to adjacent blocks, and can also charge rechargeable vehicles within range.",
|
"jei.superbwarfare.charging_station": "Generates power by consuming fuel or food, and can also accept FE energy input. This block supplies FE energy to adjacent blocks, and can also charge rechargeable vehicles within range.",
|
||||||
|
"jei.superbwarfare.gun_perks": "Available Perks",
|
||||||
|
|
||||||
"config.jade.plugin_superbwarfare.vehicle_energy": "Vehicle Energy",
|
"config.jade.plugin_superbwarfare.vehicle_energy": "Vehicle Energy",
|
||||||
"config.jade.plugin_superbwarfare.vehicle_health": "Vehicle Health",
|
"config.jade.plugin_superbwarfare.vehicle_health": "Vehicle Health",
|
||||||
|
|
|
@ -592,6 +592,7 @@
|
||||||
|
|
||||||
"jei.superbwarfare.ancient_cpu": "神秘的古代科技,可以在古城找到。",
|
"jei.superbwarfare.ancient_cpu": "神秘的古代科技,可以在古城找到。",
|
||||||
"jei.superbwarfare.charging_station": "使用燃料或食物进行发电,也可以接收主动输入的FE能量。能够为相邻的方块提供FE能量,为周围一定范围内的可充能载具充能。",
|
"jei.superbwarfare.charging_station": "使用燃料或食物进行发电,也可以接收主动输入的FE能量。能够为相邻的方块提供FE能量,为周围一定范围内的可充能载具充能。",
|
||||||
|
"jei.superbwarfare.gun_perks": "武器可用模组",
|
||||||
|
|
||||||
"config.jade.plugin_superbwarfare.vehicle_energy": "载具能量",
|
"config.jade.plugin_superbwarfare.vehicle_energy": "载具能量",
|
||||||
"config.jade.plugin_superbwarfare.vehicle_health": "载具血量",
|
"config.jade.plugin_superbwarfare.vehicle_health": "载具血量",
|
||||||
|
|
Loading…
Add table
Reference in a new issue