Merge pull request #35 from huanmeng-qwq/master

fix: correct player spawn in 1.20.1-
This commit is contained in:
Tofaa 2025-07-07 22:38:50 +04:00 committed by GitHub
commit 49943c9515
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 18 deletions

View file

@ -77,17 +77,7 @@ public class WrapperEntity implements Tickable {
this.spawned = true;
sendPacketsToViewers(
new WrapperPlayServerSpawnEntity(
entityId,
Optional.of(this.uuid),
entityType,
location.getPosition(),
location.getPitch(),
location.getYaw(),
location.getYaw(),
getObjectData(),
createVeloPacket()
),
createSpawnPacket(),
entityMeta.createPacket()
);
@ -238,7 +228,7 @@ public class WrapperEntity implements Tickable {
sendPacketToViewers(new WrapperPlayServerSystemChatMessage(true, message));
}
protected WrapperPlayServerSpawnEntity createSpawnPacket() {
protected PacketWrapper<?> createSpawnPacket() {
return new WrapperPlayServerSpawnEntity(
entityId,
Optional.of(this.uuid),

View file

@ -1,16 +1,24 @@
package me.tofaa.entitylib.wrapper;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.player.*;
import com.github.retrooper.packetevents.protocol.world.Location;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.protocol.player.GameMode;
import com.github.retrooper.packetevents.protocol.player.TextureProperty;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.*;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityHeadLook;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityRotation;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnPlayer;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.meta.EntityMeta;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import java.util.*;
import org.jetbrains.annotations.NotNull;
public class WrapperPlayer extends WrapperLivingEntity {
@ -25,6 +33,27 @@ public class WrapperPlayer extends WrapperLivingEntity {
this.profile = profile;
}
@Override
protected PacketWrapper<?> createSpawnPacket() {
if (EntityLib.getApi().getPacketEvents().getServerManager().getVersion().isOlderThanOrEquals(ServerVersion.V_1_20_1)) {
return new WrapperPlayServerSpawnPlayer(
getEntityId(),
profile.getUUID(),
getLocation(),
getEntityMeta().entityData()
);
}
return super.createSpawnPacket();
}
@Override
public @NotNull List<PacketWrapper<?>> createSpawnPackets() {
final List<PacketWrapper<?>> packets = super.createSpawnPackets();
packets.add(new WrapperPlayServerEntityRotation(getEntityId(), getYaw(), getPitch(), isOnGround()));
packets.add(new WrapperPlayServerEntityHeadLook(getEntityId(), getYaw()));
return packets;
}
public WrapperPlayServerPlayerInfoUpdate tabListPacket() {
EnumSet<WrapperPlayServerPlayerInfoUpdate.Action> actions = EnumSet.of(
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,