Search in sources :

Example 6 with CachedEntity

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

the class PCUpdateHealthPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) {
    // Always round up
    int newHealth = (int) Math.ceil(packet.getHealth());
    SetHealthPacket h = new SetHealthPacket(newHealth);
    CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
    peSelfPlayer.attributes.put(PEEntityAttribute.HEALTH, PEEntityAttribute.findAttribute(PEEntityAttribute.HEALTH).setValue(newHealth));
    if (peSelfPlayer.foodPacketCount == 0) {
        peSelfPlayer.attributes.put(PEEntityAttribute.FOOD, PEEntityAttribute.findAttribute(PEEntityAttribute.FOOD).setValue(packet.getFood()));
    }
    UpdateAttributesPacket pk = new UpdateAttributesPacket();
    pk.rtid = peSelfPlayer.proxyEid;
    pk.entries = peSelfPlayer.attributes.values();
    if (newHealth <= 0)
        return new PEPacket[] { h, pk, new RespawnPacket() };
    return new PEPacket[] { h, pk };
}
Also used : SetHealthPacket(org.dragonet.protocol.packets.SetHealthPacket) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket) RespawnPacket(org.dragonet.protocol.packets.RespawnPacket)

Example 7 with CachedEntity

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

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

the class PCEntityMetadataPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityMetadataPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        if (packet.getEntityId() == session.getEntityCache().getClientEntity().eid)
            entity = session.getEntityCache().getClientEntity();
        else
            return null;
    // System.out.println("!!!!!!!!!!!!!!! TRY TO update the player meta from PCEntityMetadataPacketTranslator");
    // return null;
    }
    entity.pcMeta = packet.getMetadata();
    if (entity.spawned) {
        SetEntityDataPacket pk = new SetEntityDataPacket();
        pk.rtid = entity.proxyEid;
        pk.meta = EntityMetaTranslator.translateToPE(session, packet.getMetadata(), entity.peType);
        session.sendPacket(pk);
    } else if (entity.peType == EntityType.PLAYER || entity.peType == EntityType.PAINTING) {
    // Do nothing here !
    } else
        entity.spawn(session);
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) SetEntityDataPacket(org.dragonet.protocol.packets.SetEntityDataPacket)

Example 9 with CachedEntity

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

the class PCEntityPositionRotationPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPositionRotationPacket 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 10 with CachedEntity

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

the class PCEntitySetPassengerPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntitySetPassengersPacket packet) {
    CachedEntity vehicle = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (vehicle == null) {
        return null;
    }
    // process not passenger (dismount)
    Iterator<Long> itr = vehicle.passengers.iterator();
    while (itr.hasNext()) {
        long id = itr.next();
        CachedEntity rider = session.getEntityCache().getByLocalEID(id);
        if (rider == null) {
            continue;
        }
        if (!Arrays.asList(packet.getPassengerIds()).contains(rider.eid)) {
            SetEntityLinkPacket pk = new SetEntityLinkPacket();
            pk.riding = vehicle.proxyEid;
            pk.rider = rider.proxyEid;
            pk.type = SetEntityLinkPacket.TYPE_REMOVE;
            setRiding(session, rider, null);
            pk.unknownByte = 0x00;
            session.putCachePacket(pk);
            itr.remove();
            rider.riding = 0;
        // System.out.println("DISMOUNT\n" + DebugTools.getAllFields(pk));
        }
    }
    // process mount action
    boolean piloteSet = false;
    for (int id : packet.getPassengerIds()) {
        CachedEntity rider = session.getEntityCache().getByRemoteEID(id);
        if (rider == null) {
            continue;
        }
        SetEntityLinkPacket pk = new SetEntityLinkPacket();
        pk.riding = vehicle.proxyEid;
        pk.rider = rider.proxyEid;
        if (!piloteSet) {
            piloteSet = true;
            pk.type = SetEntityLinkPacket.TYPE_RIDE;
            setRiding(session, rider, getSeatOffset(rider.peType, 1));
        } else {
            pk.type = SetEntityLinkPacket.TYPE_PASSENGER;
            setRiding(session, rider, getSeatOffset(rider.peType, 2));
        }
        pk.unknownByte = 0x00;
        session.putCachePacket(pk);
        vehicle.passengers.add(rider.proxyEid);
        rider.riding = vehicle.proxyEid;
    // System.out.println("MOUNT\n" + DebugTools.getAllFields(pk));
    }
    return null;
}
Also used : SetEntityLinkPacket(org.dragonet.protocol.packets.SetEntityLinkPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity)

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