diff --git a/src/main/java/org/betterx/bclib/BCLib.java b/src/main/java/org/betterx/bclib/BCLib.java index 7cabae04..602da7e2 100644 --- a/src/main/java/org/betterx/bclib/BCLib.java +++ b/src/main/java/org/betterx/bclib/BCLib.java @@ -19,9 +19,9 @@ 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.tag.v3.TagManager; +import org.betterx.worlds.together.util.Logger; import org.betterx.worlds.together.world.WorldConfig; import net.minecraft.resources.ResourceLocation; @@ -41,7 +41,6 @@ public class BCLib implements ModInitializer { @Override public void onInitialize() { LevelGenEvents.register(); - WorldsTogether.onInitialize(); BlockPredicates.ensureStaticInitialization(); BaseRegistry.register(); GeneratorOptions.init(); diff --git a/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java b/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java index 54277511..07a9cf20 100644 --- a/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java +++ b/src/main/java/org/betterx/bclib/api/v2/datafixer/DataFixerAPI.java @@ -7,7 +7,7 @@ import org.betterx.bclib.client.gui.screens.LevelFixErrorScreen; 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.util.Logger; import org.betterx.worlds.together.world.WorldConfig; import net.minecraft.Util; diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java index 9a2142ad..79393780 100644 --- a/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java +++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/LevelGenEvents.java @@ -7,19 +7,25 @@ import org.betterx.bclib.api.v2.datafixer.DataFixerAPI; import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource; import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig; import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI; +import org.betterx.bclib.api.v2.tag.TagAPI; import org.betterx.bclib.registry.PresetsRegistry; +import org.betterx.worlds.together.tag.v3.TagManager; +import org.betterx.worlds.together.world.WorldConfig; import org.betterx.worlds.together.world.event.WorldEvents; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import net.minecraft.core.Holder; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagLoader; import net.minecraft.world.level.chunk.ChunkGenerator; 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.List; import java.util.Map; import java.util.Optional; import java.util.function.Consumer; @@ -40,6 +46,21 @@ public class LevelGenEvents { WorldEvents.PATCH_WORLD.on(LevelGenEvents::patchExistingWorld); WorldEvents.ADAPT_WORLD_PRESET.on(LevelGenEvents::adaptWorldPresetSettings); + + WorldEvents.BEFORE_ADDING_TAGS.on(LevelGenEvents::appplyTags); + } + + private static void appplyTags( + String directory, + Map> tagsMap + ) { + //make sure we include Tags registered by the deprecated API + TagAPI.apply(directory, tagsMap); + + + if (directory.equals(TagManager.BIOMES.directory)) { + InternalBiomeAPI._runBiomeTagAdders(); + } } @@ -103,6 +124,7 @@ public class LevelGenEvents { ) { setupWorld(); if (isNewWorld) { + WorldConfig.saveFile(BCLib.MOD_ID); DataFixerAPI.initializePatchData(); } else { LevelGenUtil.migrateGeneratorSettings(); @@ -117,6 +139,7 @@ public class LevelGenEvents { setupWorld(); if (isNewWorld) { + WorldConfig.saveFile(BCLib.MOD_ID); DataFixerAPI.initializePatchData(); } else { LevelGenUtil.migrateGeneratorSettings(); diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiomeBuilder.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiomeBuilder.java index ba395cfb..bd11dab7 100644 --- a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiomeBuilder.java +++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiomeBuilder.java @@ -844,7 +844,7 @@ public class BCLBiomeBuilder { final Biome biome = builder.build(); final T res = biomeConstructor.apply(biomeID, biome, settings); - tags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, res)); + tags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, res.getBiomeKey())); //res.addBiomeTags(tags); //res.setSurface(surfaceRule); diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BiomeAPI.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BiomeAPI.java index 342a7faa..a7169b94 100644 --- a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BiomeAPI.java +++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BiomeAPI.java @@ -195,11 +195,11 @@ public class BiomeAPI { BiomeType.BIOME_TYPE_MAP.put(bclbiome.getID(), dim); if (dim != null && dim.is(BiomeType.NETHER)) { - TagManager.BIOMES.add(BiomeTags.IS_NETHER, bclbiome); - TagManager.BIOMES.add(CommonBiomeTags.IN_NETHER, bclbiome); + TagManager.BIOMES.add(BiomeTags.IS_NETHER, bclbiome.getBiomeKey()); + TagManager.BIOMES.add(CommonBiomeTags.IN_NETHER, bclbiome.getBiomeKey()); } else if (dim != null && dim.is(BiomeType.END)) { - TagManager.BIOMES.add(BiomeTags.IS_END, bclbiome); - TagManager.BIOMES.add(CommonBiomeTags.IN_END, bclbiome); + TagManager.BIOMES.add(BiomeTags.IS_END, bclbiome.getBiomeKey()); + TagManager.BIOMES.add(CommonBiomeTags.IN_END, bclbiome.getBiomeKey()); } bclbiome.afterRegistration(); diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/TemplateFeatureConfig.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/TemplateFeatureConfig.java index 2a434388..e414a37c 100644 --- a/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/TemplateFeatureConfig.java +++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/features/config/TemplateFeatureConfig.java @@ -10,6 +10,7 @@ import java.util.List; /** * @deprecated Please use {@link org.betterx.bclib.api.v3.levelgen.features.config.TemplateFeatureConfig} instead */ +@Deprecated(forRemoval = true) public class TemplateFeatureConfig extends org.betterx.bclib.api.v3.levelgen.features.config.TemplateFeatureConfig { public TemplateFeatureConfig(ResourceLocation location, int offsetY, StructurePlacementType type) { diff --git a/src/main/java/org/betterx/bclib/client/BCLibClient.java b/src/main/java/org/betterx/bclib/client/BCLibClient.java index 02417552..6a6d632b 100644 --- a/src/main/java/org/betterx/bclib/client/BCLibClient.java +++ b/src/main/java/org/betterx/bclib/client/BCLibClient.java @@ -6,8 +6,8 @@ import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI; import org.betterx.bclib.client.models.CustomModelBakery; import org.betterx.bclib.config.Configs; import org.betterx.bclib.registry.BaseBlockEntityRenders; +import org.betterx.bclib.registry.PresetsRegistryClient; 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; @@ -31,7 +31,7 @@ public class BCLibClient implements ClientModInitializer, ModelResourceProvider, ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> this); ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> this); - WorldsTogetherClient.onInitializeClient(); + PresetsRegistryClient.onLoad(); WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog(); //dumpDatapack(); } diff --git a/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java b/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java index 5fb40084..bcee77d5 100644 --- a/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java +++ b/src/main/java/org/betterx/bclib/registry/PresetsRegistry.java @@ -4,6 +4,7 @@ import org.betterx.bclib.BCLib; import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig; import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig; import org.betterx.bclib.api.v2.levelgen.LevelGenUtil; +import org.betterx.worlds.together.entrypoints.WorldPresetBootstrap; import org.betterx.worlds.together.levelgen.WorldGenUtil; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import org.betterx.worlds.together.worldPreset.WorldPresets; @@ -14,11 +15,11 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset; import java.util.Map; -public class PresetsRegistry { +public class PresetsRegistry implements WorldPresetBootstrap { public static ResourceKey BCL_WORLD; public static ResourceKey BCL_WORLD_17; - public static void onLoad() { + public void bootstrapWorldPresets() { BCL_WORLD = WorldPresets.register( BCLib.makeID("normal"), diff --git a/src/main/java/org/betterx/bclib/util/Logger.java b/src/main/java/org/betterx/bclib/util/Logger.java index 373bf2a6..d7115089 100644 --- a/src/main/java/org/betterx/bclib/util/Logger.java +++ b/src/main/java/org/betterx/bclib/util/Logger.java @@ -3,10 +3,20 @@ package org.betterx.bclib.util; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; + +/** + * @deprecated Please use {@link org.betterx.worlds.together.util.Logger} instead + */ +@Deprecated(forRemoval = true) public final class Logger { private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); private final String modPref; + + /** + * @deprecated Please use {@link org.betterx.worlds.together.util.Logger#Logger(String)} instead + */ + @Deprecated(forRemoval = true) public Logger(String modID) { this.modPref = "[" + modID + "] "; } diff --git a/src/main/java/org/betterx/worlds/together/WorldsTogether.java b/src/main/java/org/betterx/worlds/together/WorldsTogether.java index a74adba5..24ae4bef 100644 --- a/src/main/java/org/betterx/worlds/together/WorldsTogether.java +++ b/src/main/java/org/betterx/worlds/together/WorldsTogether.java @@ -1,16 +1,17 @@ package org.betterx.worlds.together; -import org.betterx.bclib.util.Logger; import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry; import org.betterx.worlds.together.tag.v3.TagManager; +import org.betterx.worlds.together.util.Logger; import org.betterx.worlds.together.world.WorldConfig; import org.betterx.worlds.together.worldPreset.WorldPresets; import net.minecraft.resources.ResourceLocation; +import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; -public class WorldsTogether { +public class WorldsTogether implements ModInitializer { public static boolean SURPRESS_EXPERIMENTAL_DIALOG = false; public static boolean FORCE_SERVER_TO_BETTERX_PRESET = false; public static final String MOD_ID = "worlds_together"; @@ -23,7 +24,7 @@ public class WorldsTogether { return FabricLoader.getInstance().isDevelopmentEnvironment(); } - public static void onInitialize() { + public void onInitialize() { TagManager.ensureStaticallyLoaded(); SurfaceRuleRegistry.ensureStaticallyLoaded(); diff --git a/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java b/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java index 1aa64f4e..2a646f80 100644 --- a/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java +++ b/src/main/java/org/betterx/worlds/together/client/WorldsTogetherClient.java @@ -2,8 +2,10 @@ package org.betterx.worlds.together.client; import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient; -public class WorldsTogetherClient { - public static void onInitializeClient() { +import net.fabricmc.api.ClientModInitializer; + +public class WorldsTogetherClient implements ClientModInitializer { + public void onInitializeClient() { WorldPresetsClient.setupClientside(); } } diff --git a/src/main/java/org/betterx/worlds/together/entrypoints/EntrypointUtil.java b/src/main/java/org/betterx/worlds/together/entrypoints/EntrypointUtil.java new file mode 100644 index 00000000..0476a601 --- /dev/null +++ b/src/main/java/org/betterx/worlds/together/entrypoints/EntrypointUtil.java @@ -0,0 +1,29 @@ +package org.betterx.worlds.together.entrypoints; + +import net.fabricmc.loader.api.FabricLoader; + +import java.util.List; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class EntrypointUtil { + private static List getEntryPoints(boolean client, Class select) { + return FabricLoader.getInstance() + .getEntrypoints( + client ? "worlds_together_client" : "worlds_together", + WorldsTogetherEntrypoint.class + ) + .stream() + .filter(o -> select.isAssignableFrom(o.getClass())) + .map(e -> (T) e) + .toList(); + } + + public static List getCommon(Class select) { + return getEntryPoints(false, select); + } + + public static List getClient(Class select) { + return getEntryPoints(true, select); + } +} diff --git a/src/main/java/org/betterx/worlds/together/entrypoints/WorldPresetBootstrap.java b/src/main/java/org/betterx/worlds/together/entrypoints/WorldPresetBootstrap.java new file mode 100644 index 00000000..238fec8e --- /dev/null +++ b/src/main/java/org/betterx/worlds/together/entrypoints/WorldPresetBootstrap.java @@ -0,0 +1,5 @@ +package org.betterx.worlds.together.entrypoints; + +public interface WorldPresetBootstrap extends WorldsTogetherEntrypoint { + void bootstrapWorldPresets(); +} diff --git a/src/main/java/org/betterx/worlds/together/entrypoints/WorldsTogetherEntrypoint.java b/src/main/java/org/betterx/worlds/together/entrypoints/WorldsTogetherEntrypoint.java new file mode 100644 index 00000000..b41b8601 --- /dev/null +++ b/src/main/java/org/betterx/worlds/together/entrypoints/WorldsTogetherEntrypoint.java @@ -0,0 +1,4 @@ +package org.betterx.worlds.together.entrypoints; + +public interface WorldsTogetherEntrypoint { +} diff --git a/src/main/java/org/betterx/worlds/together/levelgen/WorldGenUtil.java b/src/main/java/org/betterx/worlds/together/levelgen/WorldGenUtil.java index 0d58fe79..4a82f11f 100644 --- a/src/main/java/org/betterx/worlds/together/levelgen/WorldGenUtil.java +++ b/src/main/java/org/betterx/worlds/together/levelgen/WorldGenUtil.java @@ -6,6 +6,7 @@ import org.betterx.worlds.together.chunkgenerator.EnforceableChunkGenerator; import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings; import org.betterx.worlds.together.world.BiomeSourceWithSeed; import org.betterx.worlds.together.world.WorldConfig; +import org.betterx.worlds.together.world.event.WorldBootstrap; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import org.betterx.worlds.together.worldPreset.WorldPresets; @@ -15,6 +16,7 @@ import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; @@ -165,4 +167,17 @@ public class WorldGenUtil { } return settings; } + + public static ResourceLocation getBiomeID(Biome biome) { + ResourceLocation id = null; + RegistryAccess access = WorldBootstrap.getLastRegistryAccessOrElseBuiltin(); + + id = access.registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome); + + if (id == null) { + WorldsTogether.LOGGER.error("Unable to get ID for " + biome + "."); + } + + return id; + } } diff --git a/src/main/java/org/betterx/worlds/together/tag/v3/TagManager.java b/src/main/java/org/betterx/worlds/together/tag/v3/TagManager.java index fbfc4a70..e547d9cb 100644 --- a/src/main/java/org/betterx/worlds/together/tag/v3/TagManager.java +++ b/src/main/java/org/betterx/worlds/together/tag/v3/TagManager.java @@ -1,8 +1,8 @@ package org.betterx.worlds.together.tag.v3; -import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; -import org.betterx.bclib.api.v2.tag.TagAPI; +import org.betterx.worlds.together.levelgen.WorldGenUtil; import org.betterx.worlds.together.mixin.common.DiggerItemAccessor; +import org.betterx.worlds.together.world.event.WorldEventsImpl; import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.Registry; @@ -62,7 +62,7 @@ public class TagManager { "tags/worldgen/biome", (dir) -> new TagRegistry.Biomes( dir, - b -> BiomeAPI.getBiomeID(b) + b -> WorldGenUtil.getBiomeID(b) ) ); } @@ -105,7 +105,7 @@ public class TagManager { String directory, Map> tagsMap ) { - tagsMap = TagAPI.apply(directory, tagsMap); + WorldEventsImpl.BEFORE_ADDING_TAGS.emit(e -> e.apply(directory, tagsMap)); TagRegistry type = TYPES.get(directory); if (type != null) { diff --git a/src/main/java/org/betterx/worlds/together/tag/v3/TagRegistry.java b/src/main/java/org/betterx/worlds/together/tag/v3/TagRegistry.java index 1c5bb2da..27bc6153 100644 --- a/src/main/java/org/betterx/worlds/together/tag/v3/TagRegistry.java +++ b/src/main/java/org/betterx/worlds/together/tag/v3/TagRegistry.java @@ -1,8 +1,7 @@ package org.betterx.worlds.together.tag.v3; -import org.betterx.bclib.BCLib; import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome; -import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI; +import org.betterx.worlds.together.WorldsTogether; import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.Registry; @@ -90,8 +89,26 @@ public class TagRegistry { * @param tagID {@link TagKey< Biome >} tag ID. * @param elements array of Elements to add into tag. */ + public void add(TagKey tagID, ResourceKey... elements) { + if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); + Set set = getSetForTag(tagID); + for (ResourceKey element : elements) { + ResourceLocation id = element.location(); + if (id != null) { + set.add(TagEntry.element(id)); + } + } + } + + /** + * Adds one Tag to multiple Elements. + * + * @param tagID {@link TagKey< Biome >} tag ID. + * @param elements array of Elements to add into tag. + */ + @Deprecated(forRemoval = true) public void add(TagKey tagID, BCLBiome... elements) { - if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); + if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); Set set = getSetForTag(tagID); for (BCLBiome element : elements) { ResourceLocation id = element.getID(); @@ -106,7 +123,6 @@ public class TagRegistry { } public void apply(Map> tagsMap) { - InternalBiomeAPI._runBiomeTagAdders(); super.apply(tagsMap); } } @@ -209,7 +225,7 @@ public class TagRegistry { } public void addUntyped(TagKey tagID, ResourceLocation... elements) { - if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); + if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); Set set = getSetForTag(tagID); for (ResourceLocation id : elements) { if (id != null) { @@ -225,7 +241,7 @@ public class TagRegistry { } public void addOtherTags(TagKey tagID, TagKey... tags) { - if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); + if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); Set set = getSetForTag(tagID); for (TagKey tag : tags) { ResourceLocation id = tag.location(); @@ -242,7 +258,7 @@ public class TagRegistry { * @param elements array of Elements to add into tag. */ protected void add(TagKey tagID, T... elements) { - if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); + if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); Set set = getSetForTag(tagID); for (T element : elements) { ResourceLocation id = locationProvider.apply(element); @@ -260,7 +276,7 @@ public class TagRegistry { @Deprecated(forRemoval = true) protected void add(ResourceLocation tagID, T... elements) { - if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); + if (isFrozen) WorldsTogether.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); Set set = getSetForTag(tagID); for (T element : elements) { ResourceLocation id = locationProvider.apply(element); @@ -292,7 +308,7 @@ public class TagRegistry { List builder, Set ids ) { - ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(value, BCLib.MOD_ID))); + ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(value, WorldsTogether.MOD_ID))); return builder; } } diff --git a/src/main/java/org/betterx/worlds/together/util/Logger.java b/src/main/java/org/betterx/worlds/together/util/Logger.java new file mode 100644 index 00000000..8600e677 --- /dev/null +++ b/src/main/java/org/betterx/worlds/together/util/Logger.java @@ -0,0 +1,62 @@ +package org.betterx.worlds.together.util; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; + +public final class Logger { + private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); + private final String modPref; + + public Logger(String modID) { + this.modPref = "[" + modID + "] "; + } + + public void log(Level level, String message) { + LOGGER.log(level, modPref + message); + } + + public void log(Level level, String message, Object... params) { + LOGGER.log(level, modPref + message, params); + } + + public void debug(Object message) { + this.log(Level.DEBUG, message.toString()); + } + + public void debug(Object message, Object... params) { + this.log(Level.DEBUG, message.toString(), params); + } + + public void catching(Throwable ex) { + this.error(ex.getLocalizedMessage()); + LOGGER.catching(ex); + } + + public void info(String message) { + this.log(Level.INFO, message); + } + + public void info(String message, Object... params) { + this.log(Level.INFO, message, params); + } + + public void warning(String message, Object... params) { + this.log(Level.WARN, message, params); + } + + public void warning(String message, Object obj, Exception ex) { + LOGGER.warn(modPref + message, obj, ex); + } + + public void error(String message) { + this.log(Level.ERROR, message); + } + + public void error(String message, Object obj, Exception ex) { + LOGGER.error(modPref + message, obj, ex); + } + + public void error(String message, Exception ex) { + LOGGER.error(modPref + message, ex); + } +} diff --git a/src/main/java/org/betterx/worlds/together/util/ModUtil.java b/src/main/java/org/betterx/worlds/together/util/ModUtil.java index 99085a38..54dd38e1 100644 --- a/src/main/java/org/betterx/worlds/together/util/ModUtil.java +++ b/src/main/java/org/betterx/worlds/together/util/ModUtil.java @@ -1,6 +1,5 @@ package org.betterx.worlds.together.util; -import org.betterx.bclib.BCLib; import org.betterx.worlds.together.WorldsTogether; import net.fabricmc.loader.api.*; @@ -261,8 +260,6 @@ public class ModUtil { * @return The version of the locally installed Mod */ public static String getModVersion(String modID) { - if (modID == WorldsTogether.MOD_ID) modID = BCLib.MOD_ID; - Optional optional = FabricLoader.getInstance() .getModContainer(modID); if (optional.isPresent()) { diff --git a/src/main/java/org/betterx/worlds/together/world/event/BeforeAddingTags.java b/src/main/java/org/betterx/worlds/together/world/event/BeforeAddingTags.java new file mode 100644 index 00000000..1908161d --- /dev/null +++ b/src/main/java/org/betterx/worlds/together/world/event/BeforeAddingTags.java @@ -0,0 +1,14 @@ +package org.betterx.worlds.together.world.event; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagLoader; + +import java.util.List; +import java.util.Map; + +public interface BeforeAddingTags { + void apply( + String directory, + Map> tagsMap + ); +} diff --git a/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java b/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java index 01419060..5fcb9b5a 100644 --- a/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java +++ b/src/main/java/org/betterx/worlds/together/world/event/EventImpl.java @@ -4,7 +4,7 @@ import java.util.LinkedList; import java.util.List; import java.util.function.Consumer; -class EventImpl implements Event { +public class EventImpl implements Event { final List handlers = new LinkedList<>(); public final boolean on(T handler) { diff --git a/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java b/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java index 11fbe943..fd64e9b9 100644 --- a/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java +++ b/src/main/java/org/betterx/worlds/together/world/event/WorldBootstrap.java @@ -1,6 +1,5 @@ package org.betterx.worlds.together.world.event; -import org.betterx.bclib.BCLib; import org.betterx.worlds.together.WorldsTogether; import org.betterx.worlds.together.levelgen.WorldGenUtil; import org.betterx.worlds.together.mixin.common.RegistryOpsAccessor; @@ -56,10 +55,6 @@ public class WorldBootstrap { private static void initializeWorldConfig(File levelBaseDir, boolean newWorld) { WorldConfig.load(new File(levelBaseDir, "data")); - - if (newWorld) { - WorldConfig.saveFile(BCLib.MOD_ID); - } } private static void onRegistryReady(RegistryAccess a) { @@ -115,7 +110,7 @@ public class WorldBootstrap { 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"); + WorldsTogether.LOGGER.info("Creating a new World, no fixes needed"); final Map, ChunkGenerator> settings = Helpers.defaultServerDimensions(); Helpers.initializeWorldConfig(levelStorageAccess, true); @@ -241,11 +236,11 @@ public class WorldBootstrap { false )); } catch (Exception e) { - BCLib.LOGGER.error("Failed to initialize data in world", e); + WorldsTogether.LOGGER.error("Failed to initialize data in world", e); } levelStorageAccess.close(); } catch (Exception e) { - BCLib.LOGGER.error("Failed to acquire storage access", e); + WorldsTogether.LOGGER.error("Failed to acquire storage access", e); } } @@ -260,7 +255,7 @@ public class WorldBootstrap { result = WorldEventsImpl.PATCH_WORLD.applyPatches(levelStorageAccess, onResume); levelStorageAccess.close(); } catch (Exception e) { - BCLib.LOGGER.error("Failed to initialize data in world", e); + WorldsTogether.LOGGER.error("Failed to initialize data in world", e); } return result; @@ -287,7 +282,7 @@ public class WorldBootstrap { InGUI.setupNewWorldCommon(levelStorageAccess, worldPreset, worldGenSettings); levelStorageAccess.close(); } catch (Exception e) { - BCLib.LOGGER.error("Failed to initialize data in world", e); + WorldsTogether.LOGGER.error("Failed to initialize data in world", e); } } } @@ -315,7 +310,7 @@ public class WorldBootstrap { return WorldGenUtil.repairBiomeSourceInAllDimensions(acc.bcl_getRegistryAccess(), worldGenSettings); //.repairSettingsOnLoad(LAST_REGISTRY_ACCESS, worldGenSettings); } else { - BCLib.LOGGER.error("Unable to obtain registryAccess when enforcing generators."); + WorldsTogether.LOGGER.error("Unable to obtain registryAccess when enforcing generators."); } return worldGenSettings; } diff --git a/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java b/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java index 16d9f6a8..fa0ff83a 100644 --- a/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java +++ b/src/main/java/org/betterx/worlds/together/world/event/WorldEvents.java @@ -8,4 +8,6 @@ public class WorldEvents { public static final Event ON_FINALIZE_LEVEL_STEM = WorldEventsImpl.ON_FINALIZE_LEVEL_STEM; public static final Event PATCH_WORLD = WorldEventsImpl.PATCH_WORLD; public static final Event ADAPT_WORLD_PRESET = WorldEventsImpl.ADAPT_WORLD_PRESET; + + public static final Event BEFORE_ADDING_TAGS = WorldEventsImpl.BEFORE_ADDING_TAGS; } diff --git a/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java b/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java index cf37f48c..cc1e93ab 100644 --- a/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java +++ b/src/main/java/org/betterx/worlds/together/world/event/WorldEventsImpl.java @@ -1,6 +1,9 @@ package org.betterx.worlds.together.world.event; -class WorldEventsImpl { +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class WorldEventsImpl { public static final EventImpl WORLD_REGISTRY_READY = new EventImpl<>(); public static final EventImpl BEFORE_WORLD_LOAD = new EventImpl<>(); public static final EventImpl BEFORE_SERVER_WORLD_LOAD = new EventImpl<>(); @@ -10,4 +13,6 @@ class WorldEventsImpl { public static final PatchWorldEvent PATCH_WORLD = new PatchWorldEvent(); public static final AdaptWorldPresetSettingEvent ADAPT_WORLD_PRESET = new AdaptWorldPresetSettingEvent(); + + public static final EventImpl BEFORE_ADDING_TAGS = new EventImpl<>(); } diff --git a/src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java b/src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java index 32fd264e..a77273f7 100644 --- a/src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java +++ b/src/main/java/org/betterx/worlds/together/worldPreset/WorldPresets.java @@ -1,7 +1,8 @@ package org.betterx.worlds.together.worldPreset; -import org.betterx.bclib.registry.PresetsRegistry; import org.betterx.worlds.together.WorldsTogether; +import org.betterx.worlds.together.entrypoints.EntrypointUtil; +import org.betterx.worlds.together.entrypoints.WorldPresetBootstrap; import org.betterx.worlds.together.levelgen.WorldGenUtil; import org.betterx.worlds.together.tag.v3.TagManager; import org.betterx.worlds.together.tag.v3.TagRegistry; @@ -83,7 +84,8 @@ public class WorldPresets { WorldGenUtil.Context netherContext, WorldGenUtil.Context endContext ) { - PresetsRegistry.onLoad(); + EntrypointUtil.getCommon(WorldPresetBootstrap.class) + .forEach(e -> e.bootstrapWorldPresets()); for (Map.Entry, PresetBuilder> e : BUILDERS.entrySet()) { TogetherWorldPreset preset = e.getValue().create(overworldStem, netherContext, endContext); diff --git a/src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java b/src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java index ff0768db..e65a8803 100644 --- a/src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java +++ b/src/main/java/org/betterx/worlds/together/worldPreset/client/WorldPresetsClient.java @@ -1,7 +1,5 @@ package org.betterx.worlds.together.worldPreset.client; -import org.betterx.bclib.registry.PresetsRegistryClient; - import net.minecraft.client.gui.screens.worldselection.PresetEditor; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.levelgen.presets.WorldPreset; @@ -20,6 +18,5 @@ public class WorldPresetsClient { } public static void setupClientside() { - PresetsRegistryClient.onLoad(); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index bef018ed..ea76eab7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,6 +29,9 @@ ], "modmenu": [ "org.betterx.bclib.integration.modmenu.ModMenuEntryPoint" + ], + "worlds_together": [ + "org.betterx.bclib.registry.PresetsRegistry" ] }, "accessWidener": "bclib.accesswidener",