基础核心及jei配方设置
This commit is contained in:
parent
6005b7cfbb
commit
44de25edce
|
|
@ -3,12 +3,12 @@ package com.extendedae_plus.integration.jei;
|
||||||
import com.extendedae_plus.ExtendedAEPlus;
|
import com.extendedae_plus.ExtendedAEPlus;
|
||||||
import com.extendedae_plus.ae.definitions.upgrades.EntitySpeedCardItem;
|
import com.extendedae_plus.ae.definitions.upgrades.EntitySpeedCardItem;
|
||||||
import com.extendedae_plus.init.ModItems;
|
import com.extendedae_plus.init.ModItems;
|
||||||
|
import com.extendedae_plus.item.BasicCoreItem;
|
||||||
import com.extendedae_plus.util.ModCheckUtils;
|
import com.extendedae_plus.util.ModCheckUtils;
|
||||||
import mezz.jei.api.IModPlugin;
|
import mezz.jei.api.IModPlugin;
|
||||||
import mezz.jei.api.JeiPlugin;
|
import mezz.jei.api.JeiPlugin;
|
||||||
import mezz.jei.api.registration.ISubtypeRegistration;
|
import mezz.jei.api.registration.ISubtypeRegistration;
|
||||||
import mezz.jei.api.runtime.IJeiRuntime;
|
import mezz.jei.api.runtime.IJeiRuntime;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
@JeiPlugin
|
@JeiPlugin
|
||||||
|
|
@ -27,33 +27,40 @@ public class ExtendedAEJeiPlugin implements IModPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerItemSubtypes(ISubtypeRegistration registration) {
|
public void registerItemSubtypes(ISubtypeRegistration registration) {
|
||||||
// Register NBT-based subtype interpreter so JEI treats different multipliers as distinct items
|
// Entity Speed Card
|
||||||
registration.registerSubtypeInterpreter(
|
registration.registerSubtypeInterpreter(
|
||||||
ModItems.ENTITY_SPEED_CARD.get(),
|
ModItems.ENTITY_SPEED_CARD.get(),
|
||||||
(stack, context) -> String.valueOf(EntitySpeedCardItem.readMultiplier(stack))
|
(stack, ctx) -> String.valueOf(EntitySpeedCardItem.readMultiplier(stack))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Basic Core – 使用 CustomModelData + core_stage
|
||||||
registration.registerSubtypeInterpreter(
|
registration.registerSubtypeInterpreter(
|
||||||
ModItems.BASIC_CORE.get(),
|
ModItems.BASIC_CORE.get(),
|
||||||
(stack, context) -> {
|
(stack, ctx) -> {
|
||||||
CompoundTag tag = stack.getTag();
|
if (!BasicCoreItem.isTyped(stack)) {
|
||||||
if (tag == null || !tag.contains("core_type") || !tag.contains("core_stage")) {
|
|
||||||
return "untyped";
|
return "untyped";
|
||||||
}
|
}
|
||||||
int type = tag.getInt("core_type");
|
|
||||||
int stage = tag.getInt("core_stage");
|
|
||||||
|
|
||||||
if (!isCoreTypeAvailable(type)) {
|
BasicCoreItem.CoreType type = BasicCoreItem.getType(stack).orElse(null);
|
||||||
return "hidden"; // JEI 忽略
|
if (type == null) {
|
||||||
|
return "untyped";
|
||||||
}
|
}
|
||||||
return type + "_" + stage;
|
|
||||||
|
int stage = BasicCoreItem.getStage(stack);
|
||||||
|
|
||||||
|
// 依赖检查
|
||||||
|
if (!isCoreTypeAvailable(type.id)) {
|
||||||
|
return "hidden"; // JEI 隐藏
|
||||||
|
}
|
||||||
|
|
||||||
|
return type.id + "_" + stage; // 如 "0_1", "1_4"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCoreTypeAvailable(int typeId) {
|
private boolean isCoreTypeAvailable(int typeId) {
|
||||||
return switch (typeId) {
|
return switch (typeId) {
|
||||||
case 0, 1 -> true; // storage, spatial
|
case 0, 1 -> true; // storage, spatial
|
||||||
case 2 -> ModCheckUtils.isAppfluxLoading();
|
case 2 -> ModCheckUtils.isAppfluxLoading();
|
||||||
case 3 -> ModCheckUtils.isAAELoading();
|
case 3 -> ModCheckUtils.isAAELoading();
|
||||||
default -> false;
|
default -> false;
|
||||||
|
|
|
||||||
|
|
@ -19,40 +19,38 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BasicCoreItem extends Item {
|
public class BasicCoreItem extends Item {
|
||||||
private static final String NBT_TYPE = "core_type"; // 0=存储, 1=空间, 2=能源, 3=量子
|
private static final String NBT_MODEL = "CustomModelData"; // 1~4 = 类型, 无或0 = 未定型
|
||||||
private static final String NBT_STAGE = "core_stage"; // 0=未定型, 1~4=四个阶段
|
private static final String NBT_STAGE = "core_stage"; // 0~4 = 阶段
|
||||||
private static final int MAX_STAGE = 4;
|
private static final int MAX_STAGE = 4;
|
||||||
|
|
||||||
public BasicCoreItem(Properties props) {
|
public BasicCoreItem(Properties props) {
|
||||||
super(props.stacksTo(1).setNoRepair());
|
super(props.stacksTo(1).setNoRepair());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// ==================== 工厂方法:CustomModelData = CoreType.id (1~4) ====================
|
||||||
* 创建指定类型和阶段的核心(用于配方输出)
|
|
||||||
*
|
|
||||||
* @param type 核心类型
|
|
||||||
* @param stage 阶段(1-4),0=未定型
|
|
||||||
*/
|
|
||||||
public static ItemStack of(CoreType type, int stage) {
|
public static ItemStack of(CoreType type, int stage) {
|
||||||
ItemStack stack = new ItemStack(ModItems.BASIC_CORE.get());
|
ItemStack stack = new ItemStack(ModItems.BASIC_CORE.get());
|
||||||
if (type != null && stage >= 0 && stage <= MAX_STAGE) {
|
if (type != null && stage >= 0 && stage <= MAX_STAGE) {
|
||||||
CompoundTag tag = stack.getOrCreateTag();
|
CompoundTag tag = stack.getOrCreateTag();
|
||||||
tag.putInt(NBT_TYPE, type.id);
|
tag.putInt(NBT_MODEL, type.id);
|
||||||
tag.putInt(NBT_STAGE, stage);
|
tag.putInt(NBT_STAGE, stage);
|
||||||
}
|
}
|
||||||
|
// 无 NBT → 默认模型
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 工厂方法:支持 4 条线路 + 4 个阶段 ====================
|
public static ItemStack storageStage(int stage) { return of(CoreType.STORAGE, stage); }
|
||||||
public static ItemStack storageStage(int stage) {return of(CoreType.STORAGE, stage);}
|
public static ItemStack spatialStage(int stage) { return of(CoreType.SPATIAL, stage); }
|
||||||
public static ItemStack spatialStage(int stage) {return of(CoreType.SPATIAL, stage);}
|
public static ItemStack energyStage(int stage) { return of(CoreType.ENERGY, stage); }
|
||||||
public static ItemStack energyStage(int stage) {return of(CoreType.ENERGY, stage);}
|
public static ItemStack quantumStage(int stage) { return of(CoreType.QUANTUM, stage); }
|
||||||
public static ItemStack quantumStage(int stage) {return of(CoreType.QUANTUM, stage);}
|
|
||||||
|
|
||||||
// ==================== NBT 查询 ====================
|
// ==================== NBT 查询 ====================
|
||||||
public static Optional<CoreType> getType(ItemStack stack) {
|
public static Optional<CoreType> getType(ItemStack stack) {
|
||||||
if (!stack.hasTag()) return Optional.empty();
|
if (!stack.hasTag() || !stack.getTag().contains(NBT_MODEL)) {
|
||||||
return CoreType.byId(stack.getTag().getInt(NBT_TYPE));
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
int cmd = stack.getTag().getInt(NBT_MODEL);
|
||||||
|
return CoreType.byId(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStage(ItemStack stack) {
|
public static int getStage(ItemStack stack) {
|
||||||
|
|
@ -60,25 +58,23 @@ public class BasicCoreItem extends Item {
|
||||||
return Math.min(stack.getTag().getInt(NBT_STAGE), MAX_STAGE);
|
return Math.min(stack.getTag().getInt(NBT_STAGE), MAX_STAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTyped(ItemStack stack) {return getStage(stack) > 0;}
|
public static boolean isTyped(ItemStack stack) { return getType(stack).isPresent(); }
|
||||||
|
|
||||||
public static boolean isFinalStage(ItemStack stack) {return getStage(stack) >= MAX_STAGE;}
|
public static boolean isFinalStage(ItemStack stack) { return getStage(stack) >= MAX_STAGE; }
|
||||||
|
|
||||||
// ==================== 耐久条 ====================
|
// ==================== 耐久条 ====================
|
||||||
@Override
|
@Override
|
||||||
public boolean isBarVisible(ItemStack stack) {
|
public boolean isBarVisible(ItemStack stack) {
|
||||||
return getStage(stack) > 0;
|
return isTyped(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarWidth(@NotNull ItemStack stack) {
|
public int getBarWidth(@NotNull ItemStack stack) {
|
||||||
int stage = getStage(stack);
|
return isTyped(stack) ? Math.round(13.0f * getStage(stack) / MAX_STAGE) : 0;
|
||||||
return stage == 0 ? 0 : Math.round(13.0f * stage / MAX_STAGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarColor(@NotNull ItemStack stack) {
|
public int getBarColor(@NotNull ItemStack stack) {
|
||||||
int stage = getStage(stack);
|
|
||||||
return getType(stack)
|
return getType(stack)
|
||||||
.map(type -> type.getTextColor().getColor())
|
.map(type -> type.getTextColor().getColor())
|
||||||
.orElse(0xFFFFFF);
|
.orElse(0xFFFFFF);
|
||||||
|
|
@ -88,32 +84,28 @@ public class BasicCoreItem extends Item {
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
|
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
|
||||||
int stage = getStage(stack);
|
if (!isTyped(stack)) {
|
||||||
|
|
||||||
if (stage == 0) {
|
|
||||||
tooltip.add(Component.translatable("tooltip." + ExtendedAEPlus.MODID + ".basic_core.untyped")
|
tooltip.add(Component.translatable("tooltip." + ExtendedAEPlus.MODID + ".basic_core.untyped")
|
||||||
.withStyle(ChatFormatting.GRAY));
|
.withStyle(ChatFormatting.GRAY));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getType(stack).ifPresent(type -> {
|
getType(stack).ifPresent(type -> {
|
||||||
// 显示目标终极核心
|
|
||||||
String finalKey = "item." + ExtendedAEPlus.MODID + "." + type.key + "_core";
|
String finalKey = "item." + ExtendedAEPlus.MODID + "." + type.key + "_core";
|
||||||
tooltip.add(Component.translatable("tooltip." + ExtendedAEPlus.MODID + ".basic_core.evolving_to",
|
tooltip.add(Component.translatable("tooltip." + ExtendedAEPlus.MODID + ".basic_core.evolving_to",
|
||||||
Component.translatable(finalKey).withStyle(type.getTextColor()))
|
Component.translatable(finalKey).withStyle(type.getTextColor()))
|
||||||
.withStyle(ChatFormatting.AQUA));
|
.withStyle(ChatFormatting.AQUA));
|
||||||
|
|
||||||
tooltip.add(Component.empty());
|
tooltip.add(Component.empty());
|
||||||
|
|
||||||
tooltip.add(Component.translatable("tooltip." + ExtendedAEPlus.MODID + ".basic_core.progress")
|
tooltip.add(Component.translatable("tooltip." + ExtendedAEPlus.MODID + ".basic_core.progress")
|
||||||
.withStyle(ChatFormatting.YELLOW));
|
.withStyle(ChatFormatting.YELLOW));
|
||||||
|
|
||||||
|
int stage = getStage(stack);
|
||||||
for (int i = 1; i <= 4; i++) {
|
for (int i = 1; i <= 4; i++) {
|
||||||
String key = "item." + ExtendedAEPlus.MODID + ".basic_core." + type.key + "." + (i - 1);
|
String key = "item." + ExtendedAEPlus.MODID + ".basic_core." + type.key + "." + i;
|
||||||
ChatFormatting color = i <= stage ? ChatFormatting.GREEN : ChatFormatting.DARK_GRAY;
|
ChatFormatting color = i <= stage ? ChatFormatting.GREEN : ChatFormatting.DARK_GRAY;
|
||||||
String prefix = i <= stage ? "✔ " : "✘ ";
|
String prefix = i <= stage ? "✔ " : "✘ ";
|
||||||
tooltip.add(Component.literal(prefix).withStyle(color)
|
tooltip.add(Component.literal(prefix).withStyle(color).append(Component.translatable(key)));
|
||||||
.append(Component.translatable(key)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stage >= MAX_STAGE) {
|
if (stage >= MAX_STAGE) {
|
||||||
|
|
@ -127,32 +119,32 @@ public class BasicCoreItem extends Item {
|
||||||
// ==================== 显示名称 ====================
|
// ==================== 显示名称 ====================
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Component getName(@NotNull ItemStack stack) {
|
public @NotNull Component getName(@NotNull ItemStack stack) {
|
||||||
int stage = getStage(stack);
|
if (!isTyped(stack)) {
|
||||||
if (stage == 0) {
|
|
||||||
return Component.translatable("item." + ExtendedAEPlus.MODID + ".basic_core");
|
return Component.translatable("item." + ExtendedAEPlus.MODID + ".basic_core");
|
||||||
}
|
}
|
||||||
|
|
||||||
return getType(stack).<Component>map(type -> {
|
return getType(stack).<Component>map(type -> {
|
||||||
String key = "item." + ExtendedAEPlus.MODID + ".basic_core." + type.key + "." + (stage - 1);
|
String key = "item." + ExtendedAEPlus.MODID + ".basic_core." + type.key + "." + getStage(stack);
|
||||||
return Component.translatable(key).withStyle(type.getTextColor());
|
return Component.translatable(key).withStyle(type.getTextColor());
|
||||||
}).orElseGet(() -> Component.translatable("item." + ExtendedAEPlus.MODID + ".basic_core"));
|
}).orElseGet(() -> Component.translatable("item." + ExtendedAEPlus.MODID + ".basic_core"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Rarity getRarity(@NotNull ItemStack stack) {
|
public @NotNull Rarity getRarity(@NotNull ItemStack stack) {
|
||||||
int stage = getStage(stack);
|
return isTyped(stack)
|
||||||
return getType(stack).map(t -> t.getRarity(stage)).orElse(Rarity.COMMON);
|
? getType(stack).map(t -> t.getRarity(getStage(stack))).orElse(Rarity.COMMON)
|
||||||
|
: Rarity.COMMON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== 核心类型枚举:id = CustomModelData (1~4) ====================
|
||||||
public enum CoreType {
|
public enum CoreType {
|
||||||
STORAGE(0, "storage", ChatFormatting.AQUA), // 存储:青色
|
STORAGE (1, "storage", ChatFormatting.AQUA),
|
||||||
SPATIAL(1, "spatial", ChatFormatting.YELLOW), // 空间:金色
|
SPATIAL (2, "spatial", ChatFormatting.YELLOW),
|
||||||
ENERGY(2, "energy_storage", ChatFormatting.RED), // 能源:红色
|
ENERGY (3, "energy_storage", ChatFormatting.RED),
|
||||||
QUANTUM(3, "quantum_storage", ChatFormatting.LIGHT_PURPLE); // 量子:亮紫
|
QUANTUM (4, "quantum_storage",ChatFormatting.LIGHT_PURPLE);
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
public final String key;
|
public final String key;
|
||||||
public final ChatFormatting textColor; // 用于 Tooltip 和名称
|
public final ChatFormatting textColor;
|
||||||
|
|
||||||
CoreType(int id, String key, ChatFormatting textColor) {
|
CoreType(int id, String key, ChatFormatting textColor) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
@ -162,18 +154,15 @@ public class BasicCoreItem extends Item {
|
||||||
|
|
||||||
public static Optional<CoreType> byId(int id) {
|
public static Optional<CoreType> byId(int id) {
|
||||||
return switch (id) {
|
return switch (id) {
|
||||||
case 0 -> Optional.of(STORAGE);
|
case 1 -> Optional.of(STORAGE);
|
||||||
case 1 -> Optional.of(SPATIAL);
|
case 2 -> Optional.of(SPATIAL);
|
||||||
case 2 -> Optional.of(ENERGY);
|
case 3 -> Optional.of(ENERGY);
|
||||||
case 3 -> Optional.of(QUANTUM);
|
case 4 -> Optional.of(QUANTUM);
|
||||||
default -> Optional.empty();
|
default -> Optional.empty();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一返回同一个颜色(文本)
|
public ChatFormatting getTextColor() { return textColor; }
|
||||||
public ChatFormatting getTextColor() {
|
|
||||||
return textColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rarity getRarity(int stage) {
|
public Rarity getRarity(int stage) {
|
||||||
return stage == 0 ? Rarity.COMMON :
|
return stage == 0 ? Rarity.COMMON :
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user