AnvilScreen.java
net.minecraft.client.gui.screens.inventory.AnvilScreen
信息
- 全限定名:net.minecraft.client.gui.screens.inventory.AnvilScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.inventory
- 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/AnvilScreen.java
- 起始行号:L21
- 继承:ItemCombinerScreen
- 职责:
TODO
字段/常量
-
TEXT_FIELD_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
TEXT_FIELD_DISABLED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
ERROR_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
ANVIL_LOCATION- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
TOO_EXPENSIVE_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
name- 类型:
EditBox - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
-
player- 类型:
Player - 修饰符:
private final - 源码定位:
L28 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public AnvilScreen(AnvilMenu menu, Inventory inventory, Component title) @ L30
- 构造器名:AnvilScreen
- 源码定位:L30
- 修饰符:public
参数:
- menu: AnvilMenu
- inventory: Inventory
- title: Component
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void subInit() @ L36
- 方法名:subInit
- 源码定位:L36
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void containerTick() @ L53
- 方法名:containerTick
- 源码定位:L53
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void setInitialFocus() @ L59
- 方法名:setInitialFocus
- 源码定位:L59
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public void resize(int width, int height) @ L64
- 方法名:resize
- 源码定位:L64
- 返回类型:void
- 修饰符:public
参数:
- width: int
- height: int
说明:
TODO
public boolean keyPressed(KeyEvent event) @ L71
- 方法名:keyPressed
- 源码定位:L71
- 返回类型:boolean
- 修饰符:public
参数:
- event: KeyEvent
说明:
TODO
private void onNameChanged(String name) @ L81
- 方法名:onNameChanged
- 源码定位:L81
- 返回类型:void
- 修饰符:private
参数:
- name: String
说明:
TODO
protected void extractLabels(GuiGraphicsExtractor graphics, int xm, int ym) @ L95
- 方法名:extractLabels
- 源码定位:L95
- 返回类型:void
- 修饰符:protected
参数:
- graphics: GuiGraphicsExtractor
- xm: int
- ym: int
说明:
TODO
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L123
- 方法名:extractBackground
- 源码定位:L123
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
protected void extractErrorIcon(GuiGraphicsExtractor graphics, int xo, int yo) @ L136
- 方法名:extractErrorIcon
- 源码定位:L136
- 返回类型:void
- 修饰符:protected
参数:
- graphics: GuiGraphicsExtractor
- xo: int
- yo: int
说明:
TODO
public void slotChanged(AbstractContainerMenu container, int slotIndex, ItemStack itemStack) @ L143
- 方法名:slotChanged
- 源码定位:L143
- 返回类型:void
- 修饰符:public
参数:
- container: AbstractContainerMenu
- slotIndex: int
- itemStack: ItemStack
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class AnvilScreen extends ItemCombinerScreen<AnvilMenu> {
private static final Identifier TEXT_FIELD_SPRITE = Identifier.withDefaultNamespace("container/anvil/text_field");
private static final Identifier TEXT_FIELD_DISABLED_SPRITE = Identifier.withDefaultNamespace("container/anvil/text_field_disabled");
private static final Identifier ERROR_SPRITE = Identifier.withDefaultNamespace("container/anvil/error");
private static final Identifier ANVIL_LOCATION = Identifier.withDefaultNamespace("textures/gui/container/anvil.png");
private static final Component TOO_EXPENSIVE_TEXT = Component.translatable("container.repair.expensive");
private EditBox name;
private final Player player;
public AnvilScreen(AnvilMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, ANVIL_LOCATION);
this.player = inventory.player;
this.titleLabelX = 60;
}
@Override
protected void subInit() {
int xo = (this.width - this.imageWidth) / 2;
int yo = (this.height - this.imageHeight) / 2;
this.name = new EditBox(this.font, xo + 62, yo + 24, 103, 12, Component.translatable("container.repair"));
this.name.setCanLoseFocus(false);
this.name.setTextColor(-1);
this.name.setTextColorUneditable(-1);
this.name.setInvertHighlightedTextColor(false);
this.name.setBordered(false);
this.name.setMaxLength(50);
this.name.setResponder(this::onNameChanged);
this.name.setValue("");
this.addRenderableWidget(this.name);
this.name.setEditable(this.menu.getSlot(0).hasItem());
}
@Override
protected void containerTick() {
super.containerTick();
this.minecraft.player.experienceDisplayStartTick = this.minecraft.player.tickCount;
}
@Override
protected void setInitialFocus() {
this.setInitialFocus(this.name);
}
@Override
public void resize(int width, int height) {
String oldEdit = this.name.getValue();
this.init(width, height);
this.name.setValue(oldEdit);
}
@Override
public boolean keyPressed(KeyEvent event) {
if (event.isEscape()) {
this.minecraft.player.closeContainer();
return true;
} else {
return !this.name.keyPressed(event) && !this.name.canConsumeInput() ? super.keyPressed(event) : true;
}
}
private void onNameChanged(String name) {
Slot slot = this.menu.getSlot(0);
if (slot.hasItem()) {
String newName = name;
if (!slot.getItem().has(DataComponents.CUSTOM_NAME) && name.equals(slot.getItem().getHoverName().getString())) {
newName = "";
}
if (this.menu.setItemName(newName)) {
this.minecraft.player.connection.send(new ServerboundRenameItemPacket(newName));
}
}
}
@Override
protected void extractLabels(GuiGraphicsExtractor graphics, int xm, int ym) {
super.extractLabels(graphics, xm, ym);
int cost = this.menu.getCost();
if (cost > 0) {
int color = -8323296;
Component line;
if (cost >= 40 && !this.minecraft.player.hasInfiniteMaterials()) {
line = TOO_EXPENSIVE_TEXT;
color = -40864;
} else if (!this.menu.getSlot(2).hasItem()) {
line = null;
} else {
line = Component.translatable("container.repair.cost", cost);
if (!this.menu.getSlot(2).mayPickup(this.player)) {
color = -40864;
}
}
if (line != null) {
int tx = this.imageWidth - 8 - this.font.width(line) - 2;
int ty = 69;
graphics.fill(tx - 2, 67, this.imageWidth - 8, 79, 1325400064);
graphics.text(this.font, line, tx, 69, color);
}
}
}
@Override
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractBackground(graphics, mouseX, mouseY, a);
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED,
this.menu.getSlot(0).hasItem() ? TEXT_FIELD_SPRITE : TEXT_FIELD_DISABLED_SPRITE,
this.leftPos + 59,
this.topPos + 20,
110,
16
);
}
@Override
protected void extractErrorIcon(GuiGraphicsExtractor graphics, int xo, int yo) {
if ((this.menu.getSlot(0).hasItem() || this.menu.getSlot(1).hasItem()) && !this.menu.getSlot(this.menu.getResultSlot()).hasItem()) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, ERROR_SPRITE, xo + 99, yo + 45, 28, 21);
}
}
@Override
public void slotChanged(AbstractContainerMenu container, int slotIndex, ItemStack itemStack) {
if (slotIndex == 0) {
this.name.setValue(itemStack.isEmpty() ? "" : itemStack.getHoverName().getString());
this.name.setEditable(!itemStack.isEmpty());
this.setFocused(this.name);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
EditBox()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ServerboundRenameItemPacket()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: