Search in sources :

Example 16 with CachedEntity

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

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

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

the class PCEntityRemoveEffectPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityRemoveEffectPacket 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;
        }
    }
    int effectId = MagicValues.value(Integer.class, packet.getEffect());
    if (!entity.effects.contains(effectId)) {
        return null;
    }
    MobEffectPacket eff = new MobEffectPacket();
    eff.rtid = entity.proxyEid;
    eff.eventId = MobEffectPacket.EVENT_REMOVE;
    return new PEPacket[] { eff };
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket) MobEffectPacket(org.dragonet.protocol.packets.MobEffectPacket)

Example 19 with CachedEntity

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

the class PCEntityVelocityPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityVelocityPacket 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.motionX = packet.getMotionX();
    entity.motionY = packet.getMotionY();
    entity.motionZ = packet.getMotionZ();
    SetEntityMotionPacket pk = new SetEntityMotionPacket();
    pk.rtid = entity.proxyEid;
    pk.motion = new Vector3F((float) packet.getMotionX(), (float) packet.getMotionY(), (float) packet.getMotionZ());
    return new PEPacket[] { pk };
}
Also used : SetEntityMotionPacket(org.dragonet.protocol.packets.SetEntityMotionPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket)

Example 20 with CachedEntity

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

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