ClientBundleTooltip.java
net.minecraft.client.gui.screens.inventory.tooltip.ClientBundleTooltip
信息
- 全限定名:net.minecraft.client.gui.screens.inventory.tooltip.ClientBundleTooltip
- 类型:public class
- 包:net.minecraft.client.gui.screens.inventory.tooltip
- 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/tooltip/ClientBundleTooltip.java
- 起始行号:L22
- 实现:ClientTooltipComponent
- 职责:
TODO
字段/常量
-
PROGRESSBAR_BORDER_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
PROGRESSBAR_FILL_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
PROGRESSBAR_FULL_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
SLOT_HIGHLIGHT_BACK_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
SLOT_HIGHLIGHT_FRONT_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
SLOT_BACKGROUND_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
SLOT_MARGIN- 类型:
int - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
SLOT_SIZE- 类型:
int - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
GRID_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
PROGRESSBAR_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
PROGRESSBAR_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
PROGRESSBAR_BORDER- 类型:
int - 修饰符:
private static final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
PROGRESSBAR_FILL_MAX- 类型:
int - 修饰符:
private static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
PROGRESSBAR_MARGIN_Y- 类型:
int - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
BUNDLE_FULL_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
BUNDLE_EMPTY_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
BUNDLE_EMPTY_DESCRIPTION- 类型:
Component - 修饰符:
private static final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
contents- 类型:
BundleContents - 修饰符:
private final - 源码定位:
L40 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ClientBundleTooltip(BundleContents contents) @ L42
- 构造器名:ClientBundleTooltip
- 源码定位:L42
- 修饰符:public
参数:
- contents: BundleContents
说明:
TODO
方法
下面的方法块按源码顺序生成。
public int getHeight(Font font) @ L46
- 方法名:getHeight
- 源码定位:L46
- 返回类型:int
- 修饰符:public
参数:
- font: Font
说明:
TODO
public int getWidth(Font font) @ L51
- 方法名:getWidth
- 源码定位:L51
- 返回类型:int
- 修饰符:public
参数:
- font: Font
说明:
TODO
public boolean showTooltipWithItemInHand() @ L56
- 方法名:showTooltipWithItemInHand
- 源码定位:L56
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
private static int getEmptyBundleBackgroundHeight(Font font) @ L61
- 方法名:getEmptyBundleBackgroundHeight
- 源码定位:L61
- 返回类型:int
- 修饰符:private static
参数:
- font: Font
说明:
TODO
private int backgroundHeight() @ L65
- 方法名:backgroundHeight
- 源码定位:L65
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
private int itemGridHeight() @ L69
- 方法名:itemGridHeight
- 源码定位:L69
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
private static int getContentXOffset(int tooltipWidth) @ L73
- 方法名:getContentXOffset
- 源码定位:L73
- 返回类型:int
- 修饰符:private static
参数:
- tooltipWidth: int
说明:
TODO
private int gridSizeY() @ L77
- 方法名:gridSizeY
- 源码定位:L77
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
private int slotCount() @ L81
- 方法名:slotCount
- 源码定位:L81
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
public void extractImage(Font font, int x, int y, int w, int h, GuiGraphicsExtractor graphics) @ L85
- 方法名:extractImage
- 源码定位:L85
- 返回类型:void
- 修饰符:public
参数:
- font: Font
- x: int
- y: int
- w: int
- h: int
- graphics: GuiGraphicsExtractor
说明:
TODO
private static void extractEmptyBundleTooltip(Font font, int x, int y, int w, int h, GuiGraphicsExtractor graphics) @ L97
- 方法名:extractEmptyBundleTooltip
- 源码定位:L97
- 返回类型:void
- 修饰符:private static
参数:
- font: Font
- x: int
- y: int
- w: int
- h: int
- graphics: GuiGraphicsExtractor
说明:
TODO
private void extractBundleWithItemsTooltip(Font font, int x, int y, int w, int h, GuiGraphicsExtractor graphics, Fraction weight) @ L103
- 方法名:extractBundleWithItemsTooltip
- 源码定位:L103
- 返回类型:void
- 修饰符:private
参数:
- font: Font
- x: int
- y: int
- w: int
- h: int
- graphics: GuiGraphicsExtractor
- weight: Fraction
说明:
TODO
private List<ItemStackTemplate> getShownItems(int amountOfItemsToShow) @ L127
- 方法名:getShownItems
- 源码定位:L127
- 返回类型:List
- 修饰符:private
参数:
- amountOfItemsToShow: int
说明:
TODO
private static boolean shouldRenderSurplusText(boolean isOverflowing, int column, int row) @ L132
- 方法名:shouldRenderSurplusText
- 源码定位:L132
- 返回类型:boolean
- 修饰符:private static
参数:
- isOverflowing: boolean
- column: int
- row: int
说明:
TODO
private static boolean shouldRenderItemSlot(List<?extends ItemInstance> shownItems, int slotNumber) @ L136
- 方法名:shouldRenderItemSlot
- 源码定位:L136
- 返回类型:boolean
- 修饰符:private static
参数:
- shownItems: List<?extends ItemInstance>
- slotNumber: int
说明:
TODO
private int getAmountOfHiddenItems(List<ItemStackTemplate> shownItems) @ L140
- 方法名:getAmountOfHiddenItems
- 源码定位:L140
- 返回类型:int
- 修饰符:private
参数:
- shownItems: List
说明:
TODO
private void extractSlot(int slotNumber, int drawX, int drawY, List<ItemStackTemplate> shownItems, int slotIndex, Font font, GuiGraphicsExtractor graphics) @ L144
- 方法名:extractSlot
- 源码定位:L144
- 返回类型:void
- 修饰符:private
参数:
- slotNumber: int
- drawX: int
- drawY: int
- shownItems: List
- slotIndex: int
- font: Font
- graphics: GuiGraphicsExtractor
说明:
TODO
private static void extractCount(int drawX, int drawY, int hiddenItemCount, Font font, GuiGraphicsExtractor graphics) @ L161
- 方法名:extractCount
- 源码定位:L161
- 返回类型:void
- 修饰符:private static
参数:
- drawX: int
- drawY: int
- hiddenItemCount: int
- font: Font
- graphics: GuiGraphicsExtractor
说明:
TODO
private void extractSelectedItemTooltip(Font font, GuiGraphicsExtractor graphics, int x, int y, int w) @ L165
- 方法名:extractSelectedItemTooltip
- 源码定位:L165
- 返回类型:void
- 修饰符:private
参数:
- font: Font
- graphics: GuiGraphicsExtractor
- x: int
- y: int
- w: int
说明:
TODO
private static void extractProgressbar(int x, int y, Font font, GuiGraphicsExtractor graphics, Fraction weight) @ L184
- 方法名:extractProgressbar
- 源码定位:L184
- 返回类型:void
- 修饰符:private static
参数:
- x: int
- y: int
- font: Font
- graphics: GuiGraphicsExtractor
- weight: Fraction
说明:
TODO
private static void extractEmptyBundleDescriptionText(int x, int y, Font font, GuiGraphicsExtractor graphics) @ L193
- 方法名:extractEmptyBundleDescriptionText
- 源码定位:L193
- 返回类型:void
- 修饰符:private static
参数:
- x: int
- y: int
- font: Font
- graphics: GuiGraphicsExtractor
说明:
TODO
private static int getEmptyBundleDescriptionTextHeight(Font font) @ L197
- 方法名:getEmptyBundleDescriptionTextHeight
- 源码定位:L197
- 返回类型:int
- 修饰符:private static
参数:
- font: Font
说明:
TODO
private static int getProgressBarFill(Fraction weight) @ L201
- 方法名:getProgressBarFill
- 源码定位:L201
- 返回类型:int
- 修饰符:private static
参数:
- weight: Fraction
说明:
TODO
private static Identifier getProgressBarTexture(Fraction weight) @ L205
- 方法名:getProgressBarTexture
- 源码定位:L205
- 返回类型:Identifier
- 修饰符:private static
参数:
- weight: Fraction
说明:
TODO
private static Component getProgressBarFillText(Fraction weight) @ L209
- 方法名:getProgressBarFillText
- 源码定位:L209
- 返回类型:Component
- 修饰符:private static
参数:
- weight: Fraction
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ClientBundleTooltip implements ClientTooltipComponent {
private static final Identifier PROGRESSBAR_BORDER_SPRITE = Identifier.withDefaultNamespace("container/bundle/bundle_progressbar_border");
private static final Identifier PROGRESSBAR_FILL_SPRITE = Identifier.withDefaultNamespace("container/bundle/bundle_progressbar_fill");
private static final Identifier PROGRESSBAR_FULL_SPRITE = Identifier.withDefaultNamespace("container/bundle/bundle_progressbar_full");
private static final Identifier SLOT_HIGHLIGHT_BACK_SPRITE = Identifier.withDefaultNamespace("container/bundle/slot_highlight_back");
private static final Identifier SLOT_HIGHLIGHT_FRONT_SPRITE = Identifier.withDefaultNamespace("container/bundle/slot_highlight_front");
private static final Identifier SLOT_BACKGROUND_SPRITE = Identifier.withDefaultNamespace("container/bundle/slot_background");
private static final int SLOT_MARGIN = 4;
private static final int SLOT_SIZE = 24;
private static final int GRID_WIDTH = 96;
private static final int PROGRESSBAR_HEIGHT = 13;
private static final int PROGRESSBAR_WIDTH = 96;
private static final int PROGRESSBAR_BORDER = 1;
private static final int PROGRESSBAR_FILL_MAX = 94;
private static final int PROGRESSBAR_MARGIN_Y = 4;
private static final Component BUNDLE_FULL_TEXT = Component.translatable("item.minecraft.bundle.full");
private static final Component BUNDLE_EMPTY_TEXT = Component.translatable("item.minecraft.bundle.empty");
private static final Component BUNDLE_EMPTY_DESCRIPTION = Component.translatable("item.minecraft.bundle.empty.description");
private final BundleContents contents;
public ClientBundleTooltip(BundleContents contents) {
this.contents = contents;
}
@Override
public int getHeight(Font font) {
return this.contents.isEmpty() ? getEmptyBundleBackgroundHeight(font) : this.backgroundHeight();
}
@Override
public int getWidth(Font font) {
return 96;
}
@Override
public boolean showTooltipWithItemInHand() {
return true;
}
private static int getEmptyBundleBackgroundHeight(Font font) {
return getEmptyBundleDescriptionTextHeight(font) + 13 + 8;
}
private int backgroundHeight() {
return this.itemGridHeight() + 13 + 8;
}
private int itemGridHeight() {
return this.gridSizeY() * 24;
}
private static int getContentXOffset(int tooltipWidth) {
return (tooltipWidth - 96) / 2;
}
private int gridSizeY() {
return Mth.positiveCeilDiv(this.slotCount(), 4);
}
private int slotCount() {
return Math.min(12, this.contents.size());
}
@Override
public void extractImage(Font font, int x, int y, int w, int h, GuiGraphicsExtractor graphics) {
DataResult<Fraction> weight = this.contents.weight();
if (!weight.isError()) {
if (this.contents.isEmpty()) {
extractEmptyBundleTooltip(font, x, y, w, h, graphics);
} else {
this.extractBundleWithItemsTooltip(font, x, y, w, h, graphics, weight.getOrThrow());
}
}
}
private static void extractEmptyBundleTooltip(Font font, int x, int y, int w, int h, GuiGraphicsExtractor graphics) {
int left = x + getContentXOffset(w);
extractEmptyBundleDescriptionText(left, y, font, graphics);
extractProgressbar(left, y + getEmptyBundleDescriptionTextHeight(font) + 4, font, graphics, Fraction.ZERO);
}
private void extractBundleWithItemsTooltip(Font font, int x, int y, int w, int h, GuiGraphicsExtractor graphics, Fraction weight) {
boolean isOverflowing = this.contents.size() > 12;
List<ItemStackTemplate> shownItems = this.getShownItems(this.contents.getNumberOfItemsToShow());
int xStartPos = x + getContentXOffset(w) + 96;
int yStartPos = y + this.gridSizeY() * 24;
int slotNumber = 1;
for (int rowNumber = 1; rowNumber <= this.gridSizeY(); rowNumber++) {
for (int columnNumber = 1; columnNumber <= 4; columnNumber++) {
int drawX = xStartPos - columnNumber * 24;
int drawY = yStartPos - rowNumber * 24;
if (shouldRenderSurplusText(isOverflowing, columnNumber, rowNumber)) {
extractCount(drawX, drawY, this.getAmountOfHiddenItems(shownItems), font, graphics);
} else if (shouldRenderItemSlot(shownItems, slotNumber)) {
this.extractSlot(slotNumber, drawX, drawY, shownItems, slotNumber, font, graphics);
slotNumber++;
}
}
}
this.extractSelectedItemTooltip(font, graphics, x, y, w);
extractProgressbar(x + getContentXOffset(w), y + this.itemGridHeight() + 4, font, graphics, weight);
}
private List<ItemStackTemplate> getShownItems(int amountOfItemsToShow) {
int lastToDisplay = Math.min(this.contents.size(), amountOfItemsToShow);
return this.contents.items().subList(0, lastToDisplay);
}
private static boolean shouldRenderSurplusText(boolean isOverflowing, int column, int row) {
return isOverflowing && column * row == 1;
}
private static boolean shouldRenderItemSlot(List<? extends ItemInstance> shownItems, int slotNumber) {
return shownItems.size() >= slotNumber;
}
private int getAmountOfHiddenItems(List<ItemStackTemplate> shownItems) {
return this.contents.items().stream().skip(shownItems.size()).mapToInt(ItemInstance::count).sum();
}
private void extractSlot(int slotNumber, int drawX, int drawY, List<ItemStackTemplate> shownItems, int slotIndex, Font font, GuiGraphicsExtractor graphics) {
int itemVisualOrderIndex = shownItems.size() - slotNumber;
boolean hasHighlight = itemVisualOrderIndex == this.contents.getSelectedItemIndex();
ItemStack item = shownItems.get(itemVisualOrderIndex).create();
if (hasHighlight) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_HIGHLIGHT_BACK_SPRITE, drawX, drawY, 24, 24);
} else {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_BACKGROUND_SPRITE, drawX, drawY, 24, 24);
}
graphics.item(item, drawX + 4, drawY + 4, slotIndex);
graphics.itemDecorations(font, item, drawX + 4, drawY + 4);
if (hasHighlight) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_HIGHLIGHT_FRONT_SPRITE, drawX, drawY, 24, 24);
}
}
private static void extractCount(int drawX, int drawY, int hiddenItemCount, Font font, GuiGraphicsExtractor graphics) {
graphics.centeredText(font, "+" + hiddenItemCount, drawX + 12, drawY + 10, -1);
}
private void extractSelectedItemTooltip(Font font, GuiGraphicsExtractor graphics, int x, int y, int w) {
ItemStackTemplate selectedItem = this.contents.getSelectedItem();
if (selectedItem != null) {
ItemStack itemStack = selectedItem.create();
Component selectedItemName = itemStack.getStyledHoverName();
int textWidth = font.width(selectedItemName.getVisualOrderText());
int centerTooltip = x + w / 2 - 12;
ClientTooltipComponent selectedItemNameTooltip = ClientTooltipComponent.create(selectedItemName.getVisualOrderText());
graphics.tooltip(
font,
List.of(selectedItemNameTooltip),
centerTooltip - textWidth / 2,
y - 15,
DefaultTooltipPositioner.INSTANCE,
itemStack.get(DataComponents.TOOLTIP_STYLE)
);
}
}
private static void extractProgressbar(int x, int y, Font font, GuiGraphicsExtractor graphics, Fraction weight) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, getProgressBarTexture(weight), x + 1, y, getProgressBarFill(weight), 13);
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, PROGRESSBAR_BORDER_SPRITE, x, y, 96, 13);
Component progressBarFillText = getProgressBarFillText(weight);
if (progressBarFillText != null) {
graphics.centeredText(font, progressBarFillText, x + 48, y + 3, -1);
}
}
private static void extractEmptyBundleDescriptionText(int x, int y, Font font, GuiGraphicsExtractor graphics) {
graphics.textWithWordWrap(font, BUNDLE_EMPTY_DESCRIPTION, x, y, 96, -5592406);
}
private static int getEmptyBundleDescriptionTextHeight(Font font) {
return font.split(BUNDLE_EMPTY_DESCRIPTION, 96).size() * 9;
}
private static int getProgressBarFill(Fraction weight) {
return Mth.clamp(Mth.mulAndTruncate(weight, 94), 0, 94);
}
private static Identifier getProgressBarTexture(Fraction weight) {
return weight.compareTo(Fraction.ONE) >= 0 ? PROGRESSBAR_FULL_SPRITE : PROGRESSBAR_FILL_SPRITE;
}
private static @Nullable Component getProgressBarFillText(Fraction weight) {
if (weight.compareTo(Fraction.ZERO) == 0) {
return BUNDLE_EMPTY_TEXT;
} else {
return weight.compareTo(Fraction.ONE) >= 0 ? BUNDLE_FULL_TEXT : null;
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
实现/方法调用 - 关联成员:
ClientTooltipComponent.create()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.clamp(), Mth.mulAndTruncate(), Mth.positiveCeilDiv()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置: