Search in sources :

Example 1 with PacketPlayOutPositionHandle

use of com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutPositionHandle in project BKCommonLib by bergerhealer.

the class MapPlayerInput method updateInputInterception.

private void updateInputInterception(boolean intercept) {
    if (!intercept && _fakeMountShown) {
        _fakeMountShown = false;
        // Despawn the mount
        PacketUtil.sendPacket(player, PacketType.OUT_ENTITY_DESTROY.newInstanceSingle(this._fakeMountId));
        // Resend current player position to the player
        Location loc = this.player.getLocation();
        PacketPlayOutPositionHandle positionPacket = PacketPlayOutPositionHandle.createAbsolute(loc);
        PacketUtil.sendPacket(player, positionPacket);
        return;
    }
    if (intercept) {
        // Get expected position of the mount
        Vector pos = player.getLocation().toVector();
        pos.setZ(pos.getZ() + 0.1);
        pos.setY(pos.getY() + 0.002);
        if (!_fakeMountShown) {
            _fakeMountShown = true;
            // Generate unique mount Id (we can re-use it)
            if (this._fakeMountId == -1) {
                this._fakeMountId = EntityUtil.getUniqueEntityId();
            }
            // Store initial position
            this._fakeMountLastPos = pos;
            // Spawn the mount
            {
                DataWatcher data = new DataWatcher();
                data.set(EntityHandle.DATA_FLAGS, (byte) (EntityHandle.DATA_FLAG_INVISIBLE));
                data.set(EntityLivingHandle.DATA_HEALTH, 10.0F);
                PacketPlayOutSpawnEntityLivingHandle packet = PacketPlayOutSpawnEntityLivingHandle.createNew();
                packet.setEntityId(this._fakeMountId);
                packet.setEntityUUID(UUID.randomUUID());
                packet.setEntityType(EntityType.CHICKEN);
                packet.setPosX(pos.getX());
                packet.setPosY(pos.getY());
                packet.setPosZ(pos.getZ());
                PacketUtil.sendEntityLivingSpawnPacket(player, packet, data);
                // Send attribute for max health = 0 to hide the health bar
                PacketUtil.sendPacket(player, PacketPlayOutUpdateAttributesHandle.createZeroMaxHealth(this._fakeMountId));
            }
            sendMountPacket();
        }
        // When player position changes, refresh mount position with a simple teleport packet
        if (this._fakeMountId != -1 && !pos.equals(this._fakeMountLastPos)) {
            this._fakeMountLastPos = pos;
            PacketPlayOutEntityTeleportHandle tp_packet = PacketPlayOutEntityTeleportHandle.createNew(this._fakeMountId, pos.getX(), pos.getY(), pos.getZ(), 0.0f, 0.0f, false);
            PacketUtil.sendPacket(player, tp_packet);
        }
    }
}
Also used : Vector(org.bukkit.util.Vector) PacketPlayOutEntityTeleportHandle(com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutEntityTeleportHandle) PacketPlayOutPositionHandle(com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutPositionHandle) Location(org.bukkit.Location) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher) PacketPlayOutSpawnEntityLivingHandle(com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLivingHandle)

Aggregations

DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)1 PacketPlayOutEntityTeleportHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutEntityTeleportHandle)1 PacketPlayOutPositionHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutPositionHandle)1 PacketPlayOutSpawnEntityLivingHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLivingHandle)1 Location (org.bukkit.Location)1 Vector (org.bukkit.util.Vector)1