Search in sources :

Example 1 with Vector3F

use of org.dragonet.common.maths.Vector3F in project DragonProxy by DragonetMC.

the class PCPlayerPositionRotationPacketTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotationPacket packet) {
    CachedEntity entityPlayer = session.getEntityCache().getClientEntity();
    if (entityPlayer == null) {
    // disconnect (important missing data)
    }
    if (!session.isSpawned()) {
        if (session.getDataCache().get(CacheKey.PACKET_JOIN_GAME_PACKET) == null) {
            session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_REMOTE_ERROR));
            return null;
        }
        ServerJoinGamePacket restored = (ServerJoinGamePacket) session.getDataCache().remove(CacheKey.PACKET_JOIN_GAME_PACKET);
        if (!session.getProxy().getAuthMode().equalsIgnoreCase("online")) {
            StartGamePacket ret = new StartGamePacket();
            ret.rtid = entityPlayer.proxyEid;
            ret.eid = entityPlayer.proxyEid;
            ret.dimension = entityPlayer.dimention;
            ret.seed = 0;
            ret.generator = 1;
            ret.gamemode = restored.getGameMode() == GameMode.CREATIVE ? 1 : 0;
            ret.spawnPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
            ret.position = new Vector3F((float) packet.getX(), (float) packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, (float) packet.getZ());
            ret.yaw = packet.getYaw();
            ret.pitch = packet.getPitch();
            ret.levelId = "";
            ret.worldName = "World";
            ret.commandsEnabled = true;
            ret.defaultPlayerPermission = 2;
            ret.premiumWorldTemplateId = "";
            ret.difficulty = restored.getDifficulty();
            session.sendPacket(ret, true);
        }
        entityPlayer.absoluteMove(packet.getX(), packet.getY() + entityPlayer.peType.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch());
        session.getChunkCache().sendOrderedChunks();
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("DragonProxy");
        ClientPluginMessagePacket clientPluginMessagePacket = new ClientPluginMessagePacket("MC|Brand", out.toByteArray());
        ((PCDownstreamSession) session.getDownstream()).send(clientPluginMessagePacket);
        LoginPacket loginpacket = (LoginPacket) session.getDataCache().remove(CacheKey.PACKET_LOGIN_PACKET);
        String clientLanguage = loginpacket.decoded.clientData.has("LanguageCode") ? loginpacket.decoded.clientData.get("LanguageCode").getAsString() : "en_US";
        session.getDataCache().put(CacheKey.PLAYER_LANGUAGE, clientLanguage);
        ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(clientLanguage, (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_REQUESTED_CHUNK_RADIUS, 5), ChatVisibility.FULL, false, new SkinPart[] {}, Hand.OFF_HAND);
        ((PCDownstreamSession) session.getDownstream()).send(clientSettingsPacket);
        UpdateAttributesPacket attr = new UpdateAttributesPacket();
        attr.rtid = entityPlayer.proxyEid;
        if (entityPlayer.attributes.isEmpty()) {
            attr.entries = new ArrayList();
            attr.entries.addAll(PEEntityAttribute.getDefault());
        } else
            attr.entries = entityPlayer.attributes.values();
        session.sendPacket(attr, true);
        AdventureSettingsPacket adv = new AdventureSettingsPacket();
        // flags
        adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, restored.getGameMode().equals(GameMode.ADVENTURE));
        // adv.setFlag(AdventureSettingsPacket.NO_PVP, true);
        // adv.setFlag(AdventureSettingsPacket.AUTO_JUMP, true);
        adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, restored.getGameMode().equals(GameMode.CREATIVE) || restored.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.NO_CLIP, restored.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !restored.getGameMode().equals(GameMode.SPECTATOR) || !restored.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.FLYING, restored.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.MUTED, false);
        // custom permission flags (not necessary for now when using LEVEL_PERMISSION setting)
        // adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true);adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true);
        // adv.setFlag(AdventureSettingsPacket.DOORS_AND_SWITCHES, true);
        // adv.setFlag(AdventureSettingsPacket.OPEN_CONTAINERS, true);
        // adv.setFlag(AdventureSettingsPacket.ATTACK_PLAYERS, true);
        // adv.setFlag(AdventureSettingsPacket.ATTACK_MOBS, true);
        // adv.setFlag(AdventureSettingsPacket.OPERATOR, true);
        // adv.setFlag(AdventureSettingsPacket.TELEPORT, true);
        adv.eid = entityPlayer.proxyEid;
        // TODO update this with server configiration
        adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
        // TODO update this with server configiration
        adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
        session.sendPacket(adv, true);
        SetEntityDataPacket entityData = new SetEntityDataPacket();
        entityData.rtid = entityPlayer.proxyEid;
        entityData.meta = EntityMetaData.createDefault();
        session.sendPacket(entityData, true);
        if (restored.getGameMode().equals(GameMode.CREATIVE))
            session.sendCreativeInventory();
        if (session.getProxy().getAuthMode().equalsIgnoreCase("online")) {
            MovePlayerPacket pk = new MovePlayerPacket();
            pk.rtid = entityPlayer.proxyEid;
            pk.mode = MovePlayerPacket.MODE_TELEPORT;
            pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, (float) packet.getZ());
            pk.yaw = packet.getYaw();
            pk.pitch = packet.getPitch();
            pk.headYaw = packet.getYaw();
            if (entityPlayer.riding != 0) {
                CachedEntity vehicle = session.getEntityCache().getByLocalEID(entityPlayer.riding);
                if (vehicle != null)
                    pk.ridingRuntimeId = vehicle.eid;
            }
            session.sendPacket(pk, true);
        }
        // Notify the server
        BinaryStream bis = new BinaryStream();
        // command
        bis.putString("Notification");
        ClientPluginMessagePacket pluginMessage = new ClientPluginMessagePacket("DragonProxy", bis.get());
        session.getDownstream().send(pluginMessage);
        session.setSpawned();
        DragonProxy.getInstance().getLogger().info("Spawning " + session.getUsername() + " in world " + entityPlayer.dimention + " at " + entityPlayer.x + "/" + entityPlayer.y + "/" + entityPlayer.z);
        // send the confirmation
        ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId());
        ((PCDownstreamSession) session.getDownstream()).send(confirm);
        PlayerListPacket playerListPacket = new PlayerListPacket();
        Set<org.dragonet.protocol.type.PlayerListEntry> peEntries = new HashSet();
        for (CachedEntity entity : session.getEntityCache().getEntities().values()) {
            if (entity.peType == EntityType.PLAYER) {
                PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(entity.playerUniqueId);
                org.dragonet.protocol.type.PlayerListEntry peEntry = new org.dragonet.protocol.type.PlayerListEntry();
                peEntry.uuid = entity.playerUniqueId;
                peEntry.eid = entity.eid;
                peEntry.username = playerListEntry.getProfile().getName();
                peEntry.skin = Skin.DEFAULT_SKIN_STEVE;
                peEntry.xboxUserId = "null";
                peEntries.add(peEntry);
            }
            entity.spawn(session);
        }
        playerListPacket.type = PlayerListPacket.TYPE_ADD;
        playerListPacket.entries = peEntries.toArray(new org.dragonet.protocol.type.PlayerListEntry[peEntries.size()]);
        session.sendPacket(playerListPacket);
        entityPlayer.spawned = true;
        return null;
    }
    entityPlayer.absoluteMove(packet.getX(), packet.getY() + entityPlayer.peType.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch());
    session.getChunkCache().sendOrderedChunks();
    float offset = 0.01f;
    byte mode = MovePlayerPacket.MODE_NORMAL;
    ChunkPos chunk = new ChunkPos(NukkitMath.ceilDouble(packet.getX()) >> 4, NukkitMath.ceilDouble(packet.getZ()) >> 4);
    // check if destination is out of range
    if (!session.getChunkCache().getLoadedChunks().contains(chunk)) {
        mode = MovePlayerPacket.MODE_TELEPORT;
        offset = 0.2f;
        // System.out.println(packet.getX() + " " + packet.getZ());
        // System.out.println("out of range !" + chunk.toString());
        session.getChunkCache().sendOrderedChunks();
    // session.getChunkCache().getDebugGrid();
    }
    MovePlayerPacket pk = new MovePlayerPacket();
    pk.rtid = entityPlayer.proxyEid;
    pk.mode = mode;
    pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + EntityType.PLAYER.getOffset() + offset, (float) packet.getZ());
    pk.yaw = packet.getYaw();
    pk.pitch = packet.getPitch();
    pk.headYaw = packet.getYaw();
    if (entityPlayer.riding != 0) {
        CachedEntity vehicle = session.getEntityCache().getByLocalEID(entityPlayer.riding);
        if (vehicle != null)
            pk.ridingRuntimeId = vehicle.eid;
    }
    // System.out.println("From server " + packet.getX() + " " + packet.getY() + " " + packet.getZ() + " ");
    // System.out.println("Entity position " + entityPlayer.x + " " + (entityPlayer.y - EntityType.PLAYER.getOffset()) + " " + entityPlayer.z + " ");
    session.sendPacket(pk);
    // send the confirmation
    ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId());
    ((PCDownstreamSession) session.getDownstream()).send(confirm);
    return null;
}
Also used : ArrayList(java.util.ArrayList) PlayerListEntry(com.github.steveice10.mc.protocol.data.game.PlayerListEntry) ClientSettingsPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket) Vector3F(org.dragonet.common.maths.Vector3F) ChunkPos(org.dragonet.common.maths.ChunkPos) HashSet(java.util.HashSet) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) BinaryStream(org.dragonet.common.utilities.BinaryStream) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) ClientPluginMessagePacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) PCDownstreamSession(org.dragonet.proxy.network.PCDownstreamSession)

