RecipeBookPage.java
net.minecraft.client.gui.screens.recipebook.RecipeBookPage
信息
- 全限定名:net.minecraft.client.gui.screens.recipebook.RecipeBookPage
- 类型:public class
- 包:net.minecraft.client.gui.screens.recipebook
- 源码路径:src/main/java/net/minecraft/client/gui/screens/recipebook/RecipeBookPage.java
- 起始行号:L27
- 职责:
TODO
字段/常量
-
ITEMS_PER_PAGE- 类型:
int - 修饰符:
public static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
PAGE_FORWARD_SPRITES- 类型:
WidgetSprites - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
PAGE_BACKWARD_SPRITES- 类型:
WidgetSprites - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
NEXT_PAGE_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
PREVIOUS_PAGE_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
TURN_PAGE_SPRITE_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
TURN_PAGE_SPRITE_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
buttons- 类型:
List<RecipeButton> - 修饰符:
private final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
hoveredButton- 类型:
RecipeButton - 修饰符:
private - 源码定位:
L40 - 说明:
TODO
- 类型:
-
overlay- 类型:
OverlayRecipeComponent - 修饰符:
private final - 源码定位:
L41 - 说明:
TODO
- 类型:
-
minecraft- 类型:
Minecraft - 修饰符:
private - 源码定位:
L42 - 说明:
TODO
- 类型:
-
parent- 类型:
RecipeBookComponent<?> - 修饰符:
private final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
recipeCollections- 类型:
List<RecipeCollection> - 修饰符:
private - 源码定位:
L44 - 说明:
TODO
- 类型:
-
forwardButton- 类型:
ImageButton - 修饰符:
private - 源码定位:
L45 - 说明:
TODO
- 类型:
-
backButton- 类型:
ImageButton - 修饰符:
private - 源码定位:
L46 - 说明:
TODO
- 类型:
-
totalPages- 类型:
int - 修饰符:
private - 源码定位:
L47 - 说明:
TODO
- 类型:
-
currentPage- 类型:
int - 修饰符:
private - 源码定位:
L48 - 说明:
TODO
- 类型:
-
recipeBook- 类型:
ClientRecipeBook - 修饰符:
private - 源码定位:
L49 - 说明:
TODO
- 类型:
-
lastClickedRecipe- 类型:
RecipeDisplayId - 修饰符:
private - 源码定位:
L50 - 说明:
TODO
- 类型:
-
lastClickedRecipeCollection- 类型:
RecipeCollection - 修饰符:
private - 源码定位:
L51 - 说明:
TODO
- 类型:
-
isFiltering- 类型:
boolean - 修饰符:
private - 源码定位:
L52 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public RecipeBookPage(RecipeBookComponent<?> parent, SlotSelectTime slotSelectTime, boolean isFurnaceMenu) @ L54
- 构造器名:RecipeBookPage
- 源码定位:L54
- 修饰符:public
参数:
- parent: RecipeBookComponent<?>
- slotSelectTime: SlotSelectTime
- isFurnaceMenu: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void init(Minecraft minecraft, int xo, int yo) @ L63
- 方法名:init
- 源码定位:L63
- 返回类型:void
- 修饰符:public
参数:
- minecraft: Minecraft
- xo: int
- yo: int
说明:
TODO
public void updateCollections(List<RecipeCollection> recipeCollections, boolean resetPage, boolean isFiltering) @ L77
- 方法名:updateCollections
- 源码定位:L77
- 返回类型:void
- 修饰符:public
参数:
- recipeCollections: List
- resetPage: boolean
- isFiltering: boolean
说明:
TODO
private void updateButtonsForPage() @ L88
- 方法名:updateButtonsForPage
- 源码定位:L88
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void updateArrowButtons() @ L106
- 方法名:updateArrowButtons
- 源码定位:L106
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int xo, int yo, int mouseX, int mouseY, float a) @ L116
- 方法名:extractRenderState
- 源码定位:L116
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- xo: int
- yo: int
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
public void extractTooltip(GuiGraphicsExtractor graphics, int mouseX, int mouseY) @ L144
- 方法名:extractTooltip
- 源码定位:L144
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
说明:
TODO
public RecipeDisplayId getLastClickedRecipe() @ L152
- 方法名:getLastClickedRecipe
- 源码定位:L152
- 返回类型:RecipeDisplayId
- 修饰符:public
参数:
- 无
说明:
TODO
public RecipeCollection getLastClickedRecipeCollection() @ L156
- 方法名:getLastClickedRecipeCollection
- 源码定位:L156
- 返回类型:RecipeCollection
- 修饰符:public
参数:
- 无
说明:
TODO
public void setInvisible() @ L160
- 方法名:setInvisible
- 源码定位:L160
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean mouseClicked(MouseButtonEvent event, int xo, int yo, int imageWidth, int imageHeight, boolean doubleClick) @ L164
- 方法名:mouseClicked
- 源码定位:L164
- 返回类型:boolean
- 修饰符:public
参数:
- event: MouseButtonEvent
- xo: int
- yo: int
- imageWidth: int
- imageHeight: int
- doubleClick: boolean
说明:
TODO
public void recipeShown(RecipeDisplayId recipe) @ L214
- 方法名:recipeShown
- 源码定位:L214
- 返回类型:void
- 修饰符:public
参数:
- recipe: RecipeDisplayId
说明:
TODO
public ClientRecipeBook getRecipeBook() @ L218
- 方法名:getRecipeBook
- 源码定位:L218
- 返回类型:ClientRecipeBook
- 修饰符:public
参数:
- 无
说明:
TODO
protected void listButtons(Consumer<AbstractWidget> buttonConsumer) @ L222
- 方法名:listButtons
- 源码定位:L222
- 返回类型:void
- 修饰符:protected
参数:
- buttonConsumer: Consumer
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RecipeBookPage {
public static final int ITEMS_PER_PAGE = 20;
private static final WidgetSprites PAGE_FORWARD_SPRITES = new WidgetSprites(
Identifier.withDefaultNamespace("recipe_book/page_forward"), Identifier.withDefaultNamespace("recipe_book/page_forward_highlighted")
);
private static final WidgetSprites PAGE_BACKWARD_SPRITES = new WidgetSprites(
Identifier.withDefaultNamespace("recipe_book/page_backward"), Identifier.withDefaultNamespace("recipe_book/page_backward_highlighted")
);
private static final Component NEXT_PAGE_TEXT = Component.translatable("gui.recipebook.next_page");
private static final Component PREVIOUS_PAGE_TEXT = Component.translatable("gui.recipebook.previous_page");
private static final int TURN_PAGE_SPRITE_WIDTH = 12;
private static final int TURN_PAGE_SPRITE_HEIGHT = 17;
private final List<RecipeButton> buttons = Lists.newArrayListWithCapacity(20);
private @Nullable RecipeButton hoveredButton;
private final OverlayRecipeComponent overlay;
private Minecraft minecraft;
private final RecipeBookComponent<?> parent;
private List<RecipeCollection> recipeCollections = ImmutableList.of();
private @Nullable ImageButton forwardButton;
private @Nullable ImageButton backButton;
private int totalPages;
private int currentPage;
private ClientRecipeBook recipeBook;
private @Nullable RecipeDisplayId lastClickedRecipe;
private @Nullable RecipeCollection lastClickedRecipeCollection;
private boolean isFiltering;
public RecipeBookPage(RecipeBookComponent<?> parent, SlotSelectTime slotSelectTime, boolean isFurnaceMenu) {
this.parent = parent;
this.overlay = new OverlayRecipeComponent(slotSelectTime, isFurnaceMenu);
for (int i = 0; i < 20; i++) {
this.buttons.add(new RecipeButton(slotSelectTime));
}
}
public void init(Minecraft minecraft, int xo, int yo) {
this.minecraft = minecraft;
this.recipeBook = minecraft.player.getRecipeBook();
for (int i = 0; i < this.buttons.size(); i++) {
this.buttons.get(i).setPosition(xo + 11 + 25 * (i % 5), yo + 31 + 25 * (i / 5));
}
this.forwardButton = new ImageButton(xo + 93, yo + 137, 12, 17, PAGE_FORWARD_SPRITES, button -> this.updateArrowButtons(), NEXT_PAGE_TEXT);
this.forwardButton.setTooltip(Tooltip.create(NEXT_PAGE_TEXT));
this.backButton = new ImageButton(xo + 38, yo + 137, 12, 17, PAGE_BACKWARD_SPRITES, button -> this.updateArrowButtons(), PREVIOUS_PAGE_TEXT);
this.backButton.setTooltip(Tooltip.create(PREVIOUS_PAGE_TEXT));
}
public void updateCollections(List<RecipeCollection> recipeCollections, boolean resetPage, boolean isFiltering) {
this.recipeCollections = recipeCollections;
this.isFiltering = isFiltering;
this.totalPages = (int)Math.ceil(recipeCollections.size() / 20.0);
if (this.totalPages <= this.currentPage || resetPage) {
this.currentPage = 0;
}
this.updateButtonsForPage();
}
private void updateButtonsForPage() {
int startOffset = 20 * this.currentPage;
ContextMap context = SlotDisplayContext.fromLevel(this.minecraft.level);
for (int i = 0; i < this.buttons.size(); i++) {
RecipeButton button = this.buttons.get(i);
if (startOffset + i < this.recipeCollections.size()) {
RecipeCollection recipeCollection = this.recipeCollections.get(startOffset + i);
button.init(recipeCollection, this.isFiltering, this, context);
button.visible = true;
} else {
button.visible = false;
}
}
this.updateArrowButtons();
}
private void updateArrowButtons() {
if (this.forwardButton != null) {
this.forwardButton.visible = this.totalPages > 1 && this.currentPage < this.totalPages - 1;
}
if (this.backButton != null) {
this.backButton.visible = this.totalPages > 1 && this.currentPage > 0;
}
}
public void extractRenderState(GuiGraphicsExtractor graphics, int xo, int yo, int mouseX, int mouseY, float a) {
if (this.totalPages > 1) {
Component pageNumbers = Component.translatable("gui.recipebook.page", this.currentPage + 1, this.totalPages);
int pWidth = this.minecraft.font.width(pageNumbers);
graphics.text(this.minecraft.font, pageNumbers, xo - pWidth / 2 + 73, yo + 141, -1);
}
this.hoveredButton = null;
for (RecipeButton recipeBookButton : this.buttons) {
recipeBookButton.extractRenderState(graphics, mouseX, mouseY, a);
if (recipeBookButton.visible && recipeBookButton.isHoveredOrFocused()) {
this.hoveredButton = recipeBookButton;
}
}
if (this.forwardButton != null) {
this.forwardButton.extractRenderState(graphics, mouseX, mouseY, a);
}
if (this.backButton != null) {
this.backButton.extractRenderState(graphics, mouseX, mouseY, a);
}
graphics.nextStratum();
this.overlay.extractRenderState(graphics, mouseX, mouseY, a);
}
public void extractTooltip(GuiGraphicsExtractor graphics, int mouseX, int mouseY) {
if (this.minecraft.screen != null && this.hoveredButton != null && !this.overlay.isVisible()) {
ItemStack displayStack = this.hoveredButton.getDisplayStack();
Identifier tooltipStyle = displayStack.get(DataComponents.TOOLTIP_STYLE);
graphics.setComponentTooltipForNextFrame(this.minecraft.font, this.hoveredButton.getTooltipText(displayStack), mouseX, mouseY, tooltipStyle);
}
}
public @Nullable RecipeDisplayId getLastClickedRecipe() {
return this.lastClickedRecipe;
}
public @Nullable RecipeCollection getLastClickedRecipeCollection() {
return this.lastClickedRecipeCollection;
}
public void setInvisible() {
this.overlay.setVisible(false);
}
public boolean mouseClicked(MouseButtonEvent event, int xo, int yo, int imageWidth, int imageHeight, boolean doubleClick) {
this.lastClickedRecipe = null;
this.lastClickedRecipeCollection = null;
if (this.overlay.isVisible()) {
if (this.overlay.mouseClicked(event, doubleClick)) {
this.lastClickedRecipe = this.overlay.getLastRecipeClicked();
this.lastClickedRecipeCollection = this.overlay.getRecipeCollection();
} else {
this.overlay.setVisible(false);
}
return true;
} else if (this.forwardButton.mouseClicked(event, doubleClick)) {
this.currentPage++;
this.updateButtonsForPage();
return true;
} else if (this.backButton.mouseClicked(event, doubleClick)) {
this.currentPage--;
this.updateButtonsForPage();
return true;
} else {
ContextMap context = SlotDisplayContext.fromLevel(this.minecraft.level);
for (RecipeButton button : this.buttons) {
if (button.mouseClicked(event, doubleClick)) {
if (event.button() == 0) {
this.lastClickedRecipe = button.getCurrentRecipe();
this.lastClickedRecipeCollection = button.getCollection();
} else if (event.button() == 1 && !this.overlay.isVisible() && !button.isOnlyOption()) {
this.overlay
.init(
button.getCollection(),
context,
this.isFiltering,
button.getX(),
button.getY(),
xo + imageWidth / 2,
yo + 13 + imageHeight / 2,
button.getWidth()
);
}
return true;
}
}
return false;
}
}
public void recipeShown(RecipeDisplayId recipe) {
this.parent.recipeShown(recipe);
}
public ClientRecipeBook getRecipeBook() {
return this.recipeBook;
}
protected void listButtons(Consumer<AbstractWidget> buttonConsumer) {
this.buttons.forEach(buttonConsumer);
}
}引用的其他类
-
- 引用位置:
字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
ImageButton()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Tooltip.create()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
WidgetSprites()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
OverlayRecipeComponent()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
RecipeButton()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SlotDisplayContext.fromLevel()
- 引用位置: