[Fix] World Recreation crashes for worlds with betterx customizations
This commit is contained in:
parent
c680b19655
commit
15fbf88147
2 changed files with 14 additions and 6 deletions
|
@ -28,6 +28,9 @@ public abstract class CreateWorldScreen_Mixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
public abstract WorldCreationUiState getUiState();
|
public abstract WorldCreationUiState getUiState();
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private boolean recreated;
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void wt_init(
|
private void wt_init(
|
||||||
Minecraft minecraft,
|
Minecraft minecraft,
|
||||||
|
@ -50,6 +53,6 @@ public abstract class CreateWorldScreen_Mixin {
|
||||||
@Inject(method = "createNewWorldDirectory", at = @At("RETURN"))
|
@Inject(method = "createNewWorldDirectory", at = @At("RETURN"))
|
||||||
void wt_createNewWorld(CallbackInfoReturnable<Optional<LevelStorageSource.LevelStorageAccess>> cir) {
|
void wt_createNewWorld(CallbackInfoReturnable<Optional<LevelStorageSource.LevelStorageAccess>> cir) {
|
||||||
WorldBootstrap.InGUI.registryReadyOnNewWorld(this.getUiState().getSettings());
|
WorldBootstrap.InGUI.registryReadyOnNewWorld(this.getUiState().getSettings());
|
||||||
WorldBootstrap.InGUI.setupNewWorld(cir.getReturnValue(), this.getUiState());
|
WorldBootstrap.InGUI.setupNewWorld(cir.getReturnValue(), this.getUiState(), this.recreated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,8 @@ public class WorldBootstrap {
|
||||||
|
|
||||||
public static void setupNewWorld(
|
public static void setupNewWorld(
|
||||||
Optional<LevelStorageSource.LevelStorageAccess> levelStorageAccess,
|
Optional<LevelStorageSource.LevelStorageAccess> levelStorageAccess,
|
||||||
WorldCreationUiState uiState
|
WorldCreationUiState uiState,
|
||||||
|
boolean recreated
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (levelStorageAccess.isPresent()) {
|
if (levelStorageAccess.isPresent()) {
|
||||||
|
@ -172,7 +173,8 @@ public class WorldBootstrap {
|
||||||
Holder<WorldPreset> newPreset = setupNewWorldCommon(
|
Holder<WorldPreset> newPreset = setupNewWorldCommon(
|
||||||
levelStorageAccess.get(),
|
levelStorageAccess.get(),
|
||||||
currentPreset,
|
currentPreset,
|
||||||
uiState.getSettings().selectedDimensions()
|
uiState.getSettings().selectedDimensions(),
|
||||||
|
recreated
|
||||||
);
|
);
|
||||||
if (newPreset != null && newPreset != currentPreset) {
|
if (newPreset != null && newPreset != currentPreset) {
|
||||||
uiState.setWorldType(new WorldCreationUiState.WorldTypeEntry(newPreset));
|
uiState.setWorldType(new WorldCreationUiState.WorldTypeEntry(newPreset));
|
||||||
|
@ -186,11 +188,14 @@ public class WorldBootstrap {
|
||||||
static Holder<WorldPreset> setupNewWorldCommon(
|
static Holder<WorldPreset> setupNewWorldCommon(
|
||||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||||
Holder<WorldPreset> currentPreset,
|
Holder<WorldPreset> currentPreset,
|
||||||
WorldDimensions worldDims
|
WorldDimensions worldDims,
|
||||||
|
boolean recreated
|
||||||
) {
|
) {
|
||||||
final WorldDimensions dimensions;
|
final WorldDimensions dimensions;
|
||||||
if (currentPreset.value() instanceof TogetherWorldPreset t) {
|
if (currentPreset != null && currentPreset.value() instanceof TogetherWorldPreset t) {
|
||||||
dimensions = t.getWorldDimensions();
|
dimensions = t.getWorldDimensions();
|
||||||
|
} else if (recreated) {
|
||||||
|
dimensions = worldDims;
|
||||||
} else {
|
} else {
|
||||||
dimensions = TogetherWorldPreset.getWorldDimensions(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
dimensions = TogetherWorldPreset.getWorldDimensions(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +255,7 @@ public class WorldBootstrap {
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
var levelStorageAccess = levelSource.createAccess(levelID);
|
var levelStorageAccess = levelSource.createAccess(levelID);
|
||||||
InGUI.setupNewWorldCommon(levelStorageAccess, worldPreset, worldDims);
|
InGUI.setupNewWorldCommon(levelStorageAccess, worldPreset, worldDims, false);
|
||||||
levelStorageAccess.close();
|
levelStorageAccess.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
WorldsTogether.LOGGER.error("Failed to initialize data in world", e);
|
WorldsTogether.LOGGER.error("Failed to initialize data in world", e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue