Skip to content

Commit

Permalink
extra tooltip check just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
NotMyWing committed May 31, 2024
1 parent a03d6f4 commit bcc28c0
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/main/java/appeng/integration/modules/jei/JEIMissingItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void showError(Minecraft minecraft, int mouseX, int mouseY, @Nonnull IRec
if (b != null) {
List<String> tooltipLines = new ArrayList<>();
b.init(c, minecraft.player);
if (errored && foundAny) {
if (foundAny) {
tooltipLines.add(format("gui.tooltips.appliedenergistics2.PartialTransfer"));
b.enabled = true;
b.visible = true;
Expand All @@ -258,25 +258,27 @@ public void showError(Minecraft minecraft, int mouseX, int mouseY, @Nonnull IRec
tooltipLines.add(format("gui.tooltips.appliedenergistics2.CraftableItem", foundCraftables));
}

var longestStringWidth = minecraft.fontRenderer.getStringWidth(tooltipLines.stream()
.max(Comparator.comparingInt(String::length)).get());
if (tooltipLines.size() > 0) {
var longestStringWidth = minecraft.fontRenderer.getStringWidth(tooltipLines.stream()
.max(Comparator.comparingInt(String::length)).get());

var background = ((RecipeLayout) recipeLayout).getRecipeCategory().getBackground();
var scaledresolution = new ScaledResolution(minecraft);
var background = ((RecipeLayout) recipeLayout).getRecipeCategory().getBackground();
var scaledresolution = new ScaledResolution(minecraft);

// Mostly reverse-engineered Minecraft code.
final int offset;
if (mouseX + longestStringWidth + 4 + 12 > scaledresolution.getScaledWidth()) {
// The tooltip will appear to the left of the mouse cursor.
// Need to offset Y so that the tooltip doesn't block the ingredients.
offset = background.getHeight() + recipeY
+ (minecraft.fontRenderer.FONT_HEIGHT * tooltipLines.size()
+ 2 * (tooltipLines.size() - 1)) / 2
+ 4;
} else {
offset = mouseY;
// Mostly reverse-engineered Minecraft code.
final int offset;
if (mouseX + longestStringWidth + 4 + 12 > scaledresolution.getScaledWidth()) {
// The tooltip will appear to the left of the mouse cursor.
// Need to offset Y so that the tooltip doesn't block the ingredients.
offset = background.getHeight() + recipeY
+ (minecraft.fontRenderer.FONT_HEIGHT * tooltipLines.size()
+ 2 * (tooltipLines.size() - 1)) / 2
+ 4;
} else {
offset = mouseY;
}
TooltipRenderer.drawHoveringText(minecraft, tooltipLines, mouseX, offset);
}
TooltipRenderer.drawHoveringText(minecraft, tooltipLines, mouseX, offset);
}
}
}
Expand Down

0 comments on commit bcc28c0

Please sign in to comment.