diff --git a/build.gradle b/build.gradle index 591a039..8acfc23 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.5-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 48780b5..5458e77 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,12 +6,13 @@ org.gradle.parallel=true # check these on https://fabricmc.net/develop minecraft_version=1.20.4 yarn_mappings=1.20.4+build.3 -loader_version=0.15.6 +loader_version=0.15.11 + +# Fabric API +fabric_version=0.97.0+1.20.4 # Mod Properties -mod_version=1.22.4.1-fabric +mod_version=1.22.4.2-fabric maven_group=at.ridgo8.moreoverlays archives_base_name=moreoverlays -# Dependencies -fabric_version=0.95.4+1.20.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e09..a80b22c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/client/java/at/ridgo8/moreoverlays/ClientRegistrationHandler.java b/src/client/java/at/ridgo8/moreoverlays/ClientRegistrationHandler.java index 24f1786..2cee2f7 100644 --- a/src/client/java/at/ridgo8/moreoverlays/ClientRegistrationHandler.java +++ b/src/client/java/at/ridgo8/moreoverlays/ClientRegistrationHandler.java @@ -2,15 +2,23 @@ import at.ridgo8.moreoverlays.itemsearch.GuiHandler; import at.ridgo8.moreoverlays.itemsearch.GuiUtils; +import net.fabricmc.loader.api.FabricLoader; public final class ClientRegistrationHandler { + private static boolean enable_jei = false; + private ClientRegistrationHandler() { // EMPTY } + public static boolean isJeiInstalled() { + return enable_jei; + } + public static void setupClient() { + enable_jei = FabricLoader.getInstance().isModLoaded("jei"); KeyBindings.init(); GuiUtils.initUtil(); GuiHandler.init(); diff --git a/src/client/java/at/ridgo8/moreoverlays/MoreOverlays.java b/src/client/java/at/ridgo8/moreoverlays/MoreOverlays.java index fb989c3..1a6ba16 100644 --- a/src/client/java/at/ridgo8/moreoverlays/MoreOverlays.java +++ b/src/client/java/at/ridgo8/moreoverlays/MoreOverlays.java @@ -40,15 +40,10 @@ public void onInitialize() { ServerLifecycleEvents.SERVER_STOPPING.register(server -> { LightOverlayHandler.setEnabled(false); - if(GuiRenderer.INSTANCE.isEnabled()){ - GuiRenderer.INSTANCE.toggleMode(); - } ChunkBoundsHandler.setMode(RenderMode.NONE); }); - - Config.initialize(); ClientRegistrationHandler.setupClient(); } diff --git a/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiHandler.java b/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiHandler.java index 73fa828..190b6bc 100644 --- a/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiHandler.java +++ b/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiHandler.java @@ -1,15 +1,19 @@ package at.ridgo8.moreoverlays.itemsearch; +import at.ridgo8.moreoverlays.ClientRegistrationHandler; +import at.ridgo8.moreoverlays.chunkbounds.ChunkBoundsHandler; +import at.ridgo8.moreoverlays.chunkbounds.ChunkBoundsHandler.RenderMode; +import at.ridgo8.moreoverlays.lightoverlay.LightOverlayHandler; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; -import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.client.Minecraft; public class GuiHandler { public static void init() { - if (FabricLoader.getInstance().isModLoaded("jei")) { + if (ClientRegistrationHandler.isJeiInstalled()) { registerEvents(); } } @@ -51,6 +55,13 @@ private static void registerEvents() { if (Minecraft.getInstance().player == null) return; GuiRenderer.INSTANCE.tick(); }); + + // World unload + ServerLifecycleEvents.SERVER_STOPPING.register(server -> { + if(GuiRenderer.INSTANCE.isEnabled()){ + GuiRenderer.INSTANCE.toggleMode(); + } + }); } @Deprecated diff --git a/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiUtils.java b/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiUtils.java index 85bc676..37516fa 100644 --- a/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiUtils.java +++ b/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiUtils.java @@ -1,10 +1,14 @@ package at.ridgo8.moreoverlays.itemsearch; import at.ridgo8.moreoverlays.MoreOverlays; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.MappingResolver; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import java.lang.reflect.Field; +import org.jetbrains.annotations.NotNull; + public class GuiUtils { private static Field fieldLeft; @@ -12,16 +16,40 @@ public class GuiUtils { public static void initUtil() { try { - fieldLeft = AbstractContainerScreen.class.getDeclaredField("leftPos"); + + fieldLeft = findField(AbstractContainerScreen.class, "leftPos"); fieldLeft.setAccessible(true); - fieldTop = AbstractContainerScreen.class.getDeclaredField("topPos"); + fieldTop = findField(AbstractContainerScreen.class, "topPos"); fieldTop.setAccessible(true); } catch (NoSuchFieldException e) { - MoreOverlays.logger.error("Tried to load gui coordinate fields for reflection"); - e.printStackTrace(); - fieldTop = null; - fieldLeft = null; + try { + fieldLeft = findField(AbstractContainerScreen.class, "field_2776"); + fieldLeft.setAccessible(true); + + fieldTop = findField(AbstractContainerScreen.class, "field_2800"); + fieldTop.setAccessible(true); + } catch (NoSuchFieldException f) { + MoreOverlays.logger.error("Failed to load gui coordinate fields for reflection"); + f.printStackTrace(); + fieldTop = null; + fieldLeft = null; + } + } + } + + public static Field findField(@NotNull final Class clazz, @NotNull final String fieldName) throws NoSuchFieldException { + try { + MappingResolver resolver = FabricLoader.getInstance().getMappingResolver(); + String currentNamespace = resolver.getCurrentRuntimeNamespace(); + String className = clazz.getName().replace('.', '/'); + String mappedFieldName = resolver.mapFieldName(currentNamespace, className, fieldName, null); + + Field f = clazz.getDeclaredField(mappedFieldName); + f.setAccessible(true); + return f; + } catch (Exception e) { + throw new NoSuchFieldException("Failed to find field: " + e.getMessage()); } } diff --git a/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinEditBox.java b/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinEditBox.java index 9366ec4..9c5a956 100644 --- a/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinEditBox.java +++ b/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinEditBox.java @@ -1,5 +1,6 @@ package at.ridgo8.moreoverlays.mixin.client; +import at.ridgo8.moreoverlays.ClientRegistrationHandler; import at.ridgo8.moreoverlays.itemsearch.GuiRenderer; import at.ridgo8.moreoverlays.itemsearch.JeiModule; import net.minecraft.client.gui.components.EditBox; @@ -16,7 +17,7 @@ public abstract class MixinEditBox { private void onClick(double d, double e, CallbackInfo cir) { EditBox textField = (EditBox) (Object) this; - if(JeiModule.getJEITextField() != null && textField.getClass() == JeiModule.getJEITextField().getClass()){ + if(ClientRegistrationHandler.isJeiInstalled() && JeiModule.getJEITextField() != null && textField.getClass() == JeiModule.getJEITextField().getClass()){ long now = System.currentTimeMillis(); if (now - firstClick < 1000) { GuiRenderer.INSTANCE.toggleMode(); diff --git a/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java b/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java index c61721b..6b1733d 100644 --- a/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java +++ b/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java @@ -1,16 +1,19 @@ package at.ridgo8.moreoverlays.mixin.client; +import java.lang.reflect.Field; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - +import at.ridgo8.moreoverlays.MoreOverlays; import at.ridgo8.moreoverlays.chunkbounds.ChunkBoundsHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -20,22 +23,43 @@ public class MixinOverlayRenderer { private void onRender(GuiGraphics guiGraphics, float f, CallbackInfo ci) { Minecraft mc = Minecraft.getInstance(); try { + if (mc.getDebugOverlay().showDebugScreen()) { + return; + } // Checks if the debug screen is not shown - if (!mc.getDebugOverlay().showDebugScreen()) { + if (!ChunkBoundsHandler.regionInfo.isEmpty()) { + int y = 0; + for (String text : ChunkBoundsHandler.regionInfo) { + guiGraphics.drawString(mc.font, text, 10, y += 10, 0xFFFFFF); + } + } + } catch (NoSuchMethodError e) { + try{ + Field renderDebugField = null; + // Use reflection to check if the renderDebug field exists in mc.options. Note: remove this for future versions + try{ + renderDebugField = mc.options.getClass().getDeclaredField("field_1866"); + renderDebugField.setAccessible(true); + } catch(Exception o){ + renderDebugField = mc.options.getClass().getField("renderDebug"); + } + + boolean renderDebug = renderDebugField.getBoolean(mc.options); + + if (renderDebug) { + return; + } + if (!ChunkBoundsHandler.regionInfo.isEmpty()) { int y = 0; for (String text : ChunkBoundsHandler.regionInfo) { guiGraphics.drawString(mc.font, text, 10, y += 10, 0xFFFFFF); } } + } catch(Exception g){ + // Ignore } - } catch (NoSuchMethodError e) { - if (!ChunkBoundsHandler.regionInfo.isEmpty()) { - int y = 0; - for (String text : ChunkBoundsHandler.regionInfo) { - guiGraphics.drawString(mc.font, text, 10, y += 10, 0xFFFFFF); - } - } + } } } diff --git a/src/client/resources/fabric.mod.json b/src/client/resources/fabric.mod.json index 515d918..9784e12 100644 --- a/src/client/resources/fabric.mod.json +++ b/src/client/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "moreoverlays", "version": "${version}", "name": "MoreOverlays", - "description": "This is an example description! Tell everyone what your mod is about!", + "description": "This mod adds some of the overlays back from NEI", "authors": [ "feldim2425", "RiDGo8 / R8420"