From 56dbc9c01b98c67c27f981dff60b98a371646845 Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sun, 10 Sep 2023 02:49:47 +0200 Subject: [PATCH] Update to 1.20.2 --- build.gradle.kts | 3 +- .../api/v3/component/ComponentProvider.java | 4 +- .../cca/internal/CardinalComponentsBlock.java | 2 +- .../mixin/block/common/MixinBlockEntity.java | 5 +- ...Storage.java => MixinChunkDataSender.java} | 17 ++++--- .../mixins.cardinal_components_block.json | 2 +- .../cca/test/block/CcaBlockTestSuite.java | 2 +- ...Storage.java => MixinChunkDataSender.java} | 25 ++++------ .../mixin/chunk/common/MixinWorldChunk.java | 5 +- .../mixins.cardinal_components_chunk.json | 2 +- .../cca/test/chunk/CcaChunkTestSuite.java | 2 +- .../entity/CardinalComponentsEntity.java | 2 +- .../cca/mixin/entity/common/MixinEntity.java | 5 +- .../entity/common/MixinPlayerManager.java | 3 +- .../cca/test/entity/CcaEntityTestSuite.java | 2 +- .../level/CardinalComponentsLevel.java | 2 +- .../level/common/MixinLevelProperties.java | 5 +- .../cca/test/level/CcaLevelTestSuite.java | 2 +- .../CardinalComponentsScoreboard.java | 2 +- .../scoreboard/MixinServerScoreboard.java | 5 +- .../cca/mixin/scoreboard/MixinTeam.java | 5 +- .../scoreboard/CcaScoreboardTestSuite.java | 2 +- .../world/ComponentPersistentState.java | 11 +++++ .../mixin/world/common/DataFixTypesMixin.java | 46 +++++++++++++++++++ .../mixin/world/common/MixinServerWorld.java | 19 +++++--- .../mixins.cardinal_components_world.json | 31 +++++++------ .../cca/test/world/CcaWorldTestSuite.java | 2 +- changelog.md | 2 + gradle.properties | 16 +++---- .../componenttest/tests/CcaTestSuite.java | 2 +- 30 files changed, 149 insertions(+), 84 deletions(-) rename cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/{MixinThreadedAnvilChunkStorage.java => MixinChunkDataSender.java} (75%) rename cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/{MixinThreadedAnvilChunkStorage.java => MixinChunkDataSender.java} (62%) create mode 100644 cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/DataFixTypesMixin.java diff --git a/build.gradle.kts b/build.gradle.kts index 966aa84f..d55e5c7b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,6 +35,7 @@ allprojects { url = URI("https://maven.ladysnake.org/releases") content { includeGroup("io.github.ladysnake") + includeGroup("org.ladysnake") includeGroupByRegex("dev\\.emi.*") includeGroupByRegex("dev\\.onyxstudios.*") } @@ -55,7 +56,7 @@ allprojects { modImplementation(fabricApi.module("fabric-lifecycle-events-v1", fabricApiVersion)) modCompileOnly(fabricApi.module("fabric-gametest-api-v1", fabricApiVersion)) - modLocalImplementation("io.github.ladysnake:elmendorf:${props["elmendorf_version"]}") + modLocalImplementation("org.ladysnake:elmendorf:${props["elmendorf_version"]}") compileOnly("com.google.code.findbugs:jsr305:3.0.2") compileOnly("com.demonwav.mcdev:annotations:1.0") diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java index 553190cd..4425a045 100644 --- a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/api/v3/component/ComponentProvider.java @@ -25,8 +25,9 @@ import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import dev.onyxstudios.cca.api.v3.component.sync.ComponentPacketWriter; import dev.onyxstudios.cca.api.v3.component.sync.PlayerSyncPredicate; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; +import org.jetbrains.annotations.ApiStatus; import javax.annotation.Nullable; import java.util.List; @@ -67,6 +68,7 @@ default Iterable getRecipientsForComponentSync() { * @since 3.0.0 */ @Nullable + @ApiStatus.Experimental // TODO change the return value to Packet default CustomPayloadS2CPacket toComponentPacket(ComponentKey key, ComponentPacketWriter writer, ServerPlayerEntity recipient) { return null; } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java index 74843334..d7e7644f 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/internal/CardinalComponentsBlock.java @@ -31,7 +31,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.entity.BlockEntity; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java index bea8574c..4e19fce2 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinBlockEntity.java @@ -31,12 +31,13 @@ import dev.onyxstudios.cca.internal.block.CardinalBlockInternals; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -125,7 +126,7 @@ public CustomPayloadS2CPacket toComponentPacket( buf.writeBlockPos(this.getPos()); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsBlock.PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsBlock.PACKET_ID, buf); } } diff --git a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinThreadedAnvilChunkStorage.java b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinChunkDataSender.java similarity index 75% rename from cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinThreadedAnvilChunkStorage.java rename to cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinChunkDataSender.java index 4698c407..7252a6e7 100644 --- a/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinThreadedAnvilChunkStorage.java +++ b/cardinal-components-block/src/main/java/dev/onyxstudios/cca/mixin/block/common/MixinChunkDataSender.java @@ -24,22 +24,21 @@ import dev.onyxstudios.cca.api.v3.block.BlockEntitySyncCallback; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.network.ChunkDataSender; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.world.ServerWorld; import net.minecraft.world.chunk.WorldChunk; -import org.apache.commons.lang3.mutable.MutableObject; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ThreadedAnvilChunkStorage.class) -public abstract class MixinThreadedAnvilChunkStorage { - @Inject(method = "sendChunkDataPackets", at = @At("RETURN")) - private void sendChunkDataPackets(ServerPlayerEntity player, MutableObject mutableObject, WorldChunk chunk, CallbackInfo ci) { +@Mixin(ChunkDataSender.class) +public abstract class MixinChunkDataSender { + @Inject(method = "sendChunkData", at = @At("RETURN")) + private static void sendChunkDataPackets(ServerPlayNetworkHandler handler, ServerWorld world, WorldChunk chunk, CallbackInfo ci) { for (BlockEntity be : chunk.getBlockEntities().values()) { - BlockEntitySyncCallback.EVENT.invoker().onBlockEntitySync(player, be); + BlockEntitySyncCallback.EVENT.invoker().onBlockEntitySync(handler.player, be); } } } diff --git a/cardinal-components-block/src/main/resources/mixins.cardinal_components_block.json b/cardinal-components-block/src/main/resources/mixins.cardinal_components_block.json index 94985f38..788f0676 100644 --- a/cardinal-components-block/src/main/resources/mixins.cardinal_components_block.json +++ b/cardinal-components-block/src/main/resources/mixins.cardinal_components_block.json @@ -7,10 +7,10 @@ "common.MixinBlockDataObject", "common.MixinBlockEntity", "common.MixinBlockStateArgument", + "common.MixinChunkDataSender", "common.MixinChunkHolder", "common.MixinFallingBlockEntity", "common.MixinServerPlayerEntity", - "common.MixinThreadedAnvilChunkStorage", "common.MixinWorldChunk" ], "client": [ diff --git a/cardinal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/CcaBlockTestSuite.java b/cardinal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/CcaBlockTestSuite.java index 458efafd..40209ca0 100644 --- a/cardinal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/CcaBlockTestSuite.java +++ b/cardinal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/CcaBlockTestSuite.java @@ -25,7 +25,6 @@ import dev.onyxstudios.cca.test.base.LoadAwareTestComponent; import dev.onyxstudios.cca.test.base.TickingTestComponent; import dev.onyxstudios.cca.test.base.Vita; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntity; @@ -37,6 +36,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import org.jetbrains.annotations.NotNull; +import org.ladysnake.elmendorf.GameTestUtil; import java.util.Objects; diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkDataSender.java similarity index 62% rename from cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java rename to cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkDataSender.java index 1cd29d5f..95cff74e 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunkDataSender.java @@ -22,29 +22,20 @@ */ package dev.onyxstudios.cca.mixin.chunk.common; -import com.mojang.datafixers.DataFixer; import dev.onyxstudios.cca.api.v3.chunk.ChunkSyncCallback; -import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.network.ChunkDataSender; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.world.ServerWorld; import net.minecraft.world.chunk.WorldChunk; -import net.minecraft.world.storage.VersionedChunkStorage; -import org.apache.commons.lang3.mutable.MutableObject; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.nio.file.Path; - -@Mixin(ThreadedAnvilChunkStorage.class) -public abstract class MixinThreadedAnvilChunkStorage extends VersionedChunkStorage { - public MixinThreadedAnvilChunkStorage(Path file, DataFixer dataFixer, boolean bl) { - super(file, dataFixer, bl); - } - - @Inject(method = "sendChunkDataPackets", at = @At("RETURN")) - private void sendChunkComponentsPackets(ServerPlayerEntity player, MutableObject mutableObject, WorldChunk chunk, CallbackInfo ci) { - ChunkSyncCallback.EVENT.invoker().onChunkSync(player, chunk); +@Mixin(ChunkDataSender.class) +public abstract class MixinChunkDataSender { + @Inject(method = "sendChunkData", at = @At("RETURN")) + private static void sendChunkComponentsPackets(ServerPlayNetworkHandler handler, ServerWorld world, WorldChunk chunk, CallbackInfo ci) { + ChunkSyncCallback.EVENT.invoker().onChunkSync(handler.player, chunk); } } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java index 31dc0fa5..1988f885 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java @@ -29,8 +29,9 @@ import dev.onyxstudios.cca.internal.chunk.CardinalComponentsChunk; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.registry.Registry; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -78,7 +79,7 @@ public CustomPayloadS2CPacket toComponentPacket( buf.writeInt(pos.z); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsChunk.PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsChunk.PACKET_ID, buf); } @Inject(method = "(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/ProtoChunk;Lnet/minecraft/world/chunk/WorldChunk$EntityLoader;)V", at = @At("RETURN")) 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 6f1151d1..e75cd86d 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 @@ -5,11 +5,11 @@ "package": "dev.onyxstudios.cca.mixin.chunk", "mixins": [ "common.MixinChunk", + "common.MixinChunkDataSender", "common.MixinChunkHolder", "common.MixinChunkSerializer", "common.MixinEmptyChunk", "common.MixinServerWorld", - "common.MixinThreadedAnvilChunkStorage", "common.MixinWorldChunk", "common.MixinWrapperProtoChunk" ], diff --git a/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/CcaChunkTestSuite.java b/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/CcaChunkTestSuite.java index eec8a6c3..db917d59 100644 --- a/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/CcaChunkTestSuite.java +++ b/cardinal-components-chunk/src/testmod/java/dev/onyxstudios/cca/test/chunk/CcaChunkTestSuite.java @@ -25,7 +25,6 @@ import dev.onyxstudios.cca.test.base.LoadAwareTestComponent; import dev.onyxstudios.cca.test.base.TickingTestComponent; import dev.onyxstudios.cca.test.base.Vita; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.nbt.NbtCompound; import net.minecraft.test.GameTest; @@ -35,6 +34,7 @@ import net.minecraft.world.ChunkSerializer; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.WorldChunk; +import org.ladysnake.elmendorf.GameTestUtil; public class CcaChunkTestSuite implements FabricGameTest { @GameTest(templateName = EMPTY_STRUCTURE) diff --git a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/internal/entity/CardinalComponentsEntity.java b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/internal/entity/CardinalComponentsEntity.java index f5c221e4..136e979d 100644 --- a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/internal/entity/CardinalComponentsEntity.java +++ b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/internal/entity/CardinalComponentsEntity.java @@ -34,7 +34,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.entity.Entity; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; import net.minecraft.world.GameRules; diff --git a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java index 06eb2bbd..7997ccb2 100644 --- a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java +++ b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinEntity.java @@ -31,10 +31,11 @@ import dev.onyxstudios.cca.internal.entity.CardinalEntityInternals; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.entity.Entity; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -102,7 +103,7 @@ public CustomPayloadS2CPacket toComponentPacket( buf.writeInt(this.getId()); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsEntity.PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsEntity.PACKET_ID, buf); } } diff --git a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinPlayerManager.java b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinPlayerManager.java index 58a42eaa..7aece666 100644 --- a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinPlayerManager.java +++ b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/MixinPlayerManager.java @@ -25,6 +25,7 @@ import dev.onyxstudios.cca.api.v3.entity.PlayerSyncCallback; import net.minecraft.network.ClientConnection; import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ConnectedClientData; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -41,7 +42,7 @@ public abstract class MixinPlayerManager { target = "Lnet/minecraft/server/network/ServerPlayerEntity;getStatusEffects()Ljava/util/Collection;" ) ) - private void onPlayerLogIn(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { + private void onPlayerLogIn(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) { PlayerSyncCallback.EVENT.invoker().onPlayerSync(player); } diff --git a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java index 536c18a1..553ddcdf 100644 --- a/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java +++ b/cardinal-components-entity/src/testmod/java/dev/onyxstudios/cca/test/entity/CcaEntityTestSuite.java @@ -24,7 +24,6 @@ import dev.onyxstudios.cca.test.base.LoadAwareTestComponent; import dev.onyxstudios.cca.test.base.Vita; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.entity.Bucketable; import net.minecraft.entity.Entity; @@ -39,6 +38,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import org.ladysnake.elmendorf.GameTestUtil; public class CcaEntityTestSuite implements FabricGameTest { @GameTest(templateName = EMPTY_STRUCTURE) diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/CardinalComponentsLevel.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/CardinalComponentsLevel.java index 4790e99d..8fddbd92 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/CardinalComponentsLevel.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/internal/level/CardinalComponentsLevel.java @@ -27,7 +27,7 @@ import dev.onyxstudios.cca.api.v3.world.WorldSyncCallback; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.util.Identifier; import net.minecraft.world.WorldProperties; diff --git a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java index 9dd390f2..679401a9 100644 --- a/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java +++ b/cardinal-components-level/src/main/java/dev/onyxstudios/cca/mixin/level/common/MixinLevelProperties.java @@ -33,11 +33,12 @@ import dev.onyxstudios.cca.internal.level.CardinalComponentsLevel; import dev.onyxstudios.cca.internal.level.StaticLevelComponentPlugin; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.entity.boss.dragon.EnderDragonFight; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; @@ -97,7 +98,7 @@ public CustomPayloadS2CPacket toComponentPacket( PacketByteBuf buf = PacketByteBufs.create(); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsLevel.PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsLevel.PACKET_ID, buf); } } diff --git a/cardinal-components-level/src/testmod/java/dev/onyxstudios/cca/test/level/CcaLevelTestSuite.java b/cardinal-components-level/src/testmod/java/dev/onyxstudios/cca/test/level/CcaLevelTestSuite.java index e8730b34..0691b99f 100644 --- a/cardinal-components-level/src/testmod/java/dev/onyxstudios/cca/test/level/CcaLevelTestSuite.java +++ b/cardinal-components-level/src/testmod/java/dev/onyxstudios/cca/test/level/CcaLevelTestSuite.java @@ -23,10 +23,10 @@ package dev.onyxstudios.cca.test.level; import dev.onyxstudios.cca.test.base.TickingTestComponent; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.test.GameTest; import net.minecraft.test.TestContext; +import org.ladysnake.elmendorf.GameTestUtil; public class CcaLevelTestSuite implements FabricGameTest { @GameTest(templateName = EMPTY_STRUCTURE) diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/CardinalComponentsScoreboard.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/CardinalComponentsScoreboard.java index b6bf5156..5785d883 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/CardinalComponentsScoreboard.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/internal/scoreboard/CardinalComponentsScoreboard.java @@ -30,7 +30,7 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.scoreboard.Team; import net.minecraft.util.Identifier; diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java index 526d835f..59bb0aa1 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinServerScoreboard.java @@ -30,8 +30,9 @@ import dev.onyxstudios.cca.internal.scoreboard.ScoreboardComponentContainerFactory; import dev.onyxstudios.cca.internal.scoreboard.StaticScoreboardComponentPlugin; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.scoreboard.ServerScoreboard; import net.minecraft.scoreboard.Team; @@ -74,7 +75,7 @@ public CustomPayloadS2CPacket toComponentPacket( PacketByteBuf buf = PacketByteBufs.create(); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsScoreboard.SCOREBOARD_PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsScoreboard.SCOREBOARD_PACKET_ID, buf); } @Inject(method = "", at = @At("RETURN")) diff --git a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java index 6cec9bed..36fb876a 100644 --- a/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java +++ b/cardinal-components-scoreboard/src/main/java/dev/onyxstudios/cca/mixin/scoreboard/MixinTeam.java @@ -30,8 +30,9 @@ import dev.onyxstudios.cca.internal.scoreboard.CardinalComponentsScoreboard; import dev.onyxstudios.cca.internal.scoreboard.StaticScoreboardComponentPlugin; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.scoreboard.Team; import net.minecraft.server.network.ServerPlayerEntity; @@ -84,7 +85,7 @@ public CustomPayloadS2CPacket toComponentPacket( buf.writeString(this.getName()); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsScoreboard.TEAM_PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsScoreboard.TEAM_PACKET_ID, buf); } } diff --git a/cardinal-components-scoreboard/src/testmod/java/dev/onyxstudios/cca/test/scoreboard/CcaScoreboardTestSuite.java b/cardinal-components-scoreboard/src/testmod/java/dev/onyxstudios/cca/test/scoreboard/CcaScoreboardTestSuite.java index 986c139e..7ca9993b 100644 --- a/cardinal-components-scoreboard/src/testmod/java/dev/onyxstudios/cca/test/scoreboard/CcaScoreboardTestSuite.java +++ b/cardinal-components-scoreboard/src/testmod/java/dev/onyxstudios/cca/test/scoreboard/CcaScoreboardTestSuite.java @@ -23,10 +23,10 @@ package dev.onyxstudios.cca.test.scoreboard; import dev.onyxstudios.cca.test.base.LoadAwareTestComponent; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.test.GameTest; import net.minecraft.test.TestContext; +import org.ladysnake.elmendorf.GameTestUtil; public class CcaScoreboardTestSuite implements FabricGameTest { @GameTest(templateName = EMPTY_STRUCTURE) diff --git a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/internal/world/ComponentPersistentState.java b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/internal/world/ComponentPersistentState.java index 324a651d..f05128fa 100644 --- a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/internal/world/ComponentPersistentState.java +++ b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/internal/world/ComponentPersistentState.java @@ -23,10 +23,21 @@ package dev.onyxstudios.cca.internal.world; import dev.onyxstudios.cca.api.v3.component.ComponentContainer; +import net.minecraft.datafixer.DataFixTypes; import net.minecraft.nbt.NbtCompound; import net.minecraft.world.PersistentState; public class ComponentPersistentState extends PersistentState { + public static final ThreadLocal LOADING = ThreadLocal.withInitial(() -> false); + + public static Type getType(ComponentContainer components) { + return new Type<>( + () -> new ComponentPersistentState(components), + tag -> ComponentPersistentState.fromNbt(components, tag), + DataFixTypes.LEVEL + ); + } + private final ComponentContainer components; public ComponentPersistentState(ComponentContainer components) { diff --git a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/DataFixTypesMixin.java b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/DataFixTypesMixin.java new file mode 100644 index 00000000..62e47098 --- /dev/null +++ b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/DataFixTypesMixin.java @@ -0,0 +1,46 @@ +/* + * Cardinal-Components-API + * Copyright (C) 2019-2023 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.mixin.world.common; + +import com.mojang.datafixers.DataFixer; +import com.mojang.serialization.Dynamic; +import dev.onyxstudios.cca.internal.world.ComponentPersistentState; +import net.minecraft.datafixer.DataFixTypes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(DataFixTypes.class) +public class DataFixTypesMixin { + @Inject( + method = "update(Lcom/mojang/datafixers/DataFixer;Lcom/mojang/serialization/Dynamic;II)Lcom/mojang/serialization/Dynamic;", + at = @At("HEAD"), + cancellable = true + ) + private void cancelIfCca(DataFixer dataFixer, Dynamic dynamic, int oldVersion, int newVersion, CallbackInfoReturnable> cir) { + if (ComponentPersistentState.LOADING.get()) { + cir.setReturnValue(dynamic); + } + } +} diff --git a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java index 4bf82930..c69bf674 100644 --- a/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java +++ b/cardinal-components-world/src/main/java/dev/onyxstudios/cca/mixin/world/common/MixinServerWorld.java @@ -28,8 +28,9 @@ import dev.onyxstudios.cca.internal.world.CardinalComponentsWorld; import dev.onyxstudios.cca.internal.world.ComponentPersistentState; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.world.PersistentStateManager; @@ -56,11 +57,15 @@ public abstract class MixinServerWorld extends MixinWorld { @Inject(at = @At("RETURN"), method = "*") private void constructor(CallbackInfo ci) { - this.getPersistentStateManager().getOrCreate( - tag -> ComponentPersistentState.fromNbt(this.components, tag), - () -> new ComponentPersistentState(this.components), - PERSISTENT_STATE_KEY - ); + try { + ComponentPersistentState.LOADING.set(true); + this.getPersistentStateManager().getOrCreate( + ComponentPersistentState.getType(this.components), + PERSISTENT_STATE_KEY + ); + } finally { + ComponentPersistentState.LOADING.set(false); + } } @Inject(method = "tick", at = @At("RETURN")) @@ -79,6 +84,6 @@ public CustomPayloadS2CPacket toComponentPacket( PacketByteBuf buf = PacketByteBufs.create(); buf.writeIdentifier(key.getId()); writer.writeSyncPacket(buf, recipient); - return new CustomPayloadS2CPacket(CardinalComponentsWorld.PACKET_ID, buf); + return (CustomPayloadS2CPacket) ServerPlayNetworking.createS2CPacket(CardinalComponentsWorld.PACKET_ID, buf); } } diff --git a/cardinal-components-world/src/main/resources/mixins.cardinal_components_world.json b/cardinal-components-world/src/main/resources/mixins.cardinal_components_world.json index eab4c73a..265f6d10 100644 --- a/cardinal-components-world/src/main/resources/mixins.cardinal_components_world.json +++ b/cardinal-components-world/src/main/resources/mixins.cardinal_components_world.json @@ -1,17 +1,18 @@ { - "required": true, - "minVersion": "0.8", - "compatibilityLevel": "JAVA_8", - "package": "dev.onyxstudios.cca.mixin.world", - "mixins": [ - "common.MixinPlayerManager", - "common.MixinServerWorld", - "common.MixinWorld" - ], - "client": [ - "client.MixinClientWorld" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "package": "dev.onyxstudios.cca.mixin.world", + "mixins": [ + "common.DataFixTypesMixin", + "common.MixinPlayerManager", + "common.MixinServerWorld", + "common.MixinWorld" + ], + "client": [ + "client.MixinClientWorld" + ], + "injectors": { + "defaultRequire": 1 + } } diff --git a/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/CcaWorldTestSuite.java b/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/CcaWorldTestSuite.java index 5f9bdb65..3c610f77 100644 --- a/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/CcaWorldTestSuite.java +++ b/cardinal-components-world/src/testmod/java/dev/onyxstudios/cca/test/world/CcaWorldTestSuite.java @@ -23,10 +23,10 @@ package dev.onyxstudios.cca.test.world; import dev.onyxstudios.cca.test.base.LoadAwareTestComponent; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.test.GameTest; import net.minecraft.test.TestContext; +import org.ladysnake.elmendorf.GameTestUtil; public class CcaWorldTestSuite implements FabricGameTest { @GameTest(templateName = EMPTY_STRUCTURE) diff --git a/changelog.md b/changelog.md index da41b572..b9982e31 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,8 @@ ------------------------------------------------------ Version 5.3.0 ------------------------------------------------------ +Updated to 1.20.2 + **Additions** - Added load- and unload-aware components as an experimental feature - This can be used to implement advanced initialization and cleanup 🧽 diff --git a/gradle.properties b/gradle.properties index aeb19029..e1a3ac6d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,23 +4,23 @@ org.gradle.parallel=true fabric.loom.multiProjectOptimisation=true #see https://fabricmc.net/develop/ -minecraft_version=1.20 -yarn_mappings=1 -loader_version=0.14.19 +minecraft_version=1.20.2-pre2 +yarn_mappings=5 +loader_version=0.14.22 #Fabric api -fabric_api_version=0.81.2+1.20 +fabric_api_version=0.88.3+1.20.2 -elmendorf_version=0.11.0 +elmendorf_version=0.12.0 #Publishing mod_version = 5.3.0 curseforge_id = 318449 modrinth_id = K01OU20C -curseforge_versions = 1.20; 1.20.1 -modrinth_versions = 1.20; 1.20.1 +curseforge_versions = 1.20.2-Snapshot +modrinth_versions = 1.20.2-pre2 release_type = release display_name = Cardinal-Components-API -owners = OnyxStudios +owners = Ladysnake # Licensing license_header = MIT diff --git a/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java b/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java index 9a0d71f4..1597c4d1 100644 --- a/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java +++ b/src/testmod/java/dev/onyxstudios/componenttest/tests/CcaTestSuite.java @@ -23,13 +23,13 @@ package dev.onyxstudios.componenttest.tests; import dev.onyxstudios.cca.api.v3.component.ComponentAccess; -import io.github.ladysnake.elmendorf.GameTestUtil; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.block.Blocks; import net.minecraft.entity.EntityType; import net.minecraft.test.GameTest; import net.minecraft.test.TestContext; import net.minecraft.util.math.BlockPos; +import org.ladysnake.elmendorf.GameTestUtil; import java.util.Objects;