Skip to content

Commit

Permalink
Fix modded ComponentProvider subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Feb 2, 2022
1 parent a1acb61 commit 08100e2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ static ComponentProvider fromWorld(World world) {
/**
* @return a runtime-generated component container storing statically declared components.
*/
ComponentContainer getComponentContainer();
default ComponentContainer getComponentContainer() {
throw new UnsupportedOperationException("Please implement me");
}

/**
* @param key the key object for the type of component to retrieve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer;
import dev.onyxstudios.cca.test.base.Vita;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class CcaEntityTestMod implements ModInitializer, EntityComponentInitializer {

public static final EntityType<TestEntity> TEST_ENTITY = FabricEntityTypeBuilder.create().entityFactory(TestEntity::new).build();

public class CcaEntityTestMod implements EntityComponentInitializer {
@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
registry.beginRegistration(PlayerEntity.class, Vita.KEY).impl(PlayerVita.class).end(PlayerVita::new);
}

@Override
public void onInitialize() {
Registry.register(Registry.ENTITY_TYPE, new Identifier("cca-entity-test", "test"), TEST_ENTITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public void bucketableWorks(TestContext ctx) {
((EntityBucketItem) Items.AXOLOTL_BUCKET).onEmptied(player, ctx.getWorld(), player.getStackInHand(Hand.MAIN_HAND), ctx.getAbsolutePos(pos));
ctx.expectEntityWithDataEnd(pos, EntityType.AXOLOTL, a -> Vita.get(a).getVitality(), 3);
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void moddedEntitiesWork(TestContext ctx) {
ctx.spawnEntity(CcaEntityTestMod.TEST_ENTITY, 0, 0, 0);
ctx.complete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Cardinal-Components-API
* Copyright (C) 2019-2022 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.test.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.Packet;
import net.minecraft.world.World;

public class TestEntity extends Entity {
public TestEntity(EntityType<?> type, World world) {
super(type, world);
}

@Override
protected void initDataTracker() {

}

@Override
protected void readCustomDataFromNbt(NbtCompound nbt) {

}

@Override
protected void writeCustomDataToNbt(NbtCompound nbt) {

}

@Override
public Packet<?> createSpawnPacket() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"description": "Test mod for Cardinal Components API",
"version": "${version}",
"entrypoints": {
"main": [
"dev.onyxstudios.cca.test.entity.CcaEntityTestMod"
],
"cardinal-components": [
"dev.onyxstudios.cca.test.entity.CcaEntityTestMod"
],
"fabric-gametest": [
"dev.onyxstudios.cca.test.entity.CcaEntityTestSuite"
]
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 4.1.1
------------------------------------------------------
**Fixes**
Fixed modded ComponentProvider subclasses (as in, custom entities) on newer loom versions

------------------------------------------------------
Version 4.1.0
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_api_version=0.42.2+1.18
elmendorf_version=0.3.0

#Publishing
mod_version = 4.1.0
mod_version = 4.1.1
curseforge_id = 318449
modrinth_id = K01OU20C
curseforge_versions = 1.18-Snapshot; 1.18; 1.18.1
Expand Down

0 comments on commit 08100e2

Please sign in to comment.