Skip to content

Commit

Permalink
Make component registration trigger during mod init
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed May 18, 2024
1 parent a92970d commit 9b3f8a5
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
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;

/**
* Entrypoint getting invoked to register <em>static</em> block component factories.
*
* <p>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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public <T extends BlockEntity> BlockEntityTicker<T> getComponentTicker(World wor
}

public boolean requiresStaticFactory(Class<? extends BlockEntity> entityClass) {
StaticBlockComponentPlugin.INSTANCE.ensureInitialized();
this.ensureInitialized();

for (PredicatedComponentFactory<?> dynamicFactory : this.dynamicFactories) {
dynamicFactory.tryRegister(entityClass);
Expand All @@ -95,7 +95,7 @@ public boolean requiresStaticFactory(Class<? extends BlockEntity> entityClass) {
}

public ComponentContainer.Factory<BlockEntity> buildDedicatedFactory(Class<? extends BlockEntity> entityClass) {
StaticBlockComponentPlugin.INSTANCE.ensureInitialized();
this.ensureInitialized();

var compiled = new LinkedHashMap<>(this.beComponentFactories.getOrDefault(entityClass, Collections.emptyMap()));
Class<? extends BlockEntity> type = entityClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
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;

/**
* Entrypoint getting invoked to register <em>static</em> chunk component factories.
*
* <p>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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
package org.ladysnake.cca.api.v3.entity;

import net.fabricmc.api.ModInitializer;
import net.minecraft.entity.Entity;
import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer;

/**
* Entrypoint getting invoked to register <em>static</em> entity component factories.
*
* <p>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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
package org.ladysnake.cca.api.v3.level;

import net.fabricmc.api.ModInitializer;
import net.minecraft.world.WorldProperties;
import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer;

/**
* Entrypoint getting invoked to register <em>static</em> item component factories.
*
* <p>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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static void init() {
});
}
}
StaticLevelComponentPlugin.INSTANCE.ensureInitialized();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <em>static</em> team component factories.
*
* <p>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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
package org.ladysnake.cca.api.v3.world;

import net.fabricmc.api.ModInitializer;
import net.minecraft.world.World;
import org.ladysnake.cca.internal.base.ComponentRegistrationInitializer;

/**
* Entrypoint getting invoked to register <em>static</em> world component factories.
*
* <p>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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9b3f8a5

Please sign in to comment.