Mana Tablets, Rings and Mirrors now have a similar mana bar to that of the Terra Shatterer.

This commit is contained in:
Vasco Lavos committed 2015-10-23 16:15:00 +01:00
1 parent 6197e48dab
commit ab4314a48b
7 files changed
+165 -103

No files matched your search

@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Oct 23, 2015, 3:54:03 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* An Item that implements this has a mana tooltip display (like how the Mana Tablet
* and Mana Mirror) do.
*/
public interface IManaTooltipDisplay {
/**
* Returns the fraction of mana in this item for display. From 0 to 1 (exclusive).
*/
public float getManaFractionForDisplay(ItemStack stack);
}
@@ -42,7 +42,7 @@ public class ClientTickHandler {
public void renderTick(RenderTickEvent event) {
if(event.phase == Phase.START)
partialTicks = event.renderTickTime;
else TerraPickRankDisplayHandler.render();
else TooltipAdditionDisplayHandler.render();
}
@SubscribeEvent
@@ -1,99 +0,0 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Apr 23, 2015, 4:24:56 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.awt.Color;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
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.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import vazkii.botania.common.item.equipment.tool.terrasteel.ItemTerraPick;
import vazkii.botania.common.lib.LibObfuscation;
import cpw.mods.fml.relauncher.ReflectionHelper;
public final class TerraPickRankDisplayHandler {
public static void render() {
Minecraft mc = Minecraft.getMinecraft();
GuiScreen gui = mc.currentScreen;
if(gui != null && gui instanceof GuiContainer && mc.thePlayer != null && mc.thePlayer.inventory.getItemStack() == null) {
GuiContainer container = (GuiContainer) gui;
Slot slot = ReflectionHelper.getPrivateValue(GuiContainer.class, container, LibObfuscation.THE_SLOT);
if(slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
if(stack != null && stack.getItem() instanceof ItemTerraPick) {
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
FontRenderer font = mc.fontRenderer;
int mouseX = Mouse.getX() * res.getScaledWidth() / mc.displayWidth;
int mouseY = res.getScaledHeight() - Mouse.getY() * res.getScaledHeight() / mc.displayHeight;
List<String> tooltip = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
int width = 0;
for(String s : tooltip)
width = Math.max(width, font.getStringWidth(s));
int tooltipHeight = (tooltip.size() - 1) * 10 + 5;
int height = 3;
int offx = 11;
int offy = 17;
boolean offscreen = mouseX + width + 19 >= res.getScaledWidth();
int fixY = res.getScaledHeight() - (mouseY + tooltipHeight);
if(fixY < 0)
offy -= fixY;
if(offscreen)
offx = -13 - width;
int level = ItemTerraPick.getLevel(stack);
int max = ItemTerraPick.LEVELS[Math.min(ItemTerraPick.LEVELS.length - 1, level + 1)];
boolean ss = level >= ItemTerraPick.LEVELS.length - 1;
int curr = ItemTerraPick.getMana_(stack);
float percent = level == 0 ? 0F : (float) curr / (float) max;
int rainbowWidth = Math.min(width - (ss ? 0 : 1), (int) (width * percent));
float huePer = width == 0 ? 0F : 1F / width;
float hueOff = (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) * 0.01F;
GL11.glDisable(GL11.GL_DEPTH_TEST);
Gui.drawRect(mouseX + offx - 1, mouseY - offy - height - 1, mouseX + offx + width + 1, mouseY - offy, 0xFF000000);
for(int i = 0; i < rainbowWidth; i++)
Gui.drawRect(mouseX + offx + i, mouseY - offy - height, mouseX + offx + i + 1, mouseY - offy, Color.HSBtoRGB(hueOff + huePer * i, 1F, 1F));
Gui.drawRect(mouseX + offx + rainbowWidth, mouseY - offy - height, mouseX + offx + width, mouseY - offy, 0xFF555555);
String rank = StatCollector.translateToLocal("botania.rank" + level).replaceAll("&", "\u00a7");
boolean light = GL11.glGetBoolean(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHTING);
font.drawStringWithShadow(rank, mouseX + offx, mouseY - offy - 12, 0xFFFFFF);
if(!ss) {
rank = StatCollector.translateToLocal("botania.rank" + (level + 1)).replaceAll("&", "\u00a7");
font.drawStringWithShadow(rank, mouseX + offx + width - font.getStringWidth(rank), mouseY - offy - 12, 0xFFFFFF);
}
if(light)
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
}
}
}
}
@@ -0,0 +1,117 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Apr 23, 2015, 4:24:56 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.awt.Color;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
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.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.mana.IManaTooltipDisplay;
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 {
public static void render() {
Minecraft mc = Minecraft.getMinecraft();
GuiScreen gui = mc.currentScreen;
if(gui != null && gui instanceof GuiContainer && mc.thePlayer != null && mc.thePlayer.inventory.getItemStack() == null) {
GuiContainer container = (GuiContainer) gui;
Slot slot = ReflectionHelper.getPrivateValue(GuiContainer.class, container, LibObfuscation.THE_SLOT);
if(slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
if(stack != null) {
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
FontRenderer font = mc.fontRenderer;
int mouseX = Mouse.getX() * res.getScaledWidth() / mc.displayWidth;
int mouseY = res.getScaledHeight() - Mouse.getY() * res.getScaledHeight() / mc.displayHeight;
List<String> tooltip = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
int width = 0;
for(String s : tooltip)
width = Math.max(width, font.getStringWidth(s) + 2);
int tooltipHeight = (tooltip.size() - 1) * 10 + 5;
int height = 3;
int offx = 11;
int offy = 17;
boolean offscreen = mouseX + width + 19 >= res.getScaledWidth();
int fixY = res.getScaledHeight() - (mouseY + tooltipHeight);
if(fixY < 0)
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)
drawManaBar(stack, (IManaTooltipDisplay) stack.getItem(), mouseX, mouseY, offx, offy, width, height);
}
}
}
}
private static void drawTerraPick(ItemStack stack, int mouseX, int mouseY, int offx, int offy, int width, int height, FontRenderer font) {
int level = ItemTerraPick.getLevel(stack);
int max = ItemTerraPick.LEVELS[Math.min(ItemTerraPick.LEVELS.length - 1, level + 1)];
boolean ss = level >= ItemTerraPick.LEVELS.length - 1;
int curr = ItemTerraPick.getMana_(stack);
float percent = level == 0 ? 0F : (float) curr / (float) max;
int rainbowWidth = Math.min(width - (ss ? 0 : 1), (int) (width * percent));
float huePer = width == 0 ? 0F : 1F / width;
float hueOff = (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) * 0.01F;
GL11.glDisable(GL11.GL_DEPTH_TEST);
Gui.drawRect(mouseX + offx - 1, mouseY - offy - height - 1, mouseX + offx + width + 1, mouseY - offy, 0xFF000000);
for(int i = 0; i < rainbowWidth; i++)
Gui.drawRect(mouseX + offx + i, mouseY - offy - height, mouseX + offx + i + 1, mouseY - offy, Color.HSBtoRGB(hueOff + huePer * i, 1F, 1F));
Gui.drawRect(mouseX + offx + rainbowWidth, mouseY - offy - height, mouseX + offx + width, mouseY - offy, 0xFF555555);
String rank = StatCollector.translateToLocal("botania.rank" + level).replaceAll("&", "\u00a7");
boolean light = GL11.glGetBoolean(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHTING);
font.drawStringWithShadow(rank, mouseX + offx, mouseY - offy - 12, 0xFFFFFF);
if(!ss) {
rank = StatCollector.translateToLocal("botania.rank" + (level + 1)).replaceAll("&", "\u00a7");
font.drawStringWithShadow(rank, mouseX + offx + width - font.getStringWidth(rank), mouseY - offy - 12, 0xFFFFFF);
}
if(light)
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
private static void drawManaBar(ItemStack stack, IManaTooltipDisplay display, int mouseX, int mouseY, int offx, int offy, int width, int height) {
float fraction = display.getManaFractionForDisplay(stack);
int manaBarWidth = (int) Math.ceil(((float) width * fraction));
GL11.glDisable(GL11.GL_DEPTH_TEST);
Gui.drawRect(mouseX + offx - 1, mouseY - offy - height - 1, mouseX + offx + width + 1, mouseY - offy, 0xFF000000);
Gui.drawRect(mouseX + offx, mouseY - offy - height, mouseX + offx + manaBarWidth, mouseY - offy, Color.HSBtoRGB(0.528F, ((float) Math.sin((ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) * 0.2) + 1F) * 0.3F + 0.4F, 1F));
Gui.drawRect(mouseX + offx + manaBarWidth, mouseY - offy - height, mouseX + offx + width, mouseY - offy, 0xFF555555);
}
}
@@ -23,13 +23,14 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaPool;
import vazkii.botania.api.mana.IManaTooltipDisplay;
import vazkii.botania.api.wand.ICoordBoundItem;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.common.block.tile.mana.TilePool;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
public class ItemManaMirror extends ItemMod implements IManaItem, ICoordBoundItem {
public class ItemManaMirror extends ItemMod implements IManaItem, ICoordBoundItem, IManaTooltipDisplay {
IIcon[] icons;
@@ -267,5 +268,10 @@ public class ItemManaMirror extends ItemMod implements IManaItem, ICoordBoundIte
return pool == null || pool instanceof DummyPool ? null : getPoolCoords(stack);
}
@Override
public float getManaFractionForDisplay(ItemStack stack) {
return (float) getMana(stack) / (float) getMaxMana(stack);
}
}
@@ -24,11 +24,12 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import vazkii.botania.api.mana.ICreativeManaProvider;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaTooltipDisplay;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
public class ItemManaTablet extends ItemMod implements IManaItem, ICreativeManaProvider {
public class ItemManaTablet extends ItemMod implements IManaItem, ICreativeManaProvider, IManaTooltipDisplay {
IIcon[] icons;
@@ -162,4 +163,9 @@ public class ItemManaTablet extends ItemMod implements IManaItem, ICreativeManaP
public boolean isCreative(ItemStack stack) {
return isStackCreative(stack);
}
@Override
public float getManaFractionForDisplay(ItemStack stack) {
return (float) getMana(stack) / (float) getMaxMana(stack);
}
}
@@ -18,11 +18,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaTooltipDisplay;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
import baubles.api.BaubleType;
public class ItemManaRing extends ItemBauble implements IManaItem {
public class ItemManaRing extends ItemBauble implements IManaItem, IManaTooltipDisplay {
protected static final int MAX_MANA = 500000;
@@ -109,5 +110,10 @@ public class ItemManaRing extends ItemBauble implements IManaItem {
public boolean isNoExport(ItemStack stack) {
return false;
}
@Override
public float getManaFractionForDisplay(ItemStack stack) {
return (float) getMana(stack) / (float) getMaxMana(stack);
}
}