Last active
September 25, 2017 17:17
-
-
Save univrsal/5233976ad084a57f32c4 to your computer and use it in GitHub Desktop.
A small mod adding tooltips for items you're looking at on the ground (using Alt), holding in your hand (using Ctrl) or dragging in the inventory (using shift)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.universallp.infotooltip; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.gui.GuiScreen; | |
import net.minecraftforge.fml.client.IModGuiFactory; | |
import java.util.Set; | |
/** | |
* Created by universallp on 17.01.2016 13:06. | |
*/ | |
public class GuiFactory implements IModGuiFactory { | |
@Override | |
public void initialize(Minecraft minecraftInstance) { } | |
@Override | |
public boolean hasConfigGui() { | |
return true; | |
} | |
@Override | |
public GuiScreen createConfigGui(GuiScreen parentScreen) { | |
return new GuiITTConfig(parentScreen); | |
} | |
@Override | |
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() { return null; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.universallp.infotooltip; | |
import net.minecraft.client.gui.GuiScreen; | |
import net.minecraftforge.common.config.ConfigElement; | |
import net.minecraftforge.fml.client.config.GuiConfig; | |
import net.minecraftforge.fml.client.config.IConfigElement; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
/** | |
* Created by universallp on 17.01.2016 13:13. | |
*/ | |
public class GuiITTConfig extends GuiConfig { | |
private static final List colorOrder = Arrays.asList("innerA", "innerR", "innerG", "innerB", "outerA", "outerR", "outerG", "outerB"); | |
private static final List posOrder = Arrays.asList("posX", "posY", "rightToLeft", "bottomToTop"); | |
public GuiITTConfig(GuiScreen parentScreen) { super(parentScreen, getElements(), InfoTooltip.MOD_ID, false, false, GuiConfig.getAbridgedConfigPath(InfoTooltip.ConfigHandler.config.toString())); } | |
public static List<IConfigElement> getElements() { | |
List<IConfigElement> sliders = new ArrayList<IConfigElement>(); | |
for (String name : InfoTooltip.ConfigHandler.config.getCategoryNames()) | |
if (name.equals("colors")) | |
sliders.add(new ConfigElement(InfoTooltip.ConfigHandler.config.getCategory(name).setPropertyOrder(colorOrder))); | |
else if (name.equals("positioning")) | |
sliders.add(new ConfigElement(InfoTooltip.ConfigHandler.config.getCategory(name).setPropertyOrder(posOrder))); | |
else | |
sliders.add(new ConfigElement(InfoTooltip.ConfigHandler.config.getCategory(name))); | |
return sliders; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.universallp.infotooltip; | |
import com.google.common.base.Predicates; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.entity.EntityOtherPlayerMP; | |
import net.minecraft.client.gui.FontRenderer; | |
import net.minecraft.client.gui.ScaledResolution; | |
import net.minecraft.client.gui.inventory.GuiContainer; | |
import net.minecraft.client.renderer.BufferBuilder; | |
import net.minecraft.client.renderer.GlStateManager; | |
import net.minecraft.client.renderer.RenderHelper; | |
import net.minecraft.client.renderer.Tessellator; | |
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; | |
import net.minecraft.client.util.ITooltipFlag; | |
import net.minecraft.enchantment.Enchantment; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityLiving; | |
import net.minecraft.entity.item.EntityItem; | |
import net.minecraft.entity.item.EntityItemFrame; | |
import net.minecraft.init.Items; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.EntitySelectors; | |
import net.minecraft.util.math.AxisAlignedBB; | |
import net.minecraft.util.math.RayTraceResult; | |
import net.minecraft.util.math.Vec3d; | |
import net.minecraft.util.text.TextFormatting; | |
import net.minecraftforge.client.event.GuiScreenEvent; | |
import net.minecraftforge.client.event.RenderGameOverlayEvent; | |
import net.minecraftforge.common.MinecraftForge; | |
import net.minecraftforge.common.config.Configuration; | |
import net.minecraftforge.common.config.Property; | |
import net.minecraftforge.fml.client.config.GuiConfig; | |
import net.minecraftforge.fml.client.config.GuiConfigEntries; | |
import net.minecraftforge.fml.client.event.ConfigChangedEvent; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; | |
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
import org.lwjgl.input.Keyboard; | |
import org.lwjgl.input.Mouse; | |
import java.io.File; | |
import java.util.Arrays; | |
import java.util.List; | |
@Mod(modid = InfoTooltip.MOD_ID, version = InfoTooltip.VERSION, clientSideOnly = true, guiFactory = "de.universallp.infotooltip.GuiFactory") | |
public class InfoTooltip { | |
static final String MOD_ID = "infotip"; | |
static final String VERSION = "1.12.2-1.0"; | |
private static int TOOLTIP_WIDTH = 0; | |
private static int TOOLTIP_HEIGHT = 0; | |
private static Minecraft mc = Minecraft.getMinecraft(); | |
private enum EnumBind { HOVERED, DRAGGED, HELD } | |
@Mod.EventHandler | |
public void preInit(FMLPreInitializationEvent event) { | |
ConfigHandler.loadConfig(event.getSuggestedConfigurationFile()); | |
ConfigHandler.pRD.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.innerA.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.innerR.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.innerG.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.innerB.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.outerA.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.outerR.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.outerG.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.outerB.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class); | |
ConfigHandler.kDragged.setConfigEntryClass(KeybindEntry.class); | |
ConfigHandler.kHovered.setConfigEntryClass(KeybindEntry.class); | |
ConfigHandler.kHeld.setConfigEntryClass(KeybindEntry.class); | |
} | |
@Mod.EventHandler | |
public void postInit(FMLPostInitializationEvent event) { | |
MinecraftForge.EVENT_BUS.register(new ToolTipHandler()); | |
ConfigHandler.loadPostInit(); | |
} | |
class ToolTipHandler { | |
@SubscribeEvent | |
public void drawGuiScreen(GuiScreenEvent event) { | |
if (event.getGui() != null && getIsBindPressed(EnumBind.DRAGGED) && event.getGui() instanceof GuiContainer) { | |
ItemStack heldStack = mc.player.inventory.getItemStack(); | |
renderItemToolTip(heldStack, getMouseX(), getMouseY()); // Draw the tooltip | |
} else if (event.getGui() != null && event.getGui() instanceof GuiConfig && !(event.getGui() instanceof GuiITTConfig)) { | |
GuiConfigEntries eL = ((GuiConfig) event.getGui()).entryList; | |
GuiConfig cfg = (GuiConfig) event.getGui(); | |
if (cfg.titleLine2 != null) | |
if (cfg.titleLine2.equals("colors")) { | |
int color1 = argb(getInt(0, eL), getInt(1, eL), getInt(2, eL), getInt(3, eL)); | |
int color2 = argb(getInt(4, eL), getInt(5, eL), getInt(6, eL), getInt(7, eL)); | |
renderToolTip(mc.fontRenderer, 5, 20, Arrays.asList("Sample Tooltip", TextFormatting.GRAY + "Sample Description"), color2, color1); | |
} else if (cfg.titleLine2.equals("positioning")) { | |
int x = getCustomPosX(getInt(0, eL), getBoolean(2, eL)); | |
int y = getCustomPosY(getInt(1, eL), getBoolean(3, eL)); | |
ItemStack stack = new ItemStack(Items.BOW, 1); | |
stack.addEnchantment(Enchantment.getEnchantmentByID(0), 1); | |
stack.addEnchantment(Enchantment.getEnchantmentByID(2), 5); | |
renderItemToolTip(stack, x, y); | |
} | |
} | |
} | |
@SubscribeEvent | |
public void drawOverlay(RenderGameOverlayEvent event) { | |
if (event.getType() == RenderGameOverlayEvent.ElementType.POTION_ICONS) { | |
ItemStack mainHand = mc.player.getHeldItemMainhand(); | |
ItemStack offHand = mc.player.getHeldItemOffhand(); | |
boolean oHUsed = !offHand.isEmpty(); | |
boolean mHUsed = !mainHand.isEmpty(); | |
if (getIsBindPressed(EnumBind.HELD) && mc.currentScreen == null) { // Drawing held item tooltip | |
if ((mHUsed && mainHand.getTooltip(mc.player, getToolTipFlags()).size() > 1) || | |
(oHUsed && offHand.getTooltip(mc.player, getToolTipFlags()).size() > 1)) { | |
renderOverlayToolTip(offHand, mainHand, oHUsed); | |
} else | |
renderOverlayToolTip(offHand, mainHand, oHUsed); | |
} else if (getIsBindPressed(EnumBind.HOVERED) && mc.currentScreen == null) { // Draw looked at item or the held item of the looked at player | |
Entity hovered = getMouseOver(event.getPartialTicks(), ConfigHandler.reachDistance); | |
if (hovered != null) { | |
if (hovered instanceof EntityItem) { | |
if (!((EntityItem) hovered).getItem().isEmpty()) | |
renderOverlayToolTip(((EntityItem) hovered).getItem(), ItemStack.EMPTY, oHUsed); | |
} else if (hovered instanceof EntityOtherPlayerMP) { | |
EntityOtherPlayerMP pl = (EntityOtherPlayerMP) hovered; | |
renderOverlayToolTip(pl.getHeldItemOffhand(), pl.getHeldItemMainhand(), oHUsed); | |
} else if (hovered instanceof EntityLiving) { | |
EntityLiving l = (EntityLiving) hovered; | |
renderOverlayToolTip(l.getHeldItemOffhand(), l.getHeldItemMainhand(), oHUsed); | |
} else if (hovered instanceof EntityItemFrame) { | |
renderOverlayToolTip(((EntityItemFrame) hovered).getDisplayedItem(), ItemStack.EMPTY, oHUsed); | |
} | |
} | |
} | |
} | |
} | |
// Util methods | |
private boolean getIsBindPressed(EnumBind bind) { | |
switch (bind) { | |
case DRAGGED: | |
return !ConfigHandler.kDragged.getString().equals("NONE") && Keyboard.isKeyDown(Integer.valueOf(ConfigHandler.kDragged.getString())); | |
case HELD: | |
return !ConfigHandler.kHeld.getString().equals("NONE") && Keyboard.isKeyDown(Integer.valueOf(ConfigHandler.kHeld.getString())); | |
case HOVERED: | |
return !ConfigHandler.kHovered.getString().equals("NONE") && Keyboard.isKeyDown(Integer.valueOf(ConfigHandler.kHovered.getString())); | |
} | |
return false; | |
} | |
/** | |
* Stolen from EntityRenderer and optimized for this case | |
*/ | |
private Entity getMouseOver(float partialTicks, double distance) { | |
Entity entity = mc.getRenderViewEntity(); | |
Entity pointedEntity = null; | |
if (entity != null) { | |
if (mc.world != null) { | |
Vec3d vec3 = entity.getPositionEyes(partialTicks); | |
Vec3d vec31 = entity.getLook(partialTicks); | |
Vec3d vec32 = vec3.addVector(vec31.x * distance, vec31.y * distance, vec31.z * distance); | |
float f = 1.0F; | |
List<Entity> list = mc.world.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().grow(vec31.x * distance, vec31.y * distance, vec31.z * distance).expand((double)f, (double)f, (double)f), Predicates.and(EntitySelectors.NOT_SPECTATING)); | |
double d2 = distance; | |
for (Entity entity1 : list) { | |
float f1 = entity1.getCollisionBorderSize(); | |
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double) f1, (double) f1, (double) f1); | |
RayTraceResult movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32); | |
if (axisalignedbb.contains(vec3)) { | |
if (d2 >= 0.0D) { | |
pointedEntity = entity1; | |
d2 = 0.0D; | |
} | |
} else if (movingobjectposition != null) { | |
double d3 = vec3.distanceTo(movingobjectposition.hitVec); | |
if (d3 < d2 || d2 == 0.0D) { | |
if (entity1 == entity.getRidingEntity() && !entity.canRiderInteract()) { | |
if (d2 == 0.0D) { | |
pointedEntity = entity1; | |
} | |
} else { | |
pointedEntity = entity1; | |
d2 = d3; | |
} | |
} | |
} | |
} | |
} | |
} | |
return pointedEntity; | |
} | |
private int getInt(int i, GuiConfigEntries eL) { | |
if (i < eL.getSize() && eL.getListEntry(i) != null && String.valueOf(eL.getListEntry(i).getCurrentValue()).length() > 0 && String.valueOf(eL.getListEntry(i).getCurrentValue()).length() < 5 | |
&& !String.valueOf(eL.getListEntry(i).getCurrentValue()).equals("-")) | |
return Integer.valueOf(String.valueOf(eL.getListEntry(i).getCurrentValue())); | |
return -1; | |
} | |
private boolean getBoolean(int i, GuiConfigEntries eL) { | |
if (i < eL.getSize() && eL.getListEntry(i) != null) | |
return Boolean.valueOf(String.valueOf(eL.getListEntry(i).getCurrentValue())); | |
return false; | |
} | |
private int argb(int A, int R, int G, int B){ | |
byte[] colorByteArr = { (byte) A, (byte) R, (byte) G, (byte) B }; | |
return (colorByteArr[0] << 24) + ((colorByteArr[1] & 0xFF) << 16) + ((colorByteArr[2] & 0xFF) << 8) + (colorByteArr[3] & 0xFF); | |
} | |
private void renderOverlayToolTip(ItemStack offHand, ItemStack mainHand, boolean offHandUsed) { | |
if (!offHand.isEmpty() && !mainHand.isEmpty()) { | |
int tooltipWidth1 = getTooltipWidht(offHand); | |
int tooltipWidth2 = getTooltipWidht(mainHand); | |
int tooltipHeight1 = getTooltipHeight(offHand); | |
int tooltipHeight2 = getTooltipHeight(mainHand); | |
if (getScaledWidth() / 2 - (offHandUsed ? 138 : 108) - tooltipWidth1 < 1 || getScaledWidth() / 2 - 108 < tooltipWidth2) { | |
renderItemToolTip(offHand, 0, getScaledHeight() / 2 - tooltipHeight2 / 2); | |
renderItemToolTip(mainHand, getScaledWidth() - tooltipWidth2 - 20, getScaledHeight() / 2 - tooltipHeight2 / 2); | |
} else { | |
renderItemToolTip(offHand, getScaledWidth() / 2 - (offHandUsed ? 139 : 109) - tooltipWidth1, getScaledHeight() - tooltipHeight1 + 6); | |
renderItemToolTip(mainHand, getScaledWidth() / 2 + 86, getScaledHeight() - tooltipHeight2 + 6); | |
} | |
} else if (!offHand.isEmpty() || !mainHand.isEmpty()){ | |
ItemStack stack = !offHand.isEmpty() ? offHand : mainHand; | |
int tooltipWidth = getTooltipWidht(stack); | |
int tooltipHeight = getTooltipHeight(stack); | |
if (ConfigHandler.posX == -1 || ConfigHandler.posY == -1) | |
if (getScaledWidth() / 2 - (offHandUsed ? 138 : 108) - tooltipWidth < 1) | |
renderItemToolTip(stack, 0, getScaledHeight() / 2 - tooltipHeight / 2); | |
else | |
renderItemToolTip(stack, getScaledWidth() / 2 - (offHandUsed ? 139 : 109) - tooltipWidth, getScaledHeight() - tooltipHeight + 6); | |
else | |
renderItemToolTip(stack, getCustomPosX(ConfigHandler.posX, ConfigHandler.rightToLeft), getCustomPosY(ConfigHandler.posY, ConfigHandler.bottomToTop)); | |
} | |
} | |
private int getCustomPosX(int x, boolean rightToLeft) { | |
if (x != -2) | |
if (x == -1) | |
return getScaledWidth() / 2 - 109 - TOOLTIP_WIDTH; | |
else if (!rightToLeft) | |
return x + TOOLTIP_WIDTH > new ScaledResolution(mc).getScaledWidth() - 17 ? x - TOOLTIP_WIDTH - 25 : x - 8; | |
else | |
return getScaledWidth() - (x + TOOLTIP_WIDTH + 17); | |
else | |
return getScaledWidth() / 2 - TOOLTIP_WIDTH / 2 - 10; | |
} | |
private int getCustomPosY(int y, boolean bottomToTop) { | |
ScaledResolution sR = new ScaledResolution(mc); | |
if (y != -2) | |
if (y == -1) | |
return getScaledHeight() - TOOLTIP_HEIGHT + 6; | |
else if (!bottomToTop) | |
return y > 17 ? ((y > (sR.getScaledHeight() - TOOLTIP_HEIGHT + 6)) ? (sR.getScaledHeight() - TOOLTIP_HEIGHT + 6) : y) : 17; | |
else | |
return getScaledHeight() - (y + TOOLTIP_HEIGHT - 7); | |
else | |
return getScaledHeight() / 2 - TOOLTIP_HEIGHT / 2 + 10; | |
} | |
private int getMouseX() { | |
ScaledResolution resolution = new ScaledResolution(mc); | |
int mX = Mouse.getX() * resolution.getScaledWidth() / mc.displayWidth; | |
if (mX + TOOLTIP_WIDTH > resolution.getScaledWidth() - 17) | |
return mX - TOOLTIP_WIDTH - 25; | |
else | |
return mX + 1; | |
} | |
private int getMouseY() { | |
ScaledResolution resolution = new ScaledResolution(mc); | |
int mY = resolution.getScaledHeight() - Mouse.getY() * resolution.getScaledHeight() / mc.displayHeight - 1; | |
return (mY > 17) ? ((mY > (resolution.getScaledHeight() - TOOLTIP_HEIGHT + 6)) ? (resolution.getScaledHeight() - TOOLTIP_HEIGHT + 6) : mY) : 17; | |
} | |
private int getScaledHeight() { return new ScaledResolution(mc).getScaledHeight(); } | |
private int getScaledWidth() { return new ScaledResolution(mc).getScaledWidth(); } | |
private int getTooltipWidht(ItemStack s) { | |
if (s == null) return 0; | |
int var6; | |
int var7; | |
int var5 = 0; | |
List<String> list = s.getTooltip(mc.player, getToolTipFlags()); | |
for (var6 = 0; var6 < list.size(); ++var6) { | |
var7 = mc.fontRenderer.getStringWidth(list.get(var6)); | |
if (var7 > var5) | |
var5 = var7; | |
} | |
return var5; | |
} | |
private int getTooltipHeight(ItemStack s) { | |
int var9 = 8; | |
if (s == null) return 0; | |
List<String> list = s.getTooltip(mc.player, getToolTipFlags()); | |
if (list.size() > 1) | |
var9 += 2 + (list.size() - 1) * 10; | |
return var9; | |
} | |
private void renderItemToolTip(ItemStack stack, int x, int y) { | |
if (stack.isEmpty()) | |
return; | |
List<String> list = stack.getTooltip(mc.player, getToolTipFlags()); | |
for (int i = 0; i < list.size(); ++i) | |
if (i == 0) | |
list.set(i, stack.getRarity().rarityColor + list.get(i)); | |
else | |
list.set(i, TextFormatting.GRAY + list.get(i)); | |
FontRenderer font = stack.getItem().getFontRenderer(stack); | |
if (font == null) font = mc.fontRenderer; | |
byte[] color1ByteArr = { (byte) ConfigHandler.INNER_ARGB[0], (byte) ConfigHandler.INNER_ARGB[1], (byte)ConfigHandler.INNER_ARGB[2], (byte) ConfigHandler.INNER_ARGB[3] }; | |
byte[] color2ByteArr = { (byte) ConfigHandler.OUTER_ARGB[0], (byte) ConfigHandler.OUTER_ARGB[1], (byte) ConfigHandler.OUTER_ARGB[2], (byte) ConfigHandler.OUTER_ARGB[3]}; | |
int color1 = (color1ByteArr[0] << 24) + ((color1ByteArr[1] & 0xFF) << 16) + ((color1ByteArr[2] & 0xFF) << 8) + (color1ByteArr[3] & 0xFF); | |
int color2 = (color2ByteArr[0] << 24) + ((color2ByteArr[1] & 0xFF) << 16) + ((color2ByteArr[2] & 0xFF) << 8) + (color2ByteArr[3] & 0xFF); | |
renderToolTip(font, x, y, list, color2, color1); | |
} | |
private ITooltipFlag getToolTipFlags() { | |
return mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL; | |
} | |
private void renderToolTip(FontRenderer fontRenderer, int x, int y, List<String> tooltipData, int color, int color2) { | |
if (!tooltipData.isEmpty()) { | |
GlStateManager.disableRescaleNormal(); | |
RenderHelper.disableStandardItemLighting(); | |
GlStateManager.disableLighting(); | |
GlStateManager.disableDepth(); | |
int var5 = 0; | |
int var6; | |
int var7; | |
for (var6 = 0; var6 < tooltipData.size(); ++var6) { | |
var7 = fontRenderer.getStringWidth(tooltipData.get(var6)); | |
if (var7 > var5) | |
var5 = var7; | |
} | |
var6 = x + 12; | |
var7 = y - 12; | |
int var9 = 8; | |
if (tooltipData.size() > 1) | |
var9 += 2 + (tooltipData.size() - 1) * 10; | |
TOOLTIP_WIDTH = var5; | |
TOOLTIP_HEIGHT = var9; | |
float z = 300F; | |
drawGradientRect(var6 - 3, var7 - 4, z, var6 + var5 + 3, var7 - 3, color2, color2); | |
drawGradientRect(var6 - 3, var7 + var9 + 3, z, var6 + var5 + 3, var7 + var9 + 4, color2, color2); | |
drawGradientRect(var6 - 3, var7 - 3, z, var6 + var5 + 3, var7 + var9 + 3, color2, color2); | |
drawGradientRect(var6 - 4, var7 - 3, z, var6 - 3, var7 + var9 + 3, color2, color2); | |
drawGradientRect(var6 + var5 + 3, var7 - 3, z, var6 + var5 + 4, var7 + var9 + 3, color2, color2); | |
int var12; | |
if (color == 1347420415) | |
var12 = (color & 0xFFFFFF) >> 1 | color & -16777216; | |
else | |
var12 = color; | |
drawGradientRect(var6 - 3, var7 - 3 + 1, z, var6 - 3 + 1, var7 + var9 + 3 - 1, color, var12); | |
drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, z, var6 + var5 + 3, var7 + var9 + 3 - 1, color, var12); | |
drawGradientRect(var6 - 3, var7 - 3, z, var6 + var5 + 3, var7 - 3 + 1, color, color); | |
drawGradientRect(var6 - 3, var7 + var9 + 2, z, var6 + var5 + 3, var7 + var9 + 3, var12, var12); | |
GlStateManager.disableDepth(); | |
for (int var13 = 0; var13 < tooltipData.size(); ++var13) { | |
String var14 = tooltipData.get(var13); | |
fontRenderer.drawStringWithShadow(var14, var6, var7, -1); | |
if (var13 == 0) | |
var7 += 2; | |
var7 += 10; | |
} | |
GlStateManager.enableDepth(); | |
} | |
GlStateManager.color(1F, 1F, 1F, 1F); | |
} | |
private void drawGradientRect(int left, int top, float z, int right, int bottom, int startColor, int endColor) { | |
float f = (float)(startColor >> 24 & 255) / 255.0F; | |
float f1 = (float)(startColor >> 16 & 255) / 255.0F; | |
float f2 = (float)(startColor >> 8 & 255) / 255.0F; | |
float f3 = (float)(startColor & 255) / 255.0F; | |
float f4 = (float)(endColor >> 24 & 255) / 255.0F; | |
float f5 = (float)(endColor >> 16 & 255) / 255.0F; | |
float f6 = (float)(endColor >> 8 & 255) / 255.0F; | |
float f7 = (float)(endColor & 255) / 255.0F; | |
GlStateManager.disableTexture2D(); | |
GlStateManager.enableBlend(); | |
GlStateManager.disableAlpha(); | |
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); | |
GlStateManager.shadeModel(7425); | |
Tessellator tessellator = Tessellator.getInstance(); | |
BufferBuilder bufferBuilder = tessellator.getBuffer(); | |
bufferBuilder.begin(7, DefaultVertexFormats.POSITION_COLOR); | |
bufferBuilder.pos((double)right, (double)top, (double) z).color(f1, f2, f3, f).endVertex(); | |
bufferBuilder.pos((double)left, (double)top, (double) z).color(f1, f2, f3, f).endVertex(); | |
bufferBuilder.pos((double)left, (double)bottom, (double) z).color(f5, f6, f7, f4).endVertex(); | |
bufferBuilder.pos((double)right, (double)bottom, (double) z).color(f5, f6, f7, f4).endVertex(); | |
tessellator.draw(); | |
GlStateManager.shadeModel(7424); | |
GlStateManager.disableBlend(); | |
GlStateManager.enableAlpha(); | |
GlStateManager.enableTexture2D(); | |
} | |
} | |
static class ConfigHandler { | |
static int[] INNER_ARGB = new int[4]; | |
static int[] OUTER_ARGB = new int[4]; | |
static int posX = -1; | |
static int posY = -1; | |
static int reachDistance = 6; | |
static Property pRD; | |
static boolean rightToLeft = false; | |
static boolean bottomToTop = false; | |
static Property kHovered; | |
static Property kDragged; | |
static Property kHeld; | |
static Property innerA; | |
static Property innerR; | |
static Property innerG; | |
static Property innerB; | |
static Property outerA; | |
static Property outerR; | |
static Property outerG; | |
static Property outerB; | |
static Configuration config; | |
private static final String CATEGORY_COLORS = "colors"; | |
private static final String CATEGORY_POSITION = "positioning"; | |
private static final String CATEGORY_MISC = "misc"; | |
private static final String CATEGORY_KEYS = "keybinds"; | |
static void loadConfig(File configFile) { | |
if (config == null) | |
config = new Configuration(configFile); | |
load(); | |
MinecraftForge.EVENT_BUS.register(new ConfigHandler()); | |
} | |
static void load() { | |
pRD = config.get(CATEGORY_MISC, "reachDistance", 6, "The max distance between player and item", 1, 50); | |
reachDistance = pRD.getInt(); | |
kDragged = config.get(CATEGORY_KEYS, "kDragged", Keyboard.KEY_LSHIFT, "Keycode for showing the dragged item", -1000, 3000); | |
kHovered = config.get(CATEGORY_KEYS, "kHovered", Keyboard.KEY_LMENU, "Keycode for showing the hovered item", -1000, 3000); | |
kHeld = config.get(CATEGORY_KEYS, "kHeld", Keyboard.KEY_LCONTROL, "Keycode for showing the held item", -1000, 3000); | |
innerA = config.get(CATEGORY_COLORS, "innerA", 240, "Alpha value of the inner tooltip rectangle", 5, 255); | |
innerR = config.get(CATEGORY_COLORS, "innerR", 16, "Red value of the inner tooltip rectangle", 0, 255); | |
innerG = config.get(CATEGORY_COLORS, "innerG", 0, "Green value of the inner tooltip rectangle", 0, 255); | |
innerB = config.get(CATEGORY_COLORS, "innerB", 16, "Blue value of the inner tooltip rectangle", 0, 255); | |
INNER_ARGB[0] = innerA.getInt(); | |
INNER_ARGB[1] = innerR.getInt(); | |
INNER_ARGB[2] = innerG.getInt(); | |
INNER_ARGB[3] = innerB.getInt(); | |
outerA = config.get(CATEGORY_COLORS, "outerA", 80, "Alpha value of the tooltip border", 5, 255); | |
outerR = config.get(CATEGORY_COLORS, "outerR", 80, "Red value of the tooltip border", 0, 255); | |
outerG = config.get(CATEGORY_COLORS, "outerG", 0, "Green value of the tooltip border", 0, 255); | |
outerB = config.get(CATEGORY_COLORS, "outerB", 255, "Blue value of the tooltip border", 0, 255); | |
OUTER_ARGB[0] = outerA.getInt(); | |
OUTER_ARGB[1] = outerR.getInt(); | |
OUTER_ARGB[2] = outerG.getInt(); | |
OUTER_ARGB[3] = outerB.getInt(); | |
posX = config.getInt("posX", CATEGORY_POSITION, -1, -2, 5000, "Custom X-Position of the tooltip, -1 to disable, -2 to center"); | |
posY = config.getInt("posY", CATEGORY_POSITION, -1, -2, 5000, "Custom Y-Position of the tooltip, -1 to disable, -2 to center"); | |
rightToLeft = config.getBoolean("rightToLeft", CATEGORY_POSITION, false, "When true X-Position will count from the left"); | |
bottomToTop = config.getBoolean("bottomToTop", CATEGORY_POSITION, false, "When true Y-Position will count from the bottom"); | |
if (config.hasChanged()) | |
config.save(); | |
} | |
static void loadPostInit() { if(config.hasChanged()) config.save(); } | |
@SubscribeEvent | |
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) { | |
if(eventArgs.getModID().equals(MOD_ID)) { | |
config.save(); | |
load(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.universallp.infotooltip; | |
import com.mojang.realmsclient.gui.ChatFormatting; | |
import net.minecraftforge.fml.client.config.GuiConfig; | |
import net.minecraftforge.fml.client.config.GuiConfigEntries; | |
import net.minecraftforge.fml.client.config.IConfigElement; | |
import net.minecraftforge.fml.common.FMLLog; | |
import org.apache.logging.log4j.Level; | |
import org.lwjgl.input.Keyboard; | |
/** | |
* Created by universallp on 27.02.2016 11:51. | |
* Custom config entry for keybinds | |
* Since the mc keybinds act weired if two actions are bound on the same keybind | |
*/ | |
public class KeybindEntry extends GuiConfigEntries.StringEntry { | |
String keyValue = null; | |
private boolean hasChanged = false; | |
public KeybindEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement configElement) { | |
super(owningScreen, owningEntryList, configElement); | |
textFieldValue.setText(cfgValueToText(configElement.get())); | |
} | |
@Override | |
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float pT) { | |
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, pT); | |
if (this.enabled() && textFieldValue.isFocused() && !hasChanged) { | |
isValidValue = false; | |
textFieldValue.setText("Press any Key"); | |
} else | |
isValidValue = true; | |
if (!textFieldValue.isFocused()) { | |
hasChanged = false; | |
if (keyValue == null && configElement.get() == null) | |
setToDefault(); | |
else | |
textFieldValue.setText(cfgValueToText(keyValue == null ? configElement.get() : keyValue)); | |
} | |
if (textFieldValue.getText().equals("NONE")) | |
owningScreen.mc.fontRenderer.drawString(ChatFormatting.RED + "[Disabled]", x + 5, y + 4, 0, true); | |
} | |
@Override | |
public void keyTyped(char eventChar, int eventKey) { | |
if(textFieldValue.isFocused() && this.enabled()) { | |
hasChanged = true; | |
keyValue = String.valueOf(eventKey); | |
textFieldValue.setText(Keyboard.getKeyName(eventKey)); | |
} | |
} | |
@Override | |
public void setToDefault() { | |
if(this.enabled()) { | |
this.textFieldValue.setText(cfgValueToText(this.configElement.getDefault().toString())); | |
this.textFieldValue.setFocused(false); | |
keyValue = this.configElement.getDefault().toString(); | |
this.keyTyped('\u0000', 199); | |
isValidValue = true; | |
} | |
} | |
@Override | |
public boolean isDefault() { | |
return this.configElement.getDefault() != null && cfgValueToText(configElement.getDefault()).equals(textFieldValue.getText()); | |
} | |
@Override | |
public boolean isChanged() { | |
return this.beforeValue != null && !cfgValueToText(beforeValue).equals(textFieldValue.getText()); | |
} | |
@Override | |
public void undoChanges() { | |
if(this.enabled()) { | |
textFieldValue.setFocused(false); | |
keyValue = this.beforeValue; | |
this.textFieldValue.setText(cfgValueToText(this.beforeValue)); | |
} | |
} | |
@Override | |
public boolean saveConfigElement() { | |
if(this.enabled()) { | |
if(this.isChanged() && this.isValidValue) { | |
this.configElement.set(keyValue); | |
return this.configElement.requiresMcRestart(); | |
} | |
if(this.isChanged() && !this.isValidValue) | |
this.configElement.setToDefault(); | |
} | |
return false; | |
} | |
private String cfgValueToText(Object obj) { | |
if (obj == null) | |
return "NULL"; | |
int out = 0; | |
try { | |
out = Integer.valueOf(obj.toString()); | |
} catch (NumberFormatException e) { | |
FMLLog.log(InfoTooltip.MOD_ID, Level.ERROR, e.getCause(), "Error while converting config value to key name"); | |
} | |
return Keyboard.getKeyName(out); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment