From 9b3f8a594ef927147e70c51f7e5bf6f18fcfadc6 Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sat, 18 May 2024 22:38:24 +0200 Subject: [PATCH] Make component registration trigger during mod init --- .../cca/api/v3/block/BlockComponentInitializer.java | 3 ++- .../ladysnake/cca/internal/CardinalComponentsBlock.java | 2 ++ .../cca/internal/block/StaticBlockComponentPlugin.java | 4 ++-- .../cca/api/v3/chunk/ChunkComponentInitializer.java | 3 ++- .../cca/internal/chunk/CardinalComponentsChunk.java | 1 + .../cca/api/v3/entity/EntityComponentInitializer.java | 3 ++- .../cca/internal/entity/CardinalComponentsEntity.java | 1 + .../cca/api/v3/level/LevelComponentInitializer.java | 3 ++- .../cca/internal/level/CardinalComponentsLevel.java | 1 + .../api/v3/scoreboard/ScoreboardComponentInitializer.java | 3 ++- .../internal/scoreboard/CardinalComponentsScoreboard.java | 1 + .../cca/api/v3/world/WorldComponentInitializer.java | 3 ++- .../cca/internal/world/CardinalComponentsWorld.java | 1 + changelog.md | 7 ++++++- gradle.properties | 8 ++++---- 15 files changed, 31 insertions(+), 13 deletions(-) diff --git a/cardinal-components-block/src/main/java/org/ladysnake/cca/api/v3/block/BlockComponentInitializer.java b/cardinal-components-block/src/main/java/org/ladysnake/cca/api/v3/block/BlockComponentInitializer.java index 3578ec03..b96b7f8c 100644 --- a/cardinal-components-block/src/main/java/org/ladysnake/cca/api/v3/block/BlockComponentInitializer.java +++ b/cardinal-components-block/src/main/java/org/ladysnake/cca/api/v3/block/BlockComponentInitializer.java @@ -22,6 +22,7 @@ */ package org.ladysnake.cca.api.v3.block; +import net.fabricmc.api.ModInitializer; import net.minecraft.block.entity.BlockEntity; import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer; @@ -29,7 +30,7 @@ * Entrypoint getting invoked to register static block component factories. * *

The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-block"} in the mod json and runs for any environment. - * It usually executes right before the first {@link BlockEntity} instance is created. + * It executes during {@linkplain ModInitializer mod init}, or right before the first {@link BlockEntity} instance is created, whichever comes first. * * @since 2.5.0 */ diff --git a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CardinalComponentsBlock.java b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CardinalComponentsBlock.java index 85781a0c..585e9759 100644 --- a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CardinalComponentsBlock.java +++ b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/CardinalComponentsBlock.java @@ -32,6 +32,7 @@ import org.ladysnake.cca.api.v3.component.ComponentProvider; import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent; import org.ladysnake.cca.internal.base.ComponentUpdatePayload; +import org.ladysnake.cca.internal.block.StaticBlockComponentPlugin; public class CardinalComponentsBlock { @@ -63,5 +64,6 @@ public static void init() { ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.register((be, world) -> ((ComponentProvider) be).getComponentContainer().onServerLoad()); ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((be, world) -> ((ComponentProvider) be).getComponentContainer().onServerUnload()); } + StaticBlockComponentPlugin.INSTANCE.ensureInitialized(); } } diff --git a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/block/StaticBlockComponentPlugin.java b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/block/StaticBlockComponentPlugin.java index 8b30044a..09cd7ece 100644 --- a/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/block/StaticBlockComponentPlugin.java +++ b/cardinal-components-block/src/main/java/org/ladysnake/cca/internal/block/StaticBlockComponentPlugin.java @@ -85,7 +85,7 @@ public BlockEntityTicker getComponentTicker(World wor } public boolean requiresStaticFactory(Class entityClass) { - StaticBlockComponentPlugin.INSTANCE.ensureInitialized(); + this.ensureInitialized(); for (PredicatedComponentFactory dynamicFactory : this.dynamicFactories) { dynamicFactory.tryRegister(entityClass); @@ -95,7 +95,7 @@ public boolean requiresStaticFactory(Class entityClass) { } public ComponentContainer.Factory buildDedicatedFactory(Class entityClass) { - StaticBlockComponentPlugin.INSTANCE.ensureInitialized(); + this.ensureInitialized(); var compiled = new LinkedHashMap<>(this.beComponentFactories.getOrDefault(entityClass, Collections.emptyMap())); Class type = entityClass; diff --git a/cardinal-components-chunk/src/main/java/org/ladysnake/cca/api/v3/chunk/ChunkComponentInitializer.java b/cardinal-components-chunk/src/main/java/org/ladysnake/cca/api/v3/chunk/ChunkComponentInitializer.java index fa55d823..fb255742 100644 --- a/cardinal-components-chunk/src/main/java/org/ladysnake/cca/api/v3/chunk/ChunkComponentInitializer.java +++ b/cardinal-components-chunk/src/main/java/org/ladysnake/cca/api/v3/chunk/ChunkComponentInitializer.java @@ -22,6 +22,7 @@ */ package org.ladysnake.cca.api.v3.chunk; +import net.fabricmc.api.ModInitializer; import net.minecraft.world.chunk.Chunk; import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer; @@ -29,7 +30,7 @@ * Entrypoint getting invoked to register static chunk component factories. * *

