From 9bb3951b1101ae0802c09c77a974beb445b62d4e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 1 Mar 2019 20:51:43 +0100 Subject: [PATCH] move some more patchouli stuff around --- build.gradle | 2 +- .../de/ellpeck/naturesaura/compat/Compat.java | 6 --- .../compat/patchouli/PatchouliCompat.java | 42 ++++++++++++++++--- .../naturesaura/events/ClientEvents.java | 25 +---------- .../naturesaura/proxy/ClientProxy.java | 1 - 5 files changed, 40 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index 10ecb49b..fa0decaf 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ repositories { } dependencies { - compile "vazkii.patchouli:Patchouli:1.0-18.91" + compile "vazkii.patchouli:Patchouli:1.0-18.92" 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 5c2e9694..8c805303 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java @@ -1,7 +1,5 @@ package de.ellpeck.naturesaura.compat; -import de.ellpeck.naturesaura.ModConfig; -import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat; import net.minecraftforge.common.MinecraftForge; @@ -24,10 +22,6 @@ 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 5e26505e..ce7fe19e 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/patchouli/PatchouliCompat.java @@ -3,22 +3,54 @@ package de.ellpeck.naturesaura.compat.patchouli; import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.multiblock.Matcher; +import de.ellpeck.naturesaura.events.ClientEvents; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.client.config.GuiUtils; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import vazkii.patchouli.api.PatchouliAPI; +import java.time.LocalDateTime; +import java.time.Month; +import java.util.Collections; + public final class PatchouliCompat { - public static Class bookGuiClass; + private static final ResourceLocation BOOK = new ResourceLocation(NaturesAura.MOD_ID, "book"); public static void preInit() { PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.enabledFeatures.rfConverter); } - public static void preInitClient() { + @SideOnly(Side.CLIENT) + public static void onGuiRender(GuiScreen gui, int mouseX, int mouseY) { + boolean display = false; try { - bookGuiClass = Class.forName("vazkii.patchouli.client.book.gui.GuiBook"); - } catch (ClassNotFoundException e) { - NaturesAura.LOGGER.warn("Couldn't find Patchouli book class, not loading special visuals :("); + ResourceLocation open = PatchouliAPI.instance.getOpenBookGui(); + display = open != null && open.equals(BOOK); + } catch (Throwable ignored) { + // TODO remove this once Patchouli update is out long enough + } + 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); + + 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); + } } } diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 814e49d5..06e2a11a 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -58,9 +58,6 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.lwjgl.opengl.GL11; import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.Month; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -69,7 +66,7 @@ import java.util.Map; public class ClientEvents { public static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png"); - private static final ResourceLocation BOOK_GUI = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/book.png"); + public static final ResourceLocation BOOK_GUI = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/book.png"); private static final ItemStack ITEM_FRAME = new ItemStack(Items.ITEM_FRAME); private static final Map> SHOWING_EFFECTS = new HashMap<>(); private static ItemStack heldCache = ItemStack.EMPTY; @@ -107,25 +104,7 @@ public class ClientEvents { @SubscribeEvent public void onGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) { - GuiScreen gui = event.getGui(); - if (PatchouliCompat.bookGuiClass != null && PatchouliCompat.bookGuiClass.isAssignableFrom(gui.getClass())) { - int mouseX = event.getMouseX(); - int mouseY = event.getMouseY(); - 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(BOOK_GUI); - Gui.drawModalRectWithCustomSizedTexture(x, y, 469, 0, 43, 42, 512, 256); - - 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); - } - } + PatchouliCompat.onGuiRender(event.getGui(), event.getMouseX(), event.getMouseY()); } @SubscribeEvent diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index 622651a6..85769a56 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -36,7 +36,6 @@ public class ClientProxy implements IProxy { @Override public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new ClientEvents()); - Compat.preInitClient(); } @Override