From 25ede9f5bd9e1c47a7fd0f1211d5f756c7bd50b6 Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sun, 4 Feb 2024 20:08:33 +0100 Subject: [PATCH] Update CCA compatibility --- build.gradle.kts | 5 ++- gradle.properties | 4 +- .../elmendorf/CheckedConnection.java | 2 +- .../elmendorf/PacketSequenceChecker.java | 2 +- .../elmendorf/impl/MockClientConnection.java | 38 +++++++++++-------- .../ladysnake/ripstop/RipstopComponents.java | 14 +++---- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b637011..ec3b779 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,6 +23,7 @@ chenille { val dummy: SourceSet by sourceSets.creating {} repositories { + mavenLocal() mavenCentral() chenille.repositories { ladysnake() @@ -43,8 +44,8 @@ dependencies { modApi(fabricApi.module("fabric-gametest-api-v1", fabricApiVersion)) modLocalImplementation(fabricApi.module("fabric-networking-api-v1", fabricApiVersion)) - modCompileOnly("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${ccaVersion}") - modCompileOnly("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${ccaVersion}") + modCompileOnly("org.ladysnake.cardinal-components-api:cardinal-components-base:${ccaVersion}") + modCompileOnly("org.ladysnake.cardinal-components-api:cardinal-components-entity:${ccaVersion}") api("junit:junit:4.13.2") "testmodImplementation"(sourceSets.main.get().output) annotationProcessor(dummy.output) diff --git a/gradle.properties b/gradle.properties index 6f597e4..dba2a4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G java_version=17 # Mod Properties - mod_version = 0.12.0-SNAPSHOT + mod_version = 0.12.0-beta.1 maven_group = org.ladysnake archives_base_name = elmendorf @@ -19,4 +19,4 @@ org.gradle.jvmargs=-Xmx1G # Dependencies fabric_version=0.95.4+1.20.5 - cca_version=5.1.0 + cca_version=6.0.0-SNAPSHOT diff --git a/src/main/java/org/ladysnake/elmendorf/CheckedConnection.java b/src/main/java/org/ladysnake/elmendorf/CheckedConnection.java index 7f831d8..3293636 100644 --- a/src/main/java/org/ladysnake/elmendorf/CheckedConnection.java +++ b/src/main/java/org/ladysnake/elmendorf/CheckedConnection.java @@ -22,12 +22,12 @@ */ package org.ladysnake.elmendorf; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; import net.minecraft.entity.Entity; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.Packet; import org.jetbrains.annotations.Nullable; +import org.ladysnake.cca.api.v3.component.ComponentKey; import java.util.Queue; import java.util.function.Consumer; diff --git a/src/main/java/org/ladysnake/elmendorf/PacketSequenceChecker.java b/src/main/java/org/ladysnake/elmendorf/PacketSequenceChecker.java index a4ae3c2..aec5ae7 100644 --- a/src/main/java/org/ladysnake/elmendorf/PacketSequenceChecker.java +++ b/src/main/java/org/ladysnake/elmendorf/PacketSequenceChecker.java @@ -22,11 +22,11 @@ */ package org.ladysnake.elmendorf; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; import net.minecraft.entity.Entity; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.Packet; import org.jetbrains.annotations.Nullable; +import org.ladysnake.cca.api.v3.component.ComponentKey; import java.util.function.Consumer; import java.util.function.Predicate; diff --git a/src/main/java/org/ladysnake/elmendorf/impl/MockClientConnection.java b/src/main/java/org/ladysnake/elmendorf/impl/MockClientConnection.java index 1b28965..6563730 100644 --- a/src/main/java/org/ladysnake/elmendorf/impl/MockClientConnection.java +++ b/src/main/java/org/ladysnake/elmendorf/impl/MockClientConnection.java @@ -22,7 +22,6 @@ */ package org.ladysnake.elmendorf.impl; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; import net.minecraft.entity.Entity; import net.minecraft.network.ClientConnection; import net.minecraft.network.NetworkSide; @@ -35,6 +34,8 @@ import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.ladysnake.cca.api.v3.component.ComponentKey; +import org.ladysnake.cca.internal.entity.CardinalComponentsEntity; import org.ladysnake.elmendorf.ByteBufChecker; import org.ladysnake.elmendorf.CheckedConnection; import org.ladysnake.elmendorf.ConnectionTestConfiguration; @@ -98,7 +99,7 @@ public

> PacketSequenceChecker sent(Class

packetType, Pre @Override public PacketSequenceChecker sent(CustomPayload.Id channelId) { - return sent(packet -> packet instanceof CustomPayloadS2CPacket p && Objects.equals(p.payload().getId().id(), channelId), "Expected packet for channel " + channelId); + return sent(packet -> packet instanceof CustomPayloadS2CPacket p && Objects.equals(p.payload().getId(), channelId), "Expected packet for channel " + channelId); } @Override @@ -137,18 +138,20 @@ public PacketSequenceChecker sent(Predicate> test, String errorMessage return new PacketSequenceCheckerImpl(errorMessage, packets); } + // Don't access internal API at home kids + @SuppressWarnings("UnstableApiUsage") @Override public PacketSequenceChecker sentEntityComponentUpdate(@Nullable Entity synced, ComponentKey key, Consumer expect) { if (synced != null) GameTestUtil.assertTrue("Expected " + synced + " to provide component " + key.getId(), key.isProvidedBy(synced)); List suppressed = new ArrayList<>(); try { - throw new UnsupportedOperationException(); - // Don't access internal API at home kids - //noinspection UnstableApiUsage -// return sent( -// createCheckerTest(CardinalComponentsEntity.PACKET_ID, ((Consumer) c -> c.checkInt(synced == null ? ByteBufChecker.any() : synced.getId()).checkIdentifier(key.getId())).andThen(expect), suppressed), -// "Expected sync packet for component " + key.getId() -// ); + return sent( + createCheckerTest(CardinalComponentsEntity.PACKET_ID, payload -> { + GameTestUtil.assertTrue("Expected component update to target entity " + synced, synced == null || payload.targetData() == synced.getId()); + expect.accept(new ByteBufChecker(payload.buf())); + }, suppressed), + "Expected sync packet for component " + key.getId() + ); } catch (GameTestException e) { suppressed.forEach(e::addSuppressed); throw e; @@ -234,18 +237,21 @@ public PacketSequenceChecker thenSent(Delay delay, Cus } } + // Don't access internal API at home kids + @SuppressWarnings("UnstableApiUsage") @Override public PacketSequenceChecker thenSentComponentUpdate(Delay delay, @Nullable Entity synced, ComponentKey key, Consumer expect) { if (synced != null) GameTestUtil.assertTrue("Expected " + synced + " to provide component " + key.getId(), key.isProvidedBy(synced)); List suppressed = new ArrayList<>(); try { - throw new UnsupportedOperationException(); - // Don't access internal API at home kids - //noinspection UnstableApiUsage -// return thenSent(delay, -// createCheckerTest(CardinalComponentsEntity.PACKET_ID, ((Consumer) c -> c.checkInt(synced == null ? ByteBufChecker.any() : synced.getId()).checkIdentifier(key.getId())).andThen(expect), suppressed), -// "Expected sync packet for component " + key.getId() -// ); + return thenSent( + delay, + createCheckerTest(CardinalComponentsEntity.PACKET_ID, payload -> { + GameTestUtil.assertTrue("Expected component update to target entity " + synced, synced == null || payload.targetData() == synced.getId()); + expect.accept(new ByteBufChecker(payload.buf())); + }, suppressed), + "Expected sync packet for component " + key.getId() + ); } catch (GameTestException e) { suppressed.forEach(e::addSuppressed); throw e; diff --git a/src/testmod/java/org/ladysnake/ripstop/RipstopComponents.java b/src/testmod/java/org/ladysnake/ripstop/RipstopComponents.java index dbfb479..3818557 100644 --- a/src/testmod/java/org/ladysnake/ripstop/RipstopComponents.java +++ b/src/testmod/java/org/ladysnake/ripstop/RipstopComponents.java @@ -22,17 +22,17 @@ */ package org.ladysnake.ripstop; -import dev.onyxstudios.cca.api.v3.component.Component; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; -import dev.onyxstudios.cca.api.v3.component.ComponentRegistry; -import dev.onyxstudios.cca.api.v3.component.TransientComponent; -import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; -import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry; -import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer; import net.minecraft.entity.passive.AxolotlEntity; import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; +import org.ladysnake.cca.api.v3.component.Component; +import org.ladysnake.cca.api.v3.component.ComponentKey; +import org.ladysnake.cca.api.v3.component.ComponentRegistry; +import org.ladysnake.cca.api.v3.component.TransientComponent; +import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent; +import org.ladysnake.cca.api.v3.entity.EntityComponentFactoryRegistry; +import org.ladysnake.cca.api.v3.entity.EntityComponentInitializer; public class RipstopComponents implements EntityComponentInitializer { public static final ComponentKey TEST = ComponentRegistry.getOrCreate(new Identifier("ripstop", "test-component"), Component.class);