The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-chunk"} in the mod json and runs for any environment. - * It usually executes right before the first {@link Chunk} instance is created. + * It usually executes during {@linkplain ModInitializer mod init}, or right before the first {@link Chunk} instance is created, whichever comes first. * * @since 2.4.0 */ diff --git a/cardinal-components-chunk/src/main/java/org/ladysnake/cca/internal/chunk/CardinalComponentsChunk.java b/cardinal-components-chunk/src/main/java/org/ladysnake/cca/internal/chunk/CardinalComponentsChunk.java index 41bfc272..2bec8c67 100644 --- a/cardinal-components-chunk/src/main/java/org/ladysnake/cca/internal/chunk/CardinalComponentsChunk.java +++ b/cardinal-components-chunk/src/main/java/org/ladysnake/cca/internal/chunk/CardinalComponentsChunk.java @@ -48,5 +48,6 @@ public static void init() { ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> ((ComponentProvider) chunk).getComponentContainer().onServerLoad()); ServerChunkEvents.CHUNK_UNLOAD.register((world, chunk) -> ((ComponentProvider) chunk).getComponentContainer().onServerUnload()); } + StaticChunkComponentPlugin.INSTANCE.ensureInitialized(); } } diff --git a/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/EntityComponentInitializer.java b/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/EntityComponentInitializer.java index 18b1b81d..e17f38f0 100644 --- a/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/EntityComponentInitializer.java +++ b/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/EntityComponentInitializer.java @@ -22,6 +22,7 @@ */ package org.ladysnake.cca.api.v3.entity; +import net.fabricmc.api.ModInitializer; import net.minecraft.entity.Entity; import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer; @@ -29,7 +30,7 @@ * Entrypoint getting invoked to register static entity component factories. * *

