Skip to content

Commit 28a94ed

Browse files
committed
Added Modonomicon Integration
1 parent 0d6a9b7 commit 28a94ed

File tree

12 files changed

+324
-29
lines changed

12 files changed

+324
-29
lines changed

build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ repositories {
2323
includeGroup "maven.modrinth"
2424
}
2525
}
26+
27+
maven {
28+
// location of the maven that hosts JEI files
29+
name = "Progwml6's maven"
30+
url = "https://dvs1.progwml6.com/files/maven/"
31+
}
32+
maven {
33+
// location of the maven that hosts JEI files
34+
name = "Jared's maven"
35+
url = "https://maven.blamejared.com/"
36+
}
37+
maven {
38+
// location of a maven mirror for JEI files, as a fallback
39+
name = "ModMaven"
40+
url = "https://modmaven.dev"
41+
}
42+
43+
maven {
44+
url "https://dl.cloudsmith.io/public/klikli-dev/mods/maven/"
45+
content {
46+
includeGroup "com.klikli_dev"
47+
}
48+
}
2649
}
2750

2851
fabricApi {
@@ -42,6 +65,15 @@ dependencies {
4265

4366
// AspectsLib Dependency (Required)
4467
modImplementation "maven.modrinth:aspectslib:${project.aspectslib_version}"
68+
69+
// Modonomicon Dependency (Optional)
70+
modImplementation "com.klikli_dev:modonomicon-${minecraft_version}-fabric:${modonomicon_version}"
71+
modRuntimeOnly "com.klikli_dev:modonomicon-${minecraft_version}-fabric:${modonomicon_version}"
72+
73+
// compile against the JEI API but do not include it at runtime
74+
modCompileOnlyApi("mezz.jei:jei-${minecraft_version}-fabric-api:${jei_version}")
75+
// at runtime, use the full JEI jar for Fabric
76+
modRuntimeOnly("mezz.jei:jei-${minecraft_version}-fabric:${jei_version}")
4577

4678
}
4779

gradle.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ archives_base_name=thaumaturge
2121
fabric_version=0.92.6+1.20.1
2222

2323
# AspectsLib (Version: 1.1.7)
24-
aspectslib_version=L7mbyqXC
24+
aspectslib_version=L7mbyqXC
25+
26+
jei_version=15.2.0.27
27+
28+
modonomicon_version=1.79.2
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package dev.overgrown.thaumaturge.integration.modonomicon;
2+
3+
import dev.overgrown.thaumaturge.Thaumaturge;
4+
import net.fabricmc.loader.api.FabricLoader;
5+
import net.minecraft.item.ItemStack;
6+
import net.minecraft.nbt.NbtCompound;
7+
import net.minecraft.util.Identifier;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
public class ModonomiconIntegration {
11+
private static final boolean MODONOMICON_LOADED = FabricLoader.getInstance().isModLoaded("modonomicon");
12+
13+
public static boolean isModonomiconLoaded() {
14+
return MODONOMICON_LOADED;
15+
}
16+
17+
@Nullable
18+
public static Object getBookGuiManager() {
19+
if (!MODONOMICON_LOADED) return null;
20+
21+
try {
22+
Class<?> bookGuiManagerClass = Class.forName("com.klikli_dev.modonomicon.client.gui.BookGuiManager");
23+
return bookGuiManagerClass.getMethod("get").invoke(null);
24+
} catch (Exception e) {
25+
Thaumaturge.LOGGER.warn("Failed to access Modonomicon BookGuiManager", e);
26+
return null;
27+
}
28+
}
29+
30+
public static boolean openBook(Identifier bookId) {
31+
if (!MODONOMICON_LOADED) return false;
32+
33+
try {
34+
Object bookGuiManager = getBookGuiManager();
35+
if (bookGuiManager != null) {
36+
bookGuiManager.getClass().getMethod("openBook", Identifier.class).invoke(bookGuiManager, bookId);
37+
return true;
38+
}
39+
} catch (Exception e) {
40+
Thaumaturge.LOGGER.warn("Failed to open Modonomicon book: " + bookId, e);
41+
}
42+
return false;
43+
}
44+
45+
public static void setBookOpenState(ItemStack stack, boolean open) {
46+
if (!MODONOMICON_LOADED) return;
47+
48+
try {
49+
NbtCompound nbt = stack.getOrCreateNbt();
50+
nbt.putString("modonomicon:book_open_state", open ? "open" : "closed");
51+
52+
// Also update the original open state for consistency
53+
nbt.putBoolean("Open", open);
54+
} catch (Exception e) {
55+
Thaumaturge.LOGGER.warn("Failed to set Modonomicon book open state", e);
56+
}
57+
}
58+
59+
public static boolean isBookOpen(ItemStack stack) {
60+
if (!MODONOMICON_LOADED) return false;
61+
62+
try {
63+
NbtCompound nbt = stack.getNbt();
64+
if (nbt != null && nbt.contains("modonomicon:book_open_state")) {
65+
return "open".equals(nbt.getString("modonomicon:book_open_state"));
66+
}
67+
} catch (Exception e) {
68+
Thaumaturge.LOGGER.warn("Failed to check Modonomicon book open state", e);
69+
}
70+
return false;
71+
}
72+
73+
// New method to register GUI close listener
74+
public static void registerCloseListener() {
75+
if (!MODONOMICON_LOADED) return;
76+
77+
try {
78+
} catch (Exception e) {
79+
Thaumaturge.LOGGER.warn("Failed to register Modonomicon close listener", e);
80+
}
81+
}
82+
}
Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package dev.overgrown.thaumaturge.item.apophenia;
22

3+
import dev.overgrown.thaumaturge.integration.modonomicon.ModonomiconIntegration;
4+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
35
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
6+
import net.minecraft.client.MinecraftClient;
47
import net.minecraft.client.item.TooltipContext;
58
import net.minecraft.entity.player.PlayerEntity;
69
import net.minecraft.item.Item;
710
import net.minecraft.item.ItemStack;
811
import net.minecraft.nbt.NbtCompound;
912
import net.minecraft.text.Text;
1013
import net.minecraft.util.Hand;
14+
import net.minecraft.util.Identifier;
1115
import net.minecraft.util.TypedActionResult;
1216
import net.minecraft.util.UseAction;
1317
import net.minecraft.world.World;
@@ -17,18 +21,59 @@
1721

1822
public class ApopheniaItem extends Item {
1923
private static final String OPEN_KEY = "Open";
24+
private static final Identifier THAUMATURGE_BOOK_ID = new Identifier("thaumaturge", "apophenia");
25+
26+
// Track if we're waiting for GUI to close
27+
private static boolean waitingForGuiClose = false;
28+
private static ItemStack lastOpenedStack = null;
2029

2130
public ApopheniaItem() {
2231
super(new FabricItemSettings().maxCount(1));
32+
33+
// Register client tick event to check for GUI close
34+
if (ModonomiconIntegration.isModonomiconLoaded()) {
35+
ClientTickEvents.END_CLIENT_TICK.register(client -> {
36+
onClientTick(client);
37+
});
38+
}
39+
}
40+
41+
private void onClientTick(MinecraftClient client) {
42+
if (waitingForGuiClose && lastOpenedStack != null) {
43+
// Check if the Modonomicon GUI is no longer open
44+
if (client.currentScreen == null) {
45+
// GUI was closed, update the item state
46+
setBookOpenState(lastOpenedStack, false);
47+
waitingForGuiClose = false;
48+
lastOpenedStack = null;
49+
}
50+
}
2351
}
2452

2553
@Override
2654
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
2755
ItemStack stack = user.getStackInHand(hand);
28-
if (!world.isClient()) {
56+
57+
if (world.isClient()) {
58+
// Try to open Modonomicon book first
59+
if (ModonomiconIntegration.isModonomiconLoaded()) {
60+
if (ModonomiconIntegration.openBook(THAUMATURGE_BOOK_ID)) {
61+
ModonomiconIntegration.setBookOpenState(stack, true);
62+
user.getItemCooldownManager().set(this, 5);
63+
64+
// Start tracking for GUI close
65+
waitingForGuiClose = true;
66+
lastOpenedStack = stack;
67+
68+
return TypedActionResult.success(stack);
69+
}
70+
}
71+
72+
// Fallback to original behavior if Modonomicon is not installed or failed to open
2973
toggleState(stack);
30-
user.getItemCooldownManager().set(this, 5); // Small cooldown to prevent spamming
74+
user.getItemCooldownManager().set(this, 5);
3175
}
76+
3277
return TypedActionResult.success(stack, world.isClient());
3378
}
3479

@@ -38,24 +83,55 @@ private void toggleState(ItemStack stack) {
3883
nbt.putBoolean(OPEN_KEY, !isOpen);
3984
}
4085

86+
private void setBookOpenState(ItemStack stack, boolean open) {
87+
if (ModonomiconIntegration.isModonomiconLoaded()) {
88+
ModonomiconIntegration.setBookOpenState(stack, open);
89+
} else {
90+
NbtCompound nbt = stack.getOrCreateNbt();
91+
nbt.putBoolean(OPEN_KEY, open);
92+
}
93+
}
94+
4195
public static boolean isOpen(ItemStack stack) {
96+
// Check Modonomicon open state first
97+
if (ModonomiconIntegration.isModonomiconLoaded() && ModonomiconIntegration.isBookOpen(stack)) {
98+
return true;
99+
}
100+
101+
// Fallback to original NBT check
42102
if (!stack.hasNbt()) return false;
43103
NbtCompound nbt = stack.getNbt();
44104
return nbt != null && nbt.getBoolean(OPEN_KEY);
45105
}
46106

47107
@Override
48108
public UseAction getUseAction(ItemStack stack) {
49-
return UseAction.TOOT_HORN; // Gives a nice animation when used
109+
return UseAction.TOOT_HORN;
50110
}
51111

52112
@Override
53113
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
54114
super.appendTooltip(stack, world, tooltip, context);
55-
if (isOpen(stack)) {
56-
tooltip.add(Text.translatable("item.thaumaturge.apophenia.tooltip.open"));
115+
116+
if (ModonomiconIntegration.isModonomiconLoaded()) {
117+
tooltip.add(Text.translatable("item.thaumaturge.apophenia.tooltip.modonomicon"));
118+
} else {
119+
if (isOpen(stack)) {
120+
tooltip.add(Text.translatable("item.thaumaturge.apophenia.tooltip.open"));
121+
} else {
122+
tooltip.add(Text.translatable("item.thaumaturge.apophenia.tooltip.closed"));
123+
}
124+
}
125+
}
126+
127+
// Method to handle when the book is closed (called from screen close event if needed)
128+
public static void onBookClosed(ItemStack stack) {
129+
if (ModonomiconIntegration.isModonomiconLoaded()) {
130+
ModonomiconIntegration.setBookOpenState(stack, false);
57131
} else {
58-
tooltip.add(Text.translatable("item.thaumaturge.apophenia.tooltip.closed"));
132+
// Reset to closed state for original behavior
133+
NbtCompound nbt = stack.getOrCreateNbt();
134+
nbt.putBoolean(OPEN_KEY, false);
59135
}
60136
}
61137
}
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.overgrown.thaumaturge.item.apophenia.predicate;
22

33
import dev.overgrown.thaumaturge.Thaumaturge;
4+
import dev.overgrown.thaumaturge.integration.modonomicon.ModonomiconIntegration;
45
import dev.overgrown.thaumaturge.item.apophenia.ApopheniaItem;
56
import net.minecraft.client.item.ModelPredicateProviderRegistry;
67
import net.minecraft.util.Identifier;
@@ -9,7 +10,24 @@ public class ApopheniaModelProvider {
910
public static void register() {
1011
ModelPredicateProviderRegistry.register(
1112
new Identifier(Thaumaturge.MOD_ID, "open"),
12-
(stack, world, entity, seed) -> ApopheniaItem.isOpen(stack) ? 1.0F : 0.0F
13+
(stack, world, entity, seed) -> {
14+
// Use Modonomicon's open state if available, otherwise fall back to original behavior
15+
if (ModonomiconIntegration.isModonomiconLoaded()) {
16+
return ModonomiconIntegration.isBookOpen(stack) ? 1.0F : 0.0F;
17+
} else {
18+
return ApopheniaItem.isOpen(stack) ? 1.0F : 0.0F;
19+
}
20+
}
1321
);
22+
23+
// Also register Modonomicon's open state property for compatibility
24+
if (ModonomiconIntegration.isModonomiconLoaded()) {
25+
ModelPredicateProviderRegistry.register(
26+
new Identifier("modonomicon", "open_state"),
27+
(stack, world, entity, seed) -> {
28+
return ModonomiconIntegration.isBookOpen(stack) ? 1.0F : 0.0F;
29+
}
30+
);
31+
}
1432
}
1533
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dev.overgrown.thaumaturge.mixin.modonomicon;
2+
3+
import dev.overgrown.thaumaturge.item.apophenia.ApopheniaItem;
4+
import net.minecraft.client.MinecraftClient;
5+
import net.minecraft.client.gui.screen.Screen;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraft.util.Hand;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(Screen.class)
14+
public class ApopheniaModonomiconScreenMixin {
15+
16+
@Inject(method = "close", at = @At("HEAD"))
17+
private void onScreenClose(CallbackInfo ci) {
18+
Screen self = (Screen) (Object) this;
19+
MinecraftClient client = MinecraftClient.getInstance();
20+
21+
// Check if this screen is a Modonomicon book screen
22+
if (self.getClass().getName().startsWith("com.klikli_dev.modonomicon.client.gui.book")) {
23+
// Update any Apophenia items that might be open
24+
if (client.player != null) {
25+
for (Hand hand : Hand.values()) {
26+
ItemStack stack = client.player.getStackInHand(hand);
27+
if (stack.getItem() instanceof ApopheniaItem) {
28+
ApopheniaItem.onBookClosed(stack);
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}

src/main/resources/assets/thaumaturge/lang/en_us.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@
1414
"item.thaumaturge.bonewits_dust": "Bonewits Dust",
1515

1616
"item.thaumaturge.apophenia": "Apophenia",
17+
"item.thaumaturge.apophenia.tooltip.modonomicon": "Right-click to open the Thaumaturge compendium",
1718
"item.thaumaturge.apophenia.tooltip.open": "§7Open",
1819
"item.thaumaturge.apophenia.tooltip.closed": "§7Closed",
1920

21+
"book.thaumaturge.apophenia.name": "Apophenia",
22+
"book.thaumaturge.apophenia.tooltip": "The Thaumaturge's compendium of knowledge",
23+
"category.thaumaturge.apophenia.introduction.name": "Introduction",
24+
"category.thaumaturge.apophenia.introduction.description": "Getting started with Thaumaturgy",
25+
"entry.thaumaturge.apophenia.introduction.welcome.name": "Welcome",
26+
"page.thaumaturge.apophenia.introduction.welcome.title": "Welcome to Thaumaturgy",
27+
"page.thaumaturge.apophenia.introduction.welcome.text": "Welcome to the world of Thaumaturgy. This book will guide you through the mysteries of spellcasting and magical theory.",
28+
2029
"block.thaumaturge.vessel": "Vessel",
2130

2231
"item.thaumaturge.aspect_lens": "Aspect Lens",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "book.thaumaturge.apophenia.name",
3+
"tooltip": "book.thaumaturge.apophenia.tooltip",
4+
"model": "thaumaturge:apophenia",
5+
"book_text_offset": 5,
6+
"creative_tab": "thaumaturge:tools_and_utilities",
7+
"show_progress": false,
8+
"auto_add_books_to_creative": false,
9+
"i18n": true,
10+
"generate_book_item": false,
11+
"custom_book_item": "thaumaturge:apophenia"
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "category.thaumaturge.apophenia.introduction.name",
3+
"description": "category.thaumaturge.apophenia.introduction.description",
4+
"icon": "thaumaturge:apophenia",
5+
"sort_number": 0,
6+
"entry_textures": "modonomicon:textures/gui/entry_textures.png",
7+
"background": "modonomicon:textures/gui/dark_slate_seamless.png",
8+
"background_width": 512,
9+
"background_height": 512,
10+
"background_texture_zoom_multiplier": 1.0
11+
}

0 commit comments

Comments
 (0)