Skip to content

Commit

Permalink
Dynamic held item tooltip position (fixes #232)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarloscp52 committed Mar 18, 2023
1 parent 0c9c510 commit 3c7a451
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -12,9 +12,11 @@
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.item.BundleTooltipData;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.*;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -38,6 +40,22 @@ public int drawItemWithCustomTooltips(TextRenderer fontRenderer, MatrixStack mat
final int screenBorder = settings.getScreenSafeArea();
int tooltipOffset = 0;

//Set tooltip position depending on hotbar displayed information
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if(null ==player || null==MinecraftClient.getInstance().interactionManager)
return 0;
if(MinecraftClient.getInstance().interactionManager.hasStatusBars()){
y-=16;
if(player.getArmor()>0){
y-=10;
}
if(player.getAbsorptionAmount()>0){
y-=10;
}
}else if((player.getVehicle()!=null && player.getVehicle() instanceof LivingEntity)){
y-=16;
}

// Draw item tooltips if the option is enabled.
if(settings.getHeldItemTooltip()>0) {
// Get the current held item tooltips and convert to Text.
Expand Down
Expand Up @@ -27,7 +27,7 @@ public class ItemTooltipsMixin {
*/
@Redirect(method = "renderHeldItemTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;drawWithShadow(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/text/Text;FFI)I"))
private int drawCustomTooltips(TextRenderer fontRenderer, MatrixStack matrices, Text text, float x, float y, int color) {
return BedrockifyClient.getInstance().heldItemTooltips.drawItemWithCustomTooltips(fontRenderer, matrices, text, x, y, color, currentStack);
return BedrockifyClient.getInstance().heldItemTooltips.drawItemWithCustomTooltips(fontRenderer, matrices, text, x, MinecraftClient.getInstance().getWindow().getScaledHeight() - 38, color, currentStack);
}
/**
* Draw custom tooltips for effects and enchantments before the heldItemTooltip is rendered.
Expand Down

0 comments on commit 3c7a451

Please sign in to comment.