From c07080650a73a009e90e8da388ee9f76cb3d90e7 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Fri, 3 Nov 2017 09:24:57 +0100 Subject: [PATCH] Fix realms notifications not being offset with button (fixes #22 GH) --- .../core/handler/MainMenuHandler.java | 58 ++++++++++++++++++- src/main/resources/META-INF/replaymod_at.cfg | 4 ++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/replaymod/core/handler/MainMenuHandler.java b/src/main/java/com/replaymod/core/handler/MainMenuHandler.java index d3fd3cab..df59a4c4 100644 --- a/src/main/java/com/replaymod/core/handler/MainMenuHandler.java +++ b/src/main/java/com/replaymod/core/handler/MainMenuHandler.java @@ -2,9 +2,14 @@ package com.replaymod.core.handler; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiScreenRealmsProxy; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.opengl.GL11; + +import java.io.IOException; /** * Moves certain buttons on the main menu upwards so we can inject our own. @@ -17,6 +22,8 @@ public class MainMenuHandler { @SubscribeEvent public void onInit(GuiScreenEvent.InitGuiEvent.Post event) { if (event.getGui() instanceof GuiMainMenu) { + GuiMainMenu gui = (GuiMainMenu) event.getGui(); + int realmsOffset = 0; for (GuiButton button : event.getButtonList()) { // Buttons that aren't in a rectangle directly above our space don't need moving if (button.x + button.width < event.getGui().width / 2 - 100 @@ -24,8 +31,57 @@ public class MainMenuHandler { || button.y > event.getGui().height / 4 + 10 + 4 * 24) continue; // Move button up to make space for two rows of buttons // and then move back down by 10 to compensate for the space to the exit button that was already there - button.y -= 2 * 24 - 10; + int offset = -2 * 24 + 10; + button.y += offset; + if (button == gui.realmsButton) { + realmsOffset = offset; + } + } + if (realmsOffset != 0 && gui.realmsNotification instanceof GuiScreenRealmsProxy) { + gui.realmsNotification = new RealmsNotificationProxy((GuiScreenRealmsProxy) gui.realmsNotification, realmsOffset); } } } + + private static class RealmsNotificationProxy extends GuiScreen { + private final GuiScreenRealmsProxy proxy; + private final int offset; + + private RealmsNotificationProxy(GuiScreenRealmsProxy proxy, int offset) { + this.proxy = proxy; + this.offset = offset; + } + + @Override + public void setGuiSize(int w, int h) { + proxy.setGuiSize(w, h); + } + + @Override + public void initGui() { + proxy.initGui(); + } + + @Override + public void updateScreen() { + proxy.updateScreen(); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + GL11.glTranslated(0, offset, 0); + proxy.drawScreen(mouseX, mouseY - offset, partialTicks); + GL11.glTranslated(0, -offset, 0); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + proxy.mouseClicked(mouseX, mouseY - offset, mouseButton); + } + + @Override + public void onGuiClosed() { + proxy.onGuiClosed(); + } + } } diff --git a/src/main/resources/META-INF/replaymod_at.cfg b/src/main/resources/META-INF/replaymod_at.cfg index d35f4c3c..7aad0d79 100644 --- a/src/main/resources/META-INF/replaymod_at.cfg +++ b/src/main/resources/META-INF/replaymod_at.cfg @@ -42,6 +42,10 @@ public net.minecraft.network.play.server.SPacketSpawnPlayer field_148960_i # wat # GuiTextField public net.minecraft.client.gui.GuiTextField field_146216_j # text +# GuiMainMenu +public net.minecraft.client.gui.GuiMainMenu field_175372_K # realmsButton +public net.minecraft.client.gui.GuiMainMenu field_183503_M # realmsNotification + # Entity public net.minecraft.entity.Entity field_70180_af # dataWatcher