fix: correct player spawn in 1.20.1-

This commit is contained in:
huanmeng-qwq 2025-07-08 02:00:05 +08:00
parent 34db96d434
commit 8478e87a38
No known key found for this signature in database
GPG key ID: A282328441529B42
2 changed files with 26 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,17 +1,22 @@
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.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.*;
public class WrapperPlayer extends WrapperLivingEntity {
private UserProfile profile;
@ -25,6 +30,19 @@ 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();
}
public WrapperPlayServerPlayerInfoUpdate tabListPacket() {
EnumSet<WrapperPlayServerPlayerInfoUpdate.Action> actions = EnumSet.of(
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,