Skip to content

Commit

Permalink
Merge branch '1.16' into 1.17
Browse files Browse the repository at this point in the history
# Conflicts:
#	cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/asm/StaticComponentPluginBase.java
#	cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/block/StaticBlockComponentPlugin.java
#	cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/internal/chunk/StaticChunkComponentPlugin.java
#	cardinal-components-entity/src/main/java/dev/onyxstudios/cca/internal/entity/StaticEntityComponentPlugin.java
#	cardinal-components-item/src/main/java/dev/onyxstudios/cca/internal/item/StaticItemComponentPlugin.java
#	cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/StaticLevelComponentPlugin.java
#	cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/StaticScoreboardComponentPlugin.java
#	cardinal-components-world/src/main/java/dev/onyxstudios/cca/internal/world/StaticWorldComponentPlugin.java
#	changelog.md
#	gradle.properties
#	src/testmod/java/dev/onyxstudios/componenttest/CardinalComponentsTest.java
  • Loading branch information
Pyrofab committed Nov 14, 2020
2 parents 8ccb4d2 + 059626f commit 46dcea2
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Cardinal-Components-API
* Copyright (C) 2019-2020 OnyxStudios
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
*/
package dev.onyxstudios.cca.internal.base;

/**
* Internal marker for {@code "cardinal-components"} entrypoints
*/
public interface ComponentRegistrationInitializer {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import dev.onyxstudios.cca.api.v3.component.ComponentContainer;
import dev.onyxstudios.cca.api.v3.component.ComponentFactory;
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import dev.onyxstudios.cca.internal.base.LazyDispatcher;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
import org.objectweb.asm.MethodVisitor;
Expand All @@ -38,6 +40,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -156,6 +159,18 @@ public static <I> void processInitializers(Collection<EntrypointContainer<I>> en
}
}

public static <I extends ComponentRegistrationInitializer> Collection<EntrypointContainer<I>> getComponentEntrypoints(String key, Class<I> type) {
Collection<EntrypointContainer<ComponentRegistrationInitializer>> generic = FabricLoader.getInstance().getEntrypointContainers("cardinal-components", ComponentRegistrationInitializer.class);
Collection<EntrypointContainer<I>> specific = new ArrayList<>(FabricLoader.getInstance().getEntrypointContainers(key, type));
for (EntrypointContainer<ComponentRegistrationInitializer> container : generic) {
if (type.isInstance(container.getEntrypoint())) {
@SuppressWarnings("unchecked") EntrypointContainer<I> c = (EntrypointContainer<I>) container;
specific.add(c);
}
}
return specific;
}

protected abstract Collection<EntrypointContainer<I>> getEntrypoints();

protected abstract void dispatchRegistration(I entrypoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
*/
package dev.onyxstudios.cca.api.v3.block;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.block.entity.BlockEntity;
import org.jetbrains.annotations.ApiStatus;

/**
* Entrypoint getting invoked to register <em>static</em> block component factories.
*
* <p>The entrypoint is exposed as {@code cardinal-components-block} in the mod json and runs for any environment.
* <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.
*
* @since 2.5.0
*/
@ApiStatus.Experimental
public interface BlockComponentInitializer {
public interface BlockComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public <C extends Component, B extends BlockEntity> Registration<C, B> beginRegi
@Override
protected void init() {
StaticComponentPluginBase.processInitializers(
FabricLoader.getInstance().getEntrypointContainers("cardinal-components-block", BlockComponentInitializer.class),
StaticComponentPluginBase.getComponentEntrypoints("cardinal-components-block", BlockComponentInitializer.class),
initializer -> initializer.registerBlockComponentFactories(this)
);
this.wildcard = this.blockComponentFactories.getOrDefault(null, Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
*/
package dev.onyxstudios.cca.api.v3.chunk;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.world.chunk.Chunk;

/**
* Entrypoint getting invoked to register <em>static</em> chunk component factories.
*
* <p>The entrypoint is exposed as {@code cardinal-components-chunk} in the mod json and runs for any environment.
* <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.
*
* @since 2.4.0
*/
public interface ChunkComponentInitializer {
public interface ChunkComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private StaticChunkComponentPlugin() {

@Override
protected Collection<EntrypointContainer<ChunkComponentInitializer>> getEntrypoints() {
return FabricLoader.getInstance().getEntrypointContainers("cardinal-components-chunk", ChunkComponentInitializer.class);
return getComponentEntrypoints("cardinal-components-chunk", ChunkComponentInitializer.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package dev.onyxstudios.cca.api.v3.entity;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.entity.Entity;

/**
Expand All @@ -32,7 +33,7 @@
*
* @since 2.4.0
*/
public interface EntityComponentInitializer {
public interface EntityComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Class<? extends ComponentContainer.Factory<?>> spinDedicatedFactory(Class
@Override
protected void init() {
StaticComponentPluginBase.processInitializers(
FabricLoader.getInstance().getEntrypointContainers("cardinal-components-entity", EntityComponentInitializer.class),
StaticComponentPluginBase.getComponentEntrypoints("cardinal-components-entity", EntityComponentInitializer.class),
initializer -> initializer.registerEntityComponentFactories(this)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
*/
package dev.onyxstudios.cca.api.v3.item;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.item.ItemStack;

/**
* Entrypoint getting invoked to register <em>static</em> item component factories.
*
* <p>The entrypoint is exposed as {@code "cardinal-components-item"} in the mod json and runs for any environment.
* <p>The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-item"} in the mod json and runs for any environment.
* It usually executes right before the first {@link ItemStack} instance is created.
*
* @since 2.4.0
*/
public interface ItemComponentInitializer {
public interface ItemComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ComponentContainer.Factory<ItemStack> getFactoryClass(Item item, Identifi
@Override
protected void init() {
StaticComponentPluginBase.processInitializers(
FabricLoader.getInstance().getEntrypointContainers("cardinal-components-item", ItemComponentInitializer.class),
StaticComponentPluginBase.getComponentEntrypoints("cardinal-components-item", ItemComponentInitializer.class),
initializer -> initializer.registerItemComponentFactories(this)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
*/
package dev.onyxstudios.cca.api.v3.level;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.world.WorldProperties;
import org.jetbrains.annotations.ApiStatus;

/**
* Entrypoint getting invoked to register <em>static</em> item component factories.
*
* <p>The entrypoint is exposed as {@code cardinal-components-level} in the mod json and runs for any environment.
* <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.
*
* @since 2.4.0
*/
@ApiStatus.Experimental
public interface LevelComponentInitializer {
public interface LevelComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private StaticLevelComponentPlugin() {

@Override
protected Collection<EntrypointContainer<LevelComponentInitializer>> getEntrypoints() {
return FabricLoader.getInstance().getEntrypointContainers("cardinal-components-level", LevelComponentInitializer.class);
return getComponentEntrypoints("cardinal-components-level", LevelComponentInitializer.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
*/
package dev.onyxstudios.cca.api.v3.scoreboard;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import org.jetbrains.annotations.ApiStatus;

/**
* Entrypoint getting invoked to register <em>static</em> team component factories.
*
* <p>The entrypoint is exposed as {@code cardinal-components-scoreboard} in the mod json and runs for any environment.
* <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.
*
* @since 2.4.2
*/
@ApiStatus.Experimental
public interface ScoreboardComponentInitializer {
public interface ScoreboardComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private StaticScoreboardComponentPlugin() {

@Override
protected Collection<EntrypointContainer<ScoreboardComponentInitializer>> getEntrypoints() {
return FabricLoader.getInstance().getEntrypointContainers("cardinal-components-scoreboard", ScoreboardComponentInitializer.class);
return getComponentEntrypoints("cardinal-components-scoreboard", ScoreboardComponentInitializer.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
*/
package dev.onyxstudios.cca.api.v3.util;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import org.jetbrains.annotations.ApiStatus;

/**
* Entrypoint getting invoked to register <em>static</em> generic (typically for third party providers)
* component factories.
*
* <p>The entrypoint is exposed as {@code "cardinal-components-util"} in the mod json and runs for any environment.
* <p>The entrypoint is exposed as either {@code "cardinal-components"} or {@code "cardinal-components-util"} in the mod json and runs for any environment.
*
* @since 2.4.0
*/
@ApiStatus.Experimental
public interface GenericComponentInitializer {
public interface GenericComponentInitializer extends ComponentRegistrationInitializer {
/**
* Called to register component factories for statically declared component types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
*/
package dev.onyxstudios.cca.api.v3.world;

import dev.onyxstudios.cca.internal.base.ComponentRegistrationInitializer;
import net.minecraft.world.World;

/**
* Entrypoint getting invoked to register <em>static</em> world component factories.
*
* <p>The entrypoint is exposed as {@code cardinal-components-world} in the mod json and runs for any environment.
* <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.
*
* @since 2.4.0
*/
public interface WorldComponentInitializer {
public interface WorldComponentInitializer extends ComponentRegistrationInitializer {
void registerWorldComponentFactories(WorldComponentFactoryRegistry registry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private StaticWorldComponentPlugin() {

@Override
protected Collection<EntrypointContainer<WorldComponentInitializer>> getEntrypoints() {
return FabricLoader.getInstance().getEntrypointContainers("cardinal-components-world", WorldComponentInitializer.class);
return getComponentEntrypoints("cardinal-components-world", WorldComponentInitializer.class);
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Changes
- Every class remaining in the `nerdhub.component.*` packages has been moved to a `dev.onyxstudios.cca.*` package
- Replaced specific factory interfaces with a generic variant (eg. `ComponentFactory`)

------------------------------------------------------
Version 2.7.5
------------------------------------------------------
Additions
- Added the universal `cardinal-components` entrypoint key
- This new key can be used for any CCA registration initializer (replaces eg. `cardinal-components-entity`)

------------------------------------------------------
Version 2.7.4
------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import dev.onyxstudios.cca.api.v3.component.CopyableComponent;
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent;
import dev.onyxstudios.cca.api.v3.util.ComponentContainerMetafactory;
import dev.onyxstudios.cca.internal.base.asm.StaticComponentLoadingException;
import dev.onyxstudios.componenttest.vita.BaseVita;
import dev.onyxstudios.componenttest.vita.Vita;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
Expand Down Expand Up @@ -112,15 +111,6 @@ public static void init() {
assert false : "Only one factory should be created for any given provider type";
} catch (IllegalStateException ignored) { }

try {
LOGGER.info(ComponentContainerMetafactory.metafactory(
TestComponents.CUSTOM_PROVIDER_2,
new TypeToken<BiFunction<UUID, PlayerEntity, ? extends ComponentContainer>>() {},
new TypeToken<BiFunction<UUID, PlayerEntity, ? extends AutoSyncedComponent>>() {}
).apply(UUID.randomUUID(), null));
assert false : "Registered factory does not return " + AutoSyncedComponent.class;
} catch (StaticComponentLoadingException ignored) { }

LOGGER.info(ComponentContainerMetafactory.metafactory(
TestComponents.CUSTOM_PROVIDER_2,
new TypeToken<BiFunction<UUID, PlayerEntity, ComponentContainer>>() {},
Expand Down
23 changes: 1 addition & 22 deletions src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,7 @@
"cardinal-components:static-init": [
"dev.onyxstudios.componenttest.TestStaticComponentInitializer"
],
"cardinal-components-block": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-chunk": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-entity": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-item": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-level": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-scoreboard": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-util": [
"dev.onyxstudios.componenttest.TestComponents"
],
"cardinal-components-world": [
"cardinal-components": [
"dev.onyxstudios.componenttest.TestComponents"
]
},
Expand Down

0 comments on commit 46dcea2

Please sign in to comment.