From ae7362742e29d481b42ac58fcfc403be076fff79 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sun, 16 Feb 2014 16:39:42 +0000 Subject: [PATCH] Added a HUD to when something can be read into with the lexicon. --- .../client/core/handler/HUDHandler.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java b/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java index ac01e957b..0b88c28ad 100644 --- a/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java +++ b/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java @@ -16,6 +16,8 @@ import java.awt.Color; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; @@ -25,7 +27,9 @@ import net.minecraftforge.event.ForgeSubscribe; import org.lwjgl.opengl.GL11; +import vazkii.botania.api.ILexiconable; import vazkii.botania.api.IWandHUD; +import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.client.core.helper.RenderHelper; import vazkii.botania.client.lib.LibResources; import vazkii.botania.common.item.ModItems; @@ -33,7 +37,8 @@ import vazkii.botania.common.item.ModItems; public final class HUDHandler { private static final ResourceLocation manaBar = new ResourceLocation(LibResources.GUI_MANA_HUD); - + private static final RenderItem itemRender = new RenderItem(); + @ForgeSubscribe public void onDrawScreen(RenderGameOverlayEvent.Post event) { if(event.type == ElementType.ALL) { @@ -44,8 +49,36 @@ public final class HUDHandler { if(Block.blocksList[id] != null && Block.blocksList[id] instanceof IWandHUD) ((IWandHUD) Block.blocksList[id]).renderHUD(mc, event.resolution, mc.theWorld, pos.blockX, pos.blockY, pos.blockZ); } + + else if(pos != null && mc.thePlayer.getCurrentEquippedItem() != null && mc.thePlayer.getCurrentEquippedItem().itemID == ModItems.lexicon.itemID) { + int id = mc.theWorld.getBlockId(pos.blockX, pos.blockY, pos.blockZ); + if(Block.blocksList[id] != null && Block.blocksList[id] instanceof ILexiconable) { + LexiconEntry entry = ((ILexiconable) Block.blocksList[id]).getEntry(mc.theWorld, pos.blockX, pos.blockY, pos.blockZ, mc.thePlayer, mc.thePlayer.getCurrentEquippedItem()); + if(entry != null) + drawLexiconGUI(entry, event.resolution); + } + } } } + + private void drawLexiconGUI(LexiconEntry entry, ScaledResolution res) { + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + Minecraft mc = Minecraft.getMinecraft(); + int x = res.getScaledWidth() / 2 + 8; + int y = res.getScaledHeight() / 2 - 4; + + int color = 0x2200FF00; + + mc.fontRenderer.drawStringWithShadow(StatCollector.translateToLocal(entry.getUnlocalizedName()), x + 18, y, color); + mc.fontRenderer.drawStringWithShadow(StatCollector.translateToLocal("botaniamisc.shiftToRead"), x + 18, y + 11, color); + itemRender.renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, new ItemStack(ModItems.lexicon), x, y); + GL11.glDisable(GL11.GL_LIGHTING); + mc.fontRenderer.drawStringWithShadow("?", x + 10, y + 8, 0xFFFFFF); + + GL11.glDisable(GL11.GL_BLEND); + GL11.glColor4f(1F, 1F, 1F, 1F); + } public static void drawSimpleManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res) { GL11.glEnable(GL11.GL_BLEND);