From 0ff2f5198d72eb6614934899df44ccc48ab861d6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 3 Mar 2019 23:33:38 +0100 Subject: [PATCH] make this whole thing work way better with that new patchouli feature I just added --- build.gradle | 2 +- .../de/ellpeck/naturesaura/compat/Compat.java | 6 ++ .../compat/patchouli/PatchouliCompat.java | 93 ++++++++++--------- .../naturesaura/events/ClientEvents.java | 5 - .../naturesaura/proxy/ClientProxy.java | 1 + 5 files changed, 55 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index fa0decaf..a64e6ffd 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ repositories { } dependencies { - compile "vazkii.patchouli:Patchouli:1.0-18.92" + compile "vazkii.patchouli:Patchouli:1.0-18.93" deobfCompile "mezz.jei:jei_1.12.2:4.14.4.267" deobfCompile "com.azanor.baubles:Baubles:1.12-1.5.2" diff --git a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java index 8c805303..55b56fa1 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java @@ -4,6 +4,8 @@ import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public final class Compat { @@ -22,6 +24,10 @@ public final class Compat { PatchouliCompat.preInit(); } + public static void preInitClient() { + PatchouliCompat.preInitClient(); + } + public static void postInit() { if (craftTweaker && mtLib) CraftTweakerCompat.postInit(); diff --git a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java index 6f2ecdd3..ef937592 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java @@ -13,9 +13,12 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.config.GuiUtils; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import vazkii.patchouli.api.BookDrawScreenEvent; import vazkii.patchouli.api.PatchouliAPI; import java.time.LocalDateTime; @@ -30,59 +33,57 @@ public final class PatchouliCompat { PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.enabledFeatures.rfConverter); } + public static void preInitClient() { + MinecraftForge.EVENT_BUS.register(new PatchouliCompat()); + } + + @SubscribeEvent @SideOnly(Side.CLIENT) - public static void onGuiRender(GuiScreen gui, int mouseX, int mouseY) { - boolean display = false; - try { - ResourceLocation open = PatchouliAPI.instance.getOpenBookGui(); - display = open != null && open.equals(BOOK); - } catch (Throwable ignored) { - // TODO remove this once Patchouli update is out long enough + public void onBookDraw(BookDrawScreenEvent event) { + if (event.book == null || !event.book.equals(BOOK)) + return; + LocalDateTime now = LocalDateTime.now(); + if (now.getMonth() == Month.MAY && now.getDayOfMonth() == 21) { + int x = event.gui.width / 2 + 272 / 2 - 16; + int y = event.gui.height / 2 - 180 / 2 - 26; + + RenderHelper.disableStandardItemLighting(); + GlStateManager.color(1, 1, 1, 1); + event.gui.mc.getTextureManager().bindTexture(ClientEvents.BOOK_GUI); + Gui.drawModalRectWithCustomSizedTexture(x, y, 469, 0, 43, 42, 512, 256); + + if (event.mouseX >= x && event.mouseY >= y && event.mouseX < x + 43 && event.mouseY < y + 42) + GuiUtils.drawHoveringText( + Collections.singletonList(TextFormatting.GOLD + "It's the author Ellpeck's birthday!"), + event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.mc.fontRenderer); } - if (display) { - LocalDateTime now = LocalDateTime.now(); - if (now.getMonth() == Month.MAY && now.getDayOfMonth() == 21) { - int x = gui.width / 2 + 272 / 2 - 16; - int y = gui.height / 2 - 180 / 2 - 26; - RenderHelper.disableStandardItemLighting(); - GlStateManager.color(1, 1, 1, 1); - gui.mc.getTextureManager().bindTexture(ClientEvents.BOOK_GUI); - Gui.drawModalRectWithCustomSizedTexture(x, y, 469, 0, 43, 42, 512, 256); + String name = event.gui.mc.player.getName(); + FancyInfo info = SupporterFancyHandler.FANCY_INFOS.get(name); + if (info != null) { + int x = event.gui.width / 2 - 272 / 2 + 20; + int y = event.gui.height / 2 + 180 / 2; - if (mouseX >= x && mouseY >= y && mouseX < x + 43 && mouseY < y + 42) - GuiUtils.drawHoveringText( - Collections.singletonList(TextFormatting.GOLD + "It's the author Ellpeck's birthday!"), - mouseX, mouseY, gui.width, gui.height, 0, gui.mc.fontRenderer); + RenderHelper.disableStandardItemLighting(); + GlStateManager.color(1, 1, 1, 1); + event.gui.mc.getTextureManager().bindTexture(ClientEvents.BOOK_GUI); + + Gui.drawModalRectWithCustomSizedTexture(x, y, 496, 44, 16, 18, 512, 256); + if (info.tier == 1) { + Gui.drawModalRectWithCustomSizedTexture(x, y, 496 - 16, 44, 16, 18, 512, 256); + } else { + float r = ((info.color >> 16) & 255) / 255F; + float g = ((info.color >> 8) & 255) / 255F; + float b = (info.color & 255) / 255F; + GlStateManager.color(r, g, b); + Gui.drawModalRectWithCustomSizedTexture(x, y, 496 - 32, 44, 16, 18, 512, 256); } - String name = gui.mc.player.getName(); - FancyInfo info = SupporterFancyHandler.FANCY_INFOS.get(name); - if (info != null) { - int x = gui.width / 2 - 272 / 2 + 20; - int y = gui.height / 2 + 180 / 2; + if (event.mouseX >= x && event.mouseY >= y && event.mouseX < x + 16 && event.mouseY < y + 18) + GuiUtils.drawHoveringText( + Collections.singletonList(TextFormatting.YELLOW + "Thanks for your support, " + name + "!"), + event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.mc.fontRenderer); - RenderHelper.disableStandardItemLighting(); - GlStateManager.color(1, 1, 1, 1); - gui.mc.getTextureManager().bindTexture(ClientEvents.BOOK_GUI); - - Gui.drawModalRectWithCustomSizedTexture(x, y, 496, 44, 16, 18, 512, 256); - if (info.tier == 1) { - Gui.drawModalRectWithCustomSizedTexture(x, y, 496 - 16, 44, 16, 18, 512, 256); - } else { - float r = ((info.color >> 16) & 255) / 255F; - float g = ((info.color >> 8) & 255) / 255F; - float b = (info.color & 255) / 255F; - GlStateManager.color(r, g, b); - Gui.drawModalRectWithCustomSizedTexture(x, y, 496 - 32, 44, 16, 18, 512, 256); - } - - if (mouseX >= x && mouseY >= y && mouseX < x + 16 && mouseY < y + 18) - GuiUtils.drawHoveringText( - Collections.singletonList(TextFormatting.YELLOW + "Thanks for your support, " + name + "!"), - mouseX, mouseY, gui.width, gui.height, 0, gui.mc.fontRenderer); - - } } } diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 06e2a11a..f1f215fd 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -102,11 +102,6 @@ public class ClientEvents { mc.profiler.endSection(); } - @SubscribeEvent - public void onGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) { - PatchouliCompat.onGuiRender(event.getGui(), event.getMouseX(), event.getMouseY()); - } - @SubscribeEvent public void onRenderLast(RenderWorldLastEvent event) { Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index adfe1b3a..32b25d27 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -37,6 +37,7 @@ public class ClientProxy implements IProxy { @Override public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new ClientEvents()); + Compat.preInitClient(); } @Override