The entrypoint is exposed as {@code cardinal-components-entity} in the mod json and runs for any environment. - * It usually executes right before the first {@link Entity} instance is created. + * It usually executes during {@linkplain ModInitializer mod init}, or right before the first {@link Entity} instance is created, whichever comes first. * * @since 2.4.0 */ diff --git a/cardinal-components-entity/src/main/java/org/ladysnake/cca/internal/entity/CardinalComponentsEntity.java b/cardinal-components-entity/src/main/java/org/ladysnake/cca/internal/entity/CardinalComponentsEntity.java index 397d340d..beab3314 100644 --- a/cardinal-components-entity/src/main/java/org/ladysnake/cca/internal/entity/CardinalComponentsEntity.java +++ b/cardinal-components-entity/src/main/java/org/ladysnake/cca/internal/entity/CardinalComponentsEntity.java @@ -103,6 +103,7 @@ public static void init() { } ServerLivingEntityEvents.MOB_CONVERSION.register(RespawnCopyStrategy.EVENT_PHASE, CardinalComponentsEntity::copyData); ServerPlayerEvents.COPY_FROM.register(RespawnCopyStrategy.EVENT_PHASE, CardinalComponentsEntity::copyData); + StaticEntityComponentPlugin.INSTANCE.ensureInitialized(); } private static void copyData(LivingEntity original, LivingEntity clone, boolean keepInventory) { diff --git a/cardinal-components-level/src/main/java/org/ladysnake/cca/api/v3/level/LevelComponentInitializer.java b/cardinal-components-level/src/main/java/org/ladysnake/cca/api/v3/level/LevelComponentInitializer.java index 4fa8d8c3..25f5062d 100644 --- a/cardinal-components-level/src/main/java/org/ladysnake/cca/api/v3/level/LevelComponentInitializer.java +++ b/cardinal-components-level/src/main/java/org/ladysnake/cca/api/v3/level/LevelComponentInitializer.java @@ -22,6 +22,7 @@ */ package org.ladysnake.cca.api.v3.level; +import net.fabricmc.api.ModInitializer; import net.minecraft.world.WorldProperties; import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer; @@ -29,7 +30,7 @@ * Entrypoint getting invoked to register static item component factories. * *

The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-level"} in the mod json and runs for any environment. - * It usually executes right before the first {@linkplain WorldProperties save properties object} gets loaded. + * It usually executes right during {@linkplain ModInitializer mod init}, or before the first {@linkplain WorldProperties save properties object} gets loaded, whichever comes first. * * @since 2.4.0 */ diff --git a/cardinal-components-level/src/main/java/org/ladysnake/cca/internal/level/CardinalComponentsLevel.java b/cardinal-components-level/src/main/java/org/ladysnake/cca/internal/level/CardinalComponentsLevel.java index 77795017..c6d0256f 100644 --- a/cardinal-components-level/src/main/java/org/ladysnake/cca/internal/level/CardinalComponentsLevel.java +++ b/cardinal-components-level/src/main/java/org/ladysnake/cca/internal/level/CardinalComponentsLevel.java @@ -56,6 +56,7 @@ public static void init() { }); } } + StaticLevelComponentPlugin.INSTANCE.ensureInitialized(); } } diff --git a/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/api/v3/scoreboard/ScoreboardComponentInitializer.java b/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/api/v3/scoreboard/ScoreboardComponentInitializer.java index bc3be668..292a1a72 100644 --- a/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/api/v3/scoreboard/ScoreboardComponentInitializer.java +++ b/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/api/v3/scoreboard/ScoreboardComponentInitializer.java @@ -22,13 +22,14 @@ */ package org.ladysnake.cca.api.v3.scoreboard; +import net.fabricmc.api.ModInitializer; import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer; /** * Entrypoint getting invoked to register static team component factories. * *

The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-scoreboard"} in the mod json and runs for any environment. - * It usually executes right before the first {@link net.minecraft.scoreboard.Scoreboard} instance is created. + * It usually executes during {@linkplain ModInitializer mod init}, or right before the first {@link net.minecraft.scoreboard.Scoreboard} instance is created, whichever comes first. * * @since 2.4.2 */ diff --git a/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/internal/scoreboard/CardinalComponentsScoreboard.java b/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/internal/scoreboard/CardinalComponentsScoreboard.java index 6ed14ed5..262cc11d 100644 --- a/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/internal/scoreboard/CardinalComponentsScoreboard.java +++ b/cardinal-components-scoreboard/src/main/java/org/ladysnake/cca/internal/scoreboard/CardinalComponentsScoreboard.java @@ -78,5 +78,6 @@ public static void init() { ServerLifecycleEvents.SERVER_STARTED.register((server) -> ((ComponentProvider) server.getScoreboard()).getComponentContainer().onServerLoad()); ServerLifecycleEvents.SERVER_STOPPED.register((server) -> ((ComponentProvider) server.getScoreboard()).getComponentContainer().onServerUnload()); } + StaticScoreboardComponentPlugin.INSTANCE.ensureInitialized(); } } diff --git a/cardinal-components-world/src/main/java/org/ladysnake/cca/api/v3/world/WorldComponentInitializer.java b/cardinal-components-world/src/main/java/org/ladysnake/cca/api/v3/world/WorldComponentInitializer.java index 5a2d9080..28d024f8 100644 --- a/cardinal-components-world/src/main/java/org/ladysnake/cca/api/v3/world/WorldComponentInitializer.java +++ b/cardinal-components-world/src/main/java/org/ladysnake/cca/api/v3/world/WorldComponentInitializer.java @@ -22,6 +22,7 @@ */ package org.ladysnake.cca.api.v3.world; +import net.fabricmc.api.ModInitializer; import net.minecraft.world.World; import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer; @@ -29,7 +30,7 @@ * Entrypoint getting invoked to register static world component factories. * *

The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-world"} in the mod json and runs for any environment. - * It usually executes right before the first {@link World} instance is created. + * It usually executes during {@linkplain ModInitializer mod init}, or right before the first {@link World} instance is created, whichever comes first. * * @since 2.4.0 */ diff --git a/cardinal-components-world/src/main/java/org/ladysnake/cca/internal/world/CardinalComponentsWorld.java b/cardinal-components-world/src/main/java/org/ladysnake/cca/internal/world/CardinalComponentsWorld.java index f66e0561..89707e66 100644 --- a/cardinal-components-world/src/main/java/org/ladysnake/cca/internal/world/CardinalComponentsWorld.java +++ b/cardinal-components-world/src/main/java/org/ladysnake/cca/internal/world/CardinalComponentsWorld.java @@ -57,6 +57,7 @@ public static void init() { ServerWorldEvents.LOAD.register((server, world) -> ((ComponentProvider) world).getComponentContainer().onServerLoad()); ServerWorldEvents.UNLOAD.register((server, world) -> ((ComponentProvider) world).getComponentContainer().onServerUnload()); } + StaticWorldComponentPlugin.INSTANCE.ensureInitialized(); } public static ComponentContainer createComponents(World world) { diff --git a/changelog.md b/changelog.md index a2d51786..167981bb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,15 @@ ------------------------------------------------------ Version 6.0.0 ------------------------------------------------------ -Updated to 1.20.5 +Updated to 1.20.5/1.20.6 This update introduces multiple breaking changes - a migration guide is available on [the Ladysnake website](https://ladysnake.org/wiki/cardinal-components-api/upgrade-instructions/CCA-6-changes). +### Pre-Release 1 +**Changes** +- Component registration now happens during mod init. This should fix some classloading-related issues, and make loading errors easier to diagnose. +- The internal ASM generation systems have been partially rewritten (thanks lukebemish !) + ### Beta 3 **Fixes** - Fixed the most basic binary incompatibilities with mods compiled for beta 1 diff --git a/gradle.properties b/gradle.properties index bec1b282..d12a239f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,12 +13,12 @@ fabric_api_version=0.98.0+1.20.6 elmendorf_version=0.12.0-SNAPSHOT #Publishing -mod_version = 6.0.0 +mod_version = 6.0.0-pre1 curseforge_id = 318449 modrinth_id = K01OU20C -curseforge_versions = 1.20.6 -modrinth_versions = 1.20.6 -release_type = release +curseforge_versions = 1.20.5; 1.20.6 +modrinth_versions = 1.20.5; 1.20.6 +release_type = beta display_name = Cardinal-Components-API owners = Ladysnake