diff --git a/implementations/1_21_1/build.gradle.kts b/implementations/1_21_1/build.gradle.kts new file mode 100644 index 0000000..8dc0423 --- /dev/null +++ b/implementations/1_21_1/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("java-library") + id("io.papermc.paperweight.userdev") version "1.7.1" +} + +val minecraftVersion = "1.21.1" + +paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION + +dependencies { + paperweight.paperDevBundle("$minecraftVersion-R0.1-SNAPSHOT") + compileOnly(project(":api")) + + testImplementation(project(":api")) + testImplementation(project(":implementations:1_20_6")) + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2") +} + +tasks { + test { + useJUnitPlatform() + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundAddEntityPacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundAddEntityPacketImplTest.java new file mode 100644 index 0000000..49b7449 --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundAddEntityPacketImplTest.java @@ -0,0 +1,65 @@ +package packets; + +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundAddEntityPacketImpl; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import org.bukkit.entity.EntityType; + +import java.util.UUID; + +class ClientboundAddEntityPacketImplTest { + + //TODO: Fix this test (registry problems) + // @Test + void createPacket() { + int entityId = 10000; + UUID entityUUID = UUID.randomUUID(); + EntityType entityType = EntityType.PIG; + + double x = 5; + double y = 57; + double z = 203; + + float yaw = 142; + float pitch = 247; + float headYaw = 90; + + int velocityX = 0; + int velocityY = 0; + int velocityZ = 0; + + int data = 0; + + ClientboundAddEntityPacketImpl packet = new ClientboundAddEntityPacketImpl( + entityId, + entityUUID, + entityType, + x, + y, + z, + yaw, + pitch, + headYaw, + velocityX, + velocityY, + velocityZ, + data + ); + + ClientboundAddEntityPacket createdPacket = (ClientboundAddEntityPacket) packet.createPacket(); + + assert createdPacket.getId() == entityId; + assert createdPacket.getUUID().equals(entityUUID); + assert createdPacket.getType().getDescriptionId().equals(entityType.getKey().getKey()); + assert createdPacket.getX() == x; + assert createdPacket.getY() == y; + assert createdPacket.getZ() == z; + assert createdPacket.getYRot() == AngelConverter.degreesToVanillaByte(yaw); + assert createdPacket.getXRot() == AngelConverter.degreesToVanillaByte(pitch); + assert createdPacket.getYHeadRot() == AngelConverter.degreesToVanillaByte(headYaw); + assert createdPacket.getXa() == velocityX; + assert createdPacket.getYa() == velocityY; + assert createdPacket.getZa() == velocityZ; + assert createdPacket.getData() == data; + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundPlayerInfoRemovePacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundPlayerInfoRemovePacketImplTest.java new file mode 100644 index 0000000..e938af2 --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundPlayerInfoRemovePacketImplTest.java @@ -0,0 +1,23 @@ +package packets; + +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundPlayerInfoRemovePacketImpl; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.UUID; + +class ClientboundPlayerInfoRemovePacketImplTest { + + @Test + void createPacket() { + List uuids = List.of(UUID.randomUUID(), UUID.randomUUID()); + + ClientboundPlayerInfoRemovePacketImpl packet = new ClientboundPlayerInfoRemovePacketImpl(uuids); + ClientboundPlayerInfoRemovePacket vanillaPacket = (ClientboundPlayerInfoRemovePacket) packet.createPacket(); + + for (UUID uuid : uuids) { + assert vanillaPacket.profileIds().contains(uuid); + } + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundPlayerInfoUpdatePacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundPlayerInfoUpdatePacketImplTest.java new file mode 100644 index 0000000..440e284 --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundPlayerInfoUpdatePacketImplTest.java @@ -0,0 +1,62 @@ +package packets; + +import de.oliver.fancysitula.api.packets.FS_ClientboundPlayerInfoUpdatePacket; +import de.oliver.fancysitula.api.utils.FS_GameProfile; +import de.oliver.fancysitula.api.utils.FS_GameType; +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundPlayerInfoUpdatePacketImpl; +import net.kyori.adventure.text.Component; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.UUID; + +class ClientboundPlayerInfoUpdatePacketImplTest { + + @Test + void createPacket() { + // Setup packet + EnumSet actions = EnumSet.noneOf(FS_ClientboundPlayerInfoUpdatePacket.Action.class); + actions.add(FS_ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER); + actions.add(FS_ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME); + actions.add(FS_ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED); + + FS_GameProfile gameProfile = new FS_GameProfile(UUID.randomUUID(), "Test name"); + boolean listed = true; + int latency = 42; + FS_GameType gameMode = FS_GameType.SURVIVAL; + Component displayName = Component.text("Test displayname"); + + List entries = new ArrayList<>(); + entries.add(new FS_ClientboundPlayerInfoUpdatePacket.Entry( + gameProfile.getUUID(), + gameProfile, + listed, + latency, + gameMode, + displayName + )); + + ClientboundPlayerInfoUpdatePacketImpl packet = new ClientboundPlayerInfoUpdatePacketImpl(actions, entries); + + ClientboundPlayerInfoUpdatePacket createdPacket = (ClientboundPlayerInfoUpdatePacket) packet.createPacket(); + + assert createdPacket.entries().size() == 1; + assert createdPacket.actions().size() == 3; + + // check entry + ClientboundPlayerInfoUpdatePacket.Entry entry = createdPacket.entries().getFirst(); + assert entry.profile().getId().equals(gameProfile.getUUID()); + assert entry.profile().getName().equals(gameProfile.getName()); + assert entry.listed() == listed; + assert entry.latency() == latency; + assert entry.gameMode().getId() == gameMode.getId(); + + // check actions + assert createdPacket.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER); + assert createdPacket.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME); + assert createdPacket.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED); + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundRemoveEntitiesPacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundRemoveEntitiesPacketImplTest.java new file mode 100644 index 0000000..3a8833d --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundRemoveEntitiesPacketImplTest.java @@ -0,0 +1,21 @@ +package packets; + +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundRemoveEntitiesPacketImpl; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class ClientboundRemoveEntitiesPacketImplTest { + + @Test + void createPacket() { + List entityIds = List.of(95, 120, 154, 187); + + ClientboundRemoveEntitiesPacketImpl packet = new ClientboundRemoveEntitiesPacketImpl(entityIds); + ClientboundRemoveEntitiesPacket createdPacket = (ClientboundRemoveEntitiesPacket) packet.createPacket(); + + assert createdPacket.getEntityIds().size() == entityIds.size(); + assert createdPacket.getEntityIds().containsAll(entityIds); + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundRotateHeadPacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundRotateHeadPacketImplTest.java new file mode 100644 index 0000000..630897c --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundRotateHeadPacketImplTest.java @@ -0,0 +1,22 @@ +package packets; + +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.api.utils.reflections.ReflectionUtils; +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundRotateHeadPacketImpl; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import org.junit.jupiter.api.Test; + +class ClientboundRotateHeadPacketImplTest { + + @Test + void createPacket() throws Exception { + int entityId = 184; + float headYaw = 45; + + ClientboundRotateHeadPacketImpl packet = new ClientboundRotateHeadPacketImpl(entityId, (byte) headYaw); + ClientboundRotateHeadPacket createdPacket = (ClientboundRotateHeadPacket) packet.createPacket(); + + assert ReflectionUtils.getField(createdPacket, "entityId").equals(entityId); + assert createdPacket.getYHeadRot() == AngelConverter.degreesToVanillaByte(headYaw); + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundSetEntityDataPacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundSetEntityDataPacketImplTest.java new file mode 100644 index 0000000..c92cf6f --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundSetEntityDataPacketImplTest.java @@ -0,0 +1,29 @@ +package packets; + +import de.oliver.fancysitula.api.packets.FS_ClientboundSetEntityDataPacket; +import de.oliver.fancysitula.api.utils.entityData.FS_TextDisplayData; +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEntityDataPacketImpl; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; + +import java.util.List; + +class ClientboundSetEntityDataPacketImplTest { + + //TODO: Fix this test (using registry) +// @Test + void createPacket() { + int entityId = 712; + List entityData = List.of( + new FS_ClientboundSetEntityDataPacket.EntityData( + FS_TextDisplayData.TEXT, + "Hello, World!" + ) + ); + + ClientboundSetEntityDataPacketImpl packet = new ClientboundSetEntityDataPacketImpl(entityId, entityData); + ClientboundSetEntityDataPacket createdPacket = (ClientboundSetEntityDataPacket) packet.createPacket(); + + assert createdPacket.id() == entityId; + assert createdPacket.packedItems().size() == 1; + } +} \ No newline at end of file diff --git a/implementations/1_21_1/src/test/java/packets/ClientboundTeleportEntityPacketImplTest.java b/implementations/1_21_1/src/test/java/packets/ClientboundTeleportEntityPacketImplTest.java new file mode 100644 index 0000000..e7ee990 --- /dev/null +++ b/implementations/1_21_1/src/test/java/packets/ClientboundTeleportEntityPacketImplTest.java @@ -0,0 +1,32 @@ +package packets; + +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundTeleportEntityPacketImpl; +import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import org.junit.jupiter.api.Test; + +class ClientboundTeleportEntityPacketImplTest { + + @Test + void createPacket() { + int entityId = 4313; + double x = 15.0; + double y = 57.0; + double z = -27.0; + float yaw = 90.0f; + float pitch = 45.0f; + boolean onGround = true; + + ClientboundTeleportEntityPacketImpl packet = new ClientboundTeleportEntityPacketImpl(entityId, x, y, z, yaw, pitch, onGround); + ClientboundTeleportEntityPacket createdPacket = (ClientboundTeleportEntityPacket) packet.createPacket(); + + assert createdPacket != null; + assert createdPacket.getId() == entityId; + assert createdPacket.getX() == x; + assert createdPacket.getY() == y; + assert createdPacket.getZ() == z; + assert createdPacket.getyRot() == AngelConverter.degreesToVanillaByte(yaw); + assert createdPacket.getxRot() == AngelConverter.degreesToVanillaByte(pitch); + assert createdPacket.isOnGround() == onGround; + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 597d99b..8113dff 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,5 +5,6 @@ include(":factories") include(":implementations") include(":implementations:1_20_6") include(":implementations:1_21") +include(":implementations:1_21_1") include(":test_plugin") \ No newline at end of file