MenuTooltipPositioner.java

net.minecraft.client.gui.screens.inventory.tooltip.MenuTooltipPositioner

信息

  • 全限定名:net.minecraft.client.gui.screens.inventory.tooltip.MenuTooltipPositioner
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.inventory.tooltip
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/tooltip/MenuTooltipPositioner.java
  • 起始行号:L11
  • 实现:ClientTooltipPositioner
  • 职责:

    TODO

字段/常量

  • MARGIN

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L12
    • 说明:

      TODO

  • MOUSE_OFFSET_X

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L13
    • 说明:

      TODO

  • MAX_OVERLAP_WITH_WIDGET

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L14
    • 说明:

      TODO

  • MAX_DISTANCE_TO_WIDGET

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L15
    • 说明:

      TODO

  • screenRectangle

    • 类型: ScreenRectangle
    • 修饰符: private final
    • 源码定位: L16
    • 说明:

      TODO

内部类/嵌套类型

构造器

public MenuTooltipPositioner(ScreenRectangle screenRectangle) @ L18

  • 构造器名:MenuTooltipPositioner
  • 源码定位:L18
  • 修饰符:public

参数:

  • screenRectangle: ScreenRectangle

说明:

TODO

方法

下面的方法块按源码顺序生成。

public Vector2ic positionTooltip(int screenWidth, int screenHeight, int x, int y, int tooltipWidth, int tooltipHeight) @ L22

  • 方法名:positionTooltip
  • 源码定位:L22
  • 返回类型:Vector2ic
  • 修饰符:public

参数:

  • screenWidth: int
  • screenHeight: int
  • x: int
  • y: int
  • tooltipWidth: int
  • tooltipHeight: int

说明:

TODO

private static int getOffset(int mouseY, int widgetY, int widgetHeight) @ L42

  • 方法名:getOffset
  • 源码定位:L42
  • 返回类型:int
  • 修饰符:private static

参数:

  • mouseY: int
  • widgetY: int
  • widgetHeight: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class MenuTooltipPositioner implements ClientTooltipPositioner {
    private static final int MARGIN = 5;
    private static final int MOUSE_OFFSET_X = 12;
    public static final int MAX_OVERLAP_WITH_WIDGET = 3;
    public static final int MAX_DISTANCE_TO_WIDGET = 5;
    private final ScreenRectangle screenRectangle;
 
    public MenuTooltipPositioner(ScreenRectangle screenRectangle) {
        this.screenRectangle = screenRectangle;
    }
 
    @Override
    public Vector2ic positionTooltip(int screenWidth, int screenHeight, int x, int y, int tooltipWidth, int tooltipHeight) {
        Vector2i result = new Vector2i(x + 12, y);
        if (result.x + tooltipWidth > screenWidth - 5) {
            result.x = Math.max(x - 12 - tooltipWidth, 9);
        }
 
        result.y += 3;
        int paddedHeight = tooltipHeight + 3 + 3;
        int lowestPossibleY = this.screenRectangle.bottom() + 3 + getOffset(0, 0, this.screenRectangle.height());
        int maxY = screenHeight - 5;
        if (lowestPossibleY + paddedHeight <= maxY) {
            result.y = result.y + getOffset(result.y, this.screenRectangle.top(), this.screenRectangle.height());
        } else {
            result.y = result.y - (paddedHeight + getOffset(result.y, this.screenRectangle.bottom(), this.screenRectangle.height()));
        }
 
        return result;
    }
 
    private static int getOffset(int mouseY, int widgetY, int widgetHeight) {
        int distance = Math.min(Math.abs(mouseY - widgetY), widgetHeight);
        return Math.round(Mth.lerp((float)distance / widgetHeight, (float)(widgetHeight - 3), 5.0F));
    }
}

引用的其他类