Search in sources :

Example 6 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PEPlayerActionPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, PlayerActionPacket packet) {
    if (packet.action == PlayerActionPacket.ACTION_RESPAWN) {
        return new Packet[] { new ClientRequestPacket(ClientRequest.RESPAWN) };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_SPRINT) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SPRINTING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SPRINT) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SPRINTING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_GLIDE) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_GLIDE) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_SNEAK) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SNEAK) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SNEAKING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SLEEPING) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.LEAVE_BED);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_DROP_ITEM) {
        ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, new Position(0, 0, 0), BlockFace.UP);
        return new Packet[] { act };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_BREAK) {
        ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, new Position(packet.position.x, packet.position.y, packet.position.z), MagicValues.key(BlockFace.class, packet.face));
        session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition());
        return new Packet[] { act };
    }
    if (session.getDataCache().containsKey(CacheKey.BLOCK_BREAKING_POSITION)) {
        if (packet.action == PlayerActionPacket.ACTION_STOP_BREAK) {
            ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.FINISH_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
            return new Packet[] { act };
        }
        if (packet.action == PlayerActionPacket.ACTION_ABORT_BREAK) {
            ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.CANCEL_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
            return new Packet[] { act };
        }
    }
    return null;
}
Also used : ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ClientPlayerStatePacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket) PlayerActionPacket(org.dragonet.protocol.packets.PlayerActionPacket) Packet(com.github.steveice10.packetlib.packet.Packet) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) BlockFace(com.github.steveice10.mc.protocol.data.game.world.block.BlockFace) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) ClientPlayerStatePacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket)

Example 7 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PCEntityEquipmentPacketTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerEntityEquipmentPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) {
            entity = session.getEntityCache().getClientEntity();
        } else {
            return null;
        }
    }
    ItemStack items = packet.getItem();
    boolean handModified = false;
    switch(packet.getSlot()) {
        case HELMET:
            entity.helmet = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case CHESTPLATE:
            entity.chestplate = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case LEGGINGS:
            entity.leggings = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case BOOTS:
            entity.boots = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case MAIN_HAND:
            entity.mainHand = ItemBlockTranslator.translateSlotToPE(items);
        case OFF_HAND:
            handModified = true;
            break;
    }
    entity.updateEquipment(session);
    if (handModified) {
        MobEquipmentPacket equipPacket = new MobEquipmentPacket();
        equipPacket.rtid = entity.proxyEid;
        equipPacket.item = entity.mainHand;
        equipPacket.inventorySlot = 0;
        equipPacket.hotbarSlot = 0;
        equipPacket.windowId = 0;
        session.sendPacket(equipPacket);
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack) MobEquipmentPacket(org.dragonet.protocol.packets.MobEquipmentPacket)

Example 8 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PCPlaySoundPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) {
    try {
        String soundName;
        if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) {
            BuiltinSound sound = (BuiltinSound) packet.getSound();
            soundName = sound.name();
        } else {
            soundName = ((CustomSound) packet.getSound()).getName();
        }
        if (soundName == null) {
            return null;
        }
        PlaySoundPacket pk = new PlaySoundPacket();
        pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
        pk.name = soundName;
        pk.volume = packet.getVolume();
        pk.pitch = packet.getPitch();
        return new PEPacket[] { pk };
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) BuiltinSound(com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound) PlaySoundPacket(org.dragonet.protocol.packets.PlaySoundPacket) ServerPlaySoundPacket(com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)

Example 9 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PEBlockPickRequestPacketTranslator method translate.

@Override
public Packet[] translate(UpstreamSession session, BlockPickRequestPacket packet) {
    ItemStack item = session.getChunkCache().getBlock(new Position(packet.x, packet.y, packet.z));
    int selectedSlot = (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_SELECTED_SLOT, 36);
    ClientCreativeInventoryActionPacket backPacket = new ClientCreativeInventoryActionPacket(selectedSlot + 36, item);
    // System.out.println("BlockPickRequestPacket " + DebugTools.getAllFields(packet));
    // System.out.println("ItemStack " + DebugTools.getAllFields(item));
    session.getChunkCache().getDebugGrid();
    return new Packet[] { backPacket };
}
Also used : Packet(com.github.steveice10.packetlib.packet.Packet) PlayerSkinPacket(org.dragonet.protocol.packets.PlayerSkinPacket) ClientCreativeInventoryActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket) BlockPickRequestPacket(org.dragonet.protocol.packets.BlockPickRequestPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ClientCreativeInventoryActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)

Example 10 with Packet

use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.

the class PEMovePlayerPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, MovePlayerPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.riding != 0 && packet.ridingRuntimeId != 0) {
        // Riding case
        ClientVehicleMovePacket pk = new ClientVehicleMovePacket(packet.position.x, packet.position.y - EntityType.PLAYER.getOffset(), packet.position.z, packet.yaw, packet.pitch);
        session.getDownstream().send(pk);
    } else {
        // not riding
        ClientPlayerPositionRotationPacket pk = new ClientPlayerPositionRotationPacket(packet.onGround, packet.position.x, // To simplify the movements
        ceilToHalf(packet.position.y - EntityType.PLAYER.getOffset()), packet.position.z, packet.yaw, packet.pitch);
        // Special blocks handling
        boolean isColliding = false;
        BlockPosition blockPos = new BlockPosition(NukkitMath.floorDouble(packet.position.x), NukkitMath.floorDouble(packet.position.y), NukkitMath.floorDouble(packet.position.z));
        // System.out.println("block " + blockPos.toString());
        try {
            ItemEntry PEBlock = session.getChunkCache().translateBlock(blockPos.asPosition());
            if (PEBlock != null) {
                Block b = Block.get(PEBlock.getId(), PEBlock.getPEDamage(), blockPos);
                if (b != null && b.collidesWithBB(session.getEntityCache().getClientEntity().boundingBox.clone())) {
                    DragonProxy.getInstance().getLogger().info("Player position : " + entity.x + ", " + entity.y + ", " + entity.z + " collide with " + b.getClass().getSimpleName() + " on " + blockPos.toString());
                    isColliding = true;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        entity.absoluteMove(pk.getX(), pk.getY(), pk.getZ(), (float) pk.getYaw(), (float) pk.getPitch());
        if (!isColliding) {
            session.getDownstream().send(pk);
            session.getChunkCache().sendOrderedChunks();
        }
    }
    return null;
}
Also used : ClientVehicleMovePacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) ClientPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket) Block(org.dragonet.common.data.blocks.Block) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Aggregations

BlockPosition (org.dragonet.common.maths.BlockPosition)5 PEPacket (org.dragonet.protocol.PEPacket)5 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)4 Packet (com.github.steveice10.packetlib.packet.Packet)4 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)4 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)2 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)2 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)2 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)2 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)2 ClientCloseWindowPacket (com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket)2 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)2 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)2 HashSet (java.util.HashSet)2 CachedWindow (org.dragonet.proxy.network.cache.CachedWindow)2 IInventoryTranslator (org.dragonet.proxy.network.translator.IInventoryTranslator)2 Timing (co.aikar.timings.Timing)1 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1