-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff83a75
commit c647673
Showing
10 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
implementations/1_21_2/src/test/java/packets/ClientboundAddEntityPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
implementations/1_21_2/src/test/java/packets/ClientboundPlayerInfoRemovePacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UUID> 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); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
implementations/1_21_2/src/test/java/packets/ClientboundPlayerInfoUpdatePacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FS_ClientboundPlayerInfoUpdatePacket.Action> 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<FS_ClientboundPlayerInfoUpdatePacket.Entry> 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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
implementations/1_21_2/src/test/java/packets/ClientboundRemoveEntitiesPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> 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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
implementations/1_21_2/src/test/java/packets/ClientboundRotateHeadPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
implementations/1_21_2/src/test/java/packets/ClientboundSetEntityDataPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FS_ClientboundSetEntityDataPacket.EntityData> 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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
implementations/1_21_2/src/test/java/packets/ClientboundSetEquipmentPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package packets; | ||
|
||
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEquipmentPacketImpl; | ||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Map; | ||
|
||
class ClientboundSetEquipmentPacketImplTest { | ||
|
||
//TODO: Fix this test (registry problems) | ||
// @Test | ||
void createPacket() { | ||
// Setup packet | ||
Map<FS_EquipmentSlot, ItemStack> equipment = Map.of( | ||
FS_EquipmentSlot.MAINHAND, new ItemStack(Material.DIAMOND_SWORD), | ||
FS_EquipmentSlot.OFFHAND, new ItemStack(Material.SHIELD), | ||
FS_EquipmentSlot.HEAD, new ItemStack(Material.DIAMOND_HELMET) | ||
); | ||
|
||
ClientboundSetEquipmentPacketImpl packet = new ClientboundSetEquipmentPacketImpl(42, equipment); | ||
ClientboundSetEquipmentPacket createdPacket = (ClientboundSetEquipmentPacket) packet.createPacket(); | ||
|
||
assert createdPacket.getEntity() == 42; | ||
assert createdPacket.getSlots().size() == 3; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
implementations/1_21_2/src/test/java/packets/ClientboundTeleportEntityPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters