Skip to content

Commit

Permalink
Merge pull request #4 from YannickMG/tank-tooltip-fix
Browse files Browse the repository at this point in the history
Tank tooltip fix
  • Loading branch information
Dream-Master authored Dec 24, 2021
2 parents cee20e2 + 75933fd commit 17c2556
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/run/
/build/
/eclipse/
.vscode
.classpath
.project
/bin/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerTooltipHandler;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidTank;
Expand All @@ -25,6 +29,8 @@
import com.darkona.adventurebackpack.util.Resources;
import com.darkona.adventurebackpack.util.TinkersUtils;

import java.util.List;

/**
* Created on 12/10/2014
*
Expand Down Expand Up @@ -101,14 +107,6 @@ else if (source == Source.HOLDING)
else
equipButton.draw(this, 77, 208);
}
if (ConfigHandler.tanksHoveringText)
{
if (tankLeft.inTank(this, mouseX, mouseY))
drawHoveringText(tankLeft.getTankTooltip(), mouseX, mouseY, fontRendererObj);

if (tankRight.inTank(this, mouseX, mouseY))
drawHoveringText(tankRight.getTankTooltip(), mouseX, mouseY, fontRendererObj);
}

if (LoadedMods.TCONSTRUCT && ConfigHandler.tinkerToolsMaintenance)
{
Expand Down Expand Up @@ -192,4 +190,55 @@ public void updateScreen()
}
}
}

/**
* An instance of this class will handle tooltips for all instances of GuiAdvBackpack
*/
public static class TooltipHandler implements IContainerTooltipHandler
{

@Override
public List<String> handleTooltip(GuiContainer gui, int mouseX, int mouseY, List<String> currenttip) {
if (gui.getClass() != GuiAdvBackpack.class)
return currenttip;

GuiWithTanks backpackGui = (GuiWithTanks) gui;

// Fluid tank tooltips
if (GuiContainerManager.shouldShowTooltip(gui) && currenttip.size() == 0)
{
if (tankLeft.inTank(backpackGui, mouseX, mouseY))
currenttip.addAll(tankLeft.getTankTooltip());

if (tankRight.inTank(backpackGui, mouseX, mouseY))
currenttip.addAll(tankRight.getTankTooltip());
}

return currenttip;
}

/**
* Required by IContainerTooltipHandler implementation but not needed here
*/
@Override
public List<String> handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List<String> currenttip) {
return currenttip;
}

/**
* Required by IContainerTooltipHandler implementation but not needed here
*/
@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip) {
return currenttip;
}
}

static {
// Only instantiate TooltipHandler if enabled in config.
if (ConfigHandler.tanksHoveringText) {
GuiContainerManager.addTooltipHandler(new TooltipHandler());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.darkona.adventurebackpack.common.Constants;
import com.darkona.adventurebackpack.config.ConfigHandler;
import com.darkona.adventurebackpack.util.LogHelper;
import com.darkona.adventurebackpack.util.TipUtils;

/**
* Created by Darkona on 12/10/2014.
Expand Down Expand Up @@ -58,8 +59,8 @@ public GuiTank(int X, int Y, int H, int W, int resolution)
public List<String> getTankTooltip()
{
FluidStack fluid = tank.getFluid();
String fluidName = (fluid != null) ? fluid.getLocalizedName() : "None";
String fluidAmount = (fluid != null) ? fluid.amount + "/" + Constants.BASIC_TANK_CAPACITY : "Empty";
String fluidName = (fluid != null) ? fluid.getLocalizedName() : TipUtils.l10n("empty");
String fluidAmount = ((fluid != null) ? fluid.amount : 0) + "/" + Constants.BASIC_TANK_CAPACITY;
ArrayList<String> tankTips = new ArrayList<String>();
tankTips.add(fluidName);
tankTips.add(fluidAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ConfigHandler
public static boolean enableTemperatureBar = false;
public static boolean enableToolsRender = true;
public static int typeTankRender = 2;
public static boolean tanksHoveringText = false;
public static boolean tanksHoveringText = true;

public static boolean statusOverlay = true;
public static boolean statusOverlayLeft = true;
Expand Down Expand Up @@ -118,7 +118,7 @@ private static void loadConfiguration()
enableFullnessBar = config.getBoolean("Enable Fullness Bar", "graphics", false, "Enable durability bar showing fullness of backpacks inventory");
enableTemperatureBar = config.getBoolean("Enable Temperature Bar", "graphics", false, "Enable durability bar showing temperature of jetpack");
enableToolsRender = config.getBoolean("Enable Tools Render", "graphics", true, "Enable rendering for tools in the backpack tool slots");
tanksHoveringText = config.getBoolean("Hovering Text", "graphics", false, "Show hovering text on fluid tanks?");
tanksHoveringText = config.getBoolean("Hovering Text", "graphics", true, "Show hovering text on fluid tanks?");

// Graphics.Status
statusOverlay = config.getBoolean("Enable Overlay", "graphics.status", true, "Show player status effects on screen?");
Expand Down

0 comments on commit 17c2556

Please sign in to comment.