配方书签分支
This commit is contained in:
parent
9b8d712c94
commit
48235b2c08
|
|
@ -7,6 +7,7 @@ import com.extendedae_plus.integration.jei.JeiRuntimeProxy;
|
||||||
import com.extendedae_plus.network.pattern.CreateCtrlQPatternC2SPacket;
|
import com.extendedae_plus.network.pattern.CreateCtrlQPatternC2SPacket;
|
||||||
import com.extendedae_plus.util.RecipeFinderUtil;
|
import com.extendedae_plus.util.RecipeFinderUtil;
|
||||||
import com.extendedae_plus.util.RecipeInfo;
|
import com.extendedae_plus.util.RecipeInfo;
|
||||||
|
import mezz.jei.api.constants.RecipeTypes;
|
||||||
import mezz.jei.api.constants.VanillaTypes;
|
import mezz.jei.api.constants.VanillaTypes;
|
||||||
import mezz.jei.api.ingredients.ITypedIngredient;
|
import mezz.jei.api.ingredients.ITypedIngredient;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
@ -28,7 +29,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
/**
|
/**
|
||||||
* Ctrl+Q键快速创建样板事件监听器
|
* Ctrl+Q键快速创建样板事件监听器
|
||||||
*
|
*
|
||||||
* <p>监听 Ctrl+Q 组合键,自动创建样板并掉落到玩家脚下</p>
|
|
||||||
* <p>应用 JEI 书签优先级选择材料,优先选择工作台配方</p>
|
* <p>应用 JEI 书签优先级选择材料,优先选择工作台配方</p>
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber(modid = ExtendedAEPlus.MODID, value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(modid = ExtendedAEPlus.MODID, value = Dist.CLIENT)
|
||||||
|
|
@ -50,6 +50,17 @@ public class CtrlQPatternKeyHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查鼠标下是否为配方书签
|
||||||
|
Optional<?> recipeBookmark = JeiRuntimeProxy.getRecipeBookmarkUnderMouse();
|
||||||
|
|
||||||
|
if (recipeBookmark.isPresent()) {
|
||||||
|
// 配方书签分支:处理带有配方类型的书签
|
||||||
|
handleRecipeBookmark(recipeBookmark.get());
|
||||||
|
event.setCanceled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 普通书签分支:保持原有逻辑
|
||||||
// 获取鼠标悬浮的物品
|
// 获取鼠标悬浮的物品
|
||||||
Optional<ITypedIngredient<?>> ingredient = JeiRuntimeProxy.getIngredientUnderMouse();
|
Optional<ITypedIngredient<?>> ingredient = JeiRuntimeProxy.getIngredientUnderMouse();
|
||||||
|
|
||||||
|
|
@ -104,6 +115,64 @@ public class CtrlQPatternKeyHandler {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理配方书签的逻辑
|
||||||
|
*
|
||||||
|
* @param recipeBookmark 配方书签对象(RecipeBookmark<?, ?>)
|
||||||
|
*/
|
||||||
|
private static void handleRecipeBookmark(Object recipeBookmark) {
|
||||||
|
// 判断配方类型
|
||||||
|
if (isCraftingRecipe(recipeBookmark)) {
|
||||||
|
// 合成配方分支
|
||||||
|
handleCraftingRecipeBookmark(recipeBookmark);
|
||||||
|
} else {
|
||||||
|
// 其他配方分支(加工配方等)
|
||||||
|
handleProcessingRecipeBookmark(recipeBookmark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断配方书签是否为合成配方
|
||||||
|
*
|
||||||
|
* @param recipeBookmark 配方书签对象
|
||||||
|
* @return true 如果是合成配方
|
||||||
|
*/
|
||||||
|
private static boolean isCraftingRecipe(Object recipeBookmark) {
|
||||||
|
try {
|
||||||
|
// 通过反射获取 RecipeBookmark 的 recipeCategory
|
||||||
|
var getRecipeCategoryMethod = recipeBookmark.getClass().getMethod("getRecipeCategory");
|
||||||
|
Object recipeCategory = getRecipeCategoryMethod.invoke(recipeBookmark);
|
||||||
|
|
||||||
|
// 获取 recipeCategory 的 recipeType
|
||||||
|
var getRecipeTypeMethod = recipeCategory.getClass().getMethod("getRecipeType");
|
||||||
|
Object recipeType = getRecipeTypeMethod.invoke(recipeCategory);
|
||||||
|
|
||||||
|
// 判断是否为 RecipeTypes.CRAFTING
|
||||||
|
return RecipeTypes.CRAFTING.equals(recipeType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理合成配方书签
|
||||||
|
*
|
||||||
|
* @param recipeBookmark 配方书签对象
|
||||||
|
*/
|
||||||
|
private static void handleCraftingRecipeBookmark(Object recipeBookmark) {
|
||||||
|
System.out.println("合成书签");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加工配方书签
|
||||||
|
*
|
||||||
|
* @param recipeBookmark 配方书签对象
|
||||||
|
*/
|
||||||
|
private static void handleProcessingRecipeBookmark(Object recipeBookmark) {
|
||||||
|
System.out.println("处理书签");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用JEI书签优先级选择配方材料
|
* 应用JEI书签优先级选择配方材料
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,46 @@ public final class JeiBookmarkBridge {
|
||||||
return typeField;
|
return typeField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取鼠标下的配方书签(如果存在)
|
||||||
|
*
|
||||||
|
* @return 配方书签对象(RecipeBookmark<?, ?>),如果不是配方书签则返回空
|
||||||
|
*/
|
||||||
|
public static Optional<?> getRecipeBookmarkUnderMouse() {
|
||||||
|
IJeiRuntime rt = getRuntime();
|
||||||
|
if (rt == null) return Optional.empty();
|
||||||
|
|
||||||
|
IBookmarkOverlay bookmarkOverlay = rt.getBookmarkOverlay();
|
||||||
|
if (!(bookmarkOverlay instanceof BookmarkOverlayAccessor accessor)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取鼠标下的元素
|
||||||
|
Optional<ITypedIngredient<?>> ingredientOpt = bookmarkOverlay.getIngredientUnderMouse();
|
||||||
|
if (ingredientOpt.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历书签列表,查找匹配的配方书签
|
||||||
|
BookmarkList bookmarkList = accessor.eap$getBookmarkList();
|
||||||
|
for (IElement<?> element : bookmarkList.getElements()) {
|
||||||
|
// 检查元素的 TypedIngredient 是否匹配
|
||||||
|
if (element.getTypedIngredient().equals(ingredientOpt.get())) {
|
||||||
|
// 检查是否有关联的书签
|
||||||
|
Optional<?> bookmarkOpt = element.getBookmark();
|
||||||
|
if (bookmarkOpt.isPresent()) {
|
||||||
|
Object bookmark = bookmarkOpt.get();
|
||||||
|
// 判断是否为 RecipeBookmark(而非 IngredientBookmark)
|
||||||
|
if (bookmark.getClass().getSimpleName().equals("RecipeBookmark")) {
|
||||||
|
return Optional.of(bookmark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 JEI 书签移除物品
|
* 从 JEI 书签移除物品
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,23 @@ public final class JeiRuntimeProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取鼠标下的配方书签(如果存在)
|
||||||
|
*
|
||||||
|
* @return 配方书签对象(RecipeBookmark<?, ?>),如果不是配方书签则返回空
|
||||||
|
*/
|
||||||
|
public static Optional<?> getRecipeBookmarkUnderMouse() {
|
||||||
|
try {
|
||||||
|
Class<?> bridge = Class.forName("com.extendedae_plus.integration.jei.JeiBookmarkBridge");
|
||||||
|
var m = bridge.getMethod("getRecipeBookmarkUnderMouse");
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Optional<?> result = (Optional<?>) m.invoke(null);
|
||||||
|
return result == null ? Optional.empty() : result;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Note: helper methods moved to bridge to avoid referencing JEI GUI at class load time.
|
// Note: helper methods moved to bridge to avoid referencing JEI GUI at class load time.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user