Search in sources :

Example 11 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity 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)

Example 12 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCAnimationPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityAnimationPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        return null;
    }
    AnimatePacket pk = new AnimatePacket();
    switch(packet.getAnimation()) {
        case CRITICAL_HIT:
            pk.action = AnimatePacket.ACTION_CRITICAL_HIT;
            break;
        case DAMAGE:
            break;
        case EAT_FOOD:
            break;
        case ENCHANTMENT_CRITICAL_HIT:
            break;
        case LEAVE_BED:
            pk.action = AnimatePacket.ANIMATION_LEAVE_BED;
            break;
        case SWING_ARM:
            pk.action = AnimatePacket.ANIMATION_SWING_ARM;
    }
    pk.eid = entity.proxyEid;
    return new PEPacket[] { pk };
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) AnimatePacket(org.dragonet.protocol.packets.AnimatePacket) PEPacket(org.dragonet.protocol.PEPacket)

Example 13 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCEntityRotationPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityRotationPacket 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;
        }
    }
    entity.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
    if (entity.shouldMove) {
        MoveEntityPacket pk = new MoveEntityPacket();
        pk.rtid = entity.proxyEid;
        pk.yaw = (byte) (entity.yaw / (360d / 256d));
        pk.headYaw = (byte) (entity.headYaw / (360d / 256d));
        pk.pitch = (byte) (entity.pitch / (360d / 256d));
        pk.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
        pk.onGround = packet.isOnGround();
        entity.shouldMove = false;
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket) MoveEntityPacket(org.dragonet.protocol.packets.MoveEntityPacket)

Example 14 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCDestroyEntitiesPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityDestroyPacket packet) {
    PEPacket[] ret = new PEPacket[packet.getEntityIds().length];
    for (int i = 0; i < ret.length; i++) {
        CachedEntity e = session.getEntityCache().removeByRemoteEID(packet.getEntityIds()[i]);
        if (e == null) {
            continue;
        }
        ret[i] = new RemoveEntityPacket();
        ((RemoveEntityPacket) ret[i]).eid = e.proxyEid;
    }
    return ret;
}
Also used : RemoveEntityPacket(org.dragonet.protocol.packets.RemoveEntityPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket)

Example 15 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCEntityPositionPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPositionPacket 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;
        }
    }
    entity.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
    if (entity.shouldMove) {
        MoveEntityPacket pk = new MoveEntityPacket();
        pk.rtid = entity.proxyEid;
        pk.yaw = (byte) (entity.yaw / (360d / 256d));
        pk.headYaw = (byte) (entity.headYaw / (360d / 256d));
        pk.pitch = (byte) (entity.pitch / (360d / 256d));
        pk.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
        pk.onGround = packet.isOnGround();
        entity.shouldMove = false;
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket) MoveEntityPacket(org.dragonet.protocol.packets.MoveEntityPacket)

Aggregations

CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)26 PEPacket (org.dragonet.protocol.PEPacket)14 Vector3F (org.dragonet.common.maths.Vector3F)9 BlockPosition (org.dragonet.common.maths.BlockPosition)5 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)3 ArrayList (java.util.ArrayList)2 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 InteractAction (com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction)1 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)1 ClientPlayerInteractEntityPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket)1 ClientPlayerPlaceBlockPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket)1 ClientPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)1 ClientPlayerSwingArmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket)1