[Change] Separated all World-Load related code to a new namespace

This commit is contained in:
Frank 2022-06-21 16:32:45 +02:00
parent 67d09676c4
commit 25fa53541f
79 changed files with 1924 additions and 814 deletions

View file

@ -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

View file

@ -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();

View file

@ -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

View file

@ -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.
* <p>
* 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<String, CompoundTag> TAGS = Maps.newHashMap();
private static final List<String> MODS = Lists.newArrayList();
private static final String TAG_CREATED = "create_version";
private static final String TAG_MODIFIED = "modify_version";
private static File dataDir;
/**
* @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<ModContainer> 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);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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<String, List<String>> 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());
}
}
}

View file

@ -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}
* <p>
@ -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.
* <p>
* {@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 <i>items</i> 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<String> getWorldDataIDPaths() {
return null;

View file

@ -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;

View file

@ -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());

View file

@ -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 {

View file

@ -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<Boolean> allDone
) {
return DataFixerAPI.fixData(storageAccess, true, allDone);
}
public static Optional<Holder<WorldPreset>> adaptWorldPresetSettings(
Optional<Holder<WorldPreset>> 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();
}
}

View file

@ -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<Integer> version) {
public static LevelStem getBCLNetherLevelStem(WorldGenUtil.Context context, Optional<Integer> 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<Integer> version) {
public static LevelStem getBCLEndLevelStem(WorldGenUtil.Context context, Optional<Integer> version) {
BCLibEndBiomeSource endSource = new BCLibEndBiomeSource(context.biomes, version);
return getBCLEndLevelStem(context, endSource);
}
public static WorldGenSettings createWorldFromPreset(
ResourceKey<WorldPreset> 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<WorldGenSettings, RegistryAccess.Frozen> 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<LevelStem> 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<LevelStem> 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<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
Optional<WorldPresetSettings> 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<DimensionType> dimension;
public final Registry<StructureSet> structureSets;
public final Registry<NormalNoise.NoiseParameters> noiseParameters;
public final Holder<NoiseGeneratorSettings> generatorSettings;
public StemContext(
Holder<DimensionType> dimension,
Registry<StructureSet> structureSets,
Registry<NormalNoise.NoiseParameters> noiseParameters,
Holder<NoiseGeneratorSettings> generatorSettings
) {
this.dimension = dimension;
this.structureSets = structureSets;
this.noiseParameters = noiseParameters;
this.generatorSettings = generatorSettings;
}
}
public static class Context extends StemContext {
public final Registry<Biome> biomes;
public Context(
Registry<Biome> biomes, Holder<DimensionType> dimension,
Registry<StructureSet> structureSets,
Registry<NormalNoise.NoiseParameters> noiseParameters,
Holder<NoiseGeneratorSettings> generatorSettings
) {
super(dimension, structureSets, noiseParameters, generatorSettings);
this.biomes = biomes;
}
}
}

View file

@ -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<Tag> regOps) {
if (regOps instanceof RegistryOpsAccessor acc) {
initRegistry(acc.bcl_getRegistryAccess());
}
}
/**
* Initialize registry for current server.
*

View file

@ -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();
}

View file

@ -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<String, ModUtil.ModInfo> mods,
Map<String, org.betterx.worlds.together.util.ModUtil.ModInfo> mods,
HelloClient.IServerModMap serverInfo
) {
this(parent, title, description, CommonComponents.GUI_BACK, mods, serverInfo);

View file

@ -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;

View file

@ -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,

View file

@ -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 {

View file

@ -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;

View file

@ -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 = "<init>", index = 3, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServerProperties$WorldGenProperties;<init>(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();
}
}

View file

@ -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 = "<init>")
private void appendGlobalFeatures(

View file

@ -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<Boolean> info) {
int x = blockPos.getX() >> 4;

View file

@ -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<FlatLevelGeneratorPreset> 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<FlatLevelGeneratorPreset> 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<FlatLevelGeneratorPreset> register(ResourceLocation loc) {
ResourceKey<FlatLevelGeneratorPreset> 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);
}
}

View file

@ -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<ResourceKey<LevelStem>, 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<LevelStem> key) {
public LevelStem createStem(WorldGenUtil.Context ctx, ResourceKey<LevelStem> 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));
}

View file

@ -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<Tag> 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<Tag>> registryOps) {
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
InternalBiomeAPI.initRegistry(acc.bcl_getRegistryAccess());
}
}
public static void setupNewWorld(
Optional<LevelStorageSource.LevelStorageAccess> 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<Holder<WorldPreset>> worldPreset
) {
InGUI.setupLoadedWorld(levelID, levelSource);
BCLWorldPreset.writeWorldPresetSettings(worldPreset);
DataFixerAPI.initializePatchData();
LifeCycleAPI._runBeforeLevelLoad();
}
}
private static Optional<Holder<WorldPreset>> adaptPresetForDatapacks(
WorldGenSettingsComponentAccessor accessor,
WorldGenSettingsComponent component
) {
LevelStem endStem = component.settings().worldGenSettings().dimensions().get(LevelStem.END);
Optional<Holder<WorldPreset>> 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<Tag>> 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;
}
}

View file

@ -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<WorldPreset> BCL_WORLD;
public static ResourceKey<WorldPreset> 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);
}
}

View file

@ -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);
});
}
}

View file

@ -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<String, ModInfo> 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.
* <p>
* The method will cache the results. You can clear that cache (and free the memory) by
* calling {@link #invalidateCachedMods()}
* <p>
* 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<String, ModInfo> 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.
* <p>
* 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<ModContainer> 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 &gt; 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 &ge; 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());
}
}
}

View file

@ -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.
* <p>
* 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<Path> 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<Path> 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);
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS =
TagAPI.registerType(
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
"tags/worldgen/flat_level_generator_preset",
(b) -> null
);
public static ResourceKey<FlatLevelGeneratorPreset> register(ResourceLocation loc) {
ResourceKey<FlatLevelGeneratorPreset> key = ResourceKey.create(
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
loc
);
FLAT_LEVEL_PRESETS.addUntyped(FlatLevelGeneratorPresetTags.VISIBLE, key.location());
return key;
}
}

View file

@ -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;<init>(Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext;Ljava/util/Optional;Ljava/util/OptionalLong;)V"))
private static Optional<ResourceKey<WorldPreset>> bcl_NewDefault(Optional<ResourceKey<WorldPreset>> 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<WorldGenSettings> bcl_NewDefaultSettings(WorldLoader.WorldDataSupplier<WorldGenSettings> worldDataSupplier) {
return (resourceManager, dataPackConfig) -> {
Pair<WorldGenSettings, RegistryAccess.Frozen> 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<Optional<LevelStorageSource.LevelStorageAccess>> cir) {
WorldBootstrap.InGUI.registryReady(this.worldGenSettingsComponent);
WorldBootstrap.InGUI.registryReadyOnNewWorld(this.worldGenSettingsComponent);
WorldBootstrap.InGUI.setupNewWorld(cir.getReturnValue(), this.worldGenSettingsComponent);
}
}

View file

@ -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;

View file

@ -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();

View file

@ -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;<init>(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;
}
}

View file

@ -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;<init>(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<Tag>> registryOps = bcl_lastRegistryAccess.get();
WorldBootstrap.InGUI.registryReady(registryOps);
WorldBootstrap.InGUI.registryReadyOnLoadedWorld(registryOps);
settings = WorldBootstrap.enforceInLoadedWorld(registryOps, settings);
bcl_lastRegistryAccess.set(Optional.empty());
return settings;

View file

@ -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;

View file

@ -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<WorldPreset> bcl_foo(ResourceKey<WorldPreset> resourceKey) {
return BCLWorldPresets.DEFAULT.orElseThrow();
return WorldPresets.DEFAULT.orElseThrow();
}
}

View file

@ -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;

View file

@ -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,19 +40,19 @@ public class WorldPresetMixin {
RecordCodecBuilder<WorldPreset, Optional<Integer>> 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<WorldPreset, Optional<WorldPresetSettings>> 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;

View file

@ -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;
}

View file

@ -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<String, ModInfo> 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.
* <p>
* The method will cache the results. You can clear that cache (and free the memory) by
* calling {@link #invalidateCachedMods()}
* <p>
* 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<String, ModInfo> 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<String> 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<ModDependency> getDepends() {
return new ArrayList<>();
}
@Override
public Collection<ModDependency> getRecommends() {
return new ArrayList<>();
}
@Override
public Collection<ModDependency> getSuggests() {
return new ArrayList<>();
}
@Override
public Collection<ModDependency> getConflicts() {
return new ArrayList<>();
}
@Override
public Collection<ModDependency> getBreaks() {
return new ArrayList<>();
}
public Collection<ModDependency> getDependencies() {
return new ArrayList<>();
}
@Override
public String getName() {
return data.get("name")
.getAsString();
}
@Override
public String getDescription() {
return "";
}
@Override
public Collection<Person> getAuthors() {
return new ArrayList<>();
}
@Override
public Collection<Person> getContributors() {
return new ArrayList<>();
}
@Override
public ContactInformation getContact() {
return null;
}
@Override
public Collection<String> getLicense() {
return new ArrayList<>();
}
@Override
public Optional<String> 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<String, CustomValue> 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.
* <p>
* 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<ModContainer> 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 &gt; 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 &ge; 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<String>());
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());
}
}
}

View file

@ -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.
* <p>
* 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<Path> 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<Path> 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]);
}
}

View file

@ -0,0 +1,5 @@
package org.betterx.worlds.together.world;
public interface BiomeSourceWithSeed {
void setSeed(long seed);
}

View file

@ -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.
* <p>
* 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<String, CompoundTag> TAGS = Maps.newHashMap();
private static final List<String> MODS = Lists.newArrayList();
private static final String TAG_CREATED = "create_version";
private static final String TAG_MODIFIED = "modify_version";
private static File dataDir;
public static void load(File dataDir) {
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<ModContainer> 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));
}
}

View file

@ -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<WorldPreset> 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<WorldGenSettings, RegistryAccess.Frozen> 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<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
Optional<WorldPresetSettings> 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<Biome> biomes;
public Context(
Registry<Biome> biomes, Holder<DimensionType> dimension,
Registry<StructureSet> structureSets,
Registry<NormalNoise.NoiseParameters> noiseParameters,
Holder<NoiseGeneratorSettings> generatorSettings
) {
super(dimension, structureSets, noiseParameters, generatorSettings);
this.biomes = biomes;
}
}
public static class StemContext {
public final Holder<DimensionType> dimension;
public final Registry<StructureSet> structureSets;
public final Registry<NormalNoise.NoiseParameters> noiseParameters;
public final Holder<NoiseGeneratorSettings> generatorSettings;
public StemContext(
Holder<DimensionType> dimension,
Registry<StructureSet> structureSets,
Registry<NormalNoise.NoiseParameters> noiseParameters,
Holder<NoiseGeneratorSettings> generatorSettings
) {
this.dimension = dimension;
this.structureSets = structureSets;
this.noiseParameters = noiseParameters;
this.generatorSettings = generatorSettings;
}
}
}

View file

@ -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<OnAdaptWorldPresetSettings> {
public Optional<Holder<WorldPreset>> emit(Optional<Holder<WorldPreset>> start, WorldGenSettings settings) {
for (OnAdaptWorldPresetSettings a : handlers) {
start = a.adapt(start, settings);
}
return start;
}
}

View file

@ -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
);
}

View file

@ -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
);
}

View file

@ -0,0 +1,5 @@
package org.betterx.worlds.together.world.event;
public interface Event<T> {
boolean on(T handler);
}

View file

@ -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<T> implements Event<T> {
final List<T> 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<T> c) {
handlers.forEach(c);
}
}

View file

@ -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<Holder<WorldPreset>> adapt(
Optional<Holder<WorldPreset>> currentPreset,
WorldGenSettings worldGenSettings
);
}

View file

@ -0,0 +1,5 @@
package org.betterx.worlds.together.world.event;
public interface OnWorldLoad {
void onLoad();
}

View file

@ -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<Boolean> allDone
);
}

View file

@ -0,0 +1,7 @@
package org.betterx.worlds.together.world.event;
import net.minecraft.core.RegistryAccess;
public interface OnWorldRegistryReady {
void initRegistry(RegistryAccess access);
}

View file

@ -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<OnWorldPatch> {
public boolean applyPatches(
LevelStorageSource.LevelStorageAccess storageAccess,
Consumer<Boolean> allDone
) {
return applyPatches(false, false, storageAccess, handlers.iterator(), allDone);
}
private boolean applyPatches(
boolean didApplyFixes,
boolean didShowUI,
LevelStorageSource.LevelStorageAccess storageAccess,
Iterator<OnWorldPatch> iterator,
Consumer<Boolean> 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;
}
}

View file

@ -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<WorldPreset> defaultServerPreset() {
return WorldPresets.get(
LAST_REGISTRY_ACCESS,
WorldPresets.DEFAULT.orElseThrow()
);
}
private static WorldPresetSettings defaultServerSettings() {
final Holder<WorldPreset> defaultPreset = defaultServerPreset();
return defaultServerSettings(defaultPreset);
}
private static WorldPresetSettings defaultServerSettings(Holder<WorldPreset> 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<Tag> 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<Holder<WorldPreset>> 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<Tag>> registryOps) {
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
Helpers.onRegistryReady(acc.bcl_getRegistryAccess());
}
}
public static void setupNewWorld(
Optional<LevelStorageSource.LevelStorageAccess> levelStorageAccess,
WorldGenSettingsComponent worldGenSettingsComponent
) {
if (levelStorageAccess.isPresent()) {
if (worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc) {
Optional<Holder<WorldPreset>> currentPreset = acc.bcl_getPreset();
Optional<Holder<WorldPreset>> 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<Holder<WorldPreset>> setupNewWorldCommon(
LevelStorageSource.LevelStorageAccess levelStorageAccess,
Optional<Holder<WorldPreset>> 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<Boolean> 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<Holder<WorldPreset>> 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<Tag>> 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;
}
}

View file

@ -0,0 +1,11 @@
package org.betterx.worlds.together.world.event;
public class WorldEvents {
public static final Event<OnWorldRegistryReady> WORLD_REGISTRY_READY = WorldEventsImpl.WORLD_REGISTRY_READY;
public static final Event<BeforeWorldLoad> BEFORE_WORLD_LOAD = WorldEventsImpl.BEFORE_WORLD_LOAD;
public static final Event<BeforeServerWorldLoad> BEFORE_SERVER_WORLD_LOAD = WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD;
public static final Event<OnWorldLoad> ON_WORLD_LOAD = WorldEventsImpl.ON_WORLD_LOAD;
public static final Event<OnWorldPatch> PATCH_WORLD = WorldEventsImpl.PATCH_WORLD;
public static final Event<OnAdaptWorldPresetSettings> ADAPT_WORLD_PRESET = WorldEventsImpl.ADAPT_WORLD_PRESET;
}

View file

@ -0,0 +1,12 @@
package org.betterx.worlds.together.world.event;
class WorldEventsImpl {
public static final EventImpl<OnWorldRegistryReady> WORLD_REGISTRY_READY = new EventImpl<>();
public static final EventImpl<BeforeWorldLoad> BEFORE_WORLD_LOAD = new EventImpl<>();
public static final EventImpl<BeforeServerWorldLoad> BEFORE_SERVER_WORLD_LOAD = new EventImpl<>();
public static final EventImpl<OnWorldLoad> ON_WORLD_LOAD = new EventImpl<>();
public static final PatchWorldEvent PATCH_WORLD = new PatchWorldEvent();
public static final AdaptWorldPresetSettingEvent ADAPT_WORLD_PRESET = new AdaptWorldPresetSettingEvent();
}

View file

@ -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<ResourceKey<LevelStem>, LevelStem> map,
Optional<Integer> sortOrder,
Optional<WorldPresetSettings> 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<ResourceKey<LevelStem>, LevelStem> map, int sortOrder, WorldPresetSettings settings) {
public TogetherWorldPreset(
Map<ResourceKey<LevelStem>, 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<ResourceKey<LevelStem>, LevelStem> getDimensions() {
@ -49,7 +55,7 @@ public class BCLWorldPreset extends WorldPreset {
}
public static WorldPresetSettings writeWorldPresetSettings(Optional<Holder<WorldPreset>> 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);
}
}

View file

@ -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;

View file

@ -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<WorldPreset> WORLD_PRESETS =
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
private static final Map<ResourceKey<WorldPreset>, WorldPresetSettings> SETTINGS = Maps.newHashMap();
public static final ResourceKey<WorldPreset> BCL_WORLD =
register(
BCLib.makeID("normal"),
(overworldStem, netherContext, endContext) ->
new BCLWorldPresetSettings(BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION).buildPreset(
overworldStem,
netherContext,
endContext
),
true
);
public static Optional<ResourceKey<WorldPreset>> DEFAULT = Optional.of(BCL_WORLD);
public static final ResourceKey<WorldPreset> 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<ResourceKey<WorldPreset>> DEFAULT = Optional.of(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
return ((access != null) ? access : BuiltinRegistries.ACCESS)
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
.getHolderOrThrow(key);
}
/**
* Registers a custom WorldPreset (with custom rules and behaviour)
* <p>
* 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<WorldPreset> register(ResourceLocation loc) {
return register(loc, true);
}
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean addToNormal) {
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) {
ResourceKey<WorldPreset> 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<WorldPreset> 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<WorldPreset> presets,
LevelStem overworldStem,
LevelGenUtil.Context netherContext,
LevelGenUtil.Context endContext
WorldGenUtil.Context netherContext,
WorldGenUtil.Context endContext
) {
PresetsRegistry.onLoad();
for (Map.Entry<ResourceKey<WorldPreset>, 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<WorldPreset> 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
);
}
}

View file

@ -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<WorldPreset> 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();
}
}

View file

@ -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;

View file

@ -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<Registry<Codec<? extends WorldPresetSettings>>> WORLD_PRESET_SETTINGS_REGISTRY =
createRegistryKey(BCLib.makeID("worldgen/world_preset_settings"));
createRegistryKey(WorldsTogether.makeID("worldgen/world_preset_settings"));
public static final Registry<Codec<? extends WorldPresetSettings>> 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();

View file

@ -7,15 +7,13 @@
"AnvilScreenMixin",
"BlockMixin",
"ClientRecipeBookMixin",
"CreateWorldScreenMixin",
"FogRendererMixin",
"GameMixin",
"MinecraftMixin",
"ModelBakeryMixin",
"ModelManagerMixin",
"SignEditScreenMixin",
"TextureAtlasMixin",
"WorldGenSettingsComponentMixin"
"TextureAtlasMixin"
],
"injectors": {
"defaultRequire": 1

View file

@ -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",

View file

@ -33,6 +33,8 @@
},
"accessWidener": "bclib.accesswidener",
"mixins": [
"together.mixins.common.json",
"together.mixins.client.json",
"bclib.mixins.common.json",
"bclib.mixins.client.json"
],

View file

@ -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
}
}

View file

@ -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
}
}