Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 1.21.2 #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public enum ServerVersion {

v1_21_3("1.21.3", 768),
v1_21_2("1.21.2", 768),
v1_21_1("1.21.1", 767),
v1_21("1.21", 767),
v1_20_6("1.20.6", 766),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FS_ClientboundPlayerInfoUpdatePacket createPlayerInfoUpdatePacket(
ServerVersion serverVersion, EnumSet<FS_ClientboundPlayerInfoUpdatePacket.Action> actions,
List<FS_ClientboundPlayerInfoUpdatePacket.Entry> entries) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundPlayerInfoUpdatePacketImpl(actions, entries);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -68,7 +68,7 @@ public FS_ClientboundAddEntityPacket createAddEntityPacket(
int velocityZ,
int data) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundAddEntityPacketImpl(entityId, entityUUID, entityType, x, y, z, yaw, pitch, headYaw, velocityX, velocityY, velocityZ, data);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -106,7 +106,7 @@ public FS_ClientboundAddEntityPacket createAddEntityPacket(
*/
public FS_ClientboundPlayerInfoRemovePacket createPlayerInfoRemovePacket(ServerVersion serverVersion, List<UUID> uuids) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundPlayerInfoRemovePacketImpl(uuids);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -147,7 +147,7 @@ public FS_ClientboundPlayerInfoRemovePacket createPlayerInfoRemovePacket(UUID uu
*/
public FS_ClientboundRemoveEntitiesPacket createRemoveEntitiesPacket(ServerVersion serverVersion, List<Integer> entityIds) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundRemoveEntitiesPacketImpl(entityIds);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -185,7 +185,7 @@ public FS_ClientboundTeleportEntityPacket createTeleportEntityPacket(
boolean onGround
) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundTeleportEntityPacketImpl(entityId, x, y, z, yaw, pitch, onGround);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -223,7 +223,7 @@ public FS_ClientboundTeleportEntityPacket createTeleportEntityPacket(
*/
public FS_ClientboundRotateHeadPacket createRotateHeadPacket(ServerVersion serverVersion, int entityId, float headYaw) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundRotateHeadPacketImpl(entityId, headYaw);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand All @@ -249,7 +249,7 @@ public FS_ClientboundRotateHeadPacket createRotateHeadPacket(int entityId, float
public FS_ClientboundSetEntityDataPacket createSetEntityDataPacket(
ServerVersion serverVersion, int entityId, List<FS_ClientboundSetEntityDataPacket.EntityData> entityData) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEntityDataPacketImpl(entityId, entityData);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand All @@ -274,7 +274,7 @@ public FS_ClientboundSetEntityDataPacket createSetEntityDataPacket(int entityId,
*/
public FS_ClientboundSetEquipmentPacket createSetEquipmentPacket(ServerVersion serverVersion, int entityId, Map<FS_EquipmentSlot, ItemStack> equipment) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEquipmentPacketImpl(entityId, equipment);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand All @@ -300,7 +300,7 @@ public FS_ClientboundSetEquipmentPacket createSetEquipmentPacket(int entityId, M
public FS_ClientboundSetPassengersPacket createSetPassengersPacket(
ServerVersion serverVersion, int entityId, List<Integer> passengers) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetPassengersPacketImpl(entityId, passengers);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -329,7 +329,7 @@ public FS_ClientboundSetPassengersPacket createSetPassengersPacket(int entityId,
*/
public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.CreateTeam createTeam) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, createTeam);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -358,7 +358,7 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str
*/
public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.RemoveTeam removeTeam) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, removeTeam);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -387,7 +387,7 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str
*/
public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.UpdateTeam updateTeam) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, updateTeam);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -416,7 +416,7 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str
*/
public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.AddEntity addEntity) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, addEntity);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down Expand Up @@ -445,7 +445,7 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str
*/
public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.RemoveEntity removeEntity) {
switch (serverVersion) {
case v1_20_5, v1_20_6, v1_21, v1_21_1 -> {
case v1_20_5, v1_20_6, v1_21, v1_21_1, v1_21_2, v1_21_3 -> {
return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, removeEntity);
}
default -> throw new IllegalArgumentException("Unsupported server version: " + serverVersion.getVersion());
Expand Down
24 changes: 24 additions & 0 deletions implementations/1_21_2/build.gradle.kts
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()
}
}
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;
}
}
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);
}
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
}
Loading
Loading