Skip to content

Commit d0a4b74

Browse files
author
NeofastFTL
committed
ee
1 parent 6fbc51a commit d0a4b74

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

src/main/java/com/neofastftl/infinitypattern/InfinityPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class InfinityPattern
3636
// Define mod id in a common place for everything to reference
3737
public static final String MODID = "infinitypattern";
3838
// Directly reference a slf4j logger
39-
private static final Logger LOGGER = LogUtils.getLogger();
39+
public static final Logger LOGGER = LogUtils.getLogger();
4040
// Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
4141
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(InfinityPattern.MODID);
4242
// Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.neofastftl.infinitypattern.client;
2+
3+
import com.neofastftl.infinitypattern.InfinityPattern;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.gui.screens.Screen;
6+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
7+
import net.minecraft.resources.ResourceLocation;
8+
import net.minecraft.world.inventory.Slot;
9+
import net.minecraft.world.item.ItemStack;
10+
import net.neoforged.api.distmarker.Dist;
11+
import net.neoforged.bus.api.SubscribeEvent;
12+
import net.neoforged.fml.common.EventBusSubscriber;
13+
import net.neoforged.neoforge.client.event.ScreenEvent;
14+
import org.lwjgl.glfw.GLFW;
15+
16+
import java.util.Optional;
17+
18+
@EventBusSubscriber(modid = InfinityPattern.MODID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.GAME)
19+
public class GuideHandler {
20+
21+
private static final ResourceLocation GUIDE_PAGE = ResourceLocation.fromNamespaceAndPath(InfinityPattern.MODID, "ifpat_intro/ifpat-index.md");
22+
23+
@SubscribeEvent
24+
public static void onKeyPressed(ScreenEvent.KeyPressed.Post event) {
25+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Key pressed: {}, G is {}", event.getKeyCode(), GLFW.GLFW_KEY_G);
26+
if (event.getKeyCode() == GLFW.GLFW_KEY_G) {
27+
Screen screen = event.getScreen();
28+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Screen: {}", screen.getClass().getName());
29+
if (screen instanceof AbstractContainerScreen<?> containerScreen) {
30+
Slot slot = containerScreen.getSlotUnderMouse();
31+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Slot under mouse: {}", slot);
32+
if (slot != null && slot.hasItem()) {
33+
ItemStack stack = slot.getItem();
34+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Item under mouse: {}", stack.getItem());
35+
if (stack.is(InfinityPattern.ITEM_INFINITE_EMPTY_PATTERN.get())) {
36+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Matches Infinite Pattern! Opening guide...");
37+
openGuide();
38+
event.setCanceled(true);
39+
}
40+
}
41+
}
42+
}
43+
}
44+
45+
private static void openGuide() {
46+
try {
47+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Attempting to open guide page: {}", GUIDE_PAGE);
48+
// In AE2 1.21.1, the guide is opened via appeng.client.guide.GuideHandler.openEntry
49+
Class<?> guideHandlerClass = Class.forName("appeng.client.guide.GuideHandler");
50+
var openEntryMethod = guideHandlerClass.getMethod("openEntry", ResourceLocation.class);
51+
openEntryMethod.invoke(null, GUIDE_PAGE);
52+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Guide openEntry called successfully.");
53+
} catch (Exception e) {
54+
InfinityPattern.LOGGER.error("[DEBUG_LOG] Failed to open guide via GuideHandler: {}", e.getMessage());
55+
try {
56+
// Fallback for older AE2 versions or different class structure
57+
Class<?> guideScreenClass = Class.forName("appeng.client.guide.GuideScreen");
58+
var showMethod = guideScreenClass.getMethod("show", ResourceLocation.class);
59+
showMethod.invoke(null, GUIDE_PAGE);
60+
InfinityPattern.LOGGER.info("[DEBUG_LOG] Guide GuideScreen.show called successfully.");
61+
} catch (Exception e2) {
62+
InfinityPattern.LOGGER.error("[DEBUG_LOG] Failed to open guide via GuideScreen fallback: {}", e2.getMessage());
63+
Minecraft.getInstance().player.displayClientMessage(
64+
net.minecraft.network.chat.Component.literal("Could not open AE2 guide: " + e.getMessage()),
65+
false
66+
);
67+
}
68+
}
69+
}
70+
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"item.infinitypattern.item_infinitypattern": "Infinite Encoded Pattern",
32
"item.infinitypattern.infinite_empty_pattern": "Infinite Empty Pattern",
4-
"itemGroup.infinitypattern": "Infinity Pattern Addon",
5-
"infinitypattern.guideme.title": "Infinity Pattern Guide",
6-
"infinitypattern.guideme.introduction.title": "Infinite Empty Pattern",
7-
"infinitypattern.guideme.introduction.text": "The Infinite Empty Pattern is a special item that can be used in the Pattern Encoding Terminal just like a normal Blank Pattern. However, it is never consumed during the encoding process, allowing for unlimited pattern creation with a single item."
3+
"itemGroup.infinitypattern": "Infinity Pattern Addon"
84
}

0 commit comments

Comments
 (0)