JigsawBlockEditScreen.java

net.minecraft.client.gui.screens.inventory.JigsawBlockEditScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.inventory.JigsawBlockEditScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.inventory
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/JigsawBlockEditScreen.java
  • 起始行号:L25
  • 继承:Screen
  • 职责:

    TODO

字段/常量

  • JOINT_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L26
    • 说明:

      TODO

  • POOL_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • NAME_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L28
    • 说明:

      TODO

  • TARGET_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L29
    • 说明:

      TODO

  • FINAL_STATE_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L30
    • 说明:

      TODO

  • PLACEMENT_PRIORITY_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L31
    • 说明:

      TODO

  • PLACEMENT_PRIORITY_TOOLTIP

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L32
    • 说明:

      TODO

  • SELECTION_PRIORITY_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L33
    • 说明:

      TODO

  • SELECTION_PRIORITY_TOOLTIP

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L34
    • 说明:

      TODO

  • jigsawEntity

    • 类型: JigsawBlockEntity
    • 修饰符: private final
    • 源码定位: L35
    • 说明:

      TODO

  • nameEdit

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L36
    • 说明:

      TODO

  • targetEdit

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L37
    • 说明:

      TODO

  • poolEdit

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L38
    • 说明:

      TODO

  • finalStateEdit

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L39
    • 说明:

      TODO

  • selectionPriorityEdit

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L40
    • 说明:

      TODO

  • placementPriorityEdit

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L41
    • 说明:

      TODO

  • levels

    • 类型: int
    • 修饰符: private
    • 源码定位: L42
    • 说明:

      TODO

  • keepJigsaws

    • 类型: boolean
    • 修饰符: private
    • 源码定位: L43
    • 说明:

      TODO

  • jointButton

    • 类型: CycleButton<JigsawBlockEntity.JointType>
    • 修饰符: private
    • 源码定位: L44
    • 说明:

      TODO

  • doneButton

    • 类型: Button
    • 修饰符: private
    • 源码定位: L45
    • 说明:

      TODO

  • generateButton

    • 类型: Button
    • 修饰符: private
    • 源码定位: L46
    • 说明:

      TODO

  • joint

    • 类型: JigsawBlockEntity.JointType
    • 修饰符: private
    • 源码定位: L47
    • 说明:

      TODO

内部类/嵌套类型

构造器

public JigsawBlockEditScreen(JigsawBlockEntity jigsawEntity) @ L49

  • 构造器名:JigsawBlockEditScreen
  • 源码定位:L49
  • 修饰符:public

参数:

  • jigsawEntity: JigsawBlockEntity

说明:

TODO

方法

下面的方法块按源码顺序生成。

private void onDone() @ L54

  • 方法名:onDone
  • 源码定位:L54
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

private void onCancel() @ L59

  • 方法名:onCancel
  • 源码定位:L59
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

private void sendToServer() @ L63

  • 方法名:sendToServer
  • 源码定位:L63
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

private int parseAsInt(String value) @ L80

  • 方法名:parseAsInt
  • 源码定位:L80
  • 返回类型:int
  • 修饰符:private

参数:

  • value: String

说明:

TODO

private void sendGenerate() @ L88

  • 方法名:sendGenerate
  • 源码定位:L88
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public void onClose() @ L92

  • 方法名:onClose
  • 源码定位:L92
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

protected void init() @ L97

  • 方法名:init
  • 源码定位:L97
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

protected void setInitialFocus() @ L169

  • 方法名:setInitialFocus
  • 源码定位:L169
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public static boolean isValidIdentifier(String location) @ L174

  • 方法名:isValidIdentifier
  • 源码定位:L174
  • 返回类型:boolean
  • 修饰符:public static

参数:

  • location: String

说明:

TODO

private void updateValidity() @ L178

  • 方法名:updateValidity
  • 源码定位:L178
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public boolean isInGameUi() @ L186

  • 方法名:isInGameUi
  • 源码定位:L186
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public void resize(int width, int height) @ L191

  • 方法名:resize
  • 源码定位:L191
  • 返回类型:void
  • 修饰符:public

参数:

  • width: int
  • height: int

说明:

TODO

public boolean keyPressed(KeyEvent event) @ L213

  • 方法名:keyPressed
  • 源码定位:L213
  • 返回类型:boolean
  • 修饰符:public

参数:

  • event: KeyEvent

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L225

  • 方法名:extractRenderState
  • 源码定位:L225
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class JigsawBlockEditScreen extends Screen {
    private static final Component JOINT_LABEL = Component.translatable("jigsaw_block.joint_label");
    private static final Component POOL_LABEL = Component.translatable("jigsaw_block.pool");
    private static final Component NAME_LABEL = Component.translatable("jigsaw_block.name");
    private static final Component TARGET_LABEL = Component.translatable("jigsaw_block.target");
    private static final Component FINAL_STATE_LABEL = Component.translatable("jigsaw_block.final_state");
    private static final Component PLACEMENT_PRIORITY_LABEL = Component.translatable("jigsaw_block.placement_priority");
    private static final Component PLACEMENT_PRIORITY_TOOLTIP = Component.translatable("jigsaw_block.placement_priority.tooltip");
    private static final Component SELECTION_PRIORITY_LABEL = Component.translatable("jigsaw_block.selection_priority");
    private static final Component SELECTION_PRIORITY_TOOLTIP = Component.translatable("jigsaw_block.selection_priority.tooltip");
    private final JigsawBlockEntity jigsawEntity;
    private EditBox nameEdit;
    private EditBox targetEdit;
    private EditBox poolEdit;
    private EditBox finalStateEdit;
    private EditBox selectionPriorityEdit;
    private EditBox placementPriorityEdit;
    private int levels;
    private boolean keepJigsaws = true;
    private CycleButton<JigsawBlockEntity.JointType> jointButton;
    private Button doneButton;
    private Button generateButton;
    private JigsawBlockEntity.JointType joint;
 
    public JigsawBlockEditScreen(JigsawBlockEntity jigsawEntity) {
        super(GameNarrator.NO_TITLE);
        this.jigsawEntity = jigsawEntity;
    }
 
    private void onDone() {
        this.sendToServer();
        this.minecraft.setScreen(null);
    }
 
    private void onCancel() {
        this.minecraft.setScreen(null);
    }
 
    private void sendToServer() {
        this.minecraft
            .getConnection()
            .send(
                new ServerboundSetJigsawBlockPacket(
                    this.jigsawEntity.getBlockPos(),
                    Identifier.parse(this.nameEdit.getValue()),
                    Identifier.parse(this.targetEdit.getValue()),
                    Identifier.parse(this.poolEdit.getValue()),
                    this.finalStateEdit.getValue(),
                    this.joint,
                    this.parseAsInt(this.selectionPriorityEdit.getValue()),
                    this.parseAsInt(this.placementPriorityEdit.getValue())
                )
            );
    }
 
    private int parseAsInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException var3) {
            return 0;
        }
    }
 
    private void sendGenerate() {
        this.minecraft.getConnection().send(new ServerboundJigsawGeneratePacket(this.jigsawEntity.getBlockPos(), this.levels, this.keepJigsaws));
    }
 
    @Override
    public void onClose() {
        this.onCancel();
    }
 
    @Override
    protected void init() {
        this.poolEdit = new EditBox(this.font, this.width / 2 - 153, 20, 300, 20, POOL_LABEL);
        this.poolEdit.setMaxLength(128);
        this.poolEdit.setValue(this.jigsawEntity.getPool().identifier().toString());
        this.poolEdit.setResponder(value -> this.updateValidity());
        this.addWidget(this.poolEdit);
        this.nameEdit = new EditBox(this.font, this.width / 2 - 153, 55, 300, 20, NAME_LABEL);
        this.nameEdit.setMaxLength(128);
        this.nameEdit.setValue(this.jigsawEntity.getName().toString());
        this.nameEdit.setResponder(value -> this.updateValidity());
        this.addWidget(this.nameEdit);
        this.targetEdit = new EditBox(this.font, this.width / 2 - 153, 90, 300, 20, TARGET_LABEL);
        this.targetEdit.setMaxLength(128);
        this.targetEdit.setValue(this.jigsawEntity.getTarget().toString());
        this.targetEdit.setResponder(value -> this.updateValidity());
        this.addWidget(this.targetEdit);
        this.finalStateEdit = new EditBox(this.font, this.width / 2 - 153, 125, 300, 20, FINAL_STATE_LABEL);
        this.finalStateEdit.setMaxLength(256);
        this.finalStateEdit.setValue(this.jigsawEntity.getFinalState());
        this.addWidget(this.finalStateEdit);
        this.selectionPriorityEdit = new EditBox(this.font, this.width / 2 - 153, 160, 98, 20, SELECTION_PRIORITY_LABEL);
        this.selectionPriorityEdit.setMaxLength(3);
        this.selectionPriorityEdit.setValue(Integer.toString(this.jigsawEntity.getSelectionPriority()));
        this.selectionPriorityEdit.setTooltip(Tooltip.create(SELECTION_PRIORITY_TOOLTIP));
        this.addWidget(this.selectionPriorityEdit);
        this.placementPriorityEdit = new EditBox(this.font, this.width / 2 - 50, 160, 98, 20, PLACEMENT_PRIORITY_LABEL);
        this.placementPriorityEdit.setMaxLength(3);
        this.placementPriorityEdit.setValue(Integer.toString(this.jigsawEntity.getPlacementPriority()));
        this.placementPriorityEdit.setTooltip(Tooltip.create(PLACEMENT_PRIORITY_TOOLTIP));
        this.addWidget(this.placementPriorityEdit);
        this.joint = this.jigsawEntity.getJoint();
        this.jointButton = this.addRenderableWidget(
            CycleButton.builder(JigsawBlockEntity.JointType::getTranslatedName, this.joint)
                .withValues(JigsawBlockEntity.JointType.values())
                .displayOnlyValue()
                .create(this.width / 2 + 54, 160, 100, 20, JOINT_LABEL, (button, value) -> this.joint = value)
        );
        boolean vertical = JigsawBlock.getFrontFacing(this.jigsawEntity.getBlockState()).getAxis().isVertical();
        this.jointButton.active = vertical;
        this.jointButton.visible = vertical;
        this.addRenderableWidget(new AbstractSliderButton(this.width / 2 - 154, 185, 100, 20, CommonComponents.EMPTY, 0.0) {
            {
                Objects.requireNonNull(JigsawBlockEditScreen.this);
                this.updateMessage();
            }
 
            @Override
            protected void updateMessage() {
                this.setMessage(Component.translatable("jigsaw_block.levels", JigsawBlockEditScreen.this.levels));
            }
 
            @Override
            protected void applyValue() {
                JigsawBlockEditScreen.this.levels = Mth.floor(Mth.clampedLerp(this.value, 0.0, 20.0));
            }
        });
        this.addRenderableWidget(
            CycleButton.onOffBuilder(this.keepJigsaws)
                .create(this.width / 2 - 50, 185, 100, 20, Component.translatable("jigsaw_block.keep_jigsaws"), (button, value) -> this.keepJigsaws = value)
        );
        this.generateButton = this.addRenderableWidget(Button.builder(Component.translatable("jigsaw_block.generate"), button -> {
            this.onDone();
            this.sendGenerate();
        }).bounds(this.width / 2 + 54, 185, 100, 20).build());
        this.doneButton = this.addRenderableWidget(
            Button.builder(CommonComponents.GUI_DONE, button -> this.onDone()).bounds(this.width / 2 - 4 - 150, 210, 150, 20).build()
        );
        this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onCancel()).bounds(this.width / 2 + 4, 210, 150, 20).build());
        this.updateValidity();
    }
 
    @Override
    protected void setInitialFocus() {
        this.setInitialFocus(this.poolEdit);
    }
 
    public static boolean isValidIdentifier(String location) {
        return Identifier.tryParse(location) != null;
    }
 
    private void updateValidity() {
        boolean isValid = isValidIdentifier(this.nameEdit.getValue())
            && isValidIdentifier(this.targetEdit.getValue())
            && isValidIdentifier(this.poolEdit.getValue());
        this.doneButton.active = isValid;
        this.generateButton.active = isValid;
    }
 
    @Override
    public boolean isInGameUi() {
        return true;
    }
 
    @Override
    public void resize(int width, int height) {
        String oldNameEdit = this.nameEdit.getValue();
        String oldTargetEdit = this.targetEdit.getValue();
        String oldPoolEdit = this.poolEdit.getValue();
        String oldFinalStateEdit = this.finalStateEdit.getValue();
        String oldSelectionPriorityEdit = this.selectionPriorityEdit.getValue();
        String oldPlacementPriorityEdit = this.placementPriorityEdit.getValue();
        int oldLevels = this.levels;
        JigsawBlockEntity.JointType oldJointType = this.joint;
        this.init(width, height);
        this.nameEdit.setValue(oldNameEdit);
        this.targetEdit.setValue(oldTargetEdit);
        this.poolEdit.setValue(oldPoolEdit);
        this.finalStateEdit.setValue(oldFinalStateEdit);
        this.levels = oldLevels;
        this.joint = oldJointType;
        this.jointButton.setValue(oldJointType);
        this.selectionPriorityEdit.setValue(oldSelectionPriorityEdit);
        this.placementPriorityEdit.setValue(oldPlacementPriorityEdit);
    }
 
    @Override
    public boolean keyPressed(KeyEvent event) {
        if (super.keyPressed(event)) {
            return true;
        } else if (this.doneButton.active && event.isConfirmation()) {
            this.onDone();
            return true;
        } else {
            return false;
        }
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.text(this.font, POOL_LABEL, this.width / 2 - 153, 10, -6250336);
        this.poolEdit.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.text(this.font, NAME_LABEL, this.width / 2 - 153, 45, -6250336);
        this.nameEdit.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.text(this.font, TARGET_LABEL, this.width / 2 - 153, 80, -6250336);
        this.targetEdit.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.text(this.font, FINAL_STATE_LABEL, this.width / 2 - 153, 115, -6250336);
        this.finalStateEdit.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.text(this.font, SELECTION_PRIORITY_LABEL, this.width / 2 - 153, 150, -6250336);
        this.placementPriorityEdit.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.text(this.font, PLACEMENT_PRIORITY_LABEL, this.width / 2 - 50, 150, -6250336);
        this.selectionPriorityEdit.extractRenderState(graphics, mouseX, mouseY, a);
        if (JigsawBlock.getFrontFacing(this.jigsawEntity.getBlockState()).getAxis().isVertical()) {
            graphics.text(this.font, JOINT_LABEL, this.width / 2 + 53, 150, -6250336);
        }
    }
}

引用的其他类

  • GuiGraphicsExtractor

    • 引用位置: 参数
  • AbstractSliderButton

    • 引用位置: 构造调用
    • 关联成员: AbstractSliderButton()
  • Button

    • 引用位置: 字段/方法调用
    • 关联成员: Button.builder()
  • CycleButton

    • 引用位置: 字段/方法调用
    • 关联成员: CycleButton.builder(), CycleButton.onOffBuilder()
  • EditBox

    • 引用位置: 字段/构造调用
    • 关联成员: EditBox()
  • Tooltip

    • 引用位置: 方法调用
    • 关联成员: Tooltip.create()
  • Screen

    • 引用位置: 继承
  • KeyEvent

    • 引用位置: 参数
  • Component

    • 引用位置: 字段/方法调用
    • 关联成员: Component.translatable()
  • ServerboundJigsawGeneratePacket

    • 引用位置: 构造调用
    • 关联成员: ServerboundJigsawGeneratePacket()
  • ServerboundSetJigsawBlockPacket

    • 引用位置: 构造调用
    • 关联成员: ServerboundSetJigsawBlockPacket()
  • Identifier

    • 引用位置: 方法调用
    • 关联成员: Identifier.parse(), Identifier.tryParse()
  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.clampedLerp(), Mth.floor()
  • JigsawBlock

    • 引用位置: 方法调用
    • 关联成员: JigsawBlock.getFrontFacing()
  • JigsawBlockEntity

    • 引用位置: 参数/字段/方法调用
    • 关联成员: JigsawBlockEntity.JointType.values()