CreateBuffetWorldScreen.java
net.minecraft.client.gui.screens.CreateBuffetWorldScreen
信息
- 全限定名:net.minecraft.client.gui.screens.CreateBuffetWorldScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens
- 源码路径:src/main/java/net/minecraft/client/gui/screens/CreateBuffetWorldScreen.java
- 起始行号:L32
- 继承:Screen
- 职责:
TODO
字段/常量
-
SEARCH_HINT- 类型:
Component - 修饰符:
private static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
SPACING- 类型:
int - 修饰符:
private static final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
SEARCH_BOX_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
layout- 类型:
HeaderAndFooterLayout - 修饰符:
private final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
parent- 类型:
Screen - 修饰符:
private final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
applySettings- 类型:
Consumer<Holder<Biome>> - 修饰符:
private final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
biomes- 类型:
Registry<Biome> - 修饰符:
private final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
list- 类型:
CreateBuffetWorldScreen.BiomeList - 修饰符:
private - 源码定位:
L40 - 说明:
TODO
- 类型:
-
biome- 类型:
Holder<Biome> - 修饰符:
private - 源码定位:
L41 - 说明:
TODO
- 类型:
-
doneButton- 类型:
Button - 修饰符:
private - 源码定位:
L42 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.screens.CreateBuffetWorldScreen.BiomeList- 类型:
class - 修饰符:
private - 源码定位:
L91 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.CreateBuffetWorldScreen.BiomeList.Entry- 类型:
class - 修饰符:
private - 源码定位:
L127 - 说明:
TODO
- 类型:
构造器
public CreateBuffetWorldScreen(Screen parent, WorldCreationContext settings, Consumer<Holder<Biome>> applySettings) @ L44
- 构造器名:CreateBuffetWorldScreen
- 源码定位:L44
- 修饰符:public
参数:
- parent: Screen
- settings: WorldCreationContext
- applySettings: Consumer<Holder
>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void onClose() @ L54
- 方法名:onClose
- 源码定位:L54
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
protected void init() @ L59
- 方法名:init
- 源码定位:L59
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void repositionElements() @ L80
- 方法名:repositionElements
- 源码定位:L80
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
private void updateButtonValidity() @ L86
- 方法名:updateButtonValidity
- 源码定位:L86
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class CreateBuffetWorldScreen extends Screen {
private static final Component SEARCH_HINT = Component.translatable("createWorld.customize.buffet.search").withStyle(EditBox.SEARCH_HINT_STYLE);
private static final int SPACING = 3;
private static final int SEARCH_BOX_HEIGHT = 15;
private final HeaderAndFooterLayout layout;
private final Screen parent;
private final Consumer<Holder<Biome>> applySettings;
private final Registry<Biome> biomes;
private CreateBuffetWorldScreen.BiomeList list;
private Holder<Biome> biome;
private Button doneButton;
public CreateBuffetWorldScreen(Screen parent, WorldCreationContext settings, Consumer<Holder<Biome>> applySettings) {
super(Component.translatable("createWorld.customize.buffet.title"));
this.parent = parent;
this.applySettings = applySettings;
this.layout = new HeaderAndFooterLayout(this, 13 + 9 + 3 + 15, 33);
this.biomes = settings.worldgenLoadContext().lookupOrThrow(Registries.BIOME);
Holder<Biome> defaultBiome = this.biomes.get(Biomes.PLAINS).or(() -> this.biomes.listElements().findAny()).orElseThrow();
this.biome = settings.selectedDimensions().overworld().getBiomeSource().possibleBiomes().stream().findFirst().orElse(defaultBiome);
}
@Override
public void onClose() {
this.minecraft.setScreen(this.parent);
}
@Override
protected void init() {
LinearLayout header = this.layout.addToHeader(LinearLayout.vertical().spacing(3));
header.defaultCellSetting().alignHorizontallyCenter();
header.addChild(new StringWidget(this.getTitle(), this.font));
EditBox search = header.addChild(new EditBox(this.font, 200, 15, Component.empty()));
CreateBuffetWorldScreen.BiomeList biomeList = new CreateBuffetWorldScreen.BiomeList();
search.setHint(SEARCH_HINT);
search.setResponder(biomeList::filterEntries);
this.list = this.layout.addToContents(biomeList);
LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
this.doneButton = footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> {
this.applySettings.accept(this.biome);
this.onClose();
}).build());
footer.addChild(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onClose()).build());
this.list.setSelected(this.list.children().stream().filter(e -> Objects.equals(e.biome, this.biome)).findFirst().orElse(null));
this.layout.visitWidgets(this::addRenderableWidget);
this.repositionElements();
}
@Override
protected void repositionElements() {
this.layout.arrangeElements();
this.list.updateSize(this.width, this.layout);
}
private void updateButtonValidity() {
this.doneButton.active = this.list.getSelected() != null;
}
@OnlyIn(Dist.CLIENT)
private class BiomeList extends ObjectSelectionList<CreateBuffetWorldScreen.BiomeList.Entry> {
private BiomeList() {
Objects.requireNonNull(CreateBuffetWorldScreen.this);
super(
CreateBuffetWorldScreen.this.minecraft,
CreateBuffetWorldScreen.this.width,
CreateBuffetWorldScreen.this.layout.getContentHeight(),
CreateBuffetWorldScreen.this.layout.getHeaderHeight(),
15
);
this.filterEntries("");
}
private void filterEntries(String filter) {
Collator localeCollator = Collator.getInstance(Locale.getDefault());
String lowercaseFilter = filter.toLowerCase(Locale.ROOT);
List<CreateBuffetWorldScreen.BiomeList.Entry> list = CreateBuffetWorldScreen.this.biomes
.listElements()
.map(x$0 -> new CreateBuffetWorldScreen.BiomeList.Entry((Holder.Reference<Biome>)x$0))
.sorted(Comparator.comparing(e -> e.name.getString(), localeCollator))
.filter(entry -> filter.isEmpty() || entry.name.getString().toLowerCase(Locale.ROOT).contains(lowercaseFilter))
.toList();
this.replaceEntries(list);
this.refreshScrollAmount();
}
public void setSelected(CreateBuffetWorldScreen.BiomeList.@Nullable Entry selected) {
super.setSelected(selected);
if (selected != null) {
CreateBuffetWorldScreen.this.biome = selected.biome;
}
CreateBuffetWorldScreen.this.updateButtonValidity();
}
@OnlyIn(Dist.CLIENT)
private class Entry extends ObjectSelectionList.Entry<CreateBuffetWorldScreen.BiomeList.Entry> {
private final Holder.Reference<Biome> biome;
private final Component name;
public Entry(Holder.Reference<Biome> biome) {
Objects.requireNonNull(BiomeList.this);
super();
this.biome = biome;
Identifier id = biome.key().identifier();
String translationKey = id.toLanguageKey("biome");
if (Language.getInstance().has(translationKey)) {
this.name = Component.translatable(translationKey);
} else {
this.name = Component.literal(id.toString());
}
}
@Override
public Component getNarration() {
return Component.translatable("narrator.select", this.name);
}
@Override
public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
graphics.text(CreateBuffetWorldScreen.this.font, this.name, this.getContentX() + 5, this.getContentY() + 2, -1);
}
@Override
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
BiomeList.this.setSelected(this);
return super.mouseClicked(event, doubleClick);
}
}
}
}引用的其他类
-
- 引用位置:
字段/方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
EditBox()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
HeaderAndFooterLayout()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
参数/字段/继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Language.getInstance()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.empty(), Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置: