Skip to content

Commit

Permalink
2.4.1 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 27, 2020
2 parents 5209117 + fcdc4e4 commit c2024cf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public synchronized <T extends Component> ComponentType<T> registerIfAbsent(Iden
} else {
registered = this.access.create(componentId, componentClass, rawId);
}
if (this.raw2Types.length < rawId) {
this.raw2Types = new ComponentType[this.raw2Types.length + 16];
if (this.raw2Types.length <= rawId) {
this.raw2Types = Arrays.copyOf(this.raw2Types, rawId + 16);
}
this.raw2Types[rawId] = registered;
this.size++;
Expand All @@ -103,7 +103,7 @@ public synchronized <T extends Component> ComponentType<T> registerIfAbsent(Iden
@Override
public <T extends Component> ComponentType<T> registerStatic(Identifier componentId, Class<T> componentClass) {
if (CcaBootstrap.INSTANCE.getGeneratedComponentTypeClass(componentId) == null) {
throw new IllegalStateException(componentId + "");
throw new IllegalStateException(componentId + " was not registered through mod metadata or plugin");
}
return this.registerIfAbsent(componentId, componentClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ public static String getComponentTypeName(Identifier identifier) {
}

public static String getJavaIdentifierName(Identifier identifier) {
return identifier.toString().replace(':', '$').replace('/', '$');
return identifier.toString()
.replace(':', '$')
.replace('/', '$')
.replace('.', '¤')
.replace('-', '£');
}

public static String getStaticStorageGetterName(Identifier identifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Class<? extends ComponentType<?>> getGeneratedComponentTypeClass(Identifi
@Override
protected void init() {
try {
Set<Identifier> staticComponentTypes = new HashSet<>();
Set<Identifier> staticComponentTypes = new TreeSet<>(Comparator.comparing(Identifier::toString));

for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
ModMetadata metadata = mod.getMetadata();
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 2.4.1
------------------------------------------------------
- Fixed crash when more than 16 components were registered
- Fixed crash when dots were used in static component identifiers

------------------------------------------------------
Version 2.4.0
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.8.8+build.202
fabric_api_version=0.13.1+build.370-1.16

#Publishing
mod_version = 2.4.0
mod_version = 2.4.1
curseforge_id = 318449
curseforge_versions = 1.16-Snapshot; 1.16; 1.16.1
changelog_url = https://github.com/OnyxStudios/Cardinal-Components-API/blob/master/changelog.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.reflect.TypeToken;
import dev.onyxstudios.cca.api.v3.component.util.ComponentContainerMetafactory;
import dev.onyxstudios.cca.internal.base.asm.StaticComponentLoadingException;
import dev.onyxstudios.componenttest.vita.Vita;
import nerdhub.cardinal.components.api.ComponentRegistry;
import nerdhub.cardinal.components.api.component.Component;
import nerdhub.cardinal.components.api.component.ComponentContainer;
Expand Down Expand Up @@ -72,16 +73,24 @@ public static Identifier id(String path) {

public static void init() {
LOGGER.info("Hello, Components!");

for (int i = 0; i < 16; i++) {
ComponentRegistry.INSTANCE.registerIfAbsent(new Identifier(String.valueOf(Math.random())), Vita.class);
}

FabricDefaultAttributeRegistry.register(VITALITY_ZOMBIE, ZombieEntity.createZombieAttributes());

try {
ComponentRegistry.INSTANCE.registerStatic(TestComponents.OLD_VITA.getId(), TestComponents.OLD_VITA.getComponentClass());
assert false : "Static components must be registered through mod metadata or plugin";
} catch (IllegalStateException ignored) { }

LOGGER.info(ComponentContainerMetafactory.metafactory(
TestComponents.CUSTOM_PROVIDER_1,
TypeToken.of(TestContainerFactory.class),
new TypeToken<BiFunction<UUID, PlayerEntity, ? extends Component>>() {}
).create(UUID.randomUUID(), null));

try {
LOGGER.info(ComponentContainerMetafactory.metafactory(
TestComponents.CUSTOM_PROVIDER_1,
Expand All @@ -90,6 +99,7 @@ public static void init() {
).create(UUID.randomUUID(), null));
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,
Expand All @@ -98,18 +108,21 @@ public static void init() {
).apply(UUID.randomUUID(), null));
assert false : "Registered factory does not return " + SyncedComponent.class;
} catch (StaticComponentLoadingException ignored) { }

LOGGER.info(ComponentContainerMetafactory.metafactory(
TestComponents.CUSTOM_PROVIDER_2,
new TypeToken<BiFunction<UUID, PlayerEntity, ComponentContainer<? extends CopyableComponent<?>>>>() {},
new TypeToken<BiFunction<UUID, PlayerEntity, ? extends CopyableComponent<?>>>() {}
).apply(UUID.randomUUID(), null));

LOGGER.info(ComponentContainerMetafactory.metafactory(
TestComponents.CUSTOM_PROVIDER_3,
TypeToken.of(TestContainerFactory.class),
TestComponents.CUSTOM_FACTORY_TYPE,
TestCallback.class,
TestCallback.EVENT
).create(UUID.randomUUID(), null));

LOGGER.info(ComponentContainerMetafactory.metafactory(
new Identifier("componenttest:no_factory"),
TypeToken.of(TestContainerFactory.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@
import nerdhub.cardinal.components.api.ComponentType;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public final class TestStaticComponentInitializer implements StaticComponentInitializer {

// note: the actual ComponentKey must not be registered in this class' <clinit>, to avoid circular initialization
public static final Identifier ALT_VITA_ID = new Identifier("componenttest:alt_vita");
public static final Identifier ALT_VITA_ID = new Identifier("componenttest", "alt-vita");

@Override
public Collection<Identifier> getSupportedComponentTypes() {
return Collections.singleton(ALT_VITA_ID);
List<Identifier> ret = new ArrayList<>(Collections.singleton(ALT_VITA_ID));
for (int i = 0; i < 128; i++) {
ret.add(new Identifier("-.-", "-random/test." + i));
}
return ret;
}

@Override
Expand Down

0 comments on commit c2024cf

Please sign in to comment.