CrafterScreen.java
net.minecraft.client.gui.screens.inventory.CrafterScreen
信息
- 全限定名:net.minecraft.client.gui.screens.inventory.CrafterScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.inventory
- 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/CrafterScreen.java
- 起始行号:L20
- 继承:AbstractContainerScreen
- 职责:
TODO
字段/常量
-
DISABLED_SLOT_LOCATION_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
POWERED_REDSTONE_LOCATION_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
UNPOWERED_REDSTONE_LOCATION_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
CONTAINER_LOCATION- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
DISABLED_SLOT_TOOLTIP- 类型:
Component - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
player- 类型:
Player - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public CrafterScreen(CrafterMenu menu, Inventory inventory, Component title) @ L28
- 构造器名:CrafterScreen
- 源码定位:L28
- 修饰符:public
参数:
- menu: CrafterMenu
- inventory: Inventory
- title: Component
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void init() @ L33
- 方法名:init
- 源码定位:L33
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void slotClicked(Slot slot, int slotId, int buttonNum, ContainerInput containerInput) @ L39
- 方法名:slotClicked
- 源码定位:L39
- 返回类型:void
- 修饰符:protected
参数:
- slot: Slot
- slotId: int
- buttonNum: int
- containerInput: ContainerInput
说明:
TODO
private void enableSlot(int slotId) @ L61
- 方法名:enableSlot
- 源码定位:L61
- 返回类型:void
- 修饰符:private
参数:
- slotId: int
说明:
TODO
private void disableSlot(int slotId) @ L65
- 方法名:disableSlot
- 源码定位:L65
- 返回类型:void
- 修饰符:private
参数:
- slotId: int
说明:
TODO
private void updateSlotState(int slotId, boolean enabled) @ L69
- 方法名:updateSlotState
- 源码定位:L69
- 返回类型:void
- 修饰符:private
参数:
- slotId: int
- enabled: boolean
说明:
TODO
public void extractSlot(GuiGraphicsExtractor graphics, Slot slot, int mouseX, int mouseY) @ L76
- 方法名:extractSlot
- 源码定位:L76
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- slot: Slot
- mouseX: int
- mouseY: int
说明:
TODO
private void extractDisabledSlot(GuiGraphicsExtractor graphics, CrafterSlot cs) @ L95
- 方法名:extractDisabledSlot
- 源码定位:L95
- 返回类型:void
- 修饰符:private
参数:
- graphics: GuiGraphicsExtractor
- cs: CrafterSlot
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L99
- 方法名:extractRenderState
- 源码定位:L99
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
private void extractRedstone(GuiGraphicsExtractor graphics) @ L112
- 方法名:extractRedstone
- 源码定位:L112
- 返回类型:void
- 修饰符:private
参数:
- graphics: GuiGraphicsExtractor
说明:
TODO
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L125
- 方法名:extractBackground
- 源码定位:L125
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class CrafterScreen extends AbstractContainerScreen<CrafterMenu> {
private static final Identifier DISABLED_SLOT_LOCATION_SPRITE = Identifier.withDefaultNamespace("container/crafter/disabled_slot");
private static final Identifier POWERED_REDSTONE_LOCATION_SPRITE = Identifier.withDefaultNamespace("container/crafter/powered_redstone");
private static final Identifier UNPOWERED_REDSTONE_LOCATION_SPRITE = Identifier.withDefaultNamespace("container/crafter/unpowered_redstone");
private static final Identifier CONTAINER_LOCATION = Identifier.withDefaultNamespace("textures/gui/container/crafter.png");
private static final Component DISABLED_SLOT_TOOLTIP = Component.translatable("gui.togglable_slot");
private final Player player;
public CrafterScreen(CrafterMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title);
this.player = inventory.player;
}
@Override
protected void init() {
super.init();
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
}
@Override
protected void slotClicked(Slot slot, int slotId, int buttonNum, ContainerInput containerInput) {
if (slot instanceof CrafterSlot && !slot.hasItem() && !this.player.isSpectator()) {
switch (containerInput) {
case PICKUP:
if (this.menu.isSlotDisabled(slotId)) {
this.enableSlot(slotId);
} else if (this.menu.getCarried().isEmpty()) {
this.disableSlot(slotId);
}
break;
case SWAP:
ItemStack playerInventoryItem = this.player.getInventory().getItem(buttonNum);
if (this.menu.isSlotDisabled(slotId) && !playerInventoryItem.isEmpty()) {
this.enableSlot(slotId);
}
}
}
super.slotClicked(slot, slotId, buttonNum, containerInput);
}
private void enableSlot(int slotId) {
this.updateSlotState(slotId, true);
}
private void disableSlot(int slotId) {
this.updateSlotState(slotId, false);
}
private void updateSlotState(int slotId, boolean enabled) {
this.menu.setSlotState(slotId, enabled);
super.handleSlotStateChanged(slotId, this.menu.containerId, enabled);
float pitch = enabled ? 1.0F : 0.75F;
this.player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), 0.4F, pitch);
}
@Override
public void extractSlot(GuiGraphicsExtractor graphics, Slot slot, int mouseX, int mouseY) {
if (slot instanceof CrafterSlot crafterSlot) {
if (this.menu.isSlotDisabled(slot.index)) {
this.extractDisabledSlot(graphics, crafterSlot);
} else {
super.extractSlot(graphics, slot, mouseX, mouseY);
}
int x0 = this.leftPos + crafterSlot.x - 2;
int y0 = this.topPos + crafterSlot.y - 2;
if (mouseX > x0 && mouseY > y0 && mouseX < x0 + 19 && mouseY < y0 + 19) {
graphics.requestCursor(CursorTypes.POINTING_HAND);
}
} else {
super.extractSlot(graphics, slot, mouseX, mouseY);
}
}
private void extractDisabledSlot(GuiGraphicsExtractor graphics, CrafterSlot cs) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, DISABLED_SLOT_LOCATION_SPRITE, cs.x - 1, cs.y - 1, 18, 18);
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractRenderState(graphics, mouseX, mouseY, a);
this.extractRedstone(graphics);
if (this.hoveredSlot instanceof CrafterSlot
&& !this.menu.isSlotDisabled(this.hoveredSlot.index)
&& this.menu.getCarried().isEmpty()
&& !this.hoveredSlot.hasItem()
&& !this.player.isSpectator()) {
graphics.setTooltipForNextFrame(this.font, DISABLED_SLOT_TOOLTIP, mouseX, mouseY);
}
}
private void extractRedstone(GuiGraphicsExtractor graphics) {
int xo = this.width / 2 + 9;
int yo = this.height / 2 - 48;
Identifier redstoneArrowTexture;
if (this.menu.isPowered()) {
redstoneArrowTexture = POWERED_REDSTONE_LOCATION_SPRITE;
} else {
redstoneArrowTexture = UNPOWERED_REDSTONE_LOCATION_SPRITE;
}
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, redstoneArrowTexture, xo, yo, 16, 16);
}
@Override
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractBackground(graphics, mouseX, mouseY, a);
int xo = (this.width - this.imageWidth) / 2;
int yo = (this.height - this.imageHeight) / 2;
graphics.blit(RenderPipelines.GUI_TEXTURED, CONTAINER_LOCATION, xo, yo, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: