Search in sources :

Example 1 with ClientboundTeleportEntityPacket

use of net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket in project hephaestus-engine by unnamed.

the class BoneView_v1_18_R2 method position.

@Override
public void position(Vector3Float position) {
    Location rootLocation = view.location();
    entity.setPos(rootLocation.getX() + position.x(), rootLocation.getY() + position.y(), rootLocation.getZ() + position.z());
    Packets.send(view.viewers(), new ClientboundTeleportEntityPacket(entity));
}
Also used : ClientboundTeleportEntityPacket(net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket) Location(org.bukkit.Location)

Example 2 with ClientboundTeleportEntityPacket

use of net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket in project fabric-carpet by gnembon.

the class EntityPlayerMPFake method createFake.

public static EntityPlayerMPFake createFake(String username, MinecraftServer server, double d0, double d1, double d2, double yaw, double pitch, ResourceKey<Level> dimensionId, GameType gamemode, boolean flying) {
    // prolly half of that crap is not necessary, but it works
    ServerLevel worldIn = server.getLevel(dimensionId);
    GameProfileCache.setUsesAuthentication(false);
    GameProfile gameprofile;
    try {
        // findByName  .orElse(null)
        gameprofile = server.getProfileCache().get(username).orElse(null);
    } finally {
        GameProfileCache.setUsesAuthentication(server.isDedicatedServer() && server.usesAuthentication());
    }
    if (gameprofile == null) {
        if (!CarpetSettings.allowSpawningOfflinePlayers) {
            return null;
        } else {
            gameprofile = new GameProfile(Player.createPlayerUUID(username), username);
        }
    }
    if (gameprofile.getProperties().containsKey("textures")) {
        AtomicReference<GameProfile> result = new AtomicReference<>();
        SkullBlockEntity.updateGameprofile(gameprofile, result::set);
        gameprofile = result.get();
    }
    EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false);
    instance.fixStartingPosition = () -> instance.moveTo(d0, d1, d2, (float) yaw, (float) pitch);
    server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance);
    instance.teleportTo(worldIn, d0, d1, d2, (float) yaw, (float) pitch);
    instance.setHealth(20.0F);
    instance.unsetRemoved();
    instance.maxUpStep = 0.6F;
    instance.gameMode.changeGameModeForPlayer(gamemode);
    // instance.dimension);
    server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), dimensionId);
    // instance.dimension);
    server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), dimensionId);
    // instance.world.getChunkManager(). updatePosition(instance);
    // show all model layers (incl. capes)
    instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f);
    instance.getAbilities().flying = flying;
    return instance;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundTeleportEntityPacket(net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket) GameProfile(com.mojang.authlib.GameProfile) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientboundRotateHeadPacket(net.minecraft.network.protocol.game.ClientboundRotateHeadPacket)

Aggregations

ClientboundTeleportEntityPacket (net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket)2 GameProfile (com.mojang.authlib.GameProfile)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ClientboundRotateHeadPacket (net.minecraft.network.protocol.game.ClientboundRotateHeadPacket)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 Location (org.bukkit.Location)1