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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations