Search in sources :

Example 1 with UpdateAttributesPacket

use of org.dragonet.protocol.packets.UpdateAttributesPacket 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 2 with UpdateAttributesPacket

use of org.dragonet.protocol.packets.UpdateAttributesPacket in project DragonProxy by DragonetMC.

the class PCRespawnPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerRespawnPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.dimention != packet.getDimension()) {
        // the player have changed dimention
        DragonProxy.getInstance().getLogger().info(session.getUsername() + " change dim " + entity.dimention + " to " + packet.getDimension());
        // entity.dimention = packet.getDimension();
        // purge and despawn
        session.getEntityCache().reset(true);
        session.getChunkCache().purge();
        // send new world gamemode
        SetPlayerGameTypePacket pkgm = new SetPlayerGameTypePacket();
        pkgm.gamemode = packet.getGameMode() == GameMode.CREATIVE ? 1 : 0;
        session.sendPacket(pkgm);
        // send new adventure settings
        AdventureSettingsPacket adv = new AdventureSettingsPacket();
        adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, packet.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, packet.getGameMode().equals(GameMode.CREATIVE) || packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.NO_CLIP, packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !packet.getGameMode().equals(GameMode.SPECTATOR) || !packet.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.FLYING, packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.MUTED, false);
        adv.eid = entity.proxyEid;
        adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
        adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
        session.sendPacket(adv);
        // send entity attributes
        UpdateAttributesPacket attr = new UpdateAttributesPacket();
        attr.rtid = entity.proxyEid;
        if (entity.attributes.isEmpty()) {
            attr.entries = new ArrayList();
            attr.entries.addAll(PEEntityAttribute.getDefault());
        } else
            attr.entries = entity.attributes.values();
        session.sendPacket(attr);
        // set world difficulty
        session.sendPacket(new SetDifficultyPacket(packet.getDifficulty()));
        if (packet.getGameMode().equals(GameMode.CREATIVE))
            session.sendCreativeInventory();
        return null;
    } else
        return new PEPacket[] { new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN) };
}
Also used : SetPlayerGameTypePacket(org.dragonet.protocol.packets.SetPlayerGameTypePacket) SetDifficultyPacket(org.dragonet.protocol.packets.SetDifficultyPacket) PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket) AdventureSettingsPacket(org.dragonet.protocol.packets.AdventureSettingsPacket) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) ArrayList(java.util.ArrayList)

Example 3 with UpdateAttributesPacket

use of org.dragonet.protocol.packets.UpdateAttributesPacket in project DragonProxy by DragonetMC.

the class PCSetExperiencePacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlayerSetExperiencePacket packet) {
    CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
    peSelfPlayer.attributes.put(PEEntityAttribute.EXPERIENCE_LEVEL, PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE_LEVEL).setValue(packet.getLevel()));
    peSelfPlayer.attributes.put(PEEntityAttribute.EXPERIENCE, PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE).setValue(packet.getSlot()));
    UpdateAttributesPacket pk = new UpdateAttributesPacket();
    pk.rtid = peSelfPlayer.proxyEid;
    pk.entries = peSelfPlayer.attributes.values();
    return new PEPacket[] { pk };
}
Also used : UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket)

Example 4 with UpdateAttributesPacket

use of org.dragonet.protocol.packets.UpdateAttributesPacket in project DragonProxy by DragonetMC.

the class PCEntityPropertiesPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPropertiesPacket 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;
        }
    }
    for (Attribute attr : packet.getAttributes()) {
        switch(attr.getType()) {
            case GENERIC_FOLLOW_RANGE:
                entity.attributes.put(PEEntityAttribute.FOLLOW_RANGE, PEEntityAttribute.findAttribute(PEEntityAttribute.FOLLOW_RANGE).setValue((float) attr.getValue()));
                break;
            case GENERIC_KNOCKBACK_RESISTANCE:
                entity.attributes.put(PEEntityAttribute.KNOCKBACK_RESISTANCE, PEEntityAttribute.findAttribute(PEEntityAttribute.KNOCKBACK_RESISTANCE).setValue((float) attr.getValue()));
                break;
            case GENERIC_MOVEMENT_SPEED:
                entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
                break;
            case GENERIC_ATTACK_DAMAGE:
                entity.attributes.put(PEEntityAttribute.ATTACK_DAMAGE, PEEntityAttribute.findAttribute(PEEntityAttribute.ATTACK_DAMAGE).setValue((float) attr.getValue()));
                break;
            case GENERIC_FLYING_SPEED:
                entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
                break;
        }
    }
    if (entity.spawned) {
        UpdateAttributesPacket pk = new UpdateAttributesPacket();
        pk.rtid = entity.proxyEid;
        pk.entries = entity.attributes.values();
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : Attribute(com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute) PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket)

Aggregations

UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)4 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)4 PEPacket (org.dragonet.protocol.PEPacket)3 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 ArrayList (java.util.ArrayList)1 PEEntityAttribute (org.dragonet.common.data.entity.PEEntityAttribute)1 AdventureSettingsPacket (org.dragonet.protocol.packets.AdventureSettingsPacket)1 PlayStatusPacket (org.dragonet.protocol.packets.PlayStatusPacket)1 RespawnPacket (org.dragonet.protocol.packets.RespawnPacket)1 SetDifficultyPacket (org.dragonet.protocol.packets.SetDifficultyPacket)1 SetHealthPacket (org.dragonet.protocol.packets.SetHealthPacket)1 SetPlayerGameTypePacket (org.dragonet.protocol.packets.SetPlayerGameTypePacket)1