diff --git a/build.gradle.kts b/build.gradle.kts index 037a3426..f84e0a70 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,8 @@ import net.fabricmc.loom.task.RemapJarTask import java.net.URI plugins { - id("fabric-loom") version "1.6-SNAPSHOT" - id("io.github.ladysnake.chenille") version "0.12.2" + id("fabric-loom") version "1.8-SNAPSHOT" + id("io.github.ladysnake.chenille") version "0.14.0" id("org.cadixdev.licenser") version "0.6.1" } diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentKey.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentKey.java index b34f2918..82245105 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentKey.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentKey.java @@ -24,6 +24,7 @@ import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.PacketCallbacks; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.packet.CustomPayload; @@ -208,7 +209,11 @@ public void syncWith(ServerPlayerEntity player, ComponentProvider provider, Comp ServerPlayNetworking.getSender(player).sendPacket(payload, PacketCallbacks.always(buf::release)); } else { if (predicate.isRequiredOnClient()) { - player.networkHandler.disconnect(Text.literal("This server requires Cardinal Components API (unhandled packet: " + payload.getId().id() + ")" + ComponentsInternals.getClientOptionalModAdvice())); + String specificMod = FabricLoader.getInstance().getModContainer(this.id.getNamespace()).map(c -> c.getMetadata().getName() + " and ").orElse(""); + player.networkHandler.disconnect(Text.literal( + "This server requires " + specificMod + "Cardinal Components API " + + "(unhandled packet: " + payload.getId().id() + ")" + + ComponentsInternals.getClientOptionalModAdvice())); } buf.release(); } diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/CcaClientInternals.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/CcaClientInternals.java index 6b716c18..55158b00 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/CcaClientInternals.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/CcaClientInternals.java @@ -42,7 +42,9 @@ public static > void registerComponentSync(C } }); } catch (UnknownComponentException e) { - ctx.player().networkHandler.onDisconnected(new DisconnectionInfo(Text.literal(e.getMessage() + "\n(you are probably missing a mod installed on the server)" + ComponentsInternals.getClientOptionalModAdvice()))); + ctx.player().networkHandler.onDisconnected(new DisconnectionInfo(Text.literal( + e.getMessage() + "\n(you are probably missing a mod installed on the server)" + ComponentsInternals.getClientOptionalModAdvice()) + )); } finally { payload.buf().release(); } diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/MorePacketCodecs.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/MorePacketCodecs.java index fc3655c4..bdf3be3c 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/MorePacketCodecs.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/internal/base/MorePacketCodecs.java @@ -25,10 +25,8 @@ import com.mojang.datafixers.util.Unit; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; -import net.minecraft.util.math.ChunkPos; public final class MorePacketCodecs { public static final PacketCodec EMPTY = PacketCodec.unit(Unit.INSTANCE); @@ -45,15 +43,4 @@ public final class MorePacketCodecs { return new RegistryByteBuf(copy, buf.getRegistryManager()); } ); - - /** - * A codec for a {@link ChunkPos}. - * - * @see PacketByteBuf#readChunkPos() - * @see PacketByteBuf#writeChunkPos(ChunkPos) - */ - public static final PacketCodec CHUNKPOS = PacketCodec.ofStatic( - PacketByteBuf::writeChunkPos, - PacketByteBuf::readChunkPos - ); } 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 3f5f081c..d9b31a3f 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 @@ -30,14 +30,13 @@ import org.ladysnake.cca.api.v3.component.ComponentKey; import org.ladysnake.cca.api.v3.component.ComponentProvider; import org.ladysnake.cca.internal.base.ComponentUpdatePayload; -import org.ladysnake.cca.internal.base.MorePacketCodecs; public final class CardinalComponentsChunk { public static final CustomPayload.Id> PACKET_ID = ComponentUpdatePayload.id("chunk_sync"); public static void init() { if (FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1")) { - ComponentUpdatePayload.register(PACKET_ID, MorePacketCodecs.CHUNKPOS); + ComponentUpdatePayload.register(PACKET_ID, ChunkPos.PACKET_CODEC); ChunkSyncCallback.EVENT.register((player, tracked) -> { for (ComponentKey key : tracked.asComponentProvider().getComponentContainer().keys()) { key.syncWith(player, (ComponentProvider) tracked); diff --git a/cardinal-components-chunk/src/main/java/org/ladysnake/cca/mixin/chunk/common/MixinChunkSerializer.java b/cardinal-components-chunk/src/main/java/org/ladysnake/cca/mixin/chunk/common/MixinSerializedChunk.java similarity index 54% rename from cardinal-components-chunk/src/main/java/org/ladysnake/cca/mixin/chunk/common/MixinChunkSerializer.java rename to cardinal-components-chunk/src/main/java/org/ladysnake/cca/mixin/chunk/common/MixinSerializedChunk.java index 5c476ed2..1ae24b93 100644 --- a/cardinal-components-chunk/src/main/java/org/ladysnake/cca/mixin/chunk/common/MixinChunkSerializer.java +++ b/cardinal-components-chunk/src/main/java/org/ladysnake/cca/mixin/chunk/common/MixinSerializedChunk.java @@ -24,37 +24,68 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.ChunkSerializer; +import net.minecraft.world.HeightLimitView; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ProtoChunk; +import net.minecraft.world.chunk.SerializedChunk; import net.minecraft.world.chunk.WrapperProtoChunk; import net.minecraft.world.poi.PointOfInterestStorage; import net.minecraft.world.storage.StorageKey; +import org.jetbrains.annotations.Nullable; import org.ladysnake.cca.internal.base.AbstractComponentContainer; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ChunkSerializer.class) -public abstract class MixinChunkSerializer { - @Inject(method = "deserialize", at = @At("RETURN")) - private static void deserialize(ServerWorld world, PointOfInterestStorage poiStorage, StorageKey key, ChunkPos chunkPos, NbtCompound tag, CallbackInfoReturnable cir) { +@Mixin(SerializedChunk.class) +public abstract class MixinSerializedChunk { + @Unique + private @Nullable NbtCompound cca$serializedComponents; + + @Inject(method = "fromNbt", at = @At("RETURN")) + private static void fromNbt(HeightLimitView world, DynamicRegistryManager registryManager, NbtCompound nbt, CallbackInfoReturnable cir) { + MixinSerializedChunk ret = (MixinSerializedChunk) (Object) cir.getReturnValue(); + if (ret != null) { + ret.cca$serializedComponents = new NbtCompound(); + ret.cca$serializedComponents.put(AbstractComponentContainer.NBT_KEY, nbt.get(AbstractComponentContainer.NBT_KEY)); + } + } + + @Inject(method = "convert", at = @At("RETURN")) + private void convert(ServerWorld world, PointOfInterestStorage poiStorage, StorageKey key, ChunkPos expectedPos, CallbackInfoReturnable cir) { + NbtCompound tag = cca$serializedComponents; + if (tag == null) return; ProtoChunk ret = cir.getReturnValue(); Chunk chunk = ret instanceof WrapperProtoChunk ? ((WrapperProtoChunk) ret).getWrappedChunk() : ret; chunk.asComponentProvider().getComponentContainer().fromTag(tag, world.getRegistryManager()); // If components have been removed, we need to make the chunk save again if (tag.contains(AbstractComponentContainer.NBT_KEY, NbtElement.COMPOUND_TYPE)) { int remainingComponentCount = tag.getCompound(AbstractComponentContainer.NBT_KEY).getSize(); - chunk.setNeedsSaving(remainingComponentCount > 0); + if (remainingComponentCount > 0) { + chunk.markNeedsSaving(); + } + } + } + + @Inject(method = "fromChunk", at = @At("RETURN")) + private static void fromChunk(ServerWorld world, Chunk chunk, CallbackInfoReturnable cir) { + MixinSerializedChunk ret = (MixinSerializedChunk) (Object) cir.getReturnValue(); + if (ret != null) { + ret.cca$serializedComponents = new NbtCompound(); + chunk.asComponentProvider().getComponentContainer().toTag(ret.cca$serializedComponents, world.getRegistryManager()); } } @Inject(method = "serialize", at = @At("RETURN")) - private static void serialize(ServerWorld world, Chunk chunk, CallbackInfoReturnable cir) { - NbtCompound ret = cir.getReturnValue(); - chunk.asComponentProvider().getComponentContainer().toTag(ret, world.getRegistryManager()); + private void serialize(CallbackInfoReturnable cir) { + if (cca$serializedComponents != null) { + NbtCompound ret = cir.getReturnValue(); + ret.put(AbstractComponentContainer.NBT_KEY, cca$serializedComponents.get(AbstractComponentContainer.NBT_KEY)); + } } } diff --git a/cardinal-components-chunk/src/main/resources/mixins.cardinal_components_chunk.json b/cardinal-components-chunk/src/main/resources/mixins.cardinal_components_chunk.json index 80bbb636..062bb16d 100644 --- a/cardinal-components-chunk/src/main/resources/mixins.cardinal_components_chunk.json +++ b/cardinal-components-chunk/src/main/resources/mixins.cardinal_components_chunk.json @@ -7,8 +7,8 @@ "common.MixinChunk", "common.MixinChunkDataSender", "common.MixinChunkHolder", - "common.MixinChunkSerializer", "common.MixinEmptyChunk", + "common.MixinSerializedChunk", "common.MixinServerWorld", "common.MixinWorldChunk", "common.MixinWrapperProtoChunk" diff --git a/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/CcaChunkTestSuite.java b/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/CcaChunkTestSuite.java index 0bdbf9c7..15bcdef6 100644 --- a/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/CcaChunkTestSuite.java +++ b/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/CcaChunkTestSuite.java @@ -28,8 +28,8 @@ import net.minecraft.test.TestContext; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.ChunkSerializer; import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.SerializedChunk; import net.minecraft.world.chunk.WorldChunk; import net.minecraft.world.storage.StorageKey; import org.ladysnake.cca.test.base.LoadAwareTestComponent; @@ -43,8 +43,9 @@ public void chunksSerialize(TestContext ctx) { ChunkPos pos = new ChunkPos(ctx.getAbsolutePos(new BlockPos(1, 0, 1))); Chunk c = new WorldChunk(ctx.getWorld(), pos); c.getComponent(Vita.KEY).setVitality(42); - NbtCompound nbt = ChunkSerializer.serialize(ctx.getWorld(), c); - Chunk c1 = ChunkSerializer.deserialize(ctx.getWorld(), ctx.getWorld().getPointOfInterestStorage(), new StorageKey("", ctx.getWorld().getRegistryKey(), ""), pos, nbt); + NbtCompound nbt = SerializedChunk.fromChunk(ctx.getWorld(), c).serialize(); + Chunk c1 = SerializedChunk.fromNbt(ctx.getWorld(), ctx.getWorld().getRegistryManager(), nbt) + .convert(ctx.getWorld(), ctx.getWorld().getPointOfInterestStorage(), new StorageKey("", ctx.getWorld().getRegistryKey(), ""), pos); GameTestUtil.assertTrue("Chunk component data should survive deserialization", c1.getComponent(Vita.KEY).getVitality() == 42); ctx.complete(); } diff --git a/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/ChunkVita.java b/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/ChunkVita.java index 4d2c2d97..dd19b5c0 100644 --- a/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/ChunkVita.java +++ b/cardinal-components-chunk/src/testmod/java/org/ladysnake/cca/test/chunk/ChunkVita.java @@ -37,6 +37,6 @@ public ChunkVita(Chunk owner) { public void setVitality(int value) { super.setVitality(value); this.owner.syncComponent(KEY); - this.owner.setNeedsSaving(true); + this.owner.markNeedsSaving(); } } 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 9d54a0f6..20999ddd 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 @@ -31,6 +31,8 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.conversion.EntityConversionContext; +import net.minecraft.entity.conversion.EntityConversionType; import net.minecraft.network.codec.PacketCodecs; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; @@ -106,18 +108,18 @@ public static void init() { StaticEntityComponentPlugin.INSTANCE.ensureInitialized(); } - private static void copyData(LivingEntity original, LivingEntity clone, boolean keepInventory) { + private static void copyData(LivingEntity original, LivingEntity clone, EntityConversionContext context) { Set> keys = ((ComponentProvider) original).getComponentContainer().keys(); for (ComponentKey key : keys) { if (key.isProvidedBy(clone)) { - copyData(original, clone, original.getRegistryManager(), false, keepInventory, true, key); + copyData(original, clone, original.getRegistryManager(), false, context.keepEquipment(), context.type() == EntityConversionType.SINGLE, key); } } } private static void copyData(ServerPlayerEntity original, ServerPlayerEntity clone, boolean lossless) { - boolean keepInventory = original.getWorld().getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || clone.isSpectator(); + boolean keepInventory = original.getServerWorld().getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || clone.isSpectator(); Set> keys = ((ComponentProvider) original).getComponentContainer().keys(); for (ComponentKey key : keys) { diff --git a/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestMod.java b/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestMod.java index 713494f6..82ffee52 100644 --- a/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestMod.java +++ b/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestMod.java @@ -31,6 +31,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; import org.ladysnake.cca.api.v3.entity.EntityComponentFactoryRegistry; import org.ladysnake.cca.api.v3.entity.EntityComponentInitializer; @@ -40,8 +42,8 @@ import org.ladysnake.cca.test.base.Vita; public class CcaEntityTestMod implements ModInitializer, EntityComponentInitializer { - - public static final EntityType TEST_ENTITY = EntityType.Builder.create(TestEntity::new, SpawnGroup.MISC).build("cca-entity-test"); + public static final RegistryKey> TEST_ENTITY_ID = RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("cca-entity-test", "test")); + public static final EntityType TEST_ENTITY = EntityType.Builder.create(TestEntity::new, SpawnGroup.MISC).build(TEST_ENTITY_ID); public static final int NATURAL_VITA_CEILING = 10; public static final int CAMEL_BASE_VITA = 50; @@ -59,6 +61,6 @@ public void registerEntityComponentFactories(EntityComponentFactoryRegistry regi @Override public void onInitialize() { - Registry.register(Registries.ENTITY_TYPE, Identifier.of("cca-entity-test", "test"), TEST_ENTITY); + Registry.register(Registries.ENTITY_TYPE, TEST_ENTITY_ID, TEST_ENTITY); } } diff --git a/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestSuite.java b/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestSuite.java index 138b0ea4..aa09c5e0 100644 --- a/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestSuite.java +++ b/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/CcaEntityTestSuite.java @@ -26,6 +26,7 @@ import net.minecraft.entity.Bucketable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.conversion.EntityConversionContext; import net.minecraft.entity.mob.ShulkerEntity; import net.minecraft.entity.passive.CamelEntity; import net.minecraft.entity.passive.CatEntity; @@ -89,9 +90,10 @@ public void moddedEntitiesWork(TestContext ctx) { @GameTest(templateName = EMPTY_STRUCTURE) public void respawnHappensOnConversion(TestContext ctx) { CamelEntity camel = ctx.spawnEntity(EntityType.CAMEL, 0, 0, 0); - CowEntity cow = camel.convertTo(EntityType.COW, true); + CowEntity cow = camel.convertTo(EntityType.COW, EntityConversionContext.create(camel, true, true), e -> {}); + assert cow != null; GameTestUtil.assertTrue("Component data should transfer according to RespawnCopyStrategy", Vita.get(cow).getVitality() == CcaEntityTestMod.CAMEL_BASE_VITA); - CatEntity cat = cow.convertTo(EntityType.CAT, true); + CatEntity cat = cow.convertTo(EntityType.CAT, EntityConversionContext.create(camel, true, true), e -> {}); GameTestUtil.assertTrue("Component data should not transfer by default", Vita.get(cat).getVitality() < CcaEntityTestMod.NATURAL_VITA_CEILING); ctx.complete(); } diff --git a/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/TestEntity.java b/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/TestEntity.java index 16e3db78..8ac88c34 100644 --- a/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/TestEntity.java +++ b/cardinal-components-entity/src/testmod/java/org/ladysnake/cca/test/entity/TestEntity.java @@ -24,8 +24,10 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.world.ServerWorld; import net.minecraft.world.World; public class TestEntity extends Entity { @@ -38,6 +40,11 @@ protected void initDataTracker(DataTracker.Builder builder) { } + @Override + public boolean damage(ServerWorld world, DamageSource source, float amount) { + return false; + } + @Override protected void readCustomDataFromNbt(NbtCompound nbt) { diff --git a/cardinal-components-item/src/main/java/org/ladysnake/cca/api/v3/item/ItemComponentInitializer.java b/cardinal-components-item/src/main/java/org/ladysnake/cca/api/v3/item/ItemComponentInitializer.java index 05dc33ac..9e8e9bf3 100644 --- a/cardinal-components-item/src/main/java/org/ladysnake/cca/api/v3/item/ItemComponentInitializer.java +++ b/cardinal-components-item/src/main/java/org/ladysnake/cca/api/v3/item/ItemComponentInitializer.java @@ -35,7 +35,7 @@ */ public interface ItemComponentInitializer extends ComponentRegistrationInitializer { /** - * Called to register component migrations from CCA to {@link net.minecraft.component.DataComponentType}. + * Called to register component migrations from CCA to {@link net.minecraft.component.ComponentType}. * * @param registry an {@link ItemComponentMigrationRegistry} for component migrations * @since 7.0.0 diff --git a/cardinal-components-level/src/main/java/org/ladysnake/cca/mixin/level/common/LevelStorageMixin.java b/cardinal-components-level/src/main/java/org/ladysnake/cca/mixin/level/common/LevelStorageMixin.java index 416ed8bb..f137dd47 100644 --- a/cardinal-components-level/src/main/java/org/ladysnake/cca/mixin/level/common/LevelStorageMixin.java +++ b/cardinal-components-level/src/main/java/org/ladysnake/cca/mixin/level/common/LevelStorageMixin.java @@ -27,7 +27,7 @@ import com.llamalad7.mixinextras.sugar.Local; import com.mojang.serialization.Dynamic; import com.mojang.serialization.Lifecycle; -import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.world.gen.GeneratorOptions; import net.minecraft.world.level.LevelInfo; import net.minecraft.world.level.LevelProperties; @@ -39,7 +39,7 @@ @Mixin(LevelStorage.class) public class LevelStorageMixin { @WrapOperation(method = "parseSaveProperties", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelProperties;readProperties(Lcom/mojang/serialization/Dynamic;Lnet/minecraft/world/level/LevelInfo;Lnet/minecraft/world/level/LevelProperties$SpecialProperty;Lnet/minecraft/world/gen/GeneratorOptions;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/world/level/LevelProperties;")) - private static LevelProperties readComponents(Dynamic dynamic, LevelInfo info, LevelProperties.SpecialProperty specialProperty, GeneratorOptions generatorOptions, Lifecycle lifecycle, Operation original, @Local(argsOnly = true) DynamicRegistryManager.Immutable registryManager) { + private static LevelProperties readComponents(Dynamic dynamic, LevelInfo info, LevelProperties.SpecialProperty specialProperty, GeneratorOptions generatorOptions, Lifecycle lifecycle, Operation original, @Local(argsOnly = true) RegistryWrapper.WrapperLookup registryManager) { LevelProperties props = original.call(dynamic, info, specialProperty, generatorOptions, lifecycle); ((ComponentProvider) props).getComponentContainer().fromDynamic(dynamic, registryManager); return props; diff --git a/changelog.md b/changelog.md index d37bc5d9..928b6703 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +------------------------------------------------------ +Version 6.2.0 +------------------------------------------------------ +Updated to 1.21.3 + ------------------------------------------------------ Version 6.1.2 ------------------------------------------------------ diff --git a/gradle.properties b/gradle.properties index 6af9f365..474df5ad 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,11 @@ org.gradle.parallel=true fabric.loom.multiProjectOptimisation=true #see https://fabricmc.net/develop/ -minecraft_version=1.21 -yarn_mappings=9 -loader_version=0.15.11 +minecraft_version=1.21.3 +yarn_mappings=2 +loader_version=0.16.7 #Fabric api -fabric_api_version=0.100.7+1.21 +fabric_api_version=0.106.1+1.21.3 elmendorf_version=0.13.0 @@ -16,8 +16,8 @@ elmendorf_version=0.13.0 mod_version = 6.1.2 curseforge_id = 318449 modrinth_id = K01OU20C -curseforge_versions = 1.21 -modrinth_versions = 1.21 +curseforge_versions = 1.21.2; 1.21.3 +modrinth_versions = 1.21.2; 1.21.3 release_type = release display_name = Cardinal-Components-API owners = Ladysnake diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f..a4b76b95 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02c..9355b415 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..f5feea6d 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,12 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +134,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +217,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32..9d21a218 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/testmod/java/org/ladysnake/componenttest/content/CardinalComponentsTest.java b/src/testmod/java/org/ladysnake/componenttest/content/CardinalComponentsTest.java index a73024f3..af3b0f0e 100644 --- a/src/testmod/java/org/ladysnake/componenttest/content/CardinalComponentsTest.java +++ b/src/testmod/java/org/ladysnake/componenttest/content/CardinalComponentsTest.java @@ -25,9 +25,9 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; -import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnGroup; @@ -71,15 +71,20 @@ public class CardinalComponentsTest { public static final Logger LOGGER = LogManager.getLogger("Component Test"); - public static final Identifier VITA_STICK_ID = id("vita_stick"); + public static final RegistryKey VITA_STICK_ID = RegistryKey.of(RegistryKeys.ITEM, id("vita_stick")); // inline self component callback registration public static final VitalityStickItem VITALITY_STICK = Registry.register(Registries.ITEM, VITA_STICK_ID, - new VitalityStickItem(new Item.Settings().maxDamage(50))); + new VitalityStickItem(new Item.Settings().maxDamage(50).registryKey(VITA_STICK_ID))); - public static final VitalityCondenser VITALITY_CONDENSER = new VitalityCondenser(FabricBlockSettings.copyOf(Blocks.STONE).dropsNothing().luminance(s -> 5).ticksRandomly()); + public static final RegistryKey VITALITY_CONDENSER_ID = RegistryKey.of(RegistryKeys.BLOCK, id("vita_condenser")); + public static final VitalityCondenser VITALITY_CONDENSER = Registry.register(Registries.BLOCK, VITALITY_CONDENSER_ID, + new VitalityCondenser(AbstractBlock.Settings.copy(Blocks.STONE).registryKey(VITALITY_CONDENSER_ID).dropsNothing().luminance(s -> 5).ticksRandomly())); - public static final EntityType VITALITY_ZOMBIE = Registry.register(Registries.ENTITY_TYPE, "componenttest:vita_zombie", - FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, VitalityZombieEntity::new).dimensions(EntityType.ZOMBIE.getDimensions()).build()); + public static final RegistryKey> VITALITY_ZOMBIE_ID = RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("vita_zombie")); + public static final EntityType VITALITY_ZOMBIE = Registry.register(Registries.ENTITY_TYPE, VITALITY_ZOMBIE_ID, + EntityType.Builder.create(VitalityZombieEntity::new, SpawnGroup.MONSTER) + .dimensions(EntityType.ZOMBIE.getDimensions().width(), EntityType.ZOMBIE.getDimensions().height()) + .build(VITALITY_ZOMBIE_ID)); public static Identifier id(String path) { return Identifier.of("componenttest", path); @@ -92,7 +97,6 @@ public static void init() { Registry.register(Registries.DATA_COMPONENT_TYPE, id("vita"), ItemVita.Data.COMPONENT_TYPE); Registry.register(Registries.DATA_COMPONENT_TYPE, id("alt_vita"), ItemVita.Data.ALT_COMPONENT_TYPE); - Registry.register(Registries.BLOCK, "componenttest:vita_condenser", VITALITY_CONDENSER); CommandRegistrationCallback.EVENT.register((dispatcher, reg, dedicated) -> VitaCommand.register(dispatcher)); FabricDefaultAttributeRegistry.register(VITALITY_ZOMBIE, ZombieEntity.createZombieAttributes()); diff --git a/src/testmod/java/org/ladysnake/componenttest/content/VitaCommand.java b/src/testmod/java/org/ladysnake/componenttest/content/VitaCommand.java index a2ca487a..3c87fada 100644 --- a/src/testmod/java/org/ladysnake/componenttest/content/VitaCommand.java +++ b/src/testmod/java/org/ladysnake/componenttest/content/VitaCommand.java @@ -45,7 +45,7 @@ public static void register(CommandDispatcher dispatcher) { .executes(context -> { Chunk chunk = context.getSource().getWorld().getChunk(BlockPosArgumentType.getBlockPos(context, "pos")); Vita.get(chunk).setVitality(IntegerArgumentType.getInteger(context, "amount")); - chunk.setNeedsSaving(true); + chunk.markNeedsSaving(); context.getSource().sendFeedback(() -> Text.of("success!"), false); return 1; }) diff --git a/src/testmod/java/org/ladysnake/componenttest/content/VitalityStickItem.java b/src/testmod/java/org/ladysnake/componenttest/content/VitalityStickItem.java index e55b0543..e738e259 100644 --- a/src/testmod/java/org/ladysnake/componenttest/content/VitalityStickItem.java +++ b/src/testmod/java/org/ladysnake/componenttest/content/VitalityStickItem.java @@ -37,7 +37,6 @@ import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.ladysnake.cca.test.base.Vita; @@ -54,7 +53,7 @@ public VitalityStickItem(Settings settings) { } @Override - public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + public ActionResult use(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); Vita vita = ItemVita.maybeGet(stack).orElseThrow(); if (!world.isClient) { @@ -71,7 +70,7 @@ public TypedActionResult use(World world, PlayerEntity player, Hand h vita.transferTo(Vita.get(player), vita.getVitality()); } } - return TypedActionResult.pass(stack); + return ActionResult.PASS; } @Override