Example 2 with Vector3F

use of org.dragonet.common.maths.Vector3F in project DragonProxy by DragonetMC.

the class CachedEntity method spawn.

public void spawn(UpstreamSession session) {
    if (this.peType == EntityType.PLAYER) {
        PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(this.playerUniqueId);
        AddPlayerPacket pk = new AddPlayerPacket();
        pk.eid = this.proxyEid;
        pk.rtid = this.proxyEid;
        pk.uuid = this.playerUniqueId;
        pk.position = new Vector3F((float) this.x, (float) this.y, (float) this.z);
        pk.motion = Vector3F.ZERO;
        pk.yaw = this.yaw;
        pk.pitch = this.pitch;
        pk.username = playerListEntry.getProfile().getName();
        pk.meta = EntityMetaTranslator.translateToPE(session, this.pcMeta, this.peType);
        // hacky for now
        pk.meta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta(playerListEntry.getProfile().getName()));
        this.spawned = true;
        session.sendPacket(pk);
    } else if (this.peType == EntityType.ITEM) {
        AddItemEntityPacket pk = new AddItemEntityPacket();
        pk.rtid = this.proxyEid;
        pk.eid = this.proxyEid;
        pk.metadata = EntityMetaTranslator.translateToPE(session, this.pcMeta, this.peType);
        pk.item = ((SlotMeta) pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot;
        pk.position = new Vector3F((float) this.x, (float) this.y + this.peType.getOffset(), (float) this.z);
        pk.motion = new Vector3F((float) this.motionX, (float) this.motionY, (float) this.motionZ);
        this.spawned = true;
        session.sendPacket(pk);
    } else if (this.peType == EntityType.PAINTING) {
        AddPaintingPacket pk = new AddPaintingPacket();
        pk.rtid = this.proxyEid;
        pk.eid = this.proxyEid;
        pk.pos = new BlockPosition((int) this.x, (int) this.y, (int) this.z);
        pk.direction = 1;
        pk.title = "Kebab";
        this.spawned = true;
    // session.sendPacket(pk); //BUGGY
    } else if (this.peType != null) {
        AddEntityPacket pk = new AddEntityPacket();
        pk.rtid = this.proxyEid;
        pk.eid = this.proxyEid;
        pk.type = this.peType.getPeType();
        pk.position = new Vector3F((float) this.x, (float) this.y - this.peType.getOffset(), (float) this.z);
        pk.motion = new Vector3F((float) this.motionX, (float) this.motionY, (float) this.motionZ);
        pk.yaw = this.yaw;
        pk.pitch = this.pitch;
        pk.meta = EntityMetaTranslator.translateToPE(session, this.pcMeta, this.peType);
        // TODO: Hack for now. ;P
        pk.attributes = this.attributes.values();
        this.spawned = true;
        session.sendPacket(pk);
    }
    this.updateLinks(session);
    // Process equipments
    this.updateEquipment(session);
}
Also used : SlotMeta(org.dragonet.common.data.entity.meta.type.SlotMeta) Vector3F(org.dragonet.common.maths.Vector3F) BlockPosition(org.dragonet.common.maths.BlockPosition) PlayerListEntry(com.github.steveice10.mc.protocol.data.game.PlayerListEntry) ByteArrayMeta(org.dragonet.common.data.entity.meta.type.ByteArrayMeta)

Example 3 with Vector3F

use of org.dragonet.common.maths.Vector3F 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 4 with Vector3F

use of org.dragonet.common.maths.Vector3F 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 5 with Vector3F

use of org.dragonet.common.maths.Vector3F 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

Vector3F (org.dragonet.common.maths.Vector3F)13 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)9 PEPacket (org.dragonet.protocol.PEPacket)8 BlockPosition (org.dragonet.common.maths.BlockPosition)5 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)2 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)2 Section (org.dragonet.protocol.type.chunk.Section)2 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 AuthenticationService (com.github.steveice10.mc.auth.service.AuthenticationService)1 MinecraftProtocol (com.github.steveice10.mc.protocol.MinecraftProtocol)1 ExplodedBlockRecord (com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord)1 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)1 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)1 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ByteArrayMeta (org.dragonet.common.data.entity.meta.type.ByteArrayMeta)1