OptimizeWorldScreen.java
net.minecraft.client.gui.screens.worldselection.OptimizeWorldScreen
信息
- 全限定名:net.minecraft.client.gui.screens.worldselection.OptimizeWorldScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.worldselection
- 源码路径:src/main/java/net/minecraft/client/gui/screens/worldselection/OptimizeWorldScreen.java
- 起始行号:L35
- 继承:Screen
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
DIMENSION_COLORS- 类型:
ToIntFunction<ResourceKey<Level>> - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
callback- 类型:
BooleanConsumer - 修饰符:
private final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
upgrader- 类型:
WorldUpgrader - 修饰符:
private final - 源码定位:
L44 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private OptimizeWorldScreen(BooleanConsumer callback, DataFixer dataFixer, LevelStorageSource.LevelStorageAccess levelSource, WorldData worldData, boolean eraseCache, RegistryAccess registryAccess) @ L75
- 构造器名:OptimizeWorldScreen
- 源码定位:L75
- 修饰符:private
参数:
- callback: BooleanConsumer
- dataFixer: DataFixer
- levelSource: LevelStorageSource.LevelStorageAccess
- worldData: WorldData
- eraseCache: boolean
- registryAccess: RegistryAccess
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static OptimizeWorldScreen create(Minecraft minecraft, BooleanConsumer callback, DataFixer dataFixer, LevelStorageSource.LevelStorageAccess levelSourceAccess, boolean eraseCache) @ L46
- 方法名:create
- 源码定位:L46
- 返回类型:OptimizeWorldScreen
- 修饰符:public static
参数:
- minecraft: Minecraft
- callback: BooleanConsumer
- dataFixer: DataFixer
- levelSourceAccess: LevelStorageSource.LevelStorageAccess
- eraseCache: boolean
说明:
TODO
protected void init() @ L88
- 方法名:init
- 源码定位:L88
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public void tick() @ L97
- 方法名:tick
- 源码定位:L97
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean shouldCloseOnEsc() @ L104
- 方法名:shouldCloseOnEsc
- 源码定位:L104
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void onClose() @ L109
- 方法名:onClose
- 源码定位:L109
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void removed() @ L114
- 方法名:removed
- 源码定位:L114
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L120
- 方法名:extractRenderState
- 源码定位:L120
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class OptimizeWorldScreen extends Screen {
private static final Logger LOGGER = LogUtils.getLogger();
private static final ToIntFunction<ResourceKey<Level>> DIMENSION_COLORS = Util.make(new Reference2IntOpenHashMap<>(), map -> {
map.put(Level.OVERWORLD, -13408734);
map.put(Level.NETHER, -10075085);
map.put(Level.END, -8943531);
map.defaultReturnValue(-2236963);
});
private final BooleanConsumer callback;
private final WorldUpgrader upgrader;
public static @Nullable OptimizeWorldScreen create(
Minecraft minecraft, BooleanConsumer callback, DataFixer dataFixer, LevelStorageSource.LevelStorageAccess levelSourceAccess, boolean eraseCache
) {
try {
WorldOpenFlows worldOpenFlows = minecraft.createWorldOpenFlows();
PackRepository packRepository = ServerPacksSource.createPackRepository(levelSourceAccess);
Dynamic<?> unfixedDataTag = levelSourceAccess.getUnfixedDataTagWithFallback();
int dataVersion = NbtUtils.getDataVersion(unfixedDataTag);
if (DataFixers.getFileFixer().requiresFileFixing(dataVersion)) {
throw new IllegalStateException("Can't optimize world before file fixing; shouldn't be able to get here");
} else {
Dynamic<?> dataTag = DataFixTypes.LEVEL.updateToCurrentVersion(DataFixers.getDataFixer(), unfixedDataTag, dataVersion);
OptimizeWorldScreen var13;
try (WorldStem worldStem = worldOpenFlows.loadWorldStem(levelSourceAccess, dataTag, false, packRepository)) {
WorldData worldData = worldStem.worldDataAndGenSettings().data();
RegistryAccess.Frozen registryAccess = worldStem.registries().compositeAccess();
levelSourceAccess.saveDataTag(worldData);
var13 = new OptimizeWorldScreen(callback, dataFixer, levelSourceAccess, worldData, eraseCache, registryAccess);
}
return var13;
}
} catch (Exception var16) {
LOGGER.warn("Failed to load datapacks, can't optimize world", (Throwable)var16);
return null;
}
}
private OptimizeWorldScreen(
BooleanConsumer callback,
DataFixer dataFixer,
LevelStorageSource.LevelStorageAccess levelSource,
WorldData worldData,
boolean eraseCache,
RegistryAccess registryAccess
) {
super(Component.translatable("optimizeWorld.title", worldData.getLevelSettings().levelName()));
this.callback = callback;
this.upgrader = new WorldUpgrader(levelSource, dataFixer, registryAccess, eraseCache, false);
}
@Override
protected void init() {
super.init();
this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> {
this.upgrader.cancel();
this.callback.accept(false);
}).bounds(this.width / 2 - 100, this.height / 4 + 150, 200, 20).build());
}
@Override
public void tick() {
if (this.upgrader.isFinished()) {
this.callback.accept(true);
}
}
@Override
public boolean shouldCloseOnEsc() {
return false;
}
@Override
public void onClose() {
this.callback.accept(false);
}
@Override
public void removed() {
this.upgrader.cancel();
this.upgrader.close();
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractRenderState(graphics, mouseX, mouseY, a);
graphics.centeredText(this.font, this.title, this.width / 2, 20, -1);
int x0 = this.width / 2 - 150;
int x1 = this.width / 2 + 150;
int y0 = this.height / 4 + 100;
int y1 = y0 + 10;
graphics.centeredText(this.font, this.upgrader.getStatus(), this.width / 2, y0 - 9 - 2, -6250336);
if (this.upgrader.getTotalChunks() > 0) {
graphics.fill(x0 - 1, y0 - 1, x1 + 1, y1 + 1, -16777216);
graphics.text(this.font, Component.translatable("optimizeWorld.info.converted", this.upgrader.getConverted()), x0, 40, -6250336);
graphics.text(this.font, Component.translatable("optimizeWorld.info.skipped", this.upgrader.getSkipped()), x0, 40 + 9 + 3, -6250336);
graphics.text(this.font, Component.translatable("optimizeWorld.info.total", this.upgrader.getTotalChunks()), x0, 40 + (9 + 3) * 2, -6250336);
int progress = 0;
for (ResourceKey<Level> dimension : this.upgrader.levels()) {
int length = Mth.floor(this.upgrader.dimensionProgress(dimension) * (x1 - x0));
graphics.fill(x0 + progress, y0, x0 + progress + length, y1, DIMENSION_COLORS.applyAsInt(dimension));
progress += length;
}
int totalProgress = this.upgrader.getConverted() + this.upgrader.getSkipped();
Component countStr = Component.translatable("optimizeWorld.progress.counter", totalProgress, this.upgrader.getTotalChunks());
Component progressStr = Component.translatable("optimizeWorld.progress.percentage", Mth.floor(this.upgrader.getTotalProgress() * 100.0F));
graphics.centeredText(this.font, countStr, this.width / 2, y0 + 2 * 9 + 2, -6250336);
graphics.centeredText(this.font, progressStr, this.width / 2, y0 + (y1 - y0) / 2 - 9 / 2, -6250336);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NbtUtils.getDataVersion()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ServerPacksSource.createPackRepository()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.floor()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.make()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
DataFixers.getDataFixer(), DataFixers.getFileFixer()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
WorldUpgrader()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: