CreateFlatWorldScreen.java

net.minecraft.client.gui.screens.CreateFlatWorldScreen

信息

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

    TODO

字段/常量

  • TITLE

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

      TODO

  • SLOT_SPRITE

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

      TODO

  • SLOT_BG_SIZE

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

      TODO

  • SLOT_STAT_HEIGHT

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

      TODO

  • SLOT_BG_X

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

      TODO

  • SLOT_BG_Y

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

      TODO

  • SLOT_FG_X

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

      TODO

  • SLOT_FG_Y

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

      TODO

  • layout

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

      TODO

  • parent

    • 类型: CreateWorldScreen
    • 修饰符: protected final
    • 源码定位: L41
    • 说明:

      TODO

  • applySettings

    • 类型: Consumer<FlatLevelGeneratorSettings>
    • 修饰符: private final
    • 源码定位: L42
    • 说明:

      TODO

  • generator

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

      TODO

  • list

    • 类型: CreateFlatWorldScreen.DetailsList
    • 修饰符: private
    • 源码定位: L44
    • 说明:

      TODO

  • deleteLayerButton

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.CreateFlatWorldScreen.DetailsList

    • 类型: class
    • 修饰符: private
    • 源码定位: L124
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.CreateFlatWorldScreen.DetailsList.Entry

    • 类型: class
    • 修饰符: private abstract static
    • 源码定位: L170
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.CreateFlatWorldScreen.DetailsList.HeaderEntry

    • 类型: class
    • 修饰符: private static
    • 源码定位: L174
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.CreateFlatWorldScreen.DetailsList.LayerEntry

    • 类型: class
    • 修饰符: private
    • 源码定位: L200
    • 说明:

      TODO

构造器

public CreateFlatWorldScreen(CreateWorldScreen parent, Consumer<FlatLevelGeneratorSettings> applySettings, FlatLevelGeneratorSettings generator) @ L47

  • 构造器名:CreateFlatWorldScreen
  • 源码定位:L47
  • 修饰符:public

参数:

  • parent: CreateWorldScreen
  • applySettings: Consumer
  • generator: FlatLevelGeneratorSettings

说明:

TODO

方法

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

public FlatLevelGeneratorSettings settings() @ L54

  • 方法名:settings
  • 源码定位:L54
  • 返回类型:FlatLevelGeneratorSettings
  • 修饰符:public

参数:

说明:

TODO

public void setConfig(FlatLevelGeneratorSettings generator) @ L58

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

参数:

  • generator: FlatLevelGeneratorSettings

说明:

TODO

protected void init() @ L66

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

参数:

说明:

TODO

protected void repositionElements() @ L99

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

参数:

说明:

TODO

private void updateButtonValidity() @ L108

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

参数:

说明:

TODO

private boolean hasValidSelection() @ L114

  • 方法名:hasValidSelection
  • 源码定位:L114
  • 返回类型:boolean
  • 修饰符:private

参数:

说明:

TODO

public void onClose() @ L118

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CreateFlatWorldScreen extends Screen {
    private static final Component TITLE = Component.translatable("createWorld.customize.flat.title");
    private static final Identifier SLOT_SPRITE = Identifier.withDefaultNamespace("container/slot");
    private static final int SLOT_BG_SIZE = 18;
    private static final int SLOT_STAT_HEIGHT = 20;
    private static final int SLOT_BG_X = 1;
    private static final int SLOT_BG_Y = 1;
    private static final int SLOT_FG_X = 2;
    private static final int SLOT_FG_Y = 2;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 33, 64);
    protected final CreateWorldScreen parent;
    private final Consumer<FlatLevelGeneratorSettings> applySettings;
    private FlatLevelGeneratorSettings generator;
    private CreateFlatWorldScreen.@Nullable DetailsList list;
    private @Nullable Button deleteLayerButton;
 
    public CreateFlatWorldScreen(CreateWorldScreen parent, Consumer<FlatLevelGeneratorSettings> applySettings, FlatLevelGeneratorSettings generator) {
        super(TITLE);
        this.parent = parent;
        this.applySettings = applySettings;
        this.generator = generator;
    }
 
    public FlatLevelGeneratorSettings settings() {
        return this.generator;
    }
 
    public void setConfig(FlatLevelGeneratorSettings generator) {
        this.generator = generator;
        if (this.list != null) {
            this.list.resetRows();
            this.updateButtonValidity();
        }
    }
 
    @Override
    protected void init() {
        this.layout.addTitleHeader(this.title, this.font);
        this.list = this.layout.addToContents(new CreateFlatWorldScreen.DetailsList());
        LinearLayout footer = this.layout.addToFooter(LinearLayout.vertical().spacing(4));
        footer.defaultCellSetting().alignVerticallyMiddle();
        LinearLayout topFooterButtons = footer.addChild(LinearLayout.horizontal().spacing(8));
        LinearLayout bottomFooterButtons = footer.addChild(LinearLayout.horizontal().spacing(8));
        this.deleteLayerButton = topFooterButtons.addChild(Button.builder(Component.translatable("createWorld.customize.flat.removeLayer"), button -> {
            if (this.list != null && this.list.getSelected() instanceof CreateFlatWorldScreen.DetailsList.LayerEntry selectedLayerEntry) {
                this.list.deleteLayer(selectedLayerEntry);
            }
        }).build());
        topFooterButtons.addChild(Button.builder(Component.translatable("createWorld.customize.presets"), button -> {
            this.minecraft.setScreen(new PresetFlatWorldScreen(this));
            this.generator.updateLayers();
            this.updateButtonValidity();
        }).build());
        bottomFooterButtons.addChild(Button.builder(CommonComponents.GUI_DONE, button -> {
            this.applySettings.accept(this.generator);
            this.onClose();
            this.generator.updateLayers();
        }).build());
        bottomFooterButtons.addChild(Button.builder(CommonComponents.GUI_CANCEL, button -> {
            this.onClose();
            this.generator.updateLayers();
        }).build());
        this.generator.updateLayers();
        this.updateButtonValidity();
        this.layout.visitWidgets(this::addRenderableWidget);
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        if (this.list != null) {
            this.list.updateSize(this.width, this.layout);
        }
 
        this.layout.arrangeElements();
    }
 
    private void updateButtonValidity() {
        if (this.deleteLayerButton != null) {
            this.deleteLayerButton.active = this.hasValidSelection();
        }
    }
 
    private boolean hasValidSelection() {
        return this.list != null && this.list.getSelected() instanceof CreateFlatWorldScreen.DetailsList.LayerEntry;
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.parent);
    }
 
    @OnlyIn(Dist.CLIENT)
    private class DetailsList extends ObjectSelectionList<CreateFlatWorldScreen.DetailsList.Entry> {
        private static final Component LAYER_MATERIAL_TITLE = Component.translatable("createWorld.customize.flat.tile").withStyle(ChatFormatting.UNDERLINE);
        private static final Component HEIGHT_TITLE = Component.translatable("createWorld.customize.flat.height").withStyle(ChatFormatting.UNDERLINE);
 
        public DetailsList() {
            Objects.requireNonNull(CreateFlatWorldScreen.this);
            super(CreateFlatWorldScreen.this.minecraft, CreateFlatWorldScreen.this.width, CreateFlatWorldScreen.this.height - 103, 43, 24);
            this.populateList();
        }
 
        private void populateList() {
            this.addEntry(new CreateFlatWorldScreen.DetailsList.HeaderEntry(CreateFlatWorldScreen.this.font), (int)(9.0 * 1.5));
            List<FlatLayerInfo> layersInfo = CreateFlatWorldScreen.this.generator.getLayersInfo().reversed();
 
            for (int i = 0; i < layersInfo.size(); i++) {
                this.addEntry(new CreateFlatWorldScreen.DetailsList.LayerEntry(layersInfo.get(i), i));
            }
        }
 
        public void setSelected(CreateFlatWorldScreen.DetailsList.@Nullable Entry selected) {
            super.setSelected(selected);
            CreateFlatWorldScreen.this.updateButtonValidity();
        }
 
        public void resetRows() {
            int index = this.children().indexOf(this.getSelected());
            this.clearEntries();
            this.populateList();
            List<CreateFlatWorldScreen.DetailsList.Entry> children = this.children();
            if (index >= 0 && index < children.size()) {
                this.setSelected(children.get(index));
            }
        }
 
        private void deleteLayer(CreateFlatWorldScreen.DetailsList.LayerEntry selectedLayerEntry) {
            List<FlatLayerInfo> layersInfo = CreateFlatWorldScreen.this.generator.getLayersInfo();
            int deletedLayerIndex = this.children().indexOf(selectedLayerEntry);
            this.removeEntry(selectedLayerEntry);
            layersInfo.remove(selectedLayerEntry.layerInfo);
            this.setSelected(layersInfo.isEmpty() ? null : this.children().get(Math.min(deletedLayerIndex, layersInfo.size())));
            CreateFlatWorldScreen.this.generator.updateLayers();
            this.resetRows();
            CreateFlatWorldScreen.this.updateButtonValidity();
        }
 
        @OnlyIn(Dist.CLIENT)
        private abstract static class Entry extends ObjectSelectionList.Entry<CreateFlatWorldScreen.DetailsList.Entry> {
        }
 
        @OnlyIn(Dist.CLIENT)
        private static class HeaderEntry extends CreateFlatWorldScreen.DetailsList.Entry {
            private final Font font;
 
            public HeaderEntry(Font font) {
                this.font = font;
            }
 
            @Override
            public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
                graphics.text(this.font, CreateFlatWorldScreen.DetailsList.LAYER_MATERIAL_TITLE, this.getContentX(), this.getContentY(), -1);
                graphics.text(
                    this.font,
                    CreateFlatWorldScreen.DetailsList.HEIGHT_TITLE,
                    this.getContentRight() - this.font.width(CreateFlatWorldScreen.DetailsList.HEIGHT_TITLE),
                    this.getContentY(),
                    -1
                );
            }
 
            @Override
            public Component getNarration() {
                return CommonComponents.joinForNarration(CreateFlatWorldScreen.DetailsList.LAYER_MATERIAL_TITLE, CreateFlatWorldScreen.DetailsList.HEIGHT_TITLE);
            }
        }
 
        @OnlyIn(Dist.CLIENT)
        private class LayerEntry extends CreateFlatWorldScreen.DetailsList.Entry {
            private final FlatLayerInfo layerInfo;
            private final int index;
 
            public LayerEntry(FlatLayerInfo layerInfo, int index) {
                Objects.requireNonNull(DetailsList.this);
                super();
                this.layerInfo = layerInfo;
                this.index = index;
            }
 
            @Override
            public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
                BlockState blockState = this.layerInfo.getBlockState();
                ItemStack itemStack = this.getDisplayItem(blockState);
                this.blitSlot(graphics, this.getContentX(), this.getContentY(), itemStack);
                int y = this.getContentYMiddle() - 9 / 2;
                graphics.text(CreateFlatWorldScreen.this.font, itemStack.getHoverName(), this.getContentX() + 18 + 5, y, -1);
                Component height;
                if (this.index == 0) {
                    height = Component.translatable("createWorld.customize.flat.layer.top", this.layerInfo.getHeight());
                } else if (this.index == CreateFlatWorldScreen.this.generator.getLayersInfo().size() - 1) {
                    height = Component.translatable("createWorld.customize.flat.layer.bottom", this.layerInfo.getHeight());
                } else {
                    height = Component.translatable("createWorld.customize.flat.layer", this.layerInfo.getHeight());
                }
 
                graphics.text(CreateFlatWorldScreen.this.font, height, this.getContentRight() - CreateFlatWorldScreen.this.font.width(height), y, -1);
            }
 
            private ItemStack getDisplayItem(BlockState blockState) {
                Item item = blockState.getBlock().asItem();
                if (item == Items.AIR) {
                    if (blockState.is(Blocks.WATER)) {
                        item = Items.WATER_BUCKET;
                    } else if (blockState.is(Blocks.LAVA)) {
                        item = Items.LAVA_BUCKET;
                    }
                }
 
                return new ItemStack(item);
            }
 
            @Override
            public Component getNarration() {
                ItemStack itemStack = this.getDisplayItem(this.layerInfo.getBlockState());
                return (Component)(!itemStack.isEmpty()
                    ? CommonComponents.joinForNarration(
                        Component.translatable("narrator.select", itemStack.getHoverName()),
                        CreateFlatWorldScreen.DetailsList.HEIGHT_TITLE,
                        Component.literal(String.valueOf(this.layerInfo.getHeight()))
                    )
                    : CommonComponents.EMPTY);
            }
 
            @Override
            public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
                DetailsList.this.setSelected((CreateFlatWorldScreen.DetailsList.Entry)this);
                return super.mouseClicked(event, doubleClick);
            }
 
            private void blitSlot(GuiGraphicsExtractor graphics, int x, int y, ItemStack itemStack) {
                this.blitSlotBg(graphics, x + 1, y + 1);
                if (!itemStack.isEmpty()) {
                    graphics.fakeItem(itemStack, x + 2, y + 2);
                }
            }
 
            private void blitSlotBg(GuiGraphicsExtractor graphics, int x, int y) {
                graphics.blitSprite(RenderPipelines.GUI_TEXTURED, CreateFlatWorldScreen.SLOT_SPRITE, x, y, 18, 18);
            }
        }
    }
}

引用的其他类

  • Button

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

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

    • 引用位置: 方法调用
    • 关联成员: LinearLayout.horizontal(), LinearLayout.vertical()
  • PresetFlatWorldScreen

    • 引用位置: 构造调用
    • 关联成员: PresetFlatWorldScreen()
  • Screen

    • 引用位置: 继承
  • CreateWorldScreen

    • 引用位置: 参数/字段
  • CommonComponents

    • 引用位置: 方法调用
    • 关联成员: CommonComponents.joinForNarration()
  • Component

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

    • 引用位置: 字段/方法调用
    • 关联成员: Identifier.withDefaultNamespace()
  • ItemStack

    • 引用位置: 构造调用
    • 关联成员: ItemStack()
  • FlatLevelGeneratorSettings

    • 引用位置: 参数/字段/返回值