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