diff --git a/gradle.properties b/gradle.properties
index 6f070ed4..a38c31df 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -5,8 +5,8 @@ loom_version=0.12-SNAPSHOT
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.19
-loader_version=0.14.7
-fabric_version=0.56.0+1.19
+loader_version=0.14.8
+fabric_version=0.56.1+1.19
# Mod Properties
mod_version=2.0.6
maven_group=org.betterx.bclib
diff --git a/src/main/java/org/betterx/bclib/BCLib.java b/src/main/java/org/betterx/bclib/BCLib.java
index a2df8ba0..74c13d2e 100644
--- a/src/main/java/org/betterx/bclib/BCLib.java
+++ b/src/main/java/org/betterx/bclib/BCLib.java
@@ -1,11 +1,11 @@
package org.betterx.bclib;
-import org.betterx.bclib.api.v2.WorldDataAPI;
import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.*;
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource;
import org.betterx.bclib.api.v2.generator.GeneratorOptions;
+import org.betterx.bclib.api.v2.levelgen.LevelGenEvents;
import org.betterx.bclib.api.v2.levelgen.features.blockpredicates.Types;
import org.betterx.bclib.api.v2.levelgen.features.placement.PlacementModifiers;
import org.betterx.bclib.api.v2.levelgen.structures.TemplatePiece;
@@ -13,12 +13,13 @@ import org.betterx.bclib.api.v2.levelgen.surface.rules.Conditions;
import org.betterx.bclib.api.v2.tag.TagAPI;
import org.betterx.bclib.commands.CommandRegistry;
import org.betterx.bclib.config.Configs;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
import org.betterx.bclib.recipes.AnvilRecipe;
import org.betterx.bclib.recipes.CraftingRecipes;
import org.betterx.bclib.registry.BaseBlockEntities;
import org.betterx.bclib.registry.BaseRegistry;
import org.betterx.bclib.util.Logger;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.world.WorldConfig;
import net.minecraft.resources.ResourceLocation;
@@ -30,15 +31,12 @@ import java.util.List;
public class BCLib implements ModInitializer {
public static final String MOD_ID = "bclib";
- public static final String TOGETHER_WORLDS = "worlds_together";
public static final Logger LOGGER = new Logger(MOD_ID);
- public static final boolean RUNS_TERRABLENDER = FabricLoader.getInstance()
- .getModContainer("terrablender")
- .isPresent();
-
@Override
public void onInitialize() {
+ LevelGenEvents.register();
+ WorldsTogether.onInitialize();
Types.ensureStaticInitialization();
BaseRegistry.register();
GeneratorOptions.init();
@@ -47,10 +45,8 @@ public class BCLib implements ModInitializer {
BCLibNetherBiomeSource.register();
TagAPI.init();
CraftingRecipes.init();
- WorldDataAPI.registerModCache(MOD_ID);
- WorldDataAPI.registerModCache(TOGETHER_WORLDS);
+ WorldConfig.registerModCache(MOD_ID);
DataExchangeAPI.registerMod(MOD_ID);
- BCLWorldPresets.registerPresets();
AnvilRecipe.register();
Conditions.registerAll();
CommandRegistry.register();
diff --git a/src/main/java/org/betterx/bclib/api/v2/LifeCycleAPI.java b/src/main/java/org/betterx/bclib/api/v2/LifeCycleAPI.java
index e237ccd4..0cd78a48 100644
--- a/src/main/java/org/betterx/bclib/api/v2/LifeCycleAPI.java
+++ b/src/main/java/org/betterx/bclib/api/v2/LifeCycleAPI.java
@@ -28,7 +28,7 @@ public class LifeCycleAPI {
/**
* Register a callback that is called before a level is loaded or created,
- * but after the {@link WorldDataAPI} was initialized and patches from
+ * but after the {@link org.betterx.worlds.together.world.WorldConfig} was initialized and patches from
* the {@link DataFixerAPI} were applied.
*
* @param call The callback Method
diff --git a/src/main/java/org/betterx/bclib/api/v2/WorldDataAPI.java b/src/main/java/org/betterx/bclib/api/v2/WorldDataAPI.java
index 3602df50..f3814f75 100644
--- a/src/main/java/org/betterx/bclib/api/v2/WorldDataAPI.java
+++ b/src/main/java/org/betterx/bclib/api/v2/WorldDataAPI.java
@@ -1,164 +1,77 @@
package org.betterx.bclib.api.v2;
-import org.betterx.bclib.BCLib;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.world.WorldConfig;
-import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
-import net.minecraft.nbt.NbtIo;
-
-import net.fabricmc.loader.api.FabricLoader;
-import net.fabricmc.loader.api.ModContainer;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
/**
- * Mod-specifix data-storage for a world.
- *
- * This class provides the ability for mod to store persistent data inside a world. The Storage for the world is
- * currently initialized as part of the {@link org.betterx.bclib.presets.worldgen.WorldBootstrap} in
- * org.betterx.bclib.presets.worldgen.WorldBootstrap.Helpers#initializeWorldDataAPI(File, boolean)
+ * @deprecated Implementation moved to {@link WorldConfig}
*/
+@Deprecated(forRemoval = true)
public class WorldDataAPI {
- private static final Map TAGS = Maps.newHashMap();
- private static final List MODS = Lists.newArrayList();
-
- private static final String TAG_CREATED = "create_version";
- private static final String TAG_MODIFIED = "modify_version";
- private static File dataDir;
-
+ /**
+ * @deprecated use {@link WorldConfig#load(File)} instead
+ */
+ @Deprecated(forRemoval = true)
public static void load(File dataDir) {
- WorldDataAPI.dataDir = dataDir;
- MODS.stream()
- .parallel()
- .forEach(modID -> {
- File file = new File(dataDir, modID + ".nbt");
- CompoundTag root = new CompoundTag();
- if (file.exists()) {
- try {
- root = NbtIo.readCompressed(file);
- } catch (IOException e) {
- BCLib.LOGGER.error("World data loading failed", e);
- }
- TAGS.put(modID, root);
- } else {
- Optional optional = FabricLoader.getInstance()
- .getModContainer(modID);
- if (optional.isPresent()) {
- ModContainer modContainer = optional.get();
- if (BCLib.isDevEnvironment()) {
- root.putString("version", "255.255.9999");
- } else {
- root.putString("version", modContainer.getMetadata()
- .getVersion()
- .toString());
- }
- TAGS.put(modID, root);
- saveFile(modID);
- }
- }
- });
+ WorldConfig.load(dataDir);
}
/**
- * Register mod cache, world cache is located in world data folder.
- *
- * @param modID - {@link String} modID.
+ * @deprecated use {@link WorldConfig#registerModCache(String)} instead
*/
+ @Deprecated(forRemoval = true)
public static void registerModCache(String modID) {
- if (!MODS.contains(modID))
- MODS.add(modID);
+ WorldConfig.registerModCache(modID);
}
/**
- * Get root {@link CompoundTag} for mod cache in world data folder.
- *
- * @param modID - {@link String} modID.
- * @return {@link CompoundTag}
+ * @deprecated use {@link WorldConfig#getRootTag(String)} instead
*/
+ @Deprecated(forRemoval = true)
public static CompoundTag getRootTag(String modID) {
- CompoundTag root = TAGS.get(modID);
- if (root == null) {
- root = new CompoundTag();
- root.putString(TAG_CREATED, ModUtil.getModVersion(modID));
- TAGS.put(modID, root);
- }
- return root;
+ return WorldConfig.getRootTag(modID);
}
+ /**
+ * @deprecated use {@link WorldConfig#hasMod(String)} instead
+ */
+ @Deprecated(forRemoval = true)
public static boolean hasMod(String modID) {
- return MODS.contains(modID);
+ return WorldConfig.hasMod(modID);
}
/**
- * Get {@link CompoundTag} with specified path from mod cache in world data folder.
- *
- * @param modID - {@link String} path to tag, dot-separated.
- * @return {@link CompoundTag}
+ * @deprecated use {@link WorldConfig#getCompoundTag(String, String)} instead
*/
+ @Deprecated(forRemoval = true)
public static CompoundTag getCompoundTag(String modID, String path) {
- String[] parts = path.split("\\.");
- CompoundTag tag = getRootTag(modID);
- for (String part : parts) {
- if (tag.contains(part)) {
- tag = tag.getCompound(part);
- } else {
- CompoundTag t = new CompoundTag();
- tag.put(part, t);
- tag = t;
- }
- }
- return tag;
+ return WorldConfig.getCompoundTag(modID, path);
}
/**
- * Forces mod cache file to be saved.
- *
- * @param modID {@link String} mod ID.
+ * @deprecated use {@link WorldConfig#saveFile(String)} instead
*/
+ @Deprecated(forRemoval = true)
public static void saveFile(String modID) {
-
- try {
- if (!dataDir.exists()) {
- dataDir.mkdirs();
- }
- CompoundTag tag = getRootTag(modID);
- tag.putString(TAG_MODIFIED, ModUtil.getModVersion(modID));
-
-
- final File tempFile = new File(dataDir, modID + "_temp.nbt");
- NbtIo.writeCompressed(tag, tempFile);
-
- final File oldFile = new File(dataDir, modID + "_old.nbt");
- final File dataFile = new File(dataDir, modID + ".nbt");
- Util.safeReplaceFile(dataFile, tempFile, oldFile);
- } catch (IOException e) {
- BCLib.LOGGER.error("World data saving failed", e);
- }
+ WorldConfig.saveFile(modID);
}
/**
- * Get stored mod version (only for mods with registered cache).
- *
- * @return {@link String} mod version.
+ * @deprecated use {@link WorldConfig#getModVersion(String)} instead
*/
+ @Deprecated(forRemoval = true)
public static String getModVersion(String modID) {
- return getRootTag(modID).getString("version");
+ return WorldConfig.getModVersion(modID);
}
/**
- * Get stored mod version as integer (only for mods with registered cache).
- *
- * @return {@code int} mod version.
+ * @deprecated use {@link WorldConfig#getIntModVersion(String)} instead
*/
+ @Deprecated(forRemoval = true)
public static int getIntModVersion(String modID) {
- return ModUtil.convertModVersion(getModVersion(modID));
+ return WorldConfig.getIntModVersion(modID);
}
}
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java
index b8368fbe..120267dd 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java
@@ -5,7 +5,7 @@ import org.betterx.bclib.api.v2.dataexchange.handler.DataExchange;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSync;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSyncID;
import org.betterx.bclib.config.Config;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.network.FriendlyByteBuf;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoFileSyncEntry.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoFileSyncEntry.java
index 05c60d71..17a3920f 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoFileSyncEntry.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoFileSyncEntry.java
@@ -3,11 +3,11 @@ package org.betterx.bclib.api.v2.dataexchange.handler.autosync;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.dataexchange.DataHandler;
import org.betterx.bclib.api.v2.dataexchange.SyncFileHash;
-import org.betterx.bclib.util.ModUtil;
-import org.betterx.bclib.util.ModUtil.ModInfo;
import org.betterx.bclib.util.Pair;
-import org.betterx.bclib.util.PathUtil;
import org.betterx.bclib.util.Triple;
+import org.betterx.worlds.together.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil.ModInfo;
+import org.betterx.worlds.together.util.PathUtil;
import net.minecraft.network.FriendlyByteBuf;
@@ -200,7 +200,10 @@ class AutoFileSyncEntry extends AutoSyncID {
}
private int serializeFileContent(FriendlyByteBuf buf) {
- if (!PathUtil.isChildOf(PathUtil.GAME_FOLDER, fileName.toPath())) {
+ if (!org.betterx.worlds.together.util.PathUtil.isChildOf(
+ org.betterx.worlds.together.util.PathUtil.GAME_FOLDER,
+ fileName.toPath()
+ )) {
BCLib.LOGGER.error(fileName + " is not within game folder " + PathUtil.GAME_FOLDER + ". Pretending it does not exist.");
buf.writeInt(0);
return 0;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSync.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSync.java
index 5604d5e0..64a3811d 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSync.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSync.java
@@ -5,7 +5,7 @@ import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
import org.betterx.bclib.api.v2.dataexchange.SyncFileHash;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.config.ServerConfig;
-import org.betterx.bclib.util.PathUtil;
+import org.betterx.worlds.together.util.PathUtil;
import net.fabricmc.loader.api.FabricLoader;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSyncID.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSyncID.java
index e9fa8412..b8ace9bc 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSyncID.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/AutoSyncID.java
@@ -2,7 +2,7 @@ package org.betterx.bclib.api.v2.dataexchange.handler.autosync;
import org.betterx.bclib.api.v2.dataexchange.DataHandler;
import org.betterx.bclib.config.Config;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.network.FriendlyByteBuf;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java
index 875a8cbd..31e883f6 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java
@@ -10,9 +10,9 @@ import org.betterx.bclib.client.gui.screens.SyncFilesScreen;
import org.betterx.bclib.client.gui.screens.WarnBCLibVersionMismatch;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.config.ServerConfig;
-import org.betterx.bclib.util.ModUtil;
-import org.betterx.bclib.util.ModUtil.ModInfo;
-import org.betterx.bclib.util.PathUtil;
+import org.betterx.worlds.together.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil.ModInfo;
+import org.betterx.worlds.together.util.PathUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloServer.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloServer.java
index 6b7b7140..df1994fa 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloServer.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloServer.java
@@ -5,7 +5,7 @@ import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
import org.betterx.bclib.api.v2.dataexchange.DataHandler;
import org.betterx.bclib.api.v2.dataexchange.DataHandlerDescriptor;
import org.betterx.bclib.config.Configs;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java
index 9ca66919..5d16a6f5 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java
@@ -6,8 +6,8 @@ import org.betterx.bclib.api.v2.dataexchange.DataHandlerDescriptor;
import org.betterx.bclib.client.gui.screens.ConfirmRestartScreen;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.util.Pair;
-import org.betterx.bclib.util.PathUtil;
import org.betterx.bclib.util.Triple;
+import org.betterx.worlds.together.util.PathUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java
index ffa8c930..b214047b 100644
--- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java
+++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java
@@ -5,7 +5,7 @@ import org.betterx.bclib.api.v2.dataexchange.DataHandler;
import org.betterx.bclib.api.v2.dataexchange.FileHash;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSyncID.ForDirectFileRequest;
import org.betterx.bclib.config.Configs;
-import org.betterx.bclib.util.PathUtil;
+import org.betterx.worlds.together.util.PathUtil;
import net.minecraft.network.FriendlyByteBuf;
diff --git a/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java b/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java
index f1855450..54277511 100644
--- a/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java
+++ b/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java
@@ -1,7 +1,6 @@
package org.betterx.bclib.api.v2.datafixer;
import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.WorldDataAPI;
import org.betterx.bclib.client.gui.screens.AtomicProgressListener;
import org.betterx.bclib.client.gui.screens.ConfirmFixScreen;
import org.betterx.bclib.client.gui.screens.LevelFixErrorScreen;
@@ -9,6 +8,7 @@ import org.betterx.bclib.client.gui.screens.LevelFixErrorScreen.Listener;
import org.betterx.bclib.client.gui.screens.ProgressScreen;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.util.Logger;
+import org.betterx.worlds.together.world.WorldConfig;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
@@ -141,7 +141,7 @@ public class DataFixerAPI {
*/
public static void initializePatchData() {
getMigrationProfile().markApplied();
- WorldDataAPI.saveFile(BCLib.MOD_ID);
+ WorldConfig.saveFile(BCLib.MOD_ID);
}
@@ -283,7 +283,7 @@ public class DataFixerAPI {
@NotNull
private static MigrationProfile getMigrationProfile() {
- final CompoundTag patchConfig = WorldDataAPI.getCompoundTag(BCLib.MOD_ID, Configs.MAIN_PATCH_CATEGORY);
+ final CompoundTag patchConfig = WorldConfig.getCompoundTag(BCLib.MOD_ID, Configs.MAIN_PATCH_CATEGORY);
MigrationProfile profile = Patch.createMigrationData(patchConfig);
return profile;
}
@@ -332,7 +332,7 @@ public class DataFixerAPI {
if (!state.didFail) {
progress.progressStage(Component.translatable("message.bclib.datafixer.progress.saving"));
profile.markApplied();
- WorldDataAPI.saveFile(BCLib.MOD_ID);
+ WorldConfig.saveFile(BCLib.MOD_ID);
}
progress.incAtomic(maxProgress);
@@ -511,7 +511,7 @@ public class DataFixerAPI {
static CompoundTag getPatchData() {
if (patchConfTag == null) {
- patchConfTag = WorldDataAPI.getCompoundTag(BCLib.MOD_ID, Configs.MAIN_PATCH_CATEGORY);
+ patchConfTag = WorldConfig.getCompoundTag(BCLib.MOD_ID, Configs.MAIN_PATCH_CATEGORY);
}
return patchConfTag;
}
diff --git a/src/main/java/org/betterx/bclib/api/v2/datafixer/MigrationProfile.java b/src/main/java/org/betterx/bclib/api/v2/datafixer/MigrationProfile.java
index 9e2d51fa..931773ca 100644
--- a/src/main/java/org/betterx/bclib/api/v2/datafixer/MigrationProfile.java
+++ b/src/main/java/org/betterx/bclib/api/v2/datafixer/MigrationProfile.java
@@ -1,10 +1,10 @@
package org.betterx.bclib.api.v2.datafixer;
import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.WorldDataAPI;
import org.betterx.bclib.interfaces.PatchBiFunction;
import org.betterx.bclib.interfaces.PatchFunction;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil;
+import org.betterx.worlds.together.world.WorldConfig;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@@ -344,22 +344,22 @@ public class MigrationProfile {
public void patchWorldData() throws PatchDidiFailException {
for (Patch patch : worldDataPatchers) {
- CompoundTag root = WorldDataAPI.getRootTag(patch.modID);
+ CompoundTag root = WorldConfig.getRootTag(patch.modID);
boolean changed = patch.getWorldDataPatcher().apply(root, this);
if (changed) {
- WorldDataAPI.saveFile(patch.modID);
+ WorldConfig.saveFile(patch.modID);
}
}
for (Map.Entry> entry : worldDataIDPaths.entrySet()) {
- CompoundTag root = WorldDataAPI.getRootTag(entry.getKey());
+ CompoundTag root = WorldConfig.getRootTag(entry.getKey());
boolean[] changed = {false};
entry.getValue().forEach(path -> {
changed[0] |= replaceIDatPath(root, path);
});
if (changed[0]) {
- WorldDataAPI.saveFile(entry.getKey());
+ WorldConfig.saveFile(entry.getKey());
}
}
}
diff --git a/src/main/java/org/betterx/bclib/api/v2/datafixer/Patch.java b/src/main/java/org/betterx/bclib/api/v2/datafixer/Patch.java
index d98e01c9..cadf2ec3 100644
--- a/src/main/java/org/betterx/bclib/api/v2/datafixer/Patch.java
+++ b/src/main/java/org/betterx/bclib/api/v2/datafixer/Patch.java
@@ -1,9 +1,8 @@
package org.betterx.bclib.api.v2.datafixer;
-import org.betterx.bclib.api.v2.WorldDataAPI;
import org.betterx.bclib.interfaces.PatchBiFunction;
import org.betterx.bclib.interfaces.PatchFunction;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@@ -149,7 +148,7 @@ public abstract class Patch {
/**
* Return a {@link PatchFunction} that is called with the content from the
- * {@link WorldDataAPI} for this Mod.
+ * {@link org.betterx.worlds.together.world.WorldConfig} for this Mod.
* The function needs to return {@code true}, if changes were made to the data.
* If an error occurs, the method should throw a {@link PatchDidiFailException}
*
@@ -202,7 +201,7 @@ public abstract class Patch {
}
/**
- * Returns a list of paths where your mod stores IDs in your {@link WorldDataAPI}-File.
+ * Returns a list of paths where your mod stores IDs in your {@link org.betterx.worlds.together.world.WorldConfig}-File.
*
* {@link DataFixerAPI} will use information from the latest patch that returns a non-null-result. This list is used
* to automatically fix changed IDs from all active patches (see {@link Patch#getIDReplacements()}
@@ -229,8 +228,8 @@ public abstract class Patch {
* if the leaf-entry is a {@link net.minecraft.nbt.ListTag}, it is handle the same as a child items entry
* of a {@link CompoundTag}.
*
- * @return {@code null} if nothing changes or a list of Paths in your {@link WorldDataAPI}-File.
- * Paths are dot-seperated (see {@link WorldDataAPI#getCompoundTag(String, String)}).
+ * @return {@code null} if nothing changes or a list of Paths in your {@link org.betterx.worlds.together.world.WorldConfig}-File.
+ * Paths are dot-seperated (see {@link org.betterx.worlds.together.world.WorldConfig#getCompoundTag(String, String)}).
*/
public List getWorldDataIDPaths() {
return null;
diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java
index ffc8ff3e..6aa079d9 100644
--- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java
+++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java
@@ -1,6 +1,7 @@
package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
+import org.betterx.worlds.together.world.BiomeSourceWithSeed;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
@@ -15,7 +16,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
-public abstract class BCLBiomeSource extends BiomeSource {
+public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed {
public static int BIOME_SOURCE_VERSION_NONE = -1;
public static int BIOME_SOURCE_VERSION_VANILLA = 0;
public static int BIOME_SOURCE_VERSION_SQUARE = 17;
diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLChunkGenerator.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLChunkGenerator.java
index 1fe8b2b1..85fe2def 100644
--- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLChunkGenerator.java
+++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLChunkGenerator.java
@@ -1,12 +1,13 @@
package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
import org.betterx.bclib.mixin.common.ChunkGeneratorAccessor;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.world.WorldGenUtil;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
@@ -73,7 +74,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
bcl.setMaxHeight(holder.value().noiseSettings().height());
}
- if (BCLib.RUNS_TERRABLENDER) {
+ if (WorldsTogether.RUNS_TERRABLENDER) {
BCLib.LOGGER.info("Make sure features are loaded from terrablender for " + biomeSource);
//terrablender is invalidating the feature initialization
@@ -99,7 +100,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
public void restoreInitialBiomeSource() {
if (initialBiomeSource != getBiomeSource()) {
if (this instanceof ChunkGeneratorAccessor acc) {
- BiomeSource bs = LevelGenUtil.getWorldSettings()
+ BiomeSource bs = WorldGenUtil.getWorldSettings()
.fixBiomeSource(initialBiomeSource, getBiomeSource().possibleBiomes());
acc.bcl_setBiomeSource(bs);
rebuildFeaturesPerStep(getBiomeSource());
diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java
index 1f18c22e..81a41f61 100644
--- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java
+++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java
@@ -3,7 +3,6 @@ package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.generator.map.hex.HexBiomeMap;
import org.betterx.bclib.api.v2.generator.map.square.SquareBiomeMap;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
@@ -12,6 +11,7 @@ import org.betterx.bclib.interfaces.BiomeMap;
import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
import org.betterx.bclib.noise.OpenSimplexNoise;
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
+import org.betterx.worlds.together.world.WorldGenUtil;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
@@ -97,7 +97,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
boolean initMaps
) {
super(biomeRegistry, list, seed, version);
- if (LevelGenUtil.getWorldSettings() instanceof BCLWorldPresetSettings settings) {
+ if (WorldGenUtil.getWorldSettings() instanceof BCLWorldPresetSettings settings) {
generateEndVoids = settings.generateEndVoid;
} else {
generateEndVoids = true;
@@ -164,7 +164,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
this.centerBiome = biomeRegistry.getOrCreateHolderOrThrow(Biomes.THE_END);
this.barrens = biomeRegistry.getOrCreateHolderOrThrow(Biomes.END_BARRENS);
- if (LevelGenUtil.getWorldSettings() instanceof BCLWorldPresetSettings settings
+ if (WorldGenUtil.getWorldSettings() instanceof BCLWorldPresetSettings settings
&& !settings.useEndTerrainGenerator) {
this.endLandFunction = null;
} else {
diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java
new file mode 100644
index 00000000..92ca6425
--- /dev/null
+++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java
@@ -0,0 +1,119 @@
+package org.betterx.bclib.api.v2.levelgen;
+
+import org.betterx.bclib.BCLib;
+import org.betterx.bclib.api.v2.LifeCycleAPI;
+import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
+import org.betterx.bclib.api.v2.datafixer.DataFixerAPI;
+import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
+import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
+import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
+import org.betterx.bclib.registry.PresetsRegistry;
+import org.betterx.worlds.together.world.event.WorldEvents;
+import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+
+import net.minecraft.core.Holder;
+import net.minecraft.core.RegistryAccess;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.world.level.dimension.LevelStem;
+import net.minecraft.world.level.levelgen.WorldGenSettings;
+import net.minecraft.world.level.levelgen.presets.WorldPreset;
+import net.minecraft.world.level.storage.LevelStorageSource;
+
+import java.util.Optional;
+import java.util.function.Consumer;
+
+public class LevelGenEvents {
+ public static void setupWorld() {
+ InternalBiomeAPI.prepareNewLevel();
+ DataExchangeAPI.prepareServerside();
+ }
+
+ public static void register() {
+ WorldEvents.BEFORE_WORLD_LOAD.on(LevelGenEvents::prepareWorld);
+ WorldEvents.BEFORE_SERVER_WORLD_LOAD.on(LevelGenEvents::prepareServerWorld);
+
+ WorldEvents.ON_WORLD_LOAD.on(LevelGenEvents::onWorldLoad);
+ WorldEvents.WORLD_REGISTRY_READY.on(LevelGenEvents::onRegistryReady);
+
+ WorldEvents.PATCH_WORLD.on(LevelGenEvents::patchExistingWorld);
+ WorldEvents.ADAPT_WORLD_PRESET.on(LevelGenEvents::adaptWorldPresetSettings);
+ }
+
+ public static boolean patchExistingWorld(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ Consumer allDone
+ ) {
+ return DataFixerAPI.fixData(storageAccess, true, allDone);
+ }
+
+ public static Optional> adaptWorldPresetSettings(
+ Optional> currentPreset,
+ WorldGenSettings worldGenSettings
+ ) {
+ LevelStem endStem = worldGenSettings.dimensions().get(LevelStem.END);
+
+ //We probably loaded a Datapack for the End
+ if (!(endStem.generator().getBiomeSource() instanceof BCLibEndBiomeSource)) {
+ BCLib.LOGGER.info("Detected Datapack for END.");
+
+ if (currentPreset.isPresent()) {
+ if (currentPreset.get().value() instanceof TogetherWorldPreset worldPreset) {
+ ResourceKey key = currentPreset.get().unwrapKey().orElse(null);
+ //user did not configure the Preset!
+ if (PresetsRegistry.BCL_WORLD.equals(key) || PresetsRegistry.BCL_WORLD_17.equals(key)) {
+ if (worldPreset.settings instanceof BCLWorldPresetSettings settings) {
+ BCLib.LOGGER.info("Changing Default WorldPreset Settings for Datapack use.");
+
+ worldPreset = worldPreset.withSettings(new BCLWorldPresetSettings(
+ settings.netherVersion,
+ settings.endVersion,
+ false,
+ false
+ ));
+ currentPreset = Optional.of(Holder.direct(worldPreset));
+ }
+ }
+ }
+ }
+ }
+ return currentPreset;
+ }
+
+ public static void onRegistryReady(RegistryAccess a) {
+ InternalBiomeAPI.initRegistry(a);
+ }
+
+ public static WorldPresetSettings prepareWorld(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ WorldPresetSettings settings,
+ boolean isNewWorld
+ ) {
+ setupWorld();
+ if (isNewWorld) {
+ DataFixerAPI.initializePatchData();
+ }
+ return settings;
+ }
+
+ public static WorldPresetSettings prepareServerWorld(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ WorldPresetSettings settings,
+ boolean isNewWorld
+ ) {
+ setupWorld();
+
+ if (isNewWorld) {
+ DataFixerAPI.initializePatchData();
+ } else {
+ DataFixerAPI.fixData(storageAccess, false, (didFix) -> {/* not called when showUI==false */});
+ }
+
+
+ return settings;
+ }
+
+ public static void onWorldLoad() {
+ LifeCycleAPI._runBeforeLevelLoad();
+ }
+}
diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenUtil.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenUtil.java
index 7321d19c..3b70fc2b 100644
--- a/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenUtil.java
+++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenUtil.java
@@ -1,41 +1,29 @@
package org.betterx.bclib.api.v2.levelgen;
import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.WorldDataAPI;
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
import org.betterx.bclib.api.v2.generator.BCLChunkGenerator;
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource;
-import org.betterx.bclib.presets.worldgen.BCLWorldPreset;
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
-import org.betterx.bclib.presets.worldgen.WorldPresetSettings;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.bclib.registry.PresetsRegistry;
+import org.betterx.worlds.together.util.ModUtil;
+import org.betterx.worlds.together.world.WorldConfig;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
-import com.mojang.datafixers.util.Pair;
-import com.mojang.serialization.Dynamic;
import com.mojang.serialization.Lifecycle;
import net.minecraft.core.Holder;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
-import net.minecraft.data.BuiltinRegistries;
import net.minecraft.nbt.CompoundTag;
-import net.minecraft.nbt.NbtOps;
-import net.minecraft.nbt.Tag;
-import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
-import net.minecraft.util.RandomSource;
-import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
-import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings;
-import net.minecraft.world.level.levelgen.presets.WorldPreset;
-import net.minecraft.world.level.levelgen.structure.StructureSet;
-import net.minecraft.world.level.levelgen.synth.NormalNoise;
import java.util.Map;
import java.util.Optional;
@@ -44,15 +32,14 @@ import org.jetbrains.annotations.NotNull;
public class LevelGenUtil {
private static final String TAG_VERSION = "version";
private static final String TAG_BN_GEN_VERSION = "generator_version";
- public static final String TAG_GENERATOR = "generator";
@NotNull
- public static LevelStem getBCLNetherLevelStem(Context context, Optional version) {
+ public static LevelStem getBCLNetherLevelStem(WorldGenUtil.Context context, Optional version) {
BCLibNetherBiomeSource netherSource = new BCLibNetherBiomeSource(context.biomes, version);
return getBCLNetherLevelStem(context, netherSource);
}
- public static LevelStem getBCLNetherLevelStem(StemContext context, BiomeSource biomeSource) {
+ public static LevelStem getBCLNetherLevelStem(WorldGenUtil.StemContext context, BiomeSource biomeSource) {
return new LevelStem(
context.dimension,
new BCLChunkGenerator(
@@ -65,7 +52,7 @@ public class LevelGenUtil {
}
@NotNull
- public static LevelStem getBCLEndLevelStem(StemContext context, BiomeSource biomeSource) {
+ public static LevelStem getBCLEndLevelStem(WorldGenUtil.StemContext context, BiomeSource biomeSource) {
return new LevelStem(
context.dimension,
new BCLChunkGenerator(
@@ -77,60 +64,11 @@ public class LevelGenUtil {
);
}
- public static LevelStem getBCLEndLevelStem(Context context, Optional version) {
+ public static LevelStem getBCLEndLevelStem(WorldGenUtil.Context context, Optional version) {
BCLibEndBiomeSource endSource = new BCLibEndBiomeSource(context.biomes, version);
return getBCLEndLevelStem(context, endSource);
}
- public static WorldGenSettings createWorldFromPreset(
- ResourceKey preset,
- RegistryAccess registryAccess,
- long seed,
- boolean generateStructures,
- boolean generateBonusChest
- ) {
- WorldGenSettings settings = registryAccess
- .registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
- .getHolderOrThrow(preset)
- .value()
- .createWorldGenSettings(seed, generateStructures, generateBonusChest);
-
- for (LevelStem stem : settings.dimensions()) {
- if (stem.generator().getBiomeSource() instanceof BCLBiomeSource bcl) {
- bcl.setSeed(seed);
- }
- }
-
- return settings;
- }
-
- public static WorldGenSettings createDefaultWorldFromPreset(
- RegistryAccess registryAccess,
- long seed,
- boolean generateStructures,
- boolean generateBonusChest
- ) {
- return createWorldFromPreset(
- BCLWorldPresets.DEFAULT.orElseThrow(),
- registryAccess,
- seed,
- generateStructures,
- generateBonusChest
- );
- }
-
- public static Pair defaultWorldDataSupplier(RegistryAccess.Frozen frozen) {
- WorldGenSettings worldGenSettings = createDefaultWorldFromPreset(frozen);
- return Pair.of(worldGenSettings, frozen);
- }
-
- public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess, long seed) {
- return createDefaultWorldFromPreset(registryAccess, seed, true, false);
- }
-
- public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess) {
- return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
- }
public static WorldGenSettings replaceGenerator(
ResourceKey dimensionKey,
@@ -261,15 +199,15 @@ public class LevelGenUtil {
generateBonusChest
);
} else if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE) {
- referenceSettings = createWorldFromPreset(
- BCLWorldPresets.BCL_WORLD_17,
+ referenceSettings = WorldGenUtil.createWorldFromPreset(
+ PresetsRegistry.BCL_WORLD_17,
registryAccess,
seed,
generateStructures,
generateBonusChest
);
} else {
- referenceSettings = createDefaultWorldFromPreset(
+ referenceSettings = WorldGenUtil.createDefaultWorldFromPreset(
registryAccess,
seed,
generateStructures,
@@ -280,7 +218,7 @@ public class LevelGenUtil {
}
public static int getBiomeVersionForCurrentWorld(ResourceKey key) {
- final CompoundTag settingsNbt = getSettingsNbt();
+ final CompoundTag settingsNbt = WorldGenUtil.getSettingsNbt();
if (!settingsNbt.contains(key.location().toString())) return BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
return settingsNbt.getInt(key.location().toString());
}
@@ -305,30 +243,14 @@ public class LevelGenUtil {
generatorSettings.putInt(key.location().toString(), getDimensionVersion(settings, key));
}
- static CompoundTag getSettingsNbt() {
- return WorldDataAPI.getCompoundTag(BCLib.TOGETHER_WORLDS, TAG_GENERATOR);
- }
-
- public static WorldPresetSettings getWorldSettings() {
- if (BuiltinRegistries.ACCESS == null) return null;
- final RegistryAccess registryAccess = BuiltinRegistries.ACCESS;
- final RegistryOps registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
-
- Optional oLevelStem = WorldPresetSettings.CODEC
- .parse(new Dynamic<>(registryOps, getSettingsNbt()))
- .resultOrPartial(BCLib.LOGGER::error);
-
- return oLevelStem.orElse(BCLWorldPresetSettings.DEFAULT);
- }
-
public static void migrateGeneratorSettings() {
- final CompoundTag settingsNbt = getSettingsNbt();
+ final CompoundTag settingsNbt = WorldGenUtil.getSettingsNbt();
if (settingsNbt.size() == 0) {
BCLib.LOGGER.info("Found World without generator Settings. Setting up data...");
int biomeSourceVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
- final CompoundTag bclRoot = WorldDataAPI.getRootTag(BCLib.MOD_ID);
+ final CompoundTag bclRoot = WorldConfig.getRootTag(BCLib.MOD_ID);
String bclVersion = "0.0.0";
if (bclRoot.contains(TAG_VERSION)) {
@@ -341,16 +263,16 @@ public class LevelGenUtil {
biomeSourceVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
}
- if (WorldDataAPI.hasMod("betternether")) {
+ if (WorldConfig.hasMod("betternether")) {
BCLib.LOGGER.info("Found Data from BetterNether, using for migration.");
- final CompoundTag bnRoot = WorldDataAPI.getRootTag("betternether");
+ final CompoundTag bnRoot = WorldConfig.getRootTag("betternether");
biomeSourceVersion = "1.17".equals(bnRoot.getString(TAG_BN_GEN_VERSION))
? BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE
: BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
}
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
- BCLWorldPreset.writeWorldPresetSettings(new BCLWorldPresetSettings(
+ TogetherWorldPreset.writeWorldPresetSettings(new BCLWorldPresetSettings(
biomeSourceVersion,
biomeSourceVersion,
true,
@@ -358,38 +280,4 @@ public class LevelGenUtil {
));
}
}
-
- public static class StemContext {
- public final Holder dimension;
- public final Registry structureSets;
- public final Registry noiseParameters;
- public final Holder generatorSettings;
-
- public StemContext(
- Holder dimension,
- Registry structureSets,
- Registry noiseParameters,
- Holder generatorSettings
- ) {
- this.dimension = dimension;
- this.structureSets = structureSets;
- this.noiseParameters = noiseParameters;
- this.generatorSettings = generatorSettings;
- }
- }
-
- public static class Context extends StemContext {
- public final Registry biomes;
-
- public Context(
- Registry biomes, Holder dimension,
- Registry structureSets,
- Registry noiseParameters,
- Holder generatorSettings
- ) {
- super(dimension, structureSets, noiseParameters, generatorSettings);
- this.biomes = biomes;
- }
- }
-
}
diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/InternalBiomeAPI.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/InternalBiomeAPI.java
index ad394065..cee11b66 100644
--- a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/InternalBiomeAPI.java
+++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/InternalBiomeAPI.java
@@ -5,14 +5,11 @@ import org.betterx.bclib.interfaces.BiomeSourceAccessor;
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
-import org.betterx.bclib.mixin.common.RegistryOpsAccessor;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
-import net.minecraft.nbt.Tag;
-import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
@@ -72,17 +69,6 @@ public class InternalBiomeAPI {
return registryAccess;
}
- /**
- * Initialize registry for current server.
- *
- * @param regOps - registryOps for the current Session.
- */
- public static void initRegistry(RegistryOps regOps) {
- if (regOps instanceof RegistryOpsAccessor acc) {
- initRegistry(acc.bcl_getRegistryAccess());
- }
- }
-
/**
* Initialize registry for current server.
*
@@ -177,7 +163,7 @@ public class InternalBiomeAPI {
}
}
}
-
+
@Deprecated(forRemoval = true)
public static void applyModificationsDeprecated(ServerLevel level) {
//TODO: Now Disabled, because we fix the settings when everything gets loaded
diff --git a/src/main/java/org/betterx/bclib/client/BCLibClient.java b/src/main/java/org/betterx/bclib/client/BCLibClient.java
index 112c35cd..02417552 100644
--- a/src/main/java/org/betterx/bclib/client/BCLibClient.java
+++ b/src/main/java/org/betterx/bclib/client/BCLibClient.java
@@ -4,8 +4,10 @@ import org.betterx.bclib.api.v2.ModIntegrationAPI;
import org.betterx.bclib.api.v2.PostInitAPI;
import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
import org.betterx.bclib.client.models.CustomModelBakery;
-import org.betterx.bclib.client.presets.WorldPresetsUI;
+import org.betterx.bclib.config.Configs;
import org.betterx.bclib.registry.BaseBlockEntityRenders;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.client.WorldsTogetherClient;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
@@ -29,7 +31,8 @@ public class BCLibClient implements ClientModInitializer, ModelResourceProvider,
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> this);
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> this);
- WorldPresetsUI.setupClientside();
+ WorldsTogetherClient.onInitializeClient();
+ WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog();
//dumpDatapack();
}
diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java
index 94d7043e..e740d781 100644
--- a/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java
+++ b/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java
@@ -5,9 +5,9 @@ import org.betterx.bclib.client.gui.gridlayout.GridColumn;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.bclib.client.gui.gridlayout.GridScreen;
-import org.betterx.bclib.util.ModUtil;
-import org.betterx.bclib.util.PathUtil;
import org.betterx.bclib.util.Triple;
+import org.betterx.worlds.together.util.ModUtil;
+import org.betterx.worlds.together.util.PathUtil;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
@@ -38,7 +38,7 @@ public class ModListScreen extends BCLibScreen {
Screen parent,
Component title,
Component description,
- Map mods,
+ Map mods,
HelloClient.IServerModMap serverInfo
) {
this(parent, title, description, CommonComponents.GUI_BACK, mods, serverInfo);
diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java
index 2453fdb4..7d5d9f8f 100644
--- a/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java
+++ b/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java
@@ -4,7 +4,7 @@ import org.betterx.bclib.api.v2.dataexchange.handler.autosync.HelloClient;
import org.betterx.bclib.client.gui.gridlayout.GridCheckboxCell;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
-import org.betterx.bclib.util.ModUtil;
+import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.CommonComponents;
diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java
index fcda7c93..8431f3ba 100644
--- a/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java
+++ b/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java
@@ -5,9 +5,9 @@ import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.client.gui.gridlayout.GridCheckboxCell;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
-import org.betterx.bclib.interfaces.WorldGenSettingsComponentAccessor;
-import org.betterx.bclib.presets.worldgen.BCLWorldPreset;
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
+import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
+import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import net.minecraft.client.gui.screens.worldselection.WorldCreationContext;
@@ -54,7 +54,7 @@ public class WorldSetupScreen extends BCLibScreen {
&& acc.bcl_getPreset()
.isPresent() && acc.bcl_getPreset()
.get()
- .value() instanceof BCLWorldPreset wp
+ .value() instanceof TogetherWorldPreset wp
&& wp.settings instanceof BCLWorldPresetSettings settings) {
netherVersion = settings.netherVersion;
endVersion = settings.endVersion;
@@ -185,7 +185,7 @@ public class WorldSetupScreen extends BCLibScreen {
&& acc.bcl_getPreset()
.isPresent() && acc.bcl_getPreset()
.get()
- .value() instanceof BCLWorldPreset worldPreset) {
+ .value() instanceof TogetherWorldPreset worldPreset) {
acc.bcl_setPreset(Optional.of(Holder.direct(worldPreset.withSettings(new BCLWorldPresetSettings(
netherVersion,
endVersion,
diff --git a/src/main/java/org/betterx/bclib/interfaces/ChunkGeneratorAccessor.java b/src/main/java/org/betterx/bclib/interfaces/ChunkGeneratorAccessor.java
index 95a6e15c..07aea210 100644
--- a/src/main/java/org/betterx/bclib/interfaces/ChunkGeneratorAccessor.java
+++ b/src/main/java/org/betterx/bclib/interfaces/ChunkGeneratorAccessor.java
@@ -1,7 +1,6 @@
package org.betterx.bclib.interfaces;
import net.minecraft.core.Registry;
-import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.levelgen.structure.StructureSet;
public interface ChunkGeneratorAccessor {
diff --git a/src/main/java/org/betterx/bclib/mixin/common/ChunkGeneratorMixin.java b/src/main/java/org/betterx/bclib/mixin/common/ChunkGeneratorMixin.java
index 4fbc4bb0..cd726c4b 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/ChunkGeneratorMixin.java
+++ b/src/main/java/org/betterx/bclib/mixin/common/ChunkGeneratorMixin.java
@@ -5,16 +5,13 @@ import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
import net.minecraft.core.Registry;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.WorldGenLevel;
-import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
diff --git a/src/main/java/org/betterx/bclib/mixin/common/DedicatedServerPropertiesMixin.java b/src/main/java/org/betterx/bclib/mixin/common/DedicatedServerPropertiesMixin.java
index 8840b4a4..07084a7b 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/DedicatedServerPropertiesMixin.java
+++ b/src/main/java/org/betterx/bclib/mixin/common/DedicatedServerPropertiesMixin.java
@@ -1,6 +1,6 @@
package org.betterx.bclib.mixin.common;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.server.dedicated.DedicatedServerProperties;
@@ -13,6 +13,6 @@ public class DedicatedServerPropertiesMixin {
//Make sure the default server properties use our Default World Preset
@ModifyArg(method = "", index = 3, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServerProperties$WorldGenProperties;(Ljava/lang/String;Lcom/google/gson/JsonObject;ZLjava/lang/String;)V"))
private String bcl_init(String levelType) {
- return BCLWorldPresets.DEFAULT.orElseThrow().location().toString();
+ return WorldPresets.DEFAULT.orElseThrow().location().toString();
}
}
diff --git a/src/main/java/org/betterx/bclib/mixin/common/MinecraftServerMixinLate.java b/src/main/java/org/betterx/bclib/mixin/common/MinecraftServerMixinLate.java
index 218aaf9e..2d9dab7b 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/MinecraftServerMixinLate.java
+++ b/src/main/java/org/betterx/bclib/mixin/common/MinecraftServerMixinLate.java
@@ -1,7 +1,6 @@
package org.betterx.bclib.mixin.common;
import org.betterx.bclib.api.v2.generator.BCLChunkGenerator;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import com.mojang.datafixers.DataFixer;
import net.minecraft.server.MinecraftServer;
@@ -9,8 +8,6 @@ import net.minecraft.server.Services;
import net.minecraft.server.WorldStem;
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
import net.minecraft.server.packs.repository.PackRepository;
-import net.minecraft.world.level.dimension.LevelStem;
-import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.storage.LevelStorageSource;
import org.spongepowered.asm.mixin.Mixin;
@@ -20,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.net.Proxy;
-@Mixin(value= MinecraftServer.class, priority = 2000)
+@Mixin(value = MinecraftServer.class, priority = 2000)
public class MinecraftServerMixinLate {
@Inject(at = @At("RETURN"), method = "")
private void appendGlobalFeatures(
diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldGenRegionMixin.java b/src/main/java/org/betterx/bclib/mixin/common/WorldGenRegionMixin.java
index 59ee6f81..3715b3fb 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/WorldGenRegionMixin.java
+++ b/src/main/java/org/betterx/bclib/mixin/common/WorldGenRegionMixin.java
@@ -17,6 +17,7 @@ public class WorldGenRegionMixin {
@Shadow
private ChunkAccess center;
+ //TODO: 1.19 Is it ok to remove this?
@Inject(method = "ensureCanWrite", at = @At("HEAD"), cancellable = true)
private void be_alterBlockCheck(BlockPos blockPos, CallbackInfoReturnable info) {
int x = blockPos.getX() >> 4;
diff --git a/src/main/java/org/betterx/bclib/presets/FlatLevelPresets.java b/src/main/java/org/betterx/bclib/presets/FlatLevelPresets.java
index 5cadf3f5..04a2c11e 100644
--- a/src/main/java/org/betterx/bclib/presets/FlatLevelPresets.java
+++ b/src/main/java/org/betterx/bclib/presets/FlatLevelPresets.java
@@ -1,29 +1,28 @@
package org.betterx.bclib.presets;
-import org.betterx.bclib.api.v2.tag.TagAPI;
import org.betterx.bclib.api.v2.tag.TagType;
-import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
-import net.minecraft.tags.FlatLevelGeneratorPresetTags;
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset;
+/**
+ * @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets} instead
+ */
+@Deprecated(forRemoval = true)
public class FlatLevelPresets {
- public static TagType.Simple FLAT_LEVEL_PRESETS =
- TagAPI.registerType(
- Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
- "tags/worldgen/flat_level_generator_preset",
- (b) -> null
- );
+ /**
+ * @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets#FLAT_LEVEL_PRESETS} instead
+ */
+ @Deprecated(forRemoval = true)
+ public static TagType.Simple FLAT_LEVEL_PRESETS = org.betterx.worlds.together.flatLevel.FlatLevelPresets.FLAT_LEVEL_PRESETS;
+ /**
+ * @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets#register(ResourceLocation)} instead
+ */
+ @Deprecated(forRemoval = true)
public static ResourceKey register(ResourceLocation loc) {
- ResourceKey key = ResourceKey.create(
- Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
- loc
- );
- FLAT_LEVEL_PRESETS.addUntyped(FlatLevelGeneratorPresetTags.VISIBLE, key.location());
- return key;
+ return org.betterx.worlds.together.flatLevel.FlatLevelPresets.register(loc);
}
}
diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java b/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java
index 1eeeb17d..1454ed54 100644
--- a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java
+++ b/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java
@@ -9,6 +9,9 @@ import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
@@ -78,18 +81,18 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
return CODEC;
}
- public BCLWorldPreset buildPreset(
+ public TogetherWorldPreset buildPreset(
LevelStem overworldStem,
- LevelGenUtil.Context netherContext,
- LevelGenUtil.Context endContext
+ WorldGenUtil.Context netherContext,
+ WorldGenUtil.Context endContext
) {
- return new BCLWorldPreset(buildDimensionMap(overworldStem, netherContext, endContext), 1000, this);
+ return new TogetherWorldPreset(buildDimensionMap(overworldStem, netherContext, endContext), 1000, this);
}
public Map, LevelStem> buildDimensionMap(
LevelStem overworldStem,
- LevelGenUtil.Context netherContext,
- LevelGenUtil.Context endContext
+ WorldGenUtil.Context netherContext,
+ WorldGenUtil.Context endContext
) {
return Map.of(
LevelStem.OVERWORLD,
@@ -108,17 +111,17 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
return BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
}
- public LevelStem createStem(LevelGenUtil.Context ctx, ResourceKey key) {
+ public LevelStem createStem(WorldGenUtil.Context ctx, ResourceKey key) {
if (key == LevelStem.NETHER) return createNetherStem(ctx);
if (key == LevelStem.END) return createEndStem(ctx);
return null;
}
- public LevelStem createNetherStem(LevelGenUtil.Context ctx) {
+ public LevelStem createNetherStem(WorldGenUtil.Context ctx) {
return LevelGenUtil.getBCLNetherLevelStem(ctx, Optional.of(netherVersion));
}
- public LevelStem createEndStem(LevelGenUtil.Context ctx) {
+ public LevelStem createEndStem(WorldGenUtil.Context ctx) {
return LevelGenUtil.getBCLEndLevelStem(ctx, Optional.of(endVersion));
}
diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/WorldBootstrap.java b/src/main/java/org/betterx/bclib/presets/worldgen/WorldBootstrap.java
deleted file mode 100644
index 6252ee87..00000000
--- a/src/main/java/org/betterx/bclib/presets/worldgen/WorldBootstrap.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package org.betterx.bclib.presets.worldgen;
-
-import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.LifeCycleAPI;
-import org.betterx.bclib.api.v2.WorldDataAPI;
-import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
-import org.betterx.bclib.api.v2.datafixer.DataFixerAPI;
-import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
-import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
-import org.betterx.bclib.interfaces.WorldGenSettingsComponentAccessor;
-import org.betterx.bclib.mixin.common.RegistryOpsAccessor;
-
-import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
-import net.minecraft.core.Holder;
-import net.minecraft.nbt.Tag;
-import net.minecraft.resources.RegistryOps;
-import net.minecraft.resources.ResourceKey;
-import net.minecraft.world.level.dimension.LevelStem;
-import net.minecraft.world.level.levelgen.WorldGenSettings;
-import net.minecraft.world.level.levelgen.presets.WorldPreset;
-import net.minecraft.world.level.storage.LevelResource;
-import net.minecraft.world.level.storage.LevelStorageSource;
-
-import java.io.File;
-import java.util.Optional;
-
-public class WorldBootstrap {
- private static class Helpers {
-
- private static void initializeWorldDataAPI(
- LevelStorageSource.LevelStorageAccess levelStorageAccess,
- boolean newWorld
- ) {
- File levelPath = levelStorageAccess.getLevelPath(LevelResource.ROOT).toFile();
- initializeWorldDataAPI(levelPath, newWorld);
- }
-
- private static void setupWorld() {
- InternalBiomeAPI.prepareNewLevel();
- DataExchangeAPI.prepareServerside();
- }
-
- private static void initializeWorldDataAPI(File levelBaseDir, boolean newWorld) {
- WorldDataAPI.load(new File(levelBaseDir, "data"));
-
- if (newWorld) {
- WorldDataAPI.saveFile(BCLib.MOD_ID);
- }
- }
- }
-
- public static class DedicatedServer {
- public static void registryReady(RegistryOps regOps) {
- InternalBiomeAPI.initRegistry(regOps);
- }
-
- public static void setupWorld(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
- Helpers.setupWorld();
-
- File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile();
- if (!levelDat.exists()) {
- BCLib.LOGGER.info("Creating a new World, no fixes needed");
- Helpers.initializeWorldDataAPI(levelStorageAccess, true);
- BCLWorldPreset.writeWorldPresetSettings(Optional.empty());
- DataFixerAPI.initializePatchData();
- } else {
- Helpers.initializeWorldDataAPI(levelStorageAccess, false);
- DataFixerAPI.fixData(levelStorageAccess, false, (didFix) -> {/* not called when showUI==false */});
- }
-
-
- LifeCycleAPI._runBeforeLevelLoad();
- }
- }
-
- public static class InGUI {
- public static void registryReady(WorldGenSettingsComponent worldGenSettingsComponent) {
- InternalBiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder());
- }
-
- public static void registryReady(Optional> registryOps) {
- if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
- InternalBiomeAPI.initRegistry(acc.bcl_getRegistryAccess());
- }
- }
-
- public static void setupNewWorld(
- Optional levelStorageAccess,
- WorldGenSettingsComponent worldGenSettingsComponent
- ) {
- if (levelStorageAccess.isPresent()) {
- Helpers.setupWorld();
-
- Helpers.initializeWorldDataAPI(levelStorageAccess.get(), true);
-
- if (worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc) {
- BCLWorldPreset.writeWorldPresetSettings(adaptPresetForDatapacks(acc, worldGenSettingsComponent));
- }
-
- DataFixerAPI.initializePatchData();
-// DataFixerAPI.createWorldData(
-// levelStorageAccess.get(),
-// worldGenSettingsComponent.settings().worldGenSettings()
-// );
-
- LifeCycleAPI._runBeforeLevelLoad();
- }
- }
-
- /**
- * Does not call {@link LifeCycleAPI#_runBeforeLevelLoad()}
- */
- public static void setupLoadedWorld(
- String levelID,
- LevelStorageSource levelSource
- ) {
- Helpers.setupWorld();
- try {
- var levelStorageAccess = levelSource.createAccess(levelID);
- Helpers.initializeWorldDataAPI(levelStorageAccess, true);
- levelStorageAccess.close();
- } catch (Exception e) {
- BCLib.LOGGER.error("Failed to initialize data in world", e);
- }
- }
- }
-
- public static class InFreshLevel {
- public static void setupNewWorld(
- String levelID,
- WorldGenSettings worldGenSettings,
- LevelStorageSource levelSource,
- Optional> worldPreset
- ) {
- InGUI.setupLoadedWorld(levelID, levelSource);
-
- BCLWorldPreset.writeWorldPresetSettings(worldPreset);
- DataFixerAPI.initializePatchData();
- LifeCycleAPI._runBeforeLevelLoad();
- }
- }
-
- private static Optional> adaptPresetForDatapacks(
- WorldGenSettingsComponentAccessor accessor,
- WorldGenSettingsComponent component
- ) {
- LevelStem endStem = component.settings().worldGenSettings().dimensions().get(LevelStem.END);
- Optional> currentPreset = accessor.bcl_getPreset();
-
- //We probably loaded a Datapack for the End
- if (!(endStem.generator().getBiomeSource() instanceof BCLibEndBiomeSource)) {
- BCLib.LOGGER.info("Detected Datapack for END.");
-
- if (currentPreset.isPresent()) {
- if (currentPreset.get().value() instanceof BCLWorldPreset worldPreset) {
- ResourceKey key = currentPreset.get().unwrapKey().orElse(null);
- //user did not configure the Preset!
- if (BCLWorldPresets.BCL_WORLD.equals(key) || BCLWorldPresets.BCL_WORLD_17.equals(key)) {
- if (worldPreset.settings instanceof BCLWorldPresetSettings settings) {
- BCLib.LOGGER.info("Changing Default WorldPreset Settings for Datapack use.");
-
- worldPreset = worldPreset.withSettings(new BCLWorldPresetSettings(
- settings.netherVersion,
- settings.endVersion,
- false,
- false
- ));
- currentPreset = Optional.of(Holder.direct(worldPreset));
- accessor.bcl_setPreset(currentPreset);
- }
- }
- }
- }
- }
- return currentPreset;
- }
-
- public static WorldGenSettings enforceInNewWorld(WorldGenSettings worldGenSettings) {
- worldGenSettings = LevelGenUtil
- .getWorldSettings()
- .repairSettingsOnLoad(InternalBiomeAPI.worldRegistryAccess(), worldGenSettings);
- return worldGenSettings;
- }
-
- public static WorldGenSettings enforceInLoadedWorld(
- Optional> registryOps,
- WorldGenSettings worldGenSettings
- ) {
- if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
- return LevelGenUtil
- .getWorldSettings()
- .repairSettingsOnLoad(acc.bcl_getRegistryAccess(), worldGenSettings);
- //.repairSettingsOnLoad(InternalBiomeAPI.worldRegistryAccess(), worldGenSettings);
- } else {
- BCLib.LOGGER.error("Unable to obtain registryAccess when enforcing generators.");
- }
- return worldGenSettings;
- }
-}
diff --git a/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java b/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java
new file mode 100644
index 00000000..45263f41
--- /dev/null
+++ b/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java
@@ -0,0 +1,48 @@
+package org.betterx.bclib.registry;
+
+import org.betterx.bclib.BCLib;
+import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
+import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.world.level.levelgen.presets.WorldPreset;
+
+import java.util.Optional;
+
+public class PresetsRegistry {
+ public static ResourceKey BCL_WORLD;
+ public static ResourceKey BCL_WORLD_17;
+
+ public static void onLoad() {
+ BCL_WORLD =
+ WorldPresets.register(
+ BCLib.makeID("normal"),
+ (overworldStem, netherContext, endContext) ->
+ new BCLWorldPresetSettings(BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION).buildPreset(
+ overworldStem,
+ netherContext,
+ endContext
+ ),
+ true
+ );
+
+ BCL_WORLD_17 = WorldPresets.register(
+ BCLib.makeID("legacy_17"),
+ (overworldStem, netherContext, endContext) ->
+ new BCLWorldPresetSettings(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE).buildPreset(
+ overworldStem,
+ netherContext,
+ endContext
+ ),
+ false
+ );
+
+ WorldPresetSettings.DEFAULT = BCLWorldPresetSettings.DEFAULT;
+ WorldPresets.DEFAULT = Optional.of(BCL_WORLD);
+
+ WorldPresetSettings.register(BCLib.makeID("bcl_world_preset_settings"), BCLWorldPresetSettings.CODEC);
+ }
+
+}
diff --git a/src/main/java/org/betterx/bclib/registry/PresetsRegistryClient.java b/src/main/java/org/betterx/bclib/registry/PresetsRegistryClient.java
new file mode 100644
index 00000000..be28feb3
--- /dev/null
+++ b/src/main/java/org/betterx/bclib/registry/PresetsRegistryClient.java
@@ -0,0 +1,16 @@
+package org.betterx.bclib.registry;
+
+import org.betterx.bclib.client.gui.screens.WorldSetupScreen;
+import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
+
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+
+@Environment(EnvType.CLIENT)
+public class PresetsRegistryClient {
+ public static void onLoad() {
+ WorldPresetsClient.registerCustomizeUI(PresetsRegistry.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
+ return new WorldSetupScreen(createWorldScreen, worldCreationContext);
+ });
+ }
+}
diff --git a/src/main/java/org/betterx/bclib/util/ModUtil.java b/src/main/java/org/betterx/bclib/util/ModUtil.java
index 0ad5abe7..e90d988a 100644
--- a/src/main/java/org/betterx/bclib/util/ModUtil.java
+++ b/src/main/java/org/betterx/bclib/util/ModUtil.java
@@ -1,6 +1,8 @@
package org.betterx.bclib.util;
import org.betterx.bclib.BCLib;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.util.PathUtil;
import net.fabricmc.loader.api.*;
import net.fabricmc.loader.api.metadata.*;
@@ -23,26 +25,25 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+/**
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil}
+ */
+@Deprecated(forRemoval = true)
public class ModUtil {
private static Map mods;
/**
- * Unloads the cache of available mods created from {@link #getMods()}
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#invalidateCachedMods()}
*/
+ @Deprecated(forRemoval = true)
public static void invalidateCachedMods() {
mods = null;
}
/**
- * return a map of all mods that were found in the 'mods'-folder.
- *
- * The method will cache the results. You can clear that cache (and free the memory) by
- * calling {@link #invalidateCachedMods()}
- *
- * An error message is printed if a mod fails to load, but the parsing will continue.
- *
- * @return A map of all found mods. (key=ModID, value={@link ModInfo})
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#getMods()} ()}
*/
+ @Deprecated(forRemoval = true)
public static Map getMods() {
if (mods != null) return mods;
@@ -234,52 +235,49 @@ public class ModUtil {
}
/**
- * Returns the {@link ModInfo} or {@code null} if the mod was not found.
- *
- * The call will also return null if the mode-Version in the jar-File is not the same
- * as the version of the loaded Mod.
- *
- * @param modID The mod ID to query
- * @return A {@link ModInfo}-Object for the querried Mod.
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#getModInfo(String)}
*/
+ @Deprecated(forRemoval = true)
public static ModInfo getModInfo(String modID) {
return getModInfo(modID, true);
}
+ /**
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#getModInfo(String, boolean)}
+ */
+ @Deprecated(forRemoval = true)
public static ModInfo getModInfo(String modID, boolean matchVersion) {
getMods();
final ModInfo mi = mods.get(modID);
- if (mi == null || (matchVersion && !getModVersion(modID).equals(mi.getVersion()))) return null;
+ if (mi == null || (matchVersion && !org.betterx.worlds.together.util.ModUtil.getModVersion(modID)
+ .equals(mi.getVersion())))
+ return null;
return mi;
}
/**
- * Local Mod Version for the queried Mod
- *
- * @param modID The mod ID to query
- * @return The version of the locally installed Mod
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#getModVersion(String)}
*/
+ @Deprecated(forRemoval = true)
public static String getModVersion(String modID) {
- if (modID == BCLib.TOGETHER_WORLDS) modID = BCLib.MOD_ID;
+ if (modID == WorldsTogether.MOD_ID) modID = BCLib.MOD_ID;
Optional optional = FabricLoader.getInstance()
.getModContainer(modID);
if (optional.isPresent()) {
ModContainer modContainer = optional.get();
- return ModInfo.versionToString(modContainer.getMetadata()
- .getVersion());
+ return org.betterx.worlds.together.util.ModUtil.ModInfo.versionToString(modContainer.getMetadata()
+ .getVersion());
}
- return getModVersionFromJar(modID);
+ return org.betterx.worlds.together.util.ModUtil.getModVersionFromJar(modID);
}
/**
- * Local Mod Version for the queried Mod from the Jar-File in the games mod-directory
- *
- * @param modID The mod ID to query
- * @return The version of the locally installed Mod
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#getModVersionFromJar(String)}
*/
+ @Deprecated(forRemoval = true)
public static String getModVersionFromJar(String modID) {
final ModInfo mi = getModInfo(modID, false);
if (mi != null) return mi.getVersion();
@@ -288,11 +286,9 @@ public class ModUtil {
}
/**
- * Get mod version from string. String should be in format: %d.%d.%d
- *
- * @param version - {@link String} mod version.
- * @return int mod version.
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#convertModVersion(String)}
*/
+ @Deprecated(forRemoval = true)
public static int convertModVersion(String version) {
if (version.isEmpty()) {
return 0;
@@ -318,11 +314,9 @@ public class ModUtil {
}
/**
- * Get mod version from integer. String will be in format %d.%d.%d
- *
- * @param version - mod version in integer form.
- * @return {@link String} mod version.
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#convertModVersion(int)}
*/
+ @Deprecated(forRemoval = true)
public static String convertModVersion(int version) {
int a = (version >> 22) & 0xFF;
int b = (version >> 14) & 0xFF;
@@ -331,25 +325,21 @@ public class ModUtil {
}
/**
- * {@code true} if the version v1 is larger than v2
- *
- * @param v1 A Version string
- * @param v2 Another Version string
- * @return v1 > v2
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#isLargerVersion(String, String)}
*/
+ @Deprecated(forRemoval = true)
public static boolean isLargerVersion(String v1, String v2) {
- return convertModVersion(v1) > convertModVersion(v2);
+ return org.betterx.worlds.together.util.ModUtil.convertModVersion(v1) > org.betterx.worlds.together.util.ModUtil.convertModVersion(
+ v2);
}
/**
- * {@code true} if the version v1 is larger or equal v2
- *
- * @param v1 A Version string
- * @param v2 Another Version string
- * @return v1 ≥ v2
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil#isLargerOrEqualVersion(String, String)}
*/
+ @Deprecated(forRemoval = true)
public static boolean isLargerOrEqualVersion(String v1, String v2) {
- return convertModVersion(v1) >= convertModVersion(v2);
+ return org.betterx.worlds.together.util.ModUtil.convertModVersion(v1) >= org.betterx.worlds.together.util.ModUtil.convertModVersion(
+ v2);
}
private static void accept(Path file) {
@@ -387,6 +377,10 @@ public class ModUtil {
}
}
+ /**
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil.ModInfo}
+ */
+ @Deprecated(forRemoval = true)
public static class ModInfo {
public final ModMetadata metadata;
public final Path jarPath;
@@ -396,13 +390,23 @@ public class ModUtil {
this.jarPath = jarPath;
}
+ /**
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil.ModInfo#versionToString(Version)}
+ */
+ @Deprecated(forRemoval = true)
public static String versionToString(Version v) {
if (v instanceof SemanticVersion) {
- return versionToString((SemanticVersion) v);
+ return org.betterx.worlds.together.util.ModUtil.ModInfo.versionToString((SemanticVersion) v);
}
- return convertModVersion(convertModVersion(v.toString()));
+ return org.betterx.worlds.together.util.ModUtil.convertModVersion(
+ org.betterx.worlds.together.util.ModUtil.convertModVersion(v.toString())
+ );
}
+ /**
+ * @deprecated Replaced by {@link org.betterx.worlds.together.util.ModUtil.ModInfo#versionToString(SemanticVersion)}
+ */
+ @Deprecated(forRemoval = true)
public static String versionToString(SemanticVersion v) {
StringBuilder stringBuilder = new StringBuilder();
boolean first = true;
@@ -429,7 +433,7 @@ public class ModUtil {
if (metadata == null) {
return "0.0.0";
}
- return versionToString(metadata.getVersion());
+ return org.betterx.worlds.together.util.ModUtil.ModInfo.versionToString(metadata.getVersion());
}
}
}
diff --git a/src/main/java/org/betterx/bclib/util/PathUtil.java b/src/main/java/org/betterx/bclib/util/PathUtil.java
index c53a6e0a..3abf09ab 100644
--- a/src/main/java/org/betterx/bclib/util/PathUtil.java
+++ b/src/main/java/org/betterx/bclib/util/PathUtil.java
@@ -1,100 +1,62 @@
package org.betterx.bclib.util;
-import net.fabricmc.loader.api.FabricLoader;
-
import java.io.File;
import java.nio.file.Path;
import java.util.function.Consumer;
+
+/**
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil}
+ */
+@Deprecated(forRemoval = true)
public class PathUtil {
- public final static Path GAME_FOLDER = FabricLoader.getInstance()
- .getGameDir()
- .normalize();
-
- public final static Path MOD_FOLDER = FabricLoader.getInstance()
- .getGameDir()
- .resolve("mods")
- .normalize();
-
- public final static Path MOD_BAK_FOLDER = MOD_FOLDER.resolve("_bclib_deactivated")
- .normalize();
+ /**
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#GAME_FOLDER}
+ */
+ @Deprecated(forRemoval = true)
+ public final static Path GAME_FOLDER = org.betterx.worlds.together.util.PathUtil.GAME_FOLDER;
/**
- * Tests if a path is a child-path.
- *
- * A path is a child of another if it is located in the parent or any of the parents subdirectories
- *
- * @param parent The folder we search for the {@code child}
- * @param child The folder you want to test
- * @return {@code true} if {@code child} is in {@code parent} or any of its sub directories
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#MOD_FOLDER}
*/
+ @Deprecated(forRemoval = true)
+ public final static Path MOD_FOLDER = org.betterx.worlds.together.util.PathUtil.MOD_FOLDER;
+
+ /**
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#MOD_BAK_FOLDER}
+ */
+ @Deprecated(forRemoval = true)
+ public final static Path MOD_BAK_FOLDER = org.betterx.worlds.together.util.PathUtil.MOD_BAK_FOLDER;
+
+ /**
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#isChildOf(Path, Path)}
+ */
+ @Deprecated(forRemoval = true)
public static boolean isChildOf(Path parent, Path child) {
- if (child == null || parent == null) return false;
- parent = parent.toAbsolutePath().normalize();
- child = child.toAbsolutePath().normalize();
-
- final int pCount = parent.getNameCount();
- final int cCount = child.getNameCount();
-
- if (cCount > pCount) return isChildOf(parent, child.getParent());
- if (cCount < pCount) return false;
-
- return child.equals(parent);
+ return org.betterx.worlds.together.util.PathUtil.isChildOf(parent, child);
}
/**
- * A simple directory walker that ignores dot-files
- *
- * @param path The path where you want to start
- * @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
- * for each visited file
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#fileWalker(File, Consumer)}
*/
+ @Deprecated(forRemoval = true)
public static void fileWalker(File path, Consumer pathConsumer) {
- fileWalker(path, true, pathConsumer);
+ org.betterx.worlds.together.util.PathUtil.fileWalker(path, pathConsumer);
}
/**
- * A simple directory walker that ignores dot-files
- *
- * @param path The path where you want to start
- * @param recursive if {@code false}, only the {@code path} is traversed
- * @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
- * for each visited file
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#fileWalker(File, boolean, Consumer)}
*/
+ @Deprecated(forRemoval = true)
public static void fileWalker(File path, boolean recursive, Consumer pathConsumer) {
- if (!path.exists()) return;
- for (final File f : path.listFiles()) {
- if (f.getName()
- .startsWith(".")) continue;
- if (f.isDirectory()) {
- if (recursive) fileWalker(f, pathConsumer);
- } else if (f.isFile()) {
- pathConsumer.accept(f.toPath());
- }
- }
+ org.betterx.worlds.together.util.PathUtil.fileWalker(path, recursive, pathConsumer);
}
/**
- * Creates a human readable File-Size
- *
- * @param size Filesize in bytes
- * @return A Human readable String
+ * @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#humanReadableFileSize(long)}
*/
+ @Deprecated(forRemoval = true)
public static String humanReadableFileSize(long size) {
- final int threshold = 2;
- final int factor = 1024;
- if (size < 0) return "? Byte";
- if (size < factor * threshold) {
- return size + " Byte";
- }
- char[] units = {'K', 'M', 'G', 'T', 'P'};
- int unitIndex = 0;
- double fSize = size;
- do {
- unitIndex++;
- fSize /= 1024;
- } while (fSize > factor * threshold && unitIndex < units.length);
-
- return String.format("%.1f %ciB", fSize, units[unitIndex - 1]);
+ return org.betterx.worlds.together.util.PathUtil.humanReadableFileSize(size);
}
}
diff --git a/src/main/java/org/betterx/worlds/together/WorldsTogether.java b/src/main/java/org/betterx/worlds/together/WorldsTogether.java
new file mode 100644
index 00000000..31a4f6cf
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/WorldsTogether.java
@@ -0,0 +1,31 @@
+package org.betterx.worlds.together;
+
+import org.betterx.bclib.util.Logger;
+import org.betterx.worlds.together.world.WorldConfig;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
+
+import net.minecraft.resources.ResourceLocation;
+
+import net.fabricmc.loader.api.FabricLoader;
+
+public class WorldsTogether {
+ public static boolean SURPRESS_EXPERIMENTAL_DIALOG = false;
+ public static final String MOD_ID = "worlds_together";
+ public static final Logger LOGGER = new Logger(MOD_ID);
+ public static final boolean RUNS_TERRABLENDER = FabricLoader.getInstance()
+ .getModContainer("terrablender")
+ .isPresent();
+
+ public static boolean isDevEnvironment() {
+ return FabricLoader.getInstance().isDevelopmentEnvironment();
+ }
+
+ public static void onInitialize() {
+ WorldConfig.registerModCache(WorldsTogether.MOD_ID);
+ WorldPresets.ensureStaticallyLoaded();
+ }
+
+ public static ResourceLocation makeID(String s) {
+ return new ResourceLocation(MOD_ID, s);
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java b/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java
new file mode 100644
index 00000000..1aa64f4e
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java
@@ -0,0 +1,9 @@
+package org.betterx.worlds.together.client;
+
+import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
+
+public class WorldsTogetherClient {
+ public static void onInitializeClient() {
+ WorldPresetsClient.setupClientside();
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/flatLevel/FlatLevelPresets.java b/src/main/java/org/betterx/worlds/together/flatLevel/FlatLevelPresets.java
new file mode 100644
index 00000000..e4881cae
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/flatLevel/FlatLevelPresets.java
@@ -0,0 +1,29 @@
+package org.betterx.worlds.together.flatLevel;
+
+import org.betterx.bclib.api.v2.tag.TagAPI;
+import org.betterx.bclib.api.v2.tag.TagType;
+
+import net.minecraft.core.Registry;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.FlatLevelGeneratorPresetTags;
+import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset;
+
+public class FlatLevelPresets {
+ public static TagType.Simple FLAT_LEVEL_PRESETS =
+ TagAPI.registerType(
+ Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
+ "tags/worldgen/flat_level_generator_preset",
+ (b) -> null
+ );
+
+
+ public static ResourceKey register(ResourceLocation loc) {
+ ResourceKey key = ResourceKey.create(
+ Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
+ loc
+ );
+ FLAT_LEVEL_PRESETS.addUntyped(FlatLevelGeneratorPresetTags.VISIBLE, key.location());
+ return key;
+ }
+}
diff --git a/src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java b/src/main/java/org/betterx/worlds/together/mixin/client/CreateWorldScreenMixin.java
similarity index 85%
rename from src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/client/CreateWorldScreenMixin.java
index 0c4d6bff..6ffa9583 100644
--- a/src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/client/CreateWorldScreenMixin.java
@@ -1,9 +1,8 @@
-package org.betterx.bclib.mixin.client;
+package org.betterx.worlds.together.mixin.client;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
-import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
-import org.betterx.bclib.presets.worldgen.WorldBootstrap;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.world.event.WorldBootstrap;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.gui.screens.Screen;
@@ -41,13 +40,13 @@ public class CreateWorldScreenMixin {
WorldGenSettingsComponent worldGenSettingsComponent,
CallbackInfo ci
) {
- InternalBiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder());
+ WorldBootstrap.InGUI.registryReadyOnNewWorld(worldGenSettingsComponent);
}
//Change the WorldPreset that is selected by default on the Create World Screen
@ModifyArg(method = "openFresh", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent;(Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext;Ljava/util/Optional;Ljava/util/OptionalLong;)V"))
private static Optional> bcl_NewDefault(Optional> preset) {
- return BCLWorldPresets.DEFAULT;
+ return WorldPresets.DEFAULT;
}
//Make sure the WorldGenSettings used to populate the create screen match the default WorldPreset
@@ -55,14 +54,14 @@ public class CreateWorldScreenMixin {
private static WorldLoader.WorldDataSupplier bcl_NewDefaultSettings(WorldLoader.WorldDataSupplier worldDataSupplier) {
return (resourceManager, dataPackConfig) -> {
Pair res = worldDataSupplier.get(resourceManager, dataPackConfig);
- return LevelGenUtil.defaultWorldDataSupplier(res.getSecond());
+ return WorldGenUtil.defaultWorldDataSupplier(res.getSecond());
};
}
//this is called when a new world is first created
@Inject(method = "createNewWorldDirectory", at = @At("RETURN"))
void bcl_createNewWorld(CallbackInfoReturnable> cir) {
- WorldBootstrap.InGUI.registryReady(this.worldGenSettingsComponent);
+ WorldBootstrap.InGUI.registryReadyOnNewWorld(this.worldGenSettingsComponent);
WorldBootstrap.InGUI.setupNewWorld(cir.getReturnValue(), this.worldGenSettingsComponent);
}
}
diff --git a/src/main/java/org/betterx/bclib/mixin/client/WorldGenSettingsComponentMixin.java b/src/main/java/org/betterx/worlds/together/mixin/client/WorldGenSettingsComponentMixin.java
similarity index 93%
rename from src/main/java/org/betterx/bclib/mixin/client/WorldGenSettingsComponentMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/client/WorldGenSettingsComponentMixin.java
index a0be8a30..943c84b5 100644
--- a/src/main/java/org/betterx/bclib/mixin/client/WorldGenSettingsComponentMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/client/WorldGenSettingsComponentMixin.java
@@ -1,6 +1,6 @@
-package org.betterx.bclib.mixin.client;
+package org.betterx.worlds.together.mixin.client;
-import org.betterx.bclib.interfaces.WorldGenSettingsComponentAccessor;
+import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.core.Holder;
diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java b/src/main/java/org/betterx/worlds/together/mixin/client/WorldOpenFlowsMixin.java
similarity index 81%
rename from src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/client/WorldOpenFlowsMixin.java
index a66a3885..6da1e173 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/client/WorldOpenFlowsMixin.java
@@ -1,9 +1,7 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.client;
-import org.betterx.bclib.api.v2.LifeCycleAPI;
-import org.betterx.bclib.api.v2.datafixer.DataFixerAPI;
-import org.betterx.bclib.config.Configs;
-import org.betterx.bclib.presets.worldgen.WorldBootstrap;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.world.event.WorldBootstrap;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
@@ -37,15 +35,16 @@ public abstract class WorldOpenFlowsMixin {
private void bcl_callFixerOnLoad(Screen screen, String levelID, CallbackInfo ci) {
WorldBootstrap.InGUI.setupLoadedWorld(levelID, this.levelSource);
- if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> {
- LifeCycleAPI._runBeforeLevelLoad();
+ //if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> {
+ if (WorldBootstrap.InGUI.applyWorldPatches(levelSource, levelID, (appliedFixes) -> {
+ WorldBootstrap.InGUI.finishedWorldLoad(levelID, this.levelSource);
this.doLoadLevel(screen, levelID, false, false);
})) {
//cancel call when fix-screen is presented
ci.cancel();
} else {
- LifeCycleAPI._runBeforeLevelLoad();
- if (Configs.CLIENT_CONFIG.suppressExperimentalDialog()) {
+ WorldBootstrap.InGUI.finishedWorldLoad(levelID, this.levelSource);
+ if (WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG) {
this.doLoadLevel(screen, levelID, false, false);
//cancel call as we manually start the level load here
ci.cancel();
diff --git a/src/main/java/org/betterx/bclib/mixin/common/MainMixin.java b/src/main/java/org/betterx/worlds/together/mixin/common/MainMixin.java
similarity index 69%
rename from src/main/java/org/betterx/bclib/mixin/common/MainMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/MainMixin.java
index c6c832d3..e8b18f9d 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/MainMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/MainMixin.java
@@ -1,11 +1,12 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
-import org.betterx.bclib.presets.worldgen.WorldBootstrap;
+import org.betterx.worlds.together.world.event.WorldBootstrap;
import com.mojang.serialization.DynamicOps;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.RegistryOps;
import net.minecraft.server.Main;
+import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.storage.LevelStorageSource;
import org.spongepowered.asm.mixin.Mixin;
@@ -30,4 +31,9 @@ abstract public class MainMixin {
return dynamicOps;
}
+ @ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
+ private static WorldGenSettings bcl_onCreateLevelData(WorldGenSettings worldGenSettings) {
+ WorldBootstrap.DedicatedServer.applyDatapackChangesOnNewWorld(worldGenSettings);
+ return worldGenSettings;
+ }
}
diff --git a/src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java b/src/main/java/org/betterx/worlds/together/mixin/common/PrimaryLevelDataMixin.java
similarity index 93%
rename from src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/PrimaryLevelDataMixin.java
index 8816ab4f..00b58840 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/PrimaryLevelDataMixin.java
@@ -1,6 +1,6 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
-import org.betterx.bclib.presets.worldgen.WorldBootstrap;
+import org.betterx.worlds.together.world.event.WorldBootstrap;
import com.mojang.datafixers.DataFixer;
import com.mojang.serialization.Dynamic;
@@ -56,11 +56,11 @@ public class PrimaryLevelDataMixin {
}
- //This is the way an loaded (existing) world is initializing the PrimaryLevelData
+ //This is the way a loaded (existing) world is initializing the PrimaryLevelData
@ModifyArg(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
private static WorldGenSettings bcl_fixSettings(WorldGenSettings settings) {
Optional> registryOps = bcl_lastRegistryAccess.get();
- WorldBootstrap.InGUI.registryReady(registryOps);
+ WorldBootstrap.InGUI.registryReadyOnLoadedWorld(registryOps);
settings = WorldBootstrap.enforceInLoadedWorld(registryOps, settings);
bcl_lastRegistryAccess.set(Optional.empty());
return settings;
diff --git a/src/main/java/org/betterx/bclib/mixin/common/RegistryOpsAccessor.java b/src/main/java/org/betterx/worlds/together/mixin/common/RegistryOpsAccessor.java
similarity index 86%
rename from src/main/java/org/betterx/bclib/mixin/common/RegistryOpsAccessor.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/RegistryOpsAccessor.java
index 0c96d19f..70a1da14 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/RegistryOpsAccessor.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/RegistryOpsAccessor.java
@@ -1,4 +1,4 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.RegistryOps;
diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldGenPropertiesMixin.java b/src/main/java/org/betterx/worlds/together/mixin/common/WorldGenPropertiesMixin.java
similarity index 86%
rename from src/main/java/org/betterx/bclib/mixin/common/WorldGenPropertiesMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/WorldGenPropertiesMixin.java
index b2b9c6d4..6f889347 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/WorldGenPropertiesMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/WorldGenPropertiesMixin.java
@@ -1,6 +1,6 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.dedicated.DedicatedServerProperties;
@@ -20,6 +20,6 @@ public class WorldGenPropertiesMixin {
//Make sure Servers use our Default World Preset
@ModifyArg(method = "create", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/core/Registry;getHolder(Lnet/minecraft/resources/ResourceKey;)Ljava/util/Optional;"))
private ResourceKey bcl_foo(ResourceKey resourceKey) {
- return BCLWorldPresets.DEFAULT.orElseThrow();
+ return WorldPresets.DEFAULT.orElseThrow();
}
}
\ No newline at end of file
diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldPresetAccessor.java b/src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetAccessor.java
similarity index 89%
rename from src/main/java/org/betterx/bclib/mixin/common/WorldPresetAccessor.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetAccessor.java
index eaa8801d..53fab46e 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/WorldPresetAccessor.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetAccessor.java
@@ -1,4 +1,4 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.dimension.LevelStem;
diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldPresetMixin.java b/src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetMixin.java
similarity index 80%
rename from src/main/java/org/betterx/bclib/mixin/common/WorldPresetMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetMixin.java
index 9cba651f..6b136efa 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/WorldPresetMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetMixin.java
@@ -1,7 +1,7 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
-import org.betterx.bclib.presets.worldgen.BCLWorldPreset;
-import org.betterx.bclib.presets.worldgen.WorldPresetSettings;
+import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.Codec;
@@ -40,21 +40,21 @@ public class WorldPresetMixin {
RecordCodecBuilder> sortBuilder = Codec.INT
.optionalFieldOf("sort_order")
- .forGetter(wp -> (wp instanceof BCLWorldPreset)
- ? Optional.of(((BCLWorldPreset) wp).sortOrder)
+ .forGetter(wp -> (wp instanceof TogetherWorldPreset)
+ ? Optional.of(((TogetherWorldPreset) wp).sortOrder)
: Optional.empty());
RecordCodecBuilder> settingsBuilder = WorldPresetSettings.CODEC
.optionalFieldOf("settings")
- .forGetter(wp -> (wp instanceof BCLWorldPreset)
- ? Optional.of(((BCLWorldPreset) wp).settings)
+ .forGetter(wp -> (wp instanceof TogetherWorldPreset)
+ ? Optional.of(((TogetherWorldPreset) wp).settings)
: Optional.empty());
return builderInstance
.group(dimensionsBuilder, sortBuilder, settingsBuilder)
- .apply(builderInstance, BCLWorldPreset::new);
+ .apply(builderInstance, TogetherWorldPreset::new);
};
-
+
return CODEC_FUNCTION;
}
}
diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldPresetsBootstrapMixin.java b/src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetsBootstrapMixin.java
similarity index 80%
rename from src/main/java/org/betterx/bclib/mixin/common/WorldPresetsBootstrapMixin.java
rename to src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetsBootstrapMixin.java
index a28c0ee0..cacc7a17 100644
--- a/src/main/java/org/betterx/bclib/mixin/common/WorldPresetsBootstrapMixin.java
+++ b/src/main/java/org/betterx/worlds/together/mixin/common/WorldPresetsBootstrapMixin.java
@@ -1,8 +1,8 @@
-package org.betterx.bclib.mixin.common;
+package org.betterx.worlds.together.mixin.common;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
-import org.betterx.bclib.presets.worldgen.WorldPresetSettings;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
@@ -11,7 +11,6 @@ import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
-import net.minecraft.world.level.levelgen.presets.WorldPresets;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
@@ -21,7 +20,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
-@Mixin(WorldPresets.Bootstrap.class)
+@Mixin(net.minecraft.world.level.levelgen.presets.WorldPresets.Bootstrap.class)
public abstract class WorldPresetsBootstrapMixin {
@Shadow
@Final
@@ -53,14 +52,14 @@ public abstract class WorldPresetsBootstrapMixin {
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)Lnet/minecraft/core/Holder;"))
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
WorldPresetSettings.bootstrap();
- LevelGenUtil.Context netherContext = new LevelGenUtil.Context(
+ WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
this.biomes,
this.netherDimensionType,
this.structureSets,
this.noises,
this.netherNoiseSettings
);
- LevelGenUtil.Context endContext = new LevelGenUtil.Context(
+ WorldGenUtil.Context endContext = new WorldGenUtil.Context(
this.biomes,
this.endDimensionType,
this.structureSets,
@@ -68,7 +67,7 @@ public abstract class WorldPresetsBootstrapMixin {
this.endNoiseSettings
);
- BCLWorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
+ WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
return overworldStem;
}
diff --git a/src/main/java/org/betterx/worlds/together/util/ModUtil.java b/src/main/java/org/betterx/worlds/together/util/ModUtil.java
new file mode 100644
index 00000000..99085a38
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/util/ModUtil.java
@@ -0,0 +1,436 @@
+package org.betterx.worlds.together.util;
+
+import org.betterx.bclib.BCLib;
+import org.betterx.worlds.together.WorldsTogether;
+
+import net.fabricmc.loader.api.*;
+import net.fabricmc.loader.api.metadata.*;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.stream.JsonReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ModUtil {
+ private static Map mods;
+
+ /**
+ * Unloads the cache of available mods created from {@link #getMods()}
+ */
+ public static void invalidateCachedMods() {
+ mods = null;
+ }
+
+ /**
+ * return a map of all mods that were found in the 'mods'-folder.
+ *
+ * The method will cache the results. You can clear that cache (and free the memory) by
+ * calling {@link #invalidateCachedMods()}
+ *
+ * An error message is printed if a mod fails to load, but the parsing will continue.
+ *
+ * @return A map of all found mods. (key=ModID, value={@link ModInfo})
+ */
+ public static Map getMods() {
+ if (mods != null) return mods;
+
+ mods = new HashMap<>();
+ PathUtil.fileWalker(PathUtil.MOD_FOLDER.toFile(), false, (ModUtil::accept));
+
+ return mods;
+ }
+
+ private static ModMetadata readJSON(InputStream is, String sourceFile) throws IOException {
+ try (JsonReader reader = new JsonReader(new InputStreamReader(
+ is,
+ StandardCharsets.UTF_8
+ ))) {
+ JsonObject data = JsonParser.parseReader(reader)
+ .getAsJsonObject();
+ Version ver;
+ try {
+ ver = SemanticVersion.parse(data.get("version").getAsString());
+ } catch (VersionParsingException e) {
+ WorldsTogether.LOGGER.error("Unable to parse Version in " + sourceFile);
+ return null;
+ }
+
+ if (data.get("id") == null) {
+ WorldsTogether.LOGGER.error("Unable to read ID in " + sourceFile);
+ return null;
+ }
+
+ if (data.get("name") == null) {
+ WorldsTogether.LOGGER.error("Unable to read name in " + sourceFile);
+ return null;
+ }
+
+ return new ModMetadata() {
+ @Override
+ public Version getVersion() {
+ return ver;
+ }
+
+ @Override
+ public String getType() {
+ return "fabric";
+ }
+
+ @Override
+ public String getId() {
+ return data.get("id")
+ .getAsString();
+ }
+
+ @Override
+ public Collection getProvides() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ModEnvironment getEnvironment() {
+ JsonElement env = data.get("environment");
+ if (env == null) {
+ WorldsTogether.LOGGER.warning("No environment specified in " + sourceFile);
+ //return ModEnvironment.UNIVERSAL;
+ }
+ final String environment = env == null ? "" : env.getAsString()
+ .toLowerCase(Locale.ROOT);
+
+ if (environment.isEmpty() || environment.equals("*") || environment.equals("\"*\"") || environment.equals(
+ "common")) {
+ JsonElement entrypoints = data.get("entrypoints");
+ boolean hasClient = true;
+
+ //check if there is an actual client entrypoint
+ if (entrypoints != null && entrypoints.isJsonObject()) {
+ JsonElement client = entrypoints.getAsJsonObject()
+ .get("client");
+ if (client != null && client.isJsonArray()) {
+ hasClient = client.getAsJsonArray()
+ .size() > 0;
+ } else if (client == null || !client.isJsonPrimitive()) {
+ hasClient = false;
+ } else if (!client.getAsJsonPrimitive()
+ .isString()) {
+ hasClient = false;
+ }
+ }
+
+ //if (hasClient == false) return ModEnvironment.SERVER;
+ return ModEnvironment.UNIVERSAL;
+ } else if (environment.equals("client")) {
+ return ModEnvironment.CLIENT;
+ } else if (environment.equals("server")) {
+ return ModEnvironment.SERVER;
+ } else {
+ WorldsTogether.LOGGER.error("Unable to read environment in " + sourceFile);
+ return ModEnvironment.UNIVERSAL;
+ }
+ }
+
+ @Override
+ public Collection getDepends() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public Collection getRecommends() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public Collection getSuggests() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public Collection getConflicts() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public Collection getBreaks() {
+ return new ArrayList<>();
+ }
+
+ public Collection getDependencies() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public String getName() {
+ return data.get("name")
+ .getAsString();
+ }
+
+ @Override
+ public String getDescription() {
+ return "";
+ }
+
+ @Override
+ public Collection getAuthors() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public Collection getContributors() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ContactInformation getContact() {
+ return null;
+ }
+
+ @Override
+ public Collection getLicense() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public Optional getIconPath(int size) {
+ return Optional.empty();
+ }
+
+ @Override
+ public boolean containsCustomValue(String key) {
+ return false;
+ }
+
+ @Override
+ public CustomValue getCustomValue(String key) {
+ return null;
+ }
+
+ @Override
+ public Map getCustomValues() {
+ return new HashMap<>();
+ }
+
+ @Override
+ public boolean containsCustomElement(String key) {
+ return false;
+ }
+
+ public JsonElement getCustomElement(String key) {
+ return null;
+ }
+ };
+ }
+ }
+
+ /**
+ * Returns the {@link ModInfo} or {@code null} if the mod was not found.
+ *
+ * The call will also return null if the mode-Version in the jar-File is not the same
+ * as the version of the loaded Mod.
+ *
+ * @param modID The mod ID to query
+ * @return A {@link ModInfo}-Object for the querried Mod.
+ */
+ public static ModInfo getModInfo(String modID) {
+ return getModInfo(modID, true);
+ }
+
+ public static ModInfo getModInfo(String modID, boolean matchVersion) {
+ getMods();
+ final ModInfo mi = mods.get(modID);
+ if (mi == null || (matchVersion && !getModVersion(modID).equals(mi.getVersion()))) return null;
+ return mi;
+ }
+
+ /**
+ * Local Mod Version for the queried Mod
+ *
+ * @param modID The mod ID to query
+ * @return The version of the locally installed Mod
+ */
+ public static String getModVersion(String modID) {
+ if (modID == WorldsTogether.MOD_ID) modID = BCLib.MOD_ID;
+
+ Optional optional = FabricLoader.getInstance()
+ .getModContainer(modID);
+ if (optional.isPresent()) {
+ ModContainer modContainer = optional.get();
+ return ModInfo.versionToString(modContainer.getMetadata()
+ .getVersion());
+
+ }
+
+ return getModVersionFromJar(modID);
+ }
+
+ /**
+ * Local Mod Version for the queried Mod from the Jar-File in the games mod-directory
+ *
+ * @param modID The mod ID to query
+ * @return The version of the locally installed Mod
+ */
+ public static String getModVersionFromJar(String modID) {
+ final ModInfo mi = getModInfo(modID, false);
+ if (mi != null) return mi.getVersion();
+
+ return "0.0.0";
+ }
+
+ /**
+ * Get mod version from string. String should be in format: %d.%d.%d
+ *
+ * @param version - {@link String} mod version.
+ * @return int mod version.
+ */
+ public static int convertModVersion(String version) {
+ if (version.isEmpty()) {
+ return 0;
+ }
+ try {
+ int res = 0;
+ final String semanticVersionPattern = "(\\d+)\\.(\\d+)(\\.(\\d+))?\\D*";
+ final Matcher matcher = Pattern.compile(semanticVersionPattern)
+ .matcher(version);
+ if (matcher.find()) {
+ if (matcher.groupCount() > 0)
+ res = matcher.group(1) == null ? 0 : ((Integer.parseInt(matcher.group(1)) & 0xFF) << 22);
+ if (matcher.groupCount() > 1)
+ res |= matcher.group(2) == null ? 0 : ((Integer.parseInt(matcher.group(2)) & 0xFF) << 14);
+ if (matcher.groupCount() > 3)
+ res |= matcher.group(4) == null ? 0 : Integer.parseInt(matcher.group(4)) & 0x3FFF;
+ }
+
+ return res;
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ /**
+ * Get mod version from integer. String will be in format %d.%d.%d
+ *
+ * @param version - mod version in integer form.
+ * @return {@link String} mod version.
+ */
+ public static String convertModVersion(int version) {
+ int a = (version >> 22) & 0xFF;
+ int b = (version >> 14) & 0xFF;
+ int c = version & 0x3FFF;
+ return String.format(Locale.ROOT, "%d.%d.%d", a, b, c);
+ }
+
+ /**
+ * {@code true} if the version v1 is larger than v2
+ *
+ * @param v1 A Version string
+ * @param v2 Another Version string
+ * @return v1 > v2
+ */
+ public static boolean isLargerVersion(String v1, String v2) {
+ return convertModVersion(v1) > convertModVersion(v2);
+ }
+
+ /**
+ * {@code true} if the version v1 is larger or equal v2
+ *
+ * @param v1 A Version string
+ * @param v2 Another Version string
+ * @return v1 ≥ v2
+ */
+ public static boolean isLargerOrEqualVersion(String v1, String v2) {
+ return convertModVersion(v1) >= convertModVersion(v2);
+ }
+
+ private static void accept(Path file) {
+ try {
+ URI uri = URI.create("jar:" + file.toUri());
+
+ FileSystem fs;
+ // boolean doClose = false;
+ try {
+ fs = FileSystems.getFileSystem(uri);
+ } catch (Exception e) {
+ // doClose = true;
+ fs = FileSystems.newFileSystem(file);
+ }
+ if (fs != null) {
+ try {
+ Path modMetaFile = fs.getPath("fabric.mod.json");
+ if (modMetaFile != null) {
+ try (InputStream is = Files.newInputStream(modMetaFile)) {
+ //ModMetadata mc = ModMetadataParser.parseMetadata(is, uri.toString(), new LinkedList());
+ ModMetadata mc = readJSON(is, uri.toString());
+ if (mc != null) {
+ mods.put(mc.getId(), new ModInfo(mc, file));
+ }
+ }
+ }
+ } catch (Exception e) {
+ WorldsTogether.LOGGER.error("Error for " + uri + ": " + e);
+ }
+ //if (doClose) fs.close();
+ }
+ } catch (Exception e) {
+ WorldsTogether.LOGGER.error("Error for " + file.toUri() + ": " + e);
+ e.printStackTrace();
+ }
+ }
+
+ public static class ModInfo {
+ public final ModMetadata metadata;
+ public final Path jarPath;
+
+ ModInfo(ModMetadata metadata, Path jarPath) {
+ this.metadata = metadata;
+ this.jarPath = jarPath;
+ }
+
+ public static String versionToString(Version v) {
+ if (v instanceof SemanticVersion) {
+ return versionToString((SemanticVersion) v);
+ }
+ return convertModVersion(convertModVersion(v.toString()));
+ }
+
+ public static String versionToString(SemanticVersion v) {
+ StringBuilder stringBuilder = new StringBuilder();
+ boolean first = true;
+ final int cCount = Math.min(v.getVersionComponentCount(), 3);
+ for (int i = 0; i < cCount; i++) {
+ if (first) {
+ first = false;
+ } else {
+ stringBuilder.append('.');
+ }
+
+ stringBuilder.append(v.getVersionComponent(i));
+ }
+
+ return stringBuilder.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "ModInfo{" + "id=" + metadata.getId() + ", version=" + metadata.getVersion() + ", jarPath=" + jarPath + '}';
+ }
+
+ public String getVersion() {
+ if (metadata == null) {
+ return "0.0.0";
+ }
+ return versionToString(metadata.getVersion());
+ }
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/util/PathUtil.java b/src/main/java/org/betterx/worlds/together/util/PathUtil.java
new file mode 100644
index 00000000..b120f4ae
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/util/PathUtil.java
@@ -0,0 +1,100 @@
+package org.betterx.worlds.together.util;
+
+import net.fabricmc.loader.api.FabricLoader;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.function.Consumer;
+
+public class PathUtil {
+ public final static Path GAME_FOLDER = FabricLoader.getInstance()
+ .getGameDir()
+ .normalize();
+
+ public final static Path MOD_FOLDER = FabricLoader.getInstance()
+ .getGameDir()
+ .resolve("mods")
+ .normalize();
+
+ public final static Path MOD_BAK_FOLDER = MOD_FOLDER.resolve("_bclib_deactivated")
+ .normalize();
+
+ /**
+ * Tests if a path is a child-path.
+ *
+ * A path is a child of another if it is located in the parent or any of the parents subdirectories
+ *
+ * @param parent The folder we search for the {@code child}
+ * @param child The folder you want to test
+ * @return {@code true} if {@code child} is in {@code parent} or any of its sub directories
+ */
+ public static boolean isChildOf(Path parent, Path child) {
+ if (child == null || parent == null) return false;
+ parent = parent.toAbsolutePath().normalize();
+ child = child.toAbsolutePath().normalize();
+
+ final int pCount = parent.getNameCount();
+ final int cCount = child.getNameCount();
+
+ if (cCount > pCount) return isChildOf(parent, child.getParent());
+ if (cCount < pCount) return false;
+
+ return child.equals(parent);
+ }
+
+ /**
+ * A simple directory walker that ignores dot-files
+ *
+ * @param path The path where you want to start
+ * @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
+ * for each visited file
+ */
+ public static void fileWalker(File path, Consumer pathConsumer) {
+ fileWalker(path, true, pathConsumer);
+ }
+
+ /**
+ * A simple directory walker that ignores dot-files
+ *
+ * @param path The path where you want to start
+ * @param recursive if {@code false}, only the {@code path} is traversed
+ * @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
+ * for each visited file
+ */
+ public static void fileWalker(File path, boolean recursive, Consumer pathConsumer) {
+ if (!path.exists()) return;
+ for (final File f : path.listFiles()) {
+ if (f.getName()
+ .startsWith(".")) continue;
+ if (f.isDirectory()) {
+ if (recursive) fileWalker(f, pathConsumer);
+ } else if (f.isFile()) {
+ pathConsumer.accept(f.toPath());
+ }
+ }
+ }
+
+ /**
+ * Creates a human readable File-Size
+ *
+ * @param size Filesize in bytes
+ * @return A Human readable String
+ */
+ public static String humanReadableFileSize(long size) {
+ final int threshold = 2;
+ final int factor = 1024;
+ if (size < 0) return "? Byte";
+ if (size < factor * threshold) {
+ return size + " Byte";
+ }
+ char[] units = {'K', 'M', 'G', 'T', 'P'};
+ int unitIndex = 0;
+ double fSize = size;
+ do {
+ unitIndex++;
+ fSize /= 1024;
+ } while (fSize > factor * threshold && unitIndex < units.length);
+
+ return String.format("%.1f %ciB", fSize, units[unitIndex - 1]);
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/BiomeSourceWithSeed.java b/src/main/java/org/betterx/worlds/together/world/BiomeSourceWithSeed.java
new file mode 100644
index 00000000..ecb0dafd
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/BiomeSourceWithSeed.java
@@ -0,0 +1,5 @@
+package org.betterx.worlds.together.world;
+
+public interface BiomeSourceWithSeed {
+ void setSeed(long seed);
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/WorldConfig.java b/src/main/java/org/betterx/worlds/together/world/WorldConfig.java
new file mode 100644
index 00000000..9edc6f17
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/WorldConfig.java
@@ -0,0 +1,165 @@
+package org.betterx.worlds.together.world;
+
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.util.ModUtil;
+import org.betterx.worlds.together.world.event.WorldBootstrap;
+
+import net.minecraft.Util;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtIo;
+
+import net.fabricmc.loader.api.FabricLoader;
+import net.fabricmc.loader.api.ModContainer;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Mod-specifix data-storage for a world.
+ *
+ * This class provides the ability for mod to store persistent data inside a world. The Storage for the world is
+ * currently initialized as part of the {@link WorldBootstrap} in
+ * org.betterx.worlds.together.world.event.WorldBootstrap.Helpers#initializeWorldDataAPI(File, boolean)
+ */
+public class WorldConfig {
+ private static final Map TAGS = Maps.newHashMap();
+ private static final List 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) {
+ WorldConfig.dataDir = dataDir;
+ MODS.stream()
+ .parallel()
+ .forEach(modID -> {
+ File file = new File(dataDir, modID + ".nbt");
+ CompoundTag root = new CompoundTag();
+ if (file.exists()) {
+ try {
+ root = NbtIo.readCompressed(file);
+ } catch (IOException e) {
+ WorldsTogether.LOGGER.error("World data loading failed", e);
+ }
+ TAGS.put(modID, root);
+ } else {
+ Optional optional = FabricLoader.getInstance()
+ .getModContainer(modID);
+ if (optional.isPresent()) {
+ ModContainer modContainer = optional.get();
+ if (WorldsTogether.isDevEnvironment()) {
+ root.putString("version", "255.255.9999");
+ } else {
+ root.putString("version", modContainer.getMetadata()
+ .getVersion()
+ .toString());
+ }
+ TAGS.put(modID, root);
+ saveFile(modID);
+ }
+ }
+ });
+ }
+
+ /**
+ * Register mod cache, world cache is located in world data folder.
+ *
+ * @param modID - {@link String} modID.
+ */
+ public static void registerModCache(String modID) {
+ if (!MODS.contains(modID))
+ MODS.add(modID);
+ }
+
+ /**
+ * Get root {@link CompoundTag} for mod cache in world data folder.
+ *
+ * @param modID - {@link String} modID.
+ * @return {@link CompoundTag}
+ */
+ public static CompoundTag getRootTag(String modID) {
+ 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.
+ *
+ * @param modID - {@link String} path to tag, dot-separated.
+ * @return {@link CompoundTag}
+ */
+ public static CompoundTag getCompoundTag(String modID, String path) {
+ String[] parts = path.split("\\.");
+ CompoundTag tag = getRootTag(modID);
+ for (String part : parts) {
+ if (tag.contains(part)) {
+ tag = tag.getCompound(part);
+ } else {
+ CompoundTag t = new CompoundTag();
+ tag.put(part, t);
+ tag = t;
+ }
+ }
+ return tag;
+ }
+
+ /**
+ * Forces mod cache file to be saved.
+ *
+ * @param modID {@link String} mod ID.
+ */
+ public static void saveFile(String modID) {
+
+ try {
+ if (!dataDir.exists()) {
+ dataDir.mkdirs();
+ }
+ CompoundTag tag = getRootTag(modID);
+ tag.putString(TAG_MODIFIED, ModUtil.getModVersion(modID));
+
+
+ final File tempFile = new File(dataDir, modID + "_temp.nbt");
+ NbtIo.writeCompressed(tag, tempFile);
+
+ final File oldFile = new File(dataDir, modID + "_old.nbt");
+ final File dataFile = new File(dataDir, modID + ".nbt");
+ Util.safeReplaceFile(dataFile, tempFile, oldFile);
+ } catch (IOException e) {
+ WorldsTogether.LOGGER.error("World data saving failed", e);
+ }
+ }
+
+ /**
+ * Get stored mod version (only for mods with registered cache).
+ *
+ * @return {@link String} mod version.
+ */
+ public static String getModVersion(String modID) {
+ return getRootTag(modID).getString("version");
+ }
+
+ /**
+ * Get stored mod version as integer (only for mods with registered cache).
+ *
+ * @return {@code int} mod version.
+ */
+ public static int getIntModVersion(String modID) {
+ return ModUtil.convertModVersion(getModVersion(modID));
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/WorldGenUtil.java b/src/main/java/org/betterx/worlds/together/world/WorldGenUtil.java
new file mode 100644
index 00000000..d22bc6c2
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/WorldGenUtil.java
@@ -0,0 +1,131 @@
+package org.betterx.worlds.together.world;
+
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+
+import com.mojang.datafixers.util.Pair;
+import com.mojang.serialization.Dynamic;
+import net.minecraft.core.Holder;
+import net.minecraft.core.Registry;
+import net.minecraft.core.RegistryAccess;
+import net.minecraft.data.BuiltinRegistries;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtOps;
+import net.minecraft.nbt.Tag;
+import net.minecraft.resources.RegistryOps;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.util.RandomSource;
+import net.minecraft.world.level.biome.Biome;
+import net.minecraft.world.level.dimension.DimensionType;
+import net.minecraft.world.level.dimension.LevelStem;
+import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
+import net.minecraft.world.level.levelgen.WorldGenSettings;
+import net.minecraft.world.level.levelgen.presets.WorldPreset;
+import net.minecraft.world.level.levelgen.structure.StructureSet;
+import net.minecraft.world.level.levelgen.synth.NormalNoise;
+
+import java.util.Optional;
+
+public class WorldGenUtil {
+ public static final String TAG_GENERATOR = "generator";
+
+ public static WorldGenSettings createWorldFromPreset(
+ ResourceKey preset,
+ RegistryAccess registryAccess,
+ long seed,
+ boolean generateStructures,
+ boolean generateBonusChest
+ ) {
+ WorldGenSettings settings = registryAccess
+ .registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
+ .getHolderOrThrow(preset)
+ .value()
+ .createWorldGenSettings(seed, generateStructures, generateBonusChest);
+
+ for (LevelStem stem : settings.dimensions()) {
+ if (stem.generator().getBiomeSource() instanceof BiomeSourceWithSeed bcl) {
+ bcl.setSeed(seed);
+ }
+ }
+
+ return settings;
+ }
+
+ public static WorldGenSettings createDefaultWorldFromPreset(
+ RegistryAccess registryAccess,
+ long seed,
+ boolean generateStructures,
+ boolean generateBonusChest
+ ) {
+ return createWorldFromPreset(
+ WorldPresets.DEFAULT.orElseThrow(),
+ registryAccess,
+ seed,
+ generateStructures,
+ generateBonusChest
+ );
+ }
+
+ public static Pair defaultWorldDataSupplier(RegistryAccess.Frozen frozen) {
+ WorldGenSettings worldGenSettings = createDefaultWorldFromPreset(frozen);
+ return Pair.of(worldGenSettings, frozen);
+ }
+
+ public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess, long seed) {
+ return createDefaultWorldFromPreset(registryAccess, seed, true, false);
+ }
+
+ public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess) {
+ return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
+ }
+
+ public static CompoundTag getSettingsNbt() {
+ return WorldConfig.getCompoundTag(WorldsTogether.MOD_ID, TAG_GENERATOR);
+ }
+
+ public static WorldPresetSettings getWorldSettings() {
+ if (BuiltinRegistries.ACCESS == null) return null;
+ final RegistryAccess registryAccess = BuiltinRegistries.ACCESS;
+ final RegistryOps registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
+
+ Optional oLevelStem = WorldPresetSettings.CODEC
+ .parse(new Dynamic<>(registryOps, getSettingsNbt()))
+ .resultOrPartial(WorldsTogether.LOGGER::error);
+
+ return oLevelStem.orElse(WorldPresetSettings.DEFAULT);
+ }
+
+ public static class Context extends StemContext {
+ public final Registry biomes;
+
+ public Context(
+ Registry biomes, Holder dimension,
+ Registry structureSets,
+ Registry noiseParameters,
+ Holder generatorSettings
+ ) {
+ super(dimension, structureSets, noiseParameters, generatorSettings);
+ this.biomes = biomes;
+ }
+ }
+
+ public static class StemContext {
+ public final Holder dimension;
+ public final Registry structureSets;
+ public final Registry noiseParameters;
+ public final Holder generatorSettings;
+
+ public StemContext(
+ Holder dimension,
+ Registry structureSets,
+ Registry noiseParameters,
+ Holder generatorSettings
+ ) {
+ this.dimension = dimension;
+ this.structureSets = structureSets;
+ this.noiseParameters = noiseParameters;
+ this.generatorSettings = generatorSettings;
+ }
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/AdaptWorldPresetSettingEvent.java b/src/main/java/org/betterx/worlds/together/world/event/AdaptWorldPresetSettingEvent.java
new file mode 100644
index 00000000..06ff376f
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/AdaptWorldPresetSettingEvent.java
@@ -0,0 +1,16 @@
+package org.betterx.worlds.together.world.event;
+
+import net.minecraft.core.Holder;
+import net.minecraft.world.level.levelgen.WorldGenSettings;
+import net.minecraft.world.level.levelgen.presets.WorldPreset;
+
+import java.util.Optional;
+
+public class AdaptWorldPresetSettingEvent extends EventImpl {
+ public Optional> emit(Optional> start, WorldGenSettings settings) {
+ for (OnAdaptWorldPresetSettings a : handlers) {
+ start = a.adapt(start, settings);
+ }
+ return start;
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/BeforeServerWorldLoad.java b/src/main/java/org/betterx/worlds/together/world/event/BeforeServerWorldLoad.java
new file mode 100644
index 00000000..3f8f49be
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/BeforeServerWorldLoad.java
@@ -0,0 +1,14 @@
+package org.betterx.worlds.together.world.event;
+
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+
+import net.minecraft.world.level.storage.LevelStorageSource;
+
+@FunctionalInterface
+public interface BeforeServerWorldLoad {
+ void prepareWorld(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ WorldPresetSettings settings,
+ boolean isNewWorld
+ );
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/BeforeWorldLoad.java b/src/main/java/org/betterx/worlds/together/world/event/BeforeWorldLoad.java
new file mode 100644
index 00000000..0109a769
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/BeforeWorldLoad.java
@@ -0,0 +1,13 @@
+package org.betterx.worlds.together.world.event;
+
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+
+import net.minecraft.world.level.storage.LevelStorageSource;
+
+public interface BeforeWorldLoad {
+ void prepareWorld(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ WorldPresetSettings settings,
+ boolean isNewWorld
+ );
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/Event.java b/src/main/java/org/betterx/worlds/together/world/event/Event.java
new file mode 100644
index 00000000..1e16526c
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/Event.java
@@ -0,0 +1,5 @@
+package org.betterx.worlds.together.world.event;
+
+public interface Event {
+ boolean on(T handler);
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java b/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java
new file mode 100644
index 00000000..01419060
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java
@@ -0,0 +1,22 @@
+package org.betterx.worlds.together.world.event;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.function.Consumer;
+
+class EventImpl implements Event {
+ final List handlers = new LinkedList<>();
+
+ public final boolean on(T handler) {
+ if (!handlers.contains(handler)) {
+ handlers.add(handler);
+ return true;
+ }
+
+ return false;
+ }
+
+ public final void emit(Consumer c) {
+ handlers.forEach(c);
+ }
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/OnAdaptWorldPresetSettings.java b/src/main/java/org/betterx/worlds/together/world/event/OnAdaptWorldPresetSettings.java
new file mode 100644
index 00000000..f333dd90
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/OnAdaptWorldPresetSettings.java
@@ -0,0 +1,15 @@
+package org.betterx.worlds.together.world.event;
+
+import net.minecraft.core.Holder;
+import net.minecraft.world.level.levelgen.WorldGenSettings;
+import net.minecraft.world.level.levelgen.presets.WorldPreset;
+
+import java.util.Optional;
+
+@FunctionalInterface
+public interface OnAdaptWorldPresetSettings {
+ Optional> adapt(
+ Optional> currentPreset,
+ WorldGenSettings worldGenSettings
+ );
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/OnWorldLoad.java b/src/main/java/org/betterx/worlds/together/world/event/OnWorldLoad.java
new file mode 100644
index 00000000..bf86c687
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/OnWorldLoad.java
@@ -0,0 +1,5 @@
+package org.betterx.worlds.together.world.event;
+
+public interface OnWorldLoad {
+ void onLoad();
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/OnWorldPatch.java b/src/main/java/org/betterx/worlds/together/world/event/OnWorldPatch.java
new file mode 100644
index 00000000..58d42b60
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/OnWorldPatch.java
@@ -0,0 +1,13 @@
+package org.betterx.worlds.together.world.event;
+
+import net.minecraft.world.level.storage.LevelStorageSource;
+
+import java.util.function.Consumer;
+
+@FunctionalInterface
+public interface OnWorldPatch {
+ boolean next(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ Consumer allDone
+ );
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/OnWorldRegistryReady.java b/src/main/java/org/betterx/worlds/together/world/event/OnWorldRegistryReady.java
new file mode 100644
index 00000000..08a7cfec
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/OnWorldRegistryReady.java
@@ -0,0 +1,7 @@
+package org.betterx.worlds.together.world.event;
+
+import net.minecraft.core.RegistryAccess;
+
+public interface OnWorldRegistryReady {
+ void initRegistry(RegistryAccess access);
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/PatchWorldEvent.java b/src/main/java/org/betterx/worlds/together/world/event/PatchWorldEvent.java
new file mode 100644
index 00000000..850f27af
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/PatchWorldEvent.java
@@ -0,0 +1,40 @@
+package org.betterx.worlds.together.world.event;
+
+import net.minecraft.world.level.storage.LevelStorageSource;
+
+import java.util.Iterator;
+import java.util.function.Consumer;
+
+class PatchWorldEvent extends EventImpl {
+
+ public boolean applyPatches(
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ Consumer allDone
+ ) {
+ return applyPatches(false, false, storageAccess, handlers.iterator(), allDone);
+ }
+
+ private boolean applyPatches(
+ boolean didApplyFixes,
+ boolean didShowUI,
+ LevelStorageSource.LevelStorageAccess storageAccess,
+ Iterator iterator,
+ Consumer allDone
+ ) {
+ if (!iterator.hasNext()) {
+ if (didShowUI) allDone.accept(didApplyFixes);
+ return didApplyFixes;
+ }
+ OnWorldPatch now = iterator.next();
+
+ boolean shouldHaltForUI = now.next(storageAccess, (appliedFixes) -> applyPatches(
+ didApplyFixes || appliedFixes, true, storageAccess, iterator, allDone
+ ));
+
+ if (!shouldHaltForUI) {
+ applyPatches(didApplyFixes, didShowUI, storageAccess, iterator, allDone);
+ }
+ return didApplyFixes || shouldHaltForUI;
+ }
+
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java b/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java
new file mode 100644
index 00000000..71385bc0
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java
@@ -0,0 +1,278 @@
+package org.betterx.worlds.together.world.event;
+
+import org.betterx.bclib.BCLib;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.mixin.common.RegistryOpsAccessor;
+import org.betterx.worlds.together.world.WorldConfig;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
+import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
+import org.betterx.worlds.together.worldPreset.WorldPresets;
+import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+
+import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
+import net.minecraft.core.Holder;
+import net.minecraft.core.RegistryAccess;
+import net.minecraft.nbt.Tag;
+import net.minecraft.resources.RegistryOps;
+import net.minecraft.world.level.levelgen.WorldGenSettings;
+import net.minecraft.world.level.levelgen.presets.WorldPreset;
+import net.minecraft.world.level.storage.LevelResource;
+import net.minecraft.world.level.storage.LevelStorageSource;
+
+import java.io.File;
+import java.util.Optional;
+import java.util.function.Consumer;
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+public class WorldBootstrap {
+ private static RegistryAccess LAST_REGISTRY_ACCESS = null;
+
+ public static class Helpers {
+ private static void initializeWorldDataAPI(
+ LevelStorageSource.LevelStorageAccess levelStorageAccess,
+ boolean newWorld
+ ) {
+ File levelPath = levelStorageAccess.getLevelPath(LevelResource.ROOT).toFile();
+ initializeWorldDataAPI(levelPath, newWorld);
+ }
+
+ private static void initializeWorldDataAPI(File levelBaseDir, boolean newWorld) {
+ WorldConfig.load(new File(levelBaseDir, "data"));
+
+ if (newWorld) {
+ WorldConfig.saveFile(BCLib.MOD_ID);
+ }
+ }
+
+ private static void onRegistryReady(RegistryAccess a) {
+ if (a != LAST_REGISTRY_ACCESS) {
+ LAST_REGISTRY_ACCESS = a;
+ WorldEventsImpl.WORLD_REGISTRY_READY.emit(e -> e.initRegistry(a));
+ }
+ }
+
+ private static Holder defaultServerPreset() {
+ return WorldPresets.get(
+ LAST_REGISTRY_ACCESS,
+ WorldPresets.DEFAULT.orElseThrow()
+ );
+ }
+
+ private static WorldPresetSettings defaultServerSettings() {
+ final Holder defaultPreset = defaultServerPreset();
+ return defaultServerSettings(defaultPreset);
+ }
+
+ private static WorldPresetSettings defaultServerSettings(Holder defaultPreset) {
+ final WorldPresetSettings settings;
+ if (defaultPreset.value() instanceof TogetherWorldPreset t) {
+ settings = t.settings;
+ } else {
+ settings = VanillaWorldPresetSettings.DEFAULT;
+ }
+ return settings;
+ }
+ }
+
+ public static class DedicatedServer {
+ public static void registryReady(RegistryOps regOps) {
+ if (regOps instanceof RegistryOpsAccessor acc) {
+ Helpers.onRegistryReady(acc.bcl_getRegistryAccess());
+ }
+ }
+
+ public static void setupWorld(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
+ File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile();
+ if (!levelDat.exists()) {
+ BCLib.LOGGER.info("Creating a new World, no fixes needed");
+ final WorldPresetSettings settings = Helpers.defaultServerSettings();
+
+ Helpers.initializeWorldDataAPI(levelStorageAccess, true);
+ WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD.emit(e -> e.prepareWorld(
+ levelStorageAccess, settings, true
+ ));
+ } else {
+ Helpers.initializeWorldDataAPI(levelStorageAccess, false);
+ WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD.emit(e -> e.prepareWorld(
+ levelStorageAccess,
+ WorldGenUtil.getWorldSettings(),
+ false
+ ));
+ WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
+ }
+ }
+
+ //Needs to get called after setupWorld
+ public static void applyDatapackChangesOnNewWorld(WorldGenSettings worldGenSettings) {
+ Optional> currentPreset = Optional.of(Helpers.defaultServerPreset());
+ var settings = Helpers.defaultServerSettings(currentPreset.orElseThrow());
+
+ currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldGenSettings);
+ if (currentPreset.map(h -> h.value()).orElse(null) instanceof TogetherWorldPreset t) {
+ settings = t.settings;
+ }
+ TogetherWorldPreset.writeWorldPresetSettings(settings);
+ WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
+ }
+ }
+
+ public static class InGUI {
+ public static void registryReadyOnNewWorld(WorldGenSettingsComponent worldGenSettingsComponent) {
+ Helpers.onRegistryReady(worldGenSettingsComponent.registryHolder());
+ }
+
+ public static void registryReadyOnLoadedWorld(Optional> registryOps) {
+ if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
+ Helpers.onRegistryReady(acc.bcl_getRegistryAccess());
+ }
+ }
+
+ public static void setupNewWorld(
+ Optional levelStorageAccess,
+ WorldGenSettingsComponent worldGenSettingsComponent
+ ) {
+ if (levelStorageAccess.isPresent()) {
+ if (worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc) {
+ Optional> currentPreset = acc.bcl_getPreset();
+ Optional> newPreset = setupNewWorldCommon(
+ levelStorageAccess.get(),
+ currentPreset,
+ worldGenSettingsComponent.settings().worldGenSettings()
+ );
+ if (newPreset != currentPreset) {
+ acc.bcl_setPreset(newPreset);
+ }
+ } else {
+ WorldsTogether.LOGGER.error("Unable to access WorldGenSettingsComponent.");
+ }
+ } else {
+ WorldsTogether.LOGGER.error("Unable to access Level Folder.");
+ }
+
+ }
+
+ static Optional> setupNewWorldCommon(
+ LevelStorageSource.LevelStorageAccess levelStorageAccess,
+ Optional> currentPreset,
+ WorldGenSettings worldgenSettings
+ ) {
+ Helpers.initializeWorldDataAPI(levelStorageAccess, true);
+
+
+ final WorldPresetSettings settings;
+ if (currentPreset.map(Holder::value).orElse(null) instanceof TogetherWorldPreset t) {
+ settings = t.settings;
+ } else {
+ settings = VanillaWorldPresetSettings.DEFAULT;
+ }
+
+ // Helpers.setupWorld();
+ // DataFixerAPI.initializePatchData();
+ WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
+ levelStorageAccess,
+ settings,
+ true
+ ));
+
+ currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldgenSettings);
+
+ TogetherWorldPreset.writeWorldPresetSettings(currentPreset);
+
+ //LifeCycleAPI._runBeforeLevelLoad();
+ WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
+
+ return currentPreset;
+ }
+
+ /**
+ * Does not call {@link WorldEventsImpl#ON_WORLD_LOAD}
+ */
+ public static void setupLoadedWorld(
+ String levelID,
+ LevelStorageSource levelSource
+ ) {
+ try {
+ var levelStorageAccess = levelSource.createAccess(levelID);
+ Helpers.initializeWorldDataAPI(levelStorageAccess, false);
+
+ //Helpers.setupWorld();
+ WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
+ levelStorageAccess,
+ WorldGenUtil.getWorldSettings(),
+ false
+ ));
+ levelStorageAccess.close();
+ } catch (Exception e) {
+ BCLib.LOGGER.error("Failed to initialize data in world", e);
+ }
+ }
+
+ public static boolean applyWorldPatches(
+ LevelStorageSource levelSource,
+ String levelID,
+ Consumer onResume
+ ) {
+ boolean result = false;
+ try {
+ var levelStorageAccess = levelSource.createAccess(levelID);
+ result = WorldEventsImpl.PATCH_WORLD.applyPatches(levelStorageAccess, onResume);
+ levelStorageAccess.close();
+ } catch (Exception e) {
+ BCLib.LOGGER.error("Failed to initialize data in world", e);
+ }
+
+ return result;
+ }
+
+ public static void finishedWorldLoad(
+ String levelID,
+ LevelStorageSource levelSource
+ ) {
+ //LifeCycleAPI._runBeforeLevelLoad();
+ WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
+ }
+ }
+
+ public static class InFreshLevel {
+ public static void setupNewWorld(
+ String levelID,
+ WorldGenSettings worldGenSettings,
+ LevelStorageSource levelSource,
+ Optional> worldPreset
+ ) {
+ try {
+ var levelStorageAccess = levelSource.createAccess(levelID);
+ InGUI.setupNewWorldCommon(levelStorageAccess, worldPreset, worldGenSettings);
+ levelStorageAccess.close();
+ } catch (Exception e) {
+ BCLib.LOGGER.error("Failed to initialize data in world", e);
+ }
+ }
+ }
+
+ public static WorldGenSettings enforceInNewWorld(WorldGenSettings worldGenSettings) {
+ worldGenSettings = WorldGenUtil
+ .getWorldSettings()
+ .repairSettingsOnLoad(LAST_REGISTRY_ACCESS, worldGenSettings);
+ return worldGenSettings;
+ }
+
+ public static WorldGenSettings enforceInLoadedWorld(
+ Optional> registryOps,
+ WorldGenSettings worldGenSettings
+ ) {
+ if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
+ return WorldGenUtil
+ .getWorldSettings()
+ .repairSettingsOnLoad(acc.bcl_getRegistryAccess(), worldGenSettings);
+ //.repairSettingsOnLoad(LAST_REGISTRY_ACCESS, worldGenSettings);
+ } else {
+ BCLib.LOGGER.error("Unable to obtain registryAccess when enforcing generators.");
+ }
+ return worldGenSettings;
+ }
+
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java b/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java
new file mode 100644
index 00000000..b1891588
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java
@@ -0,0 +1,11 @@
+package org.betterx.worlds.together.world.event;
+
+public class WorldEvents {
+ public static final Event WORLD_REGISTRY_READY = WorldEventsImpl.WORLD_REGISTRY_READY;
+ public static final Event BEFORE_WORLD_LOAD = WorldEventsImpl.BEFORE_WORLD_LOAD;
+ public static final Event BEFORE_SERVER_WORLD_LOAD = WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD;
+ public static final Event ON_WORLD_LOAD = WorldEventsImpl.ON_WORLD_LOAD;
+
+ public static final Event PATCH_WORLD = WorldEventsImpl.PATCH_WORLD;
+ public static final Event ADAPT_WORLD_PRESET = WorldEventsImpl.ADAPT_WORLD_PRESET;
+}
diff --git a/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java b/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java
new file mode 100644
index 00000000..7dd2020d
--- /dev/null
+++ b/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java
@@ -0,0 +1,12 @@
+package org.betterx.worlds.together.world.event;
+
+class WorldEventsImpl {
+ public static final EventImpl WORLD_REGISTRY_READY = new EventImpl<>();
+ public static final EventImpl BEFORE_WORLD_LOAD = new EventImpl<>();
+ public static final EventImpl BEFORE_SERVER_WORLD_LOAD = new EventImpl<>();
+
+ public static final EventImpl ON_WORLD_LOAD = new EventImpl<>();
+
+ public static final PatchWorldEvent PATCH_WORLD = new PatchWorldEvent();
+ public static final AdaptWorldPresetSettingEvent ADAPT_WORLD_PRESET = new AdaptWorldPresetSettingEvent();
+}
diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPreset.java b/src/main/java/org/betterx/worlds/together/worldPreset/TogetherWorldPreset.java
similarity index 63%
rename from src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPreset.java
rename to src/main/java/org/betterx/worlds/together/worldPreset/TogetherWorldPreset.java
index 1fe4c369..04091295 100644
--- a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPreset.java
+++ b/src/main/java/org/betterx/worlds/together/worldPreset/TogetherWorldPreset.java
@@ -1,9 +1,11 @@
-package org.betterx.bclib.presets.worldgen;
+package org.betterx.worlds.together.worldPreset;
-import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.WorldDataAPI;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
-import org.betterx.bclib.mixin.common.WorldPresetAccessor;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.mixin.common.WorldPresetAccessor;
+import org.betterx.worlds.together.world.WorldConfig;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
import net.minecraft.core.Holder;
import net.minecraft.data.BuiltinRegistries;
@@ -18,15 +20,15 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
import java.util.Map;
import java.util.Optional;
-public class BCLWorldPreset extends WorldPreset {
+public class TogetherWorldPreset extends WorldPreset {
public final WorldPresetSettings settings;
public final int sortOrder;
- private static final String TAG_GENERATOR = LevelGenUtil.TAG_GENERATOR;
+ private static final String TAG_GENERATOR = WorldGenUtil.TAG_GENERATOR;
private static int NEXT_IN_SORT_ORDER = 1000;
- public BCLWorldPreset(
+ public TogetherWorldPreset(
Map, LevelStem> map,
Optional sortOrder,
Optional settings
@@ -34,14 +36,18 @@ public class BCLWorldPreset extends WorldPreset {
this(map, sortOrder.orElse(NEXT_IN_SORT_ORDER++), settings.orElse(VanillaWorldPresetSettings.DEFAULT));
}
- public BCLWorldPreset(Map, LevelStem> map, int sortOrder, WorldPresetSettings settings) {
+ public TogetherWorldPreset(
+ Map, LevelStem> map,
+ int sortOrder,
+ WorldPresetSettings settings
+ ) {
super(map);
this.sortOrder = sortOrder;
this.settings = settings;
}
- public BCLWorldPreset withSettings(WorldPresetSettings settings) {
- return new BCLWorldPreset(getDimensions(), sortOrder, settings);
+ public TogetherWorldPreset withSettings(WorldPresetSettings settings) {
+ return new TogetherWorldPreset(getDimensions(), sortOrder, settings);
}
private Map, LevelStem> getDimensions() {
@@ -49,7 +55,7 @@ public class BCLWorldPreset extends WorldPreset {
}
public static WorldPresetSettings writeWorldPresetSettings(Optional> worldPreset) {
- if (worldPreset.isPresent() && worldPreset.get().value() instanceof BCLWorldPreset wp) {
+ if (worldPreset.isPresent() && worldPreset.get().value() instanceof TogetherWorldPreset wp) {
writeWorldPresetSettings(wp.settings);
return wp.settings;
} else {
@@ -64,12 +70,12 @@ public class BCLWorldPreset extends WorldPreset {
final var encodeResult = codec.encodeStart(registryOps, presetSettings);
if (encodeResult.result().isPresent()) {
- final CompoundTag settingsNbt = WorldDataAPI.getRootTag(BCLib.TOGETHER_WORLDS);
+ final CompoundTag settingsNbt = WorldConfig.getRootTag(WorldsTogether.MOD_ID);
settingsNbt.put(TAG_GENERATOR, encodeResult.result().get());
} else {
- BCLib.LOGGER.error("Unable to encode world generator settings generator for level.dat.");
+ WorldsTogether.LOGGER.error("Unable to encode world generator settings for level.dat.");
}
- WorldDataAPI.saveFile(BCLib.TOGETHER_WORLDS);
+ WorldConfig.saveFile(WorldsTogether.MOD_ID);
}
}
diff --git a/src/main/java/org/betterx/bclib/interfaces/WorldGenSettingsComponentAccessor.java b/src/main/java/org/betterx/worlds/together/worldPreset/WorldGenSettingsComponentAccessor.java
similarity index 85%
rename from src/main/java/org/betterx/bclib/interfaces/WorldGenSettingsComponentAccessor.java
rename to src/main/java/org/betterx/worlds/together/worldPreset/WorldGenSettingsComponentAccessor.java
index 4c448446..6cb12e14 100644
--- a/src/main/java/org/betterx/bclib/interfaces/WorldGenSettingsComponentAccessor.java
+++ b/src/main/java/org/betterx/worlds/together/worldPreset/WorldGenSettingsComponentAccessor.java
@@ -1,4 +1,4 @@
-package org.betterx.bclib.interfaces;
+package org.betterx.worlds.together.worldPreset;
import net.minecraft.core.Holder;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresets.java b/src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java
similarity index 53%
rename from src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresets.java
rename to src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java
index 0d425f35..ee5763c4 100644
--- a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresets.java
+++ b/src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java
@@ -1,12 +1,17 @@
-package org.betterx.bclib.presets.worldgen;
+package org.betterx.worlds.together.worldPreset;
-import org.betterx.bclib.BCLib;
-import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
-import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.api.v2.tag.TagAPI;
import org.betterx.bclib.api.v2.tag.TagType;
+import org.betterx.bclib.registry.PresetsRegistry;
+import org.betterx.worlds.together.WorldsTogether;
+import org.betterx.worlds.together.world.WorldGenUtil;
+import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
+import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
+import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
+import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
+import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
@@ -19,58 +24,40 @@ import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Optional;
-public class BCLWorldPresets {
+public class WorldPresets {
public static final TagType.Simple WORLD_PRESETS =
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
private static Map, PresetBuilder> BUILDERS = Maps.newHashMap();
private static final Map, WorldPresetSettings> SETTINGS = Maps.newHashMap();
- public static final ResourceKey BCL_WORLD =
- register(
- BCLib.makeID("normal"),
- (overworldStem, netherContext, endContext) ->
- new BCLWorldPresetSettings(BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION).buildPreset(
- overworldStem,
- netherContext,
- endContext
- ),
- true
- );
- public static Optional> DEFAULT = Optional.of(BCL_WORLD);
- public static final ResourceKey BCL_WORLD_17 = register(
- BCLib.makeID("legacy_17"),
- (overworldStem, netherContext, endContext) ->
- new BCLWorldPresetSettings(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE).buildPreset(
- overworldStem,
- netherContext,
- endContext
- ),
- false
- );
+ public static Optional> DEFAULT = Optional.of(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
+
+ public static Holder get(RegistryAccess access, ResourceKey key) {
+ return ((access != null) ? access : BuiltinRegistries.ACCESS)
+ .registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
+ .getHolderOrThrow(key);
+ }
/**
* Registers a custom WorldPreset (with custom rules and behaviour)
*
- * See also {@link org.betterx.bclib.client.presets.WorldPresetsUI} if you need to add a Customize Button/Screen
+ * See also {@link WorldPresetsClient} if you need to add a Customize Button/Screen
* for your preset
*
- * @param loc The ID of your Preset
+ * @param loc The ID of your Preset
+ * @param visibleInUI if true, the preset will show up in the UI on world creataion
* @return The key you may use to reference your new Preset
*/
- private static ResourceKey register(ResourceLocation loc) {
- return register(loc, true);
- }
-
- private static ResourceKey register(ResourceLocation loc, boolean addToNormal) {
+ private static ResourceKey register(ResourceLocation loc, boolean visibleInUI) {
ResourceKey key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY, loc);
- if (addToNormal) {
+ if (visibleInUI) {
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
}
return key;
}
- public static void registerPresets() {
+ public static void ensureStaticallyLoaded() {
}
@@ -82,7 +69,7 @@ public class BCLWorldPresets {
ResourceKey key = register(loc, visibleInUI);
if (BUILDERS == null) {
- BCLib.LOGGER.error("Unable to register WorldPreset '" + loc + "'.");
+ WorldsTogether.LOGGER.error("Unable to register WorldPreset '" + loc + "'.");
} else {
BUILDERS.put(key, builder);
@@ -93,12 +80,13 @@ public class BCLWorldPresets {
public static void bootstrapPresets(
Registry presets,
LevelStem overworldStem,
- LevelGenUtil.Context netherContext,
- LevelGenUtil.Context endContext
+ WorldGenUtil.Context netherContext,
+ WorldGenUtil.Context endContext
) {
+ PresetsRegistry.onLoad();
for (Map.Entry, PresetBuilder> e : BUILDERS.entrySet()) {
- BCLWorldPreset preset = e.getValue().create(overworldStem, netherContext, endContext);
+ TogetherWorldPreset preset = e.getValue().create(overworldStem, netherContext, endContext);
SETTINGS.put(e.getKey(), preset.settings);
BuiltinRegistries.register(presets, e.getKey(), preset);
}
@@ -106,15 +94,15 @@ public class BCLWorldPresets {
}
public static WorldPresetSettings getSettingsForPreset(ResourceKey key) {
- return SETTINGS.getOrDefault(key, BCLWorldPresetSettings.DEFAULT);
+ return SETTINGS.getOrDefault(key, VanillaWorldPresetSettings.DEFAULT);
}
@FunctionalInterface
public interface PresetBuilder {
- BCLWorldPreset create(
+ TogetherWorldPreset create(
LevelStem overworldStem,
- LevelGenUtil.Context netherContext,
- LevelGenUtil.Context endContext
+ WorldGenUtil.Context netherContext,
+ WorldGenUtil.Context endContext
);
}
}
diff --git a/src/main/java/org/betterx/bclib/client/presets/WorldPresetsUI.java b/src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java
similarity index 59%
rename from src/main/java/org/betterx/bclib/client/presets/WorldPresetsUI.java
rename to src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java
index 57f59afa..ff0768db 100644
--- a/src/main/java/org/betterx/bclib/client/presets/WorldPresetsUI.java
+++ b/src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java
@@ -1,7 +1,6 @@
-package org.betterx.bclib.client.presets;
+package org.betterx.worlds.together.worldPreset.client;
-import org.betterx.bclib.client.gui.screens.WorldSetupScreen;
-import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
+import org.betterx.bclib.registry.PresetsRegistryClient;
import net.minecraft.client.gui.screens.worldselection.PresetEditor;
import net.minecraft.resources.ResourceKey;
@@ -13,7 +12,7 @@ import net.fabricmc.api.Environment;
import java.util.Optional;
@Environment(EnvType.CLIENT)
-public class WorldPresetsUI {
+public class WorldPresetsClient {
public static void registerCustomizeUI(ResourceKey key, PresetEditor setupScreen) {
if (setupScreen != null) {
PresetEditor.EDITORS.put(Optional.of(key), setupScreen);
@@ -21,8 +20,6 @@ public class WorldPresetsUI {
}
public static void setupClientside() {
- registerCustomizeUI(BCLWorldPresets.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
- return new WorldSetupScreen(createWorldScreen, worldCreationContext);
- });
+ PresetsRegistryClient.onLoad();
}
}
diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/VanillaWorldPresetSettings.java b/src/main/java/org/betterx/worlds/together/worldPreset/settings/VanillaWorldPresetSettings.java
similarity index 94%
rename from src/main/java/org/betterx/bclib/presets/worldgen/VanillaWorldPresetSettings.java
rename to src/main/java/org/betterx/worlds/together/worldPreset/settings/VanillaWorldPresetSettings.java
index 1ff10b89..2e85ba2a 100644
--- a/src/main/java/org/betterx/bclib/presets/worldgen/VanillaWorldPresetSettings.java
+++ b/src/main/java/org/betterx/worlds/together/worldPreset/settings/VanillaWorldPresetSettings.java
@@ -1,4 +1,4 @@
-package org.betterx.bclib.presets.worldgen;
+package org.betterx.worlds.together.worldPreset.settings;
import com.mojang.serialization.Codec;
import net.minecraft.core.Holder;
diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/WorldPresetSettings.java b/src/main/java/org/betterx/worlds/together/worldPreset/settings/WorldPresetSettings.java
similarity index 83%
rename from src/main/java/org/betterx/bclib/presets/worldgen/WorldPresetSettings.java
rename to src/main/java/org/betterx/worlds/together/worldPreset/settings/WorldPresetSettings.java
index 7f000fa6..a0458b1c 100644
--- a/src/main/java/org/betterx/bclib/presets/worldgen/WorldPresetSettings.java
+++ b/src/main/java/org/betterx/worlds/together/worldPreset/settings/WorldPresetSettings.java
@@ -1,6 +1,6 @@
-package org.betterx.bclib.presets.worldgen;
+package org.betterx.worlds.together.worldPreset.settings;
-import org.betterx.bclib.BCLib;
+import org.betterx.worlds.together.WorldsTogether;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Lifecycle;
@@ -18,8 +18,9 @@ import java.util.Set;
import java.util.function.Function;
public abstract class WorldPresetSettings {
+ public static WorldPresetSettings DEFAULT = VanillaWorldPresetSettings.DEFAULT;
public static final ResourceKey>> WORLD_PRESET_SETTINGS_REGISTRY =
- createRegistryKey(BCLib.makeID("worldgen/world_preset_settings"));
+ createRegistryKey(WorldsTogether.makeID("worldgen/world_preset_settings"));
public static final Registry> WORLD_PRESET_SETTINGS =
registerSimple(WORLD_PRESET_SETTINGS_REGISTRY);
@@ -46,8 +47,7 @@ public abstract class WorldPresetSettings {
}
public static void bootstrap() {
- register(BCLib.makeID("bcl_world_preset_settings"), BCLWorldPresetSettings.CODEC);
- register(BCLib.makeID("vanilla_world_preset_settings"), VanillaWorldPresetSettings.CODEC);
+ register(WorldsTogether.makeID("vanilla_world_preset_settings"), VanillaWorldPresetSettings.CODEC);
}
public abstract Codec extends WorldPresetSettings> codec();
diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json
index 7a8e1113..0f258868 100644
--- a/src/main/resources/bclib.mixins.client.json
+++ b/src/main/resources/bclib.mixins.client.json
@@ -7,15 +7,13 @@
"AnvilScreenMixin",
"BlockMixin",
"ClientRecipeBookMixin",
- "CreateWorldScreenMixin",
"FogRendererMixin",
"GameMixin",
"MinecraftMixin",
"ModelBakeryMixin",
"ModelManagerMixin",
"SignEditScreenMixin",
- "TextureAtlasMixin",
- "WorldGenSettingsComponentMixin"
+ "TextureAtlasMixin"
],
"injectors": {
"defaultRequire": 1
diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json
index 9a3a31d4..e78e72ee 100644
--- a/src/main/resources/bclib.mixins.common.json
+++ b/src/main/resources/bclib.mixins.common.json
@@ -23,7 +23,6 @@
"ItemStackMixin",
"LayerLightSectionStorageMixin",
"LootPoolMixin",
- "MainMixin",
"MinecraftServerMixin",
"MinecraftServerMixinLate",
"MobSpawnSettingsAccessor",
@@ -33,22 +32,15 @@
"PortalShapeMixin",
"PotionBrewingAccessor",
"PresetEditorMixin",
- "PrimaryLevelDataMixin",
"RecipeManagerAccessor",
"RecipeManagerMixin",
- "RegistryOpsAccessor",
"ServerLevelMixin",
"ShovelItemAccessor",
"StructuresAccessor",
"SurfaceRulesContextAccessor",
"TagLoaderMixin",
"TheEndBiomeDataMixin",
- "WorldGenPropertiesMixin",
"WorldGenRegionMixin",
- "WorldOpenFlowsMixin",
- "WorldPresetAccessor",
- "WorldPresetMixin",
- "WorldPresetsBootstrapMixin",
"elytra.LivingEntityMixin",
"shears.BeehiveBlockMixin",
"shears.DiggingEnchantmentMixin",
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index 2f7d86c9..40863b9b 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -33,6 +33,8 @@
},
"accessWidener": "bclib.accesswidener",
"mixins": [
+ "together.mixins.common.json",
+ "together.mixins.client.json",
"bclib.mixins.common.json",
"bclib.mixins.client.json"
],
diff --git a/src/main/resources/together.mixins.client.json b/src/main/resources/together.mixins.client.json
new file mode 100644
index 00000000..af54d5ed
--- /dev/null
+++ b/src/main/resources/together.mixins.client.json
@@ -0,0 +1,14 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "org.betterx.worlds.together.mixin.client",
+ "compatibilityLevel": "JAVA_17",
+ "client": [
+ "CreateWorldScreenMixin",
+ "WorldGenSettingsComponentMixin",
+ "WorldOpenFlowsMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/src/main/resources/together.mixins.common.json b/src/main/resources/together.mixins.common.json
new file mode 100644
index 00000000..2b3b4326
--- /dev/null
+++ b/src/main/resources/together.mixins.common.json
@@ -0,0 +1,18 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "org.betterx.worlds.together.mixin.common",
+ "compatibilityLevel": "JAVA_17",
+ "mixins": [
+ "MainMixin",
+ "PrimaryLevelDataMixin",
+ "RegistryOpsAccessor",
+ "WorldGenPropertiesMixin",
+ "WorldPresetAccessor",
+ "WorldPresetMixin",
+ "WorldPresetsBootstrapMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}