Search in sources :

Example 1 with ClientboundRotateHeadPacket

use of net.minecraft.network.protocol.game.ClientboundRotateHeadPacket in project SilkSpawners by timbru31.

the class NMSHandler method spawnEntity.

@SuppressWarnings("resource")
@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
    final CompoundTag tag = new CompoundTag();
    tag.putString("id", entityID);
    final ServerLevel world = ((CraftWorld) w).getHandle();
    final Optional<Entity> entity = EntityType.create(tag, world);
    if (!entity.isPresent()) {
        Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
        return;
    }
    final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
    entity.get().moveTo(x, y, z, yaw, 0);
    ((CraftWorld) w).addEntity(entity.get(), SpawnReason.SPAWNER_EGG);
    final Packet<ClientGamePacketListener> rotationPacket = new ClientboundRotateHeadPacket(entity.get(), (byte) yaw);
    final ServerPlayerConnection connection = ((CraftPlayer) player).getHandle().connection;
    connection.send(rotationPacket);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) Entity(net.minecraft.world.entity.Entity) ServerPlayerConnection(net.minecraft.server.network.ServerPlayerConnection) ClientboundRotateHeadPacket(net.minecraft.network.protocol.game.ClientboundRotateHeadPacket) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) CompoundTag(net.minecraft.nbt.CompoundTag) ClientGamePacketListener(net.minecraft.network.protocol.game.ClientGamePacketListener)

Example 2 with ClientboundRotateHeadPacket

use of net.minecraft.network.protocol.game.ClientboundRotateHeadPacket in project SilkSpawners by timbru31.

the class NMSHandler method spawnEntity.

@SuppressWarnings("resource")
@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
    final CompoundTag tag = new CompoundTag();
    tag.putString("id", entityID);
    final ServerLevel world = ((CraftWorld) w).getHandle();
    final Optional<Entity> entity = EntityType.create(tag, world);
    if (!entity.isPresent()) {
        Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
        return;
    }
    final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
    entity.get().moveTo(x, y, z, yaw, 0);
    ((CraftWorld) w).addEntity(entity.get(), SpawnReason.SPAWNER_EGG);
    final Packet<ClientGamePacketListener> rotationPacket = new ClientboundRotateHeadPacket(entity.get(), (byte) yaw);
    final ServerPlayerConnection connection = ((CraftPlayer) player).getHandle().connection;
    connection.send(rotationPacket);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) Entity(net.minecraft.world.entity.Entity) ServerPlayerConnection(net.minecraft.server.network.ServerPlayerConnection) ClientboundRotateHeadPacket(net.minecraft.network.protocol.game.ClientboundRotateHeadPacket) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CompoundTag(net.minecraft.nbt.CompoundTag) ClientGamePacketListener(net.minecraft.network.protocol.game.ClientGamePacketListener)

Example 3 with ClientboundRotateHeadPacket

use of net.minecraft.network.protocol.game.ClientboundRotateHeadPacket 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)

Example 4 with ClientboundRotateHeadPacket

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

the class EntityPlayerMPFake method createShadow.

public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayer player) {
    player.getServer().getPlayerList().remove(player);
    player.connection.disconnect(new TranslatableComponent("multiplayer.disconnect.duplicate_login"));
    // .getWorld(player.dimension);
    ServerLevel worldIn = player.getLevel();
    GameProfile gameprofile = player.getGameProfile();
    EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true);
    server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow);
    playerShadow.setHealth(player.getHealth());
    playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
    playerShadow.gameMode.changeGameModeForPlayer(player.gameMode.getGameModeForPlayer());
    ((ServerPlayerEntityInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerEntityInterface) player).getActionPack());
    playerShadow.maxUpStep = 0.6F;
    playerShadow.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, player.getEntityData().get(DATA_PLAYER_MODE_CUSTOMISATION));
    server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(playerShadow, (byte) (player.yHeadRot * 256 / 360)), playerShadow.level.dimension());
    server.getPlayerList().broadcastAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, playerShadow));
    // player.world.getChunkManager().updatePosition(playerShadow);
    playerShadow.getAbilities().flying = player.getAbilities().flying;
    return playerShadow;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) GameProfile(com.mojang.authlib.GameProfile) ClientboundRotateHeadPacket(net.minecraft.network.protocol.game.ClientboundRotateHeadPacket) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 5 with ClientboundRotateHeadPacket

use of net.minecraft.network.protocol.game.ClientboundRotateHeadPacket in project SilkSpawners by timbru31.

the class NMSHandler method spawnEntity.

@SuppressWarnings("resource")
@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
    final CompoundTag tag = new CompoundTag();
    tag.putString("id", entityID);
    final ServerLevel world = ((CraftWorld) w).getHandle();
    final Optional<Entity> entity = EntityType.create(tag, world);
    if (!entity.isPresent()) {
        Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
        return;
    }
    final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
    entity.get().moveTo(x, y, z, yaw, 0);
    world.addEntity(entity.get(), SpawnReason.SPAWNER_EGG);
    final Packet<ClientGamePacketListener> rotationPacket = new ClientboundRotateHeadPacket(entity.get(), (byte) yaw);
    final ServerPlayerConnection connection = ((CraftPlayer) player).getHandle().connection;
    connection.send(rotationPacket);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) Entity(net.minecraft.world.entity.Entity) ServerPlayerConnection(net.minecraft.server.network.ServerPlayerConnection) ClientboundRotateHeadPacket(net.minecraft.network.protocol.game.ClientboundRotateHeadPacket) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) CompoundTag(net.minecraft.nbt.CompoundTag) ClientGamePacketListener(net.minecraft.network.protocol.game.ClientGamePacketListener)

Aggregations

ClientboundRotateHeadPacket (net.minecraft.network.protocol.game.ClientboundRotateHeadPacket)5 ServerLevel (net.minecraft.server.level.ServerLevel)5 CompoundTag (net.minecraft.nbt.CompoundTag)3 ClientGamePacketListener (net.minecraft.network.protocol.game.ClientGamePacketListener)3 ServerPlayerConnection (net.minecraft.server.network.ServerPlayerConnection)3 Entity (net.minecraft.world.entity.Entity)3 SpawnerBlockEntity (net.minecraft.world.level.block.entity.SpawnerBlockEntity)3 GameProfile (com.mojang.authlib.GameProfile)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)1 ClientboundTeleportEntityPacket (net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)1