Skip to content

Commit

Permalink
Update CCA compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Feb 4, 2024
1 parent ee2bf5b commit 25ede9f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ chenille {
val dummy: SourceSet by sourceSets.creating {}

repositories {
mavenLocal()
mavenCentral()
chenille.repositories {
ladysnake()
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -98,7 +99,7 @@ public <P extends Packet<?>> PacketSequenceChecker sent(Class<P> 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
Expand Down Expand Up @@ -137,18 +138,20 @@ public PacketSequenceChecker sent(Predicate<Packet<?>> 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<ByteBufChecker> expect) {
if (synced != null) GameTestUtil.assertTrue("Expected " + synced + " to provide component " + key.getId(), key.isProvidedBy(synced));
List<GameTestException> suppressed = new ArrayList<>();
try {
throw new UnsupportedOperationException();
// Don't access internal API at home kids
//noinspection UnstableApiUsage
// return sent(
// createCheckerTest(CardinalComponentsEntity.PACKET_ID, ((Consumer<ByteBufChecker>) 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;
Expand Down Expand Up @@ -234,18 +237,21 @@ public <T extends CustomPayload> 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<ByteBufChecker> expect) {
if (synced != null) GameTestUtil.assertTrue("Expected " + synced + " to provide component " + key.getId(), key.isProvidedBy(synced));
List<GameTestException> 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<ByteBufChecker>) 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;
Expand Down
14 changes: 7 additions & 7 deletions src/testmod/java/org/ladysnake/ripstop/RipstopComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component> TEST = ComponentRegistry.getOrCreate(new Identifier("ripstop", "test-component"), Component.class);
Expand Down

0 comments on commit 25ede9f

Please sign in to comment.