Correct World Preset handling
This commit is contained in:
parent
7466048a22
commit
7359c64fff
13 changed files with 451 additions and 129 deletions
|
@ -30,6 +30,9 @@ import java.util.function.Consumer;
|
|||
public class WorldDataAPI {
|
||||
private static final Map<String, CompoundTag> TAGS = Maps.newHashMap();
|
||||
private static final List<String> MODS = Lists.newArrayList();
|
||||
|
||||
private static final String TAG_CREATED = "create_version";
|
||||
private static final String TAG_MODIFIED = "modify_version";
|
||||
private static File dataDir;
|
||||
|
||||
public static void load(File dataDir) {
|
||||
|
@ -84,11 +87,16 @@ public class WorldDataAPI {
|
|||
CompoundTag root = TAGS.get(modID);
|
||||
if (root == null) {
|
||||
root = new CompoundTag();
|
||||
root.putString(TAG_CREATED, ModUtil.getModVersion(modID));
|
||||
TAGS.put(modID, root);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
public static boolean hasMod(String modID) {
|
||||
return MODS.contains(modID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link CompoundTag} with specified path from mod cache in world data folder.
|
||||
*
|
||||
|
@ -120,7 +128,9 @@ public class WorldDataAPI {
|
|||
if (!dataDir.exists()) {
|
||||
dataDir.mkdirs();
|
||||
}
|
||||
NbtIo.writeCompressed(getRootTag(modID), new File(dataDir, modID + ".nbt"));
|
||||
CompoundTag tag = getRootTag(modID);
|
||||
tag.putString(TAG_MODIFIED, ModUtil.getModVersion(modID));
|
||||
NbtIo.writeCompressed(tag, new File(dataDir, modID + ".nbt"));
|
||||
} catch (IOException e) {
|
||||
BCLib.LOGGER.error("World data saving failed", e);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package org.betterx.bclib.api.datafixer;
|
|||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.toasts.SystemToast;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.worldselection.EditWorldScreen;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.chunk.storage.RegionFile;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess;
|
||||
|
@ -24,6 +24,7 @@ import org.betterx.bclib.gui.screens.ConfirmFixScreen;
|
|||
import org.betterx.bclib.gui.screens.LevelFixErrorScreen;
|
||||
import org.betterx.bclib.gui.screens.LevelFixErrorScreen.Listener;
|
||||
import org.betterx.bclib.gui.screens.ProgressScreen;
|
||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
||||
import org.betterx.bclib.util.Logger;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -160,6 +161,13 @@ public class DataFixerAPI {
|
|||
});
|
||||
}
|
||||
|
||||
public static void createWorldData(LevelStorageSource levelSource, String levelID, WorldGenSettings settings) {
|
||||
wrapCall(levelSource, levelID, (levelStorageAccess) -> {
|
||||
createWorldData(levelStorageAccess, settings);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the DataStorage for this world. If the world is new, the patch registry is initialized to the
|
||||
* current versions of the plugins.
|
||||
|
@ -171,6 +179,12 @@ public class DataFixerAPI {
|
|||
initializeWorldData(access.getLevelPath(LevelResource.ROOT).toFile(), newWorld);
|
||||
}
|
||||
|
||||
public static void createWorldData(LevelStorageAccess access, WorldGenSettings settings) {
|
||||
initializeWorldData(access, true);
|
||||
BCLChunkGenerator.initializeWorldData(settings);
|
||||
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the DataStorage for this world. If the world is new, the patch registry is initialized to the
|
||||
* current versions of the plugins.
|
||||
|
@ -190,8 +204,8 @@ public class DataFixerAPI {
|
|||
@Environment(EnvType.CLIENT)
|
||||
private static AtomicProgressListener showProgressScreen() {
|
||||
ProgressScreen ps = new ProgressScreen(Minecraft.getInstance().screen,
|
||||
Component.translatable("title.bclib.datafixer.progress"),
|
||||
Component.translatable("message.bclib.datafixer.progress"));
|
||||
Component.translatable("title.bclib.datafixer.progress"),
|
||||
Component.translatable("message.bclib.datafixer.progress"));
|
||||
Minecraft.getInstance().setScreen(ps);
|
||||
return ps;
|
||||
}
|
||||
|
@ -298,8 +312,8 @@ public class DataFixerAPI {
|
|||
private static void showLevelFixErrorScreen(State state, Listener onContinue) {
|
||||
Minecraft.getInstance()
|
||||
.setScreen(new LevelFixErrorScreen(Minecraft.getInstance().screen,
|
||||
state.getErrorMessages(),
|
||||
onContinue));
|
||||
state.getErrorMessages(),
|
||||
onContinue));
|
||||
}
|
||||
|
||||
private static MigrationProfile loadProfileIfNeeded(File levelBaseDir) {
|
||||
|
@ -511,8 +525,8 @@ public class DataFixerAPI {
|
|||
|
||||
try {
|
||||
changed[0] |= data.patchBlockState(palette,
|
||||
((CompoundTag) tag).getList("BlockStates",
|
||||
Tag.TAG_LONG));
|
||||
((CompoundTag) tag).getList("BlockStates",
|
||||
Tag.TAG_LONG));
|
||||
} catch (PatchDidiFailException e) {
|
||||
BCLib.LOGGER.error("Failed fixing BlockState in " + pos);
|
||||
state.addError("Failed fixing BlockState in " + pos + " (" + e.getMessage() + ")");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue