StonecutterScreen.java
net.minecraft.client.gui.screens.inventory.StonecutterScreen
信息
- 全限定名:net.minecraft.client.gui.screens.inventory.StonecutterScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.inventory
- 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/StonecutterScreen.java
- 起始行号:L24
- 继承:AbstractContainerScreen
- 职责:
TODO
字段/常量
-
SCROLLER_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
SCROLLER_DISABLED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
RECIPE_SELECTED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
RECIPE_HIGHLIGHTED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
RECIPE_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
BG_LOCATION- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
SCROLLER_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
SCROLLER_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
RECIPES_COLUMNS- 类型:
int - 修饰符:
private static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
RECIPES_ROWS- 类型:
int - 修饰符:
private static final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
RECIPES_IMAGE_SIZE_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
RECIPES_IMAGE_SIZE_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
SCROLLER_FULL_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
RECIPES_X- 类型:
int - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
RECIPES_Y- 类型:
int - 修饰符:
private static final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
scrollOffs- 类型:
float - 修饰符:
private - 源码定位:
L40 - 说明:
TODO
- 类型:
-
scrolling- 类型:
boolean - 修饰符:
private - 源码定位:
L41 - 说明:
TODO
- 类型:
-
startIndex- 类型:
int - 修饰符:
private - 源码定位:
L42 - 说明:
TODO
- 类型:
-
displayRecipes- 类型:
boolean - 修饰符:
private - 源码定位:
L43 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public StonecutterScreen(StonecutterMenu menu, Inventory inventory, Component title) @ L45
- 构造器名:StonecutterScreen
- 源码定位:L45
- 修饰符:public
参数:
- menu: StonecutterMenu
- inventory: Inventory
- title: Component
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L51
- 方法名:extractBackground
- 源码定位:L51
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
protected void extractTooltip(GuiGraphicsExtractor graphics, int mouseX, int mouseY) @ L77
- 方法名:extractTooltip
- 源码定位:L77
- 返回类型:void
- 修饰符:protected
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
说明:
TODO
private void extractButtons(GuiGraphicsExtractor graphics, int xm, int ym, int x, int y, int endIndex) @ L99
- 方法名:extractButtons
- 源码定位:L99
- 返回类型:void
- 修饰符:private
参数:
- graphics: GuiGraphicsExtractor
- xm: int
- ym: int
- x: int
- y: int
- endIndex: int
说明:
TODO
private void extractRecipes(GuiGraphicsExtractor graphics, int x, int y, int endIndex) @ L122
- 方法名:extractRecipes
- 源码定位:L122
- 返回类型:void
- 修饰符:private
参数:
- graphics: GuiGraphicsExtractor
- x: int
- y: int
- endIndex: int
说明:
TODO
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) @ L136
- 方法名:mouseClicked
- 源码定位:L136
- 返回类型:boolean
- 修饰符:public
参数:
- event: MouseButtonEvent
- doubleClick: boolean
说明:
TODO
public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) @ L164
- 方法名:mouseDragged
- 源码定位:L164
- 返回类型:boolean
- 修饰符:public
参数:
- event: MouseButtonEvent
- dx: double
- dy: double
说明:
TODO
public boolean mouseReleased(MouseButtonEvent event) @ L178
- 方法名:mouseReleased
- 源码定位:L178
- 返回类型:boolean
- 修饰符:public
参数:
- event: MouseButtonEvent
说明:
TODO
public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) @ L184
- 方法名:mouseScrolled
- 源码定位:L184
- 返回类型:boolean
- 修饰符:public
参数:
- x: double
- y: double
- scrollX: double
- scrollY: double
说明:
TODO
private boolean isScrollBarActive() @ L200
- 方法名:isScrollBarActive
- 源码定位:L200
- 返回类型:boolean
- 修饰符:private
参数:
- 无
说明:
TODO
protected int getOffscreenRows() @ L204
- 方法名:getOffscreenRows
- 源码定位:L204
- 返回类型:int
- 修饰符:protected
参数:
- 无
说明:
TODO
private void containerChanged() @ L208
- 方法名:containerChanged
- 源码定位:L208
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class StonecutterScreen extends AbstractContainerScreen<StonecutterMenu> {
private static final Identifier SCROLLER_SPRITE = Identifier.withDefaultNamespace("container/stonecutter/scroller");
private static final Identifier SCROLLER_DISABLED_SPRITE = Identifier.withDefaultNamespace("container/stonecutter/scroller_disabled");
private static final Identifier RECIPE_SELECTED_SPRITE = Identifier.withDefaultNamespace("container/stonecutter/recipe_selected");
private static final Identifier RECIPE_HIGHLIGHTED_SPRITE = Identifier.withDefaultNamespace("container/stonecutter/recipe_highlighted");
private static final Identifier RECIPE_SPRITE = Identifier.withDefaultNamespace("container/stonecutter/recipe");
private static final Identifier BG_LOCATION = Identifier.withDefaultNamespace("textures/gui/container/stonecutter.png");
private static final int SCROLLER_WIDTH = 12;
private static final int SCROLLER_HEIGHT = 15;
private static final int RECIPES_COLUMNS = 4;
private static final int RECIPES_ROWS = 3;
private static final int RECIPES_IMAGE_SIZE_WIDTH = 16;
private static final int RECIPES_IMAGE_SIZE_HEIGHT = 18;
private static final int SCROLLER_FULL_HEIGHT = 54;
private static final int RECIPES_X = 52;
private static final int RECIPES_Y = 14;
private float scrollOffs;
private boolean scrolling;
private int startIndex;
private boolean displayRecipes;
public StonecutterScreen(StonecutterMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title);
menu.registerUpdateListener(this::containerChanged);
this.titleLabelY--;
}
@Override
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractBackground(graphics, mouseX, mouseY, a);
int xo = this.leftPos;
int yo = this.topPos;
graphics.blit(RenderPipelines.GUI_TEXTURED, BG_LOCATION, xo, yo, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256);
int sy = (int)(41.0F * this.scrollOffs);
Identifier sprite = this.isScrollBarActive() ? SCROLLER_SPRITE : SCROLLER_DISABLED_SPRITE;
int scrollerXStart = xo + 119;
int scrollerYStart = yo + 15;
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, sprite, scrollerXStart, scrollerYStart + sy, 12, 15);
if (mouseX >= scrollerXStart && mouseY >= scrollerYStart && mouseX < scrollerXStart + 12 && mouseY < scrollerYStart + 54) {
if (this.isScrollBarActive()) {
graphics.requestCursor(this.scrolling ? CursorTypes.RESIZE_NS : CursorTypes.POINTING_HAND);
} else {
graphics.requestCursor(CursorTypes.NOT_ALLOWED);
}
}
int x = this.leftPos + 52;
int y = this.topPos + 14;
int endIndex = this.startIndex + 12;
this.extractButtons(graphics, mouseX, mouseY, x, y, endIndex);
this.extractRecipes(graphics, x, y, endIndex);
}
@Override
protected void extractTooltip(GuiGraphicsExtractor graphics, int mouseX, int mouseY) {
super.extractTooltip(graphics, mouseX, mouseY);
if (this.displayRecipes) {
int edgeLeft = this.leftPos + 52;
int edgeTop = this.topPos + 14;
int endIndex = this.startIndex + 12;
SelectableRecipe.SingleInputSet<StonecutterRecipe> visibleRecipes = this.menu.getVisibleRecipes();
for (int index = this.startIndex; index < endIndex && index < visibleRecipes.size(); index++) {
int posIndex = index - this.startIndex;
int itemLeft = edgeLeft + posIndex % 4 * 16;
int itemRight = edgeTop + posIndex / 4 * 18 + 2;
if (mouseX >= itemLeft && mouseX < itemLeft + 16 && mouseY >= itemRight && mouseY < itemRight + 18) {
ContextMap context = SlotDisplayContext.fromLevel(this.minecraft.level);
SlotDisplay buttonIcon = visibleRecipes.entries().get(index).recipe().optionDisplay();
graphics.setTooltipForNextFrame(this.font, buttonIcon.resolveForFirstStack(context), mouseX, mouseY);
}
}
}
}
private void extractButtons(GuiGraphicsExtractor graphics, int xm, int ym, int x, int y, int endIndex) {
for (int index = this.startIndex; index < endIndex && index < this.menu.getNumberOfVisibleRecipes(); index++) {
int posIndex = index - this.startIndex;
int posX = x + posIndex % 4 * 16;
int row = posIndex / 4;
int posY = y + row * 18 + 2;
Identifier sprite;
if (index == this.menu.getSelectedRecipeIndex()) {
sprite = RECIPE_SELECTED_SPRITE;
} else if (xm >= posX && ym >= posY && xm < posX + 16 && ym < posY + 18) {
sprite = RECIPE_HIGHLIGHTED_SPRITE;
} else {
sprite = RECIPE_SPRITE;
}
int textureY = posY - 1;
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, sprite, posX, textureY, 16, 18);
if (xm >= posX && ym >= textureY && xm < posX + 16 && ym < textureY + 18) {
graphics.requestCursor(CursorTypes.POINTING_HAND);
}
}
}
private void extractRecipes(GuiGraphicsExtractor graphics, int x, int y, int endIndex) {
SelectableRecipe.SingleInputSet<StonecutterRecipe> visibleRecipes = this.menu.getVisibleRecipes();
ContextMap context = SlotDisplayContext.fromLevel(this.minecraft.level);
for (int index = this.startIndex; index < endIndex && index < visibleRecipes.size(); index++) {
int posIndex = index - this.startIndex;
int posX = x + posIndex % 4 * 16;
int row = posIndex / 4;
int posY = y + row * 18 + 2;
SlotDisplay buttonIcon = visibleRecipes.entries().get(index).recipe().optionDisplay();
graphics.item(buttonIcon.resolveForFirstStack(context), posX, posY);
}
}
@Override
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
if (this.displayRecipes) {
int xo = this.leftPos + 52;
int yo = this.topPos + 14;
int endIndex = this.startIndex + 12;
for (int index = this.startIndex; index < endIndex; index++) {
int posIndex = index - this.startIndex;
double xx = event.x() - (xo + posIndex % 4 * 16);
double yy = event.y() - (yo + posIndex / 4 * 18);
if (xx >= 0.0 && yy >= 0.0 && xx < 16.0 && yy < 18.0 && this.menu.clickMenuButton(this.minecraft.player, index)) {
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_STONECUTTER_SELECT_RECIPE, 1.0F));
this.minecraft.gameMode.handleInventoryButtonClick(this.menu.containerId, index);
return true;
}
}
xo = this.leftPos + 119;
yo = this.topPos + 9;
if (event.x() >= xo && event.x() < xo + 12 && event.y() >= yo && event.y() < yo + 54) {
this.scrolling = true;
}
}
return super.mouseClicked(event, doubleClick);
}
@Override
public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) {
if (this.scrolling && this.isScrollBarActive()) {
int yscr = this.topPos + 14;
int yscr2 = yscr + 54;
this.scrollOffs = ((float)event.y() - yscr - 7.5F) / (yscr2 - yscr - 15.0F);
this.scrollOffs = Mth.clamp(this.scrollOffs, 0.0F, 1.0F);
this.startIndex = (int)(this.scrollOffs * this.getOffscreenRows() + 0.5) * 4;
return true;
} else {
return super.mouseDragged(event, dx, dy);
}
}
@Override
public boolean mouseReleased(MouseButtonEvent event) {
this.scrolling = false;
return super.mouseReleased(event);
}
@Override
public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) {
if (super.mouseScrolled(x, y, scrollX, scrollY)) {
return true;
} else {
if (this.isScrollBarActive()) {
int offscreenRows = this.getOffscreenRows();
float scrolledDelta = (float)scrollY / offscreenRows;
this.scrollOffs = Mth.clamp(this.scrollOffs - scrolledDelta, 0.0F, 1.0F);
this.startIndex = (int)(this.scrollOffs * offscreenRows + 0.5) * 4;
}
return true;
}
}
private boolean isScrollBarActive() {
return this.displayRecipes && this.menu.getNumberOfVisibleRecipes() > 12;
}
protected int getOffscreenRows() {
return (this.menu.getNumberOfVisibleRecipes() + 4 - 1) / 4 - 3;
}
private void containerChanged() {
this.displayRecipes = this.menu.hasInputItem();
this.scrollOffs = 0.0F;
this.startIndex = 0;
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SimpleSoundInstance.forUI()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.clamp()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SlotDisplayContext.fromLevel()
- 引用位置: