WorldCreationUiState.java
net.minecraft.client.gui.screens.worldselection.WorldCreationUiState
信息
- 全限定名:net.minecraft.client.gui.screens.worldselection.WorldCreationUiState
- 类型:public class
- 包:net.minecraft.client.gui.screens.worldselection
- 源码路径:src/main/java/net/minecraft/client/gui/screens/worldselection/WorldCreationUiState.java
- 起始行号:L30
- 职责:
TODO
字段/常量
-
DEFAULT_WORLD_NAME- 类型:
Component - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
listeners- 类型:
List<Consumer<WorldCreationUiState>> - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
name- 类型:
String - 修饰符:
private - 源码定位:
L33 - 说明:
TODO
- 类型:
-
gameMode- 类型:
WorldCreationUiState.SelectedGameMode - 修饰符:
private - 源码定位:
L34 - 说明:
TODO
- 类型:
-
difficulty- 类型:
Difficulty - 修饰符:
private - 源码定位:
L35 - 说明:
TODO
- 类型:
-
allowCommands- 类型:
Boolean - 修饰符:
private - 源码定位:
L36 - 说明:
TODO
- 类型:
-
seed- 类型:
String - 修饰符:
private - 源码定位:
L37 - 说明:
TODO
- 类型:
-
generateStructures- 类型:
boolean - 修饰符:
private - 源码定位:
L38 - 说明:
TODO
- 类型:
-
bonusChest- 类型:
boolean - 修饰符:
private - 源码定位:
L39 - 说明:
TODO
- 类型:
-
savesFolder- 类型:
Path - 修饰符:
private final - 源码定位:
L40 - 说明:
TODO
- 类型:
-
targetFolder- 类型:
String - 修饰符:
private - 源码定位:
L41 - 说明:
TODO
- 类型:
-
settings- 类型:
WorldCreationContext - 修饰符:
private - 源码定位:
L42 - 说明:
TODO
- 类型:
-
worldType- 类型:
WorldCreationUiState.WorldTypeEntry - 修饰符:
private - 源码定位:
L43 - 说明:
TODO
- 类型:
-
normalPresetList- 类型:
List<WorldCreationUiState.WorldTypeEntry> - 修饰符:
private final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
altPresetList- 类型:
List<WorldCreationUiState.WorldTypeEntry> - 修饰符:
private final - 源码定位:
L45 - 说明:
TODO
- 类型:
-
gameRules- 类型:
GameRules - 修饰符:
private - 源码定位:
L46 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.screens.worldselection.WorldCreationUiState.SelectedGameMode- 类型:
enum - 修饰符:
public static - 源码定位:
L283 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.worldselection.WorldCreationUiState.WorldTypeEntry- 类型:
record - 修饰符:
public - 源码定位:
L305 - 说明:
TODO
- 类型:
构造器
public WorldCreationUiState(Path savesFolder, WorldCreationContext settings, Optional<ResourceKey<WorldPreset>> preset, OptionalLong seed) @ L48
- 构造器名:WorldCreationUiState
- 源码定位:L48
- 修饰符:public
参数:
- savesFolder: Path
- settings: WorldCreationContext
- preset: Optional<ResourceKey
> - seed: OptionalLong
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void addListener(Consumer<WorldCreationUiState> action) @ L66
- 方法名:addListener
- 源码定位:L66
- 返回类型:void
- 修饰符:public
参数:
- action: Consumer
说明:
TODO
public void onChanged() @ L70
- 方法名:onChanged
- 源码定位:L70
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void setName(String name) @ L86
- 方法名:setName
- 源码定位:L86
- 返回类型:void
- 修饰符:public
参数:
- name: String
说明:
TODO
private String findResultFolder(String name) @ L92
- 方法名:findResultFolder
- 源码定位:L92
- 返回类型:String
- 修饰符:private
参数:
- name: String
说明:
TODO
public String getName() @ L106
- 方法名:getName
- 源码定位:L106
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String getTargetFolder() @ L110
- 方法名:getTargetFolder
- 源码定位:L110
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public void setGameMode(WorldCreationUiState.SelectedGameMode gameMode) @ L114
- 方法名:setGameMode
- 源码定位:L114
- 返回类型:void
- 修饰符:public
参数:
- gameMode: WorldCreationUiState.SelectedGameMode
说明:
TODO
public WorldCreationUiState.SelectedGameMode getGameMode() @ L119
- 方法名:getGameMode
- 源码定位:L119
- 返回类型:WorldCreationUiState.SelectedGameMode
- 修饰符:public
参数:
- 无
说明:
TODO
public void setDifficulty(Difficulty difficulty) @ L123
- 方法名:setDifficulty
- 源码定位:L123
- 返回类型:void
- 修饰符:public
参数:
- difficulty: Difficulty
说明:
TODO
public Difficulty getDifficulty() @ L128
- 方法名:getDifficulty
- 源码定位:L128
- 返回类型:Difficulty
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isHardcore() @ L132
- 方法名:isHardcore
- 源码定位:L132
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void setAllowCommands(boolean allowCommands) @ L136
- 方法名:setAllowCommands
- 源码定位:L136
- 返回类型:void
- 修饰符:public
参数:
- allowCommands: boolean
说明:
TODO
public boolean isAllowCommands() @ L141
- 方法名:isAllowCommands
- 源码定位:L141
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void setSeed(String seed) @ L151
- 方法名:setSeed
- 源码定位:L151
- 返回类型:void
- 修饰符:public
参数:
- seed: String
说明:
TODO
public String getSeed() @ L157
- 方法名:getSeed
- 源码定位:L157
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public void setGenerateStructures(boolean generateStructures) @ L161
- 方法名:setGenerateStructures
- 源码定位:L161
- 返回类型:void
- 修饰符:public
参数:
- generateStructures: boolean
说明:
TODO
public boolean isGenerateStructures() @ L166
- 方法名:isGenerateStructures
- 源码定位:L166
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void setBonusChest(boolean bonusChest) @ L170
- 方法名:setBonusChest
- 源码定位:L170
- 返回类型:void
- 修饰符:public
参数:
- bonusChest: boolean
说明:
TODO
public boolean isBonusChest() @ L175
- 方法名:isBonusChest
- 源码定位:L175
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void setSettings(WorldCreationContext settings) @ L179
- 方法名:setSettings
- 源码定位:L179
- 返回类型:void
- 修饰符:public
参数:
- settings: WorldCreationContext
说明:
TODO
public WorldCreationContext getSettings() @ L185
- 方法名:getSettings
- 源码定位:L185
- 返回类型:WorldCreationContext
- 修饰符:public
参数:
- 无
说明:
TODO
public void updateDimensions(WorldCreationContext.DimensionsUpdater modifier) @ L189
- 方法名:updateDimensions
- 源码定位:L189
- 返回类型:void
- 修饰符:public
参数:
- modifier: WorldCreationContext.DimensionsUpdater
说明:
TODO
protected boolean tryUpdateDataConfiguration(WorldDataConfiguration newConfig) @ L194
- 方法名:tryUpdateDataConfiguration
- 源码定位:L194
- 返回类型:boolean
- 修饰符:protected
参数:
- newConfig: WorldDataConfiguration
说明:
TODO
public boolean isDebug() @ L212
- 方法名:isDebug
- 源码定位:L212
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void setWorldType(WorldCreationUiState.WorldTypeEntry worldType) @ L216
- 方法名:setWorldType
- 源码定位:L216
- 返回类型:void
- 修饰符:public
参数:
- worldType: WorldCreationUiState.WorldTypeEntry
说明:
TODO
public WorldCreationUiState.WorldTypeEntry getWorldType() @ L224
- 方法名:getWorldType
- 源码定位:L224
- 返回类型:WorldCreationUiState.WorldTypeEntry
- 修饰符:public
参数:
- 无
说明:
TODO
public PresetEditor getPresetEditor() @ L228
- 方法名:getPresetEditor
- 源码定位:L228
- 返回类型:PresetEditor
- 修饰符:public
参数:
- 无
说明:
TODO
public List<WorldCreationUiState.WorldTypeEntry> getNormalPresetList() @ L233
- 方法名:getNormalPresetList
- 源码定位:L233
- 返回类型:List<WorldCreationUiState.WorldTypeEntry>
- 修饰符:public
参数:
- 无
说明:
TODO
public List<WorldCreationUiState.WorldTypeEntry> getAltPresetList() @ L237
- 方法名:getAltPresetList
- 源码定位:L237
- 返回类型:List<WorldCreationUiState.WorldTypeEntry>
- 修饰符:public
参数:
- 无
说明:
TODO
private void updatePresetLists() @ L241
- 方法名:updatePresetLists
- 源码定位:L241
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private static Optional<Holder<WorldPreset>> findPreset(WorldCreationContext settings, Optional<ResourceKey<WorldPreset>> preset) @ L265
- 方法名:findPreset
- 源码定位:L265
- 返回类型:Optional<Holder
> - 修饰符:private static
参数:
- settings: WorldCreationContext
- preset: Optional<ResourceKey
>
说明:
TODO
private static Optional<List<WorldCreationUiState.WorldTypeEntry>> getNonEmptyList(Registry<WorldPreset> presetRegistry, TagKey<WorldPreset> id) @ L269
- 方法名:getNonEmptyList
- 源码定位:L269
- 返回类型:Optional<List<WorldCreationUiState.WorldTypeEntry>>
- 修饰符:private static
参数:
- presetRegistry: Registry
- id: TagKey
说明:
TODO
public void setGameRules(GameRules gameRules) @ L273
- 方法名:setGameRules
- 源码定位:L273
- 返回类型:void
- 修饰符:public
参数:
- gameRules: GameRules
说明:
TODO
public GameRules getGameRules() @ L278
- 方法名:getGameRules
- 源码定位:L278
- 返回类型:GameRules
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class WorldCreationUiState {
private static final Component DEFAULT_WORLD_NAME = Component.translatable("selectWorld.newWorld");
private final List<Consumer<WorldCreationUiState>> listeners = new ArrayList<>();
private String name = DEFAULT_WORLD_NAME.getString();
private WorldCreationUiState.SelectedGameMode gameMode = WorldCreationUiState.SelectedGameMode.SURVIVAL;
private Difficulty difficulty = Difficulty.NORMAL;
private @Nullable Boolean allowCommands;
private String seed;
private boolean generateStructures;
private boolean bonusChest;
private final Path savesFolder;
private String targetFolder;
private WorldCreationContext settings;
private WorldCreationUiState.WorldTypeEntry worldType;
private final List<WorldCreationUiState.WorldTypeEntry> normalPresetList = new ArrayList<>();
private final List<WorldCreationUiState.WorldTypeEntry> altPresetList = new ArrayList<>();
private GameRules gameRules;
public WorldCreationUiState(Path savesFolder, WorldCreationContext settings, Optional<ResourceKey<WorldPreset>> preset, OptionalLong seed) {
this.savesFolder = savesFolder;
this.settings = settings;
this.worldType = new WorldCreationUiState.WorldTypeEntry(findPreset(settings, preset).orElse(null));
this.updatePresetLists();
this.seed = seed.isPresent() ? Long.toString(seed.getAsLong()) : "";
this.generateStructures = settings.options().generateStructures();
this.bonusChest = settings.options().generateBonusChest();
this.targetFolder = this.findResultFolder(this.name);
this.gameMode = settings.initialWorldCreationOptions().selectedGameMode();
this.gameRules = new GameRules(settings.dataConfiguration().enabledFeatures());
this.gameRules.setAll(settings.initialWorldCreationOptions().gameRuleOverwrites(), null);
Optional.ofNullable(settings.initialWorldCreationOptions().flatLevelPreset())
.flatMap(key -> settings.worldgenLoadContext().lookup(Registries.FLAT_LEVEL_GENERATOR_PRESET).flatMap(registry -> registry.get(key)))
.map(reference -> reference.value().settings())
.ifPresent(generatorSettings -> this.updateDimensions(PresetEditor.flatWorldConfigurator(generatorSettings)));
}
public void addListener(Consumer<WorldCreationUiState> action) {
this.listeners.add(action);
}
public void onChanged() {
boolean bonusChest = this.isBonusChest();
if (bonusChest != this.settings.options().generateBonusChest()) {
this.settings = this.settings.withOptions(options -> options.withBonusChest(bonusChest));
}
boolean generateStructures = this.isGenerateStructures();
if (generateStructures != this.settings.options().generateStructures()) {
this.settings = this.settings.withOptions(options -> options.withStructures(generateStructures));
}
for (Consumer<WorldCreationUiState> listener : this.listeners) {
listener.accept(this);
}
}
public void setName(String name) {
this.name = name;
this.targetFolder = this.findResultFolder(name);
this.onChanged();
}
private String findResultFolder(String name) {
String trimmedName = name.trim();
try {
return FileUtil.findAvailableName(this.savesFolder, !trimmedName.isEmpty() ? trimmedName : DEFAULT_WORLD_NAME.getString(), "");
} catch (Exception var5) {
try {
return FileUtil.findAvailableName(this.savesFolder, "World", "");
} catch (IOException var4) {
throw new RuntimeException("Could not create save folder", var4);
}
}
}
public String getName() {
return this.name;
}
public String getTargetFolder() {
return this.targetFolder;
}
public void setGameMode(WorldCreationUiState.SelectedGameMode gameMode) {
this.gameMode = gameMode;
this.onChanged();
}
public WorldCreationUiState.SelectedGameMode getGameMode() {
return this.isDebug() ? WorldCreationUiState.SelectedGameMode.DEBUG : this.gameMode;
}
public void setDifficulty(Difficulty difficulty) {
this.difficulty = difficulty;
this.onChanged();
}
public Difficulty getDifficulty() {
return this.isHardcore() ? Difficulty.HARD : this.difficulty;
}
public boolean isHardcore() {
return this.getGameMode() == WorldCreationUiState.SelectedGameMode.HARDCORE;
}
public void setAllowCommands(boolean allowCommands) {
this.allowCommands = allowCommands;
this.onChanged();
}
public boolean isAllowCommands() {
if (this.isDebug()) {
return true;
} else if (this.isHardcore()) {
return false;
} else {
return this.allowCommands == null ? this.getGameMode() == WorldCreationUiState.SelectedGameMode.CREATIVE : this.allowCommands;
}
}
public void setSeed(String seed) {
this.seed = seed;
this.settings = this.settings.withOptions(options -> options.withSeed(WorldOptions.parseSeed(this.getSeed())));
this.onChanged();
}
public String getSeed() {
return this.seed;
}
public void setGenerateStructures(boolean generateStructures) {
this.generateStructures = generateStructures;
this.onChanged();
}
public boolean isGenerateStructures() {
return this.isDebug() ? false : this.generateStructures;
}
public void setBonusChest(boolean bonusChest) {
this.bonusChest = bonusChest;
this.onChanged();
}
public boolean isBonusChest() {
return !this.isDebug() && !this.isHardcore() ? this.bonusChest : false;
}
public void setSettings(WorldCreationContext settings) {
this.settings = settings;
this.updatePresetLists();
this.onChanged();
}
public WorldCreationContext getSettings() {
return this.settings;
}
public void updateDimensions(WorldCreationContext.DimensionsUpdater modifier) {
this.settings = this.settings.withDimensions(modifier);
this.onChanged();
}
protected boolean tryUpdateDataConfiguration(WorldDataConfiguration newConfig) {
WorldDataConfiguration oldConfig = this.settings.dataConfiguration();
if (oldConfig.dataPacks().getEnabled().equals(newConfig.dataPacks().getEnabled()) && oldConfig.enabledFeatures().equals(newConfig.enabledFeatures())) {
this.settings = new WorldCreationContext(
this.settings.options(),
this.settings.datapackDimensions(),
this.settings.selectedDimensions(),
this.settings.worldgenRegistries(),
this.settings.dataPackResources(),
newConfig,
this.settings.initialWorldCreationOptions()
);
return true;
} else {
return false;
}
}
public boolean isDebug() {
return this.settings.selectedDimensions().isDebug();
}
public void setWorldType(WorldCreationUiState.WorldTypeEntry worldType) {
this.worldType = worldType;
Holder<WorldPreset> preset = worldType.preset();
if (preset != null) {
this.updateDimensions((registryAccess, dimensions) -> preset.value().createWorldDimensions());
}
}
public WorldCreationUiState.WorldTypeEntry getWorldType() {
return this.worldType;
}
public @Nullable PresetEditor getPresetEditor() {
Holder<WorldPreset> preset = this.getWorldType().preset();
return preset != null ? PresetEditor.EDITORS.get(preset.unwrapKey()) : null;
}
public List<WorldCreationUiState.WorldTypeEntry> getNormalPresetList() {
return this.normalPresetList;
}
public List<WorldCreationUiState.WorldTypeEntry> getAltPresetList() {
return this.altPresetList;
}
private void updatePresetLists() {
Registry<WorldPreset> presetRegistry = this.getSettings().worldgenLoadContext().lookupOrThrow(Registries.WORLD_PRESET);
this.normalPresetList.clear();
this.normalPresetList
.addAll(
getNonEmptyList(presetRegistry, WorldPresetTags.NORMAL)
.orElseGet(() -> presetRegistry.listElements().map(WorldCreationUiState.WorldTypeEntry::new).toList())
);
this.altPresetList.clear();
this.altPresetList.addAll(getNonEmptyList(presetRegistry, WorldPresetTags.EXTENDED).orElse(this.normalPresetList));
Holder<WorldPreset> preset = this.worldType.preset();
if (preset != null) {
WorldCreationUiState.WorldTypeEntry newPreset = findPreset(this.getSettings(), preset.unwrapKey())
.map(WorldCreationUiState.WorldTypeEntry::new)
.orElse(this.normalPresetList.getFirst());
boolean isCustomizablePreset = PresetEditor.EDITORS.get(preset.unwrapKey()) != null;
if (isCustomizablePreset) {
this.worldType = newPreset;
} else {
this.setWorldType(newPreset);
}
}
}
private static Optional<Holder<WorldPreset>> findPreset(WorldCreationContext settings, Optional<ResourceKey<WorldPreset>> preset) {
return preset.flatMap(k -> settings.worldgenLoadContext().lookupOrThrow(Registries.WORLD_PRESET).get((ResourceKey<WorldPreset>)k));
}
private static Optional<List<WorldCreationUiState.WorldTypeEntry>> getNonEmptyList(Registry<WorldPreset> presetRegistry, TagKey<WorldPreset> id) {
return presetRegistry.get(id).map(tag -> tag.stream().map(WorldCreationUiState.WorldTypeEntry::new).toList()).filter(l -> !l.isEmpty());
}
public void setGameRules(GameRules gameRules) {
this.gameRules = gameRules;
this.onChanged();
}
public GameRules getGameRules() {
return this.gameRules;
}
@OnlyIn(Dist.CLIENT)
public static enum SelectedGameMode {
SURVIVAL("survival", GameType.SURVIVAL),
HARDCORE("hardcore", GameType.SURVIVAL),
CREATIVE("creative", GameType.CREATIVE),
DEBUG("spectator", GameType.SPECTATOR);
public final GameType gameType;
public final Component displayName;
private final Component info;
private SelectedGameMode(String name, GameType gameType) {
this.gameType = gameType;
this.displayName = Component.translatable("selectWorld.gameMode." + name);
this.info = Component.translatable("selectWorld.gameMode." + name + ".info");
}
public Component getInfo() {
return this.info;
}
}
@OnlyIn(Dist.CLIENT)
public record WorldTypeEntry(@Nullable Holder<WorldPreset> preset) {
private static final Component CUSTOM_WORLD_DESCRIPTION = Component.translatable("generator.custom");
public Component describePreset() {
return Optional.ofNullable(this.preset)
.flatMap(Holder::unwrapKey)
.map(key -> (Component)Component.translatable(key.identifier().toLanguageKey("generator")))
.orElse(CUSTOM_WORLD_DESCRIPTION);
}
public boolean isAmplified() {
return Optional.ofNullable(this.preset).flatMap(Holder::unwrapKey).filter(k -> k.equals(WorldPresets.AMPLIFIED)).isPresent();
}
}
}引用的其他类
-
- 引用位置:
方法调用/返回值 - 关联成员:
PresetEditor.flatWorldConfigurator()
- 引用位置:
-
- 引用位置:
参数/字段/构造调用/返回值 - 关联成员:
WorldCreationContext()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FileUtil.findAvailableName()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/构造调用/返回值 - 关联成员:
GameRules()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
WorldOptions.parseSeed()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置: