From 15f33c68424388941cbed99d2bbb7553601ac373 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Fri, 23 Oct 2015 18:15:32 +0100 Subject: [PATCH] Quick lookup. --- .../api/lexicon/LexiconRecipeMappings.java | 7 +- .../core/handler/ClientTickHandler.java | 13 ++- .../TooltipAdditionDisplayHandler.java | 98 ++++++++++++++++++- .../client/core/helper/RenderHelper.java | 2 +- .../botania/common/item/ItemLexicon.java | 8 +- .../resources/assets/botania/lang/en_US.lang | 8 +- 6 files changed, 118 insertions(+), 18 deletions(-) diff --git a/src/main/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java b/src/main/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java index f4456b9f1..33f947733 100644 --- a/src/main/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java +++ b/src/main/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java @@ -13,6 +13,7 @@ package vazkii.botania.api.lexicon; import java.util.HashMap; import java.util.Map; +import vazkii.botania.api.mana.IManaItem; import net.minecraft.item.ItemStack; /** @@ -53,9 +54,13 @@ public final class LexiconRecipeMappings { if(stack.hasTagCompound() && stack.getItem() instanceof IRecipeKeyProvider) return ((IRecipeKeyProvider) stack.getItem()).getKey(stack); - return stack.getUnlocalizedName() + "~" + stack.getItemDamage(); + return stack.getUnlocalizedName() + (ignoreMeta(stack) ? "" : ("~" + stack.getItemDamage())); } + public static boolean ignoreMeta(ItemStack stack) { + return stack.isItemStackDamageable() || stack.getItem() instanceof IManaItem; + } + public static class EntryData { public final LexiconEntry entry; diff --git a/src/main/java/vazkii/botania/client/core/handler/ClientTickHandler.java b/src/main/java/vazkii/botania/client/core/handler/ClientTickHandler.java index 46ca9815d..1db204f47 100644 --- a/src/main/java/vazkii/botania/client/core/handler/ClientTickHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/ClientTickHandler.java @@ -37,12 +37,17 @@ public class ClientTickHandler { public static int pageFlipTicks = 0; public static int ticksInGame = 0; public static float partialTicks = 0; - + public static float delta = 0; + @SubscribeEvent public void renderTick(RenderTickEvent event) { - if(event.phase == Phase.START) - partialTicks = event.renderTickTime; - else TooltipAdditionDisplayHandler.render(); + if(event.phase == Phase.START) { + float newPartialTicks = event.renderTickTime; + float newTotalTime = ticksInGame + newPartialTicks; + float oldTotalTime = ticksInGame + partialTicks; + delta = Math.abs(newTotalTime - oldTotalTime); + partialTicks = newPartialTicks; + } else TooltipAdditionDisplayHandler.render(); } @SubscribeEvent diff --git a/src/main/java/vazkii/botania/client/core/handler/TooltipAdditionDisplayHandler.java b/src/main/java/vazkii/botania/client/core/handler/TooltipAdditionDisplayHandler.java index f419dc267..07a8025e8 100644 --- a/src/main/java/vazkii/botania/client/core/handler/TooltipAdditionDisplayHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/TooltipAdditionDisplayHandler.java @@ -10,7 +10,10 @@ */ package vazkii.botania.client.core.handler; +import ibxm.Player; + import java.awt.Color; +import java.util.Arrays; import java.util.List; import net.minecraft.client.Minecraft; @@ -19,20 +22,31 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import vazkii.botania.api.lexicon.ILexicon; +import vazkii.botania.api.lexicon.LexiconRecipeMappings; +import vazkii.botania.api.lexicon.LexiconRecipeMappings.EntryData; import vazkii.botania.api.mana.IManaTooltipDisplay; +import vazkii.botania.client.core.helper.RenderHelper; +import vazkii.botania.common.Botania; +import vazkii.botania.common.item.ItemLexicon; +import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.tool.terrasteel.ItemTerraPick; import vazkii.botania.common.lib.LibObfuscation; import cpw.mods.fml.relauncher.ReflectionHelper; public final class TooltipAdditionDisplayHandler { + private static float lexiconLookupTime = 0F; + public static void render() { Minecraft mc = Minecraft.getMinecraft(); GuiScreen gui = mc.currentScreen; @@ -64,15 +78,89 @@ public final class TooltipAdditionDisplayHandler { offy -= fixY; if(offscreen) offx = -13 - width; - if(stack.getItem() instanceof ItemTerraPick) drawTerraPick(stack, mouseX, mouseY, offx, offy, width, height, font); - if(stack.getItem() instanceof IManaTooltipDisplay) + else if(stack.getItem() instanceof IManaTooltipDisplay) drawManaBar(stack, (IManaTooltipDisplay) stack.getItem(), mouseX, mouseY, offx, offy, width, height); - } - } - } + + EntryData data = LexiconRecipeMappings.getDataForStack(stack); + if(data != null) { + int lexSlot = -1; + ItemStack lexiconStack = null; + + for(int i = 0; i < mc.thePlayer.inventory.getHotbarSize(); i++) { + ItemStack stackAt = mc.thePlayer.inventory.getStackInSlot(i); + if(stackAt != null && stackAt.getItem() instanceof ILexicon && ((ILexicon) stackAt.getItem()).isKnowledgeUnlocked(stackAt, data.entry.getKnowledgeType())) { + lexiconStack = stackAt; + lexSlot = i; + break; + } + } + + if(lexSlot > -1) { + int x = mouseX + offx - 34; + int y = mouseY - offy; + GL11.glDisable(GL11.GL_DEPTH_TEST); + + Gui.drawRect(x - 4, y - 4, x + 20, y + 26, 0x44000000); + Gui.drawRect(x - 6, y - 6, x + 22, y + 28, 0x44000000); + + if(GuiScreen.isCtrlKeyDown()) { + lexiconLookupTime += ClientTickHandler.delta; + + int cx = x + 8; + int cy = y + 8; + float r = 12; + float time = 30F; + float angles = lexiconLookupTime / time * 360F; + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + + float a = 0.5F + 0.2F * ((float) Math.cos((double) (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) / 10) * 0.5F + 0.5F); + GL11.glColor4f(0F, 0.5F, 0F, a); + GL11.glVertex2i(cx, cy); + GL11.glColor4f(0F, 1F, 0F, 1F); + + for(float i = angles; i > 0; i--) { + double rad = (i - 90) / 180F * Math.PI; + GL11.glVertex2d(cx + Math.cos(rad) * r, cy + Math.sin(rad) * r); + } + GL11.glVertex2i(cx, cy); + GL11.glEnd(); + + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glShadeModel(GL11.GL_FLAT); + + if(lexiconLookupTime >= time) { + mc.thePlayer.inventory.currentItem = lexSlot; + Botania.proxy.setEntryToOpen(data.entry); + Botania.proxy.setLexiconStack(lexiconStack); + ItemLexicon.openBook(mc.thePlayer, lexiconStack, mc.theWorld, false); + + } + } else lexiconLookupTime = 0F; + + RenderItem.getInstance().renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, new ItemStack(ModItems.lexicon), x, y); + GL11.glDisable(GL11.GL_LIGHTING); + + font.drawStringWithShadow("?", x + 10, y + 8, 0xFFFFFFFF); + GL11.glScalef(0.5F, 0.5F, 1F); + mc.fontRenderer.drawStringWithShadow(EnumChatFormatting.BOLD + "Ctrl", (x + 10) * 2 - 16, (y + 8) * 2 + 20, 0xFFFFFFFF); + GL11.glScalef(2F, 2F, 1F); + + GL11.glEnable(GL11.GL_DEPTH_TEST); + } else lexiconLookupTime = 0F; + } else lexiconLookupTime = 0F; + } else lexiconLookupTime = 0F; + } else lexiconLookupTime = 0F; + } else lexiconLookupTime = 0F; } private static void drawTerraPick(ItemStack stack, int mouseX, int mouseY, int offx, int offy, int width, int height, FontRenderer font) { diff --git a/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java b/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java index 8649f67b8..ff177cbd1 100644 --- a/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java @@ -211,7 +211,7 @@ public final class RenderHelper { int centerX = x + 8; int centerY = y + 8; int degs = (int) (360 * progress); - float a = 0.5F + 0.2F * ((float) Math.cos((double) ClientTickHandler.ticksInGame / 10) * 0.5F + 0.5F); + float a = 0.5F + 0.2F * ((float) Math.cos((double) (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) / 10) * 0.5F + 0.5F); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_TEXTURE_2D); diff --git a/src/main/java/vazkii/botania/common/item/ItemLexicon.java b/src/main/java/vazkii/botania/common/item/ItemLexicon.java index 9e0fed8ec..363692f16 100644 --- a/src/main/java/vazkii/botania/common/item/ItemLexicon.java +++ b/src/main/java/vazkii/botania/common/item/ItemLexicon.java @@ -142,12 +142,14 @@ public class ItemLexicon extends ItemMod implements ILexicon, IElvenItem { return par1ItemStack; } - public void openBook(EntityPlayer player, ItemStack stack, World world, boolean skipSound) { - if(!isKnowledgeUnlocked(stack, BotaniaAPI.relicKnowledge) && isKnowledgeUnlocked(stack, BotaniaAPI.elvenKnowledge)) + public static void openBook(EntityPlayer player, ItemStack stack, World world, boolean skipSound) { + ILexicon l = (ILexicon) stack.getItem(); + + if(!l.isKnowledgeUnlocked(stack, BotaniaAPI.relicKnowledge) && l.isKnowledgeUnlocked(stack, BotaniaAPI.elvenKnowledge)) for(ItemStack rstack : ItemDice.relicStacks) { Item item = rstack.getItem(); if(player.inventory.hasItem(item)) { - unlockKnowledge(stack, BotaniaAPI.relicKnowledge); + l.unlockKnowledge(stack, BotaniaAPI.relicKnowledge); break; } } diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index f76d5405c..1429cc8fc 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -2211,7 +2211,7 @@ botania.page.warpLens1=Hakase Quarries # -- MANA PRISM botania.entry.prism=Mana Prism -botania.tagline.warpLens=Switch a Mana Burst's effective Lens on the fly +botania.tagline.prism=Switch a Mana Burst's effective Lens on the fly botania.page.prism0=The concept of &1Mana Lens&0 allows for the manipulation of the power convyed through &4Mana Bursts&0, the &1Mana Prism&0 works on that technology to allow a burst to have its lens effect switched on the fly.
Using a &1Spectral Platform&0 as a component, this block does not have a physical presence, entities and bursts can go through it as if it doesn't exist. botania.page.prism1=Right clicking it with any variety of &1Mana Lens&0 sets the lens in the prism. Whenever a &4Mana Burst&0 goes through the prism, its color and effect will be set to that of the lens in the prism. Case the lens is not dyed, the burst will turn white.
Using any of the four basic lenses also increases the time the burst can go before losing &4Mana&0, allowing it to go further. botania.page.prism2=It can also be turned off by the use of a redstone signal. @@ -2728,7 +2728,7 @@ botania.page.gatherDrum1=Tap your lands # -- CRAFTY CRATE botania.entry.craftCrate=Crafty Crate -botania.tagline.craftyCrate=A way to craft automatically +botania.tagline.craftCrate=A way to craft automatically botania.page.craftCrate0=As the name suggests, the &1Crafty Crate&0 is a counterpart to the &1Open Crate&0 with the ability to assemble items into other items similarly to a &1Crafting Table&0.
Like a &1Crafting Table&0, it has a 9 slot inventory, which can be filled with items in the pattern of a recipe. botania.page.craftCrate1=The items go in from left to right and top to bottom (illustration further in this entry), to that, there's a special item, named the &1Crafting Placeholder&0, which, when placed in, counts as an empty slot in the recipe. This is used to allow for recipes with gaps (eg, furnace, chest, pickaxe...) to also be doable. botania.page.craftCrate2=Creating the placeholder @@ -2933,7 +2933,7 @@ botania.page.laputaShard3=Size does matter # -- EQUESTRIAN VIRUS botania.entry.virus=Equestrian Virus -botania.tagline.laputaShard=Super high powered horses +botania.tagline.virus=Super high powered horses botania.page.virus0=Through the mixing of some ingredients, a type of virus that can alter the genetic code of equestrian life can be made.
Using one of these viruses on a &1Horse&0 will alter its genetic code, turning it into either a &1Zombie&0 or &1Skeleton Horse&0. Not only will it do that, but it will vastly increase all the &1Horse&0's genetic attributes. botania.page.virus1=No ponies here botania.page.virus2=None here either @@ -3409,7 +3409,7 @@ botania.page.pixieRing1=We got square heads, big pointy caps # -- GLOBETROTTER'S SASH botania.entry.superTravelBelt=Globetrotter's Sash -botania.entry.superTravelBelt=Gotta go fast +botania.tagline.superTravelBelt=Gotta go fast botania.page.superTravelBelt0=The &1Globetrotter's Sash&0 is, in layman's terms, an upgrade to then &1Soujourner's Sash&0, by using &1Gaia Spirits&0 and some Elven resources, this new belt allows the wearer to reach incredible speeds to which the &1Soujourner's Sash&0 doesn't stand a chance. botania.page.superTravelBelt1=No time for guessing, follow my plan instead