Search in sources :

Example 16 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class SpawnPlayerMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(SpawnPlayerMessage packet) {
    if (!this.getTranslator().cachedEntityIDs.contains(packet.id)) {
        //Add to the spawned entity list
        this.getTranslator().cachedEntityIDs.add(packet.id);
    }
    //Register this id as a player
    this.getTranslator().cachedPlayerEntities.add(packet.id);
    AddPlayerPacket pkAddPlayer = new AddPlayerPacket();
    pkAddPlayer.uuid = packet.getUuid();
    pkAddPlayer.eid = packet.getId();
    pkAddPlayer.username = this.getSession().getServer().getPlayer(packet.getUuid()).getDisplayName();
    pkAddPlayer.x = (float) packet.getX() / 32;
    pkAddPlayer.y = (float) packet.getY() / 32;
    pkAddPlayer.z = (float) packet.getZ() / 32;
    //return (int) (((loc.getYaw() % 360) / 360) * 256);
    pkAddPlayer.speedX = 0.0f;
    pkAddPlayer.speedY = 0.0f;
    pkAddPlayer.speedZ = 0.0f;
    pkAddPlayer.yaw = ((float) packet.getRotation() / 256) * 360;
    pkAddPlayer.pitch = ((float) packet.getPitch() / 256) * 360;
    //pkAddPlayer.metadata = EntityMetaData.getMetaDataFromPlayer((GlowPlayer) this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.getId())); TODO Fix the metadata, this one of the reasons why skins weren't working properly!
    PlayerListPacket lst = new PlayerListPacket(new PlayerListPacket.PlayerInfo(packet.getUuid(), packet.getId(), pkAddPlayer.username, true, false, DefaultSkin.getDefaultSkin()));
    return new PEPacket[] { pkAddPlayer, lst };
}
Also used : AddPlayerPacket(org.dragonet.net.packet.minecraft.AddPlayerPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) PlayerListPacket(org.dragonet.net.packet.minecraft.PlayerListPacket)

Example 17 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class EntityMetadataMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(EntityMetadataMessage packet) {
    if (!this.getTranslator().cachedEntityIDs.contains(packet.id)) {
        //Not spawned yet, let's create them
        if (this.getTranslator().cachedSpawnObjects.containsKey(packet.id)) {
            //Spawn it :) 
            SpawnObjectMessage msgObj = this.getTranslator().cachedSpawnObjects.get(packet.id);
            switch(msgObj.type) {
                case //Dropped Item
                2:
                    AddItemEntityPacket pkAddItemEntity = new AddItemEntityPacket();
                    pkAddItemEntity.eid = msgObj.id;
                    pkAddItemEntity.item = new PEInventorySlot((short) (((ItemStack) packet.entries.get(0).value).getTypeId() & 0xFFFF), (byte) (((ItemStack) packet.entries.get(0).value).getAmount() & 0xFF), (short) (((ItemStack) packet.entries.get(0).value).getDurability() & 0xFFFF));
                    pkAddItemEntity.x = (float) msgObj.velX / 32;
                    pkAddItemEntity.y = (float) msgObj.velY / 32;
                    pkAddItemEntity.z = (float) msgObj.velZ / 32;
                    return new PEPacket[] { pkAddItemEntity };
            }
            //Remove it
            this.getTranslator().cachedSpawnObjects.remove(packet.id);
        } else {
            return null;
        }
    }
    return null;
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) AddItemEntityPacket(org.dragonet.net.packet.minecraft.AddItemEntityPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) PEInventorySlot(org.dragonet.inventory.PEInventorySlot)

Example 18 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class EntityVelocityMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(EntityVelocityMessage packet) {
    SetEntityMotionPacket pkMotion = new SetEntityMotionPacket();
    SetEntityMotionPacket.EntityMotionData data = new SetEntityMotionPacket.EntityMotionData();
    data.eid = packet.id;
    data.motionX = (float) packet.velocityX / 32;
    data.motionY = (float) packet.velocityY / 32;
    data.motionZ = (float) packet.velocityZ / 32;
    pkMotion.motions = new SetEntityMotionPacket.EntityMotionData[] { data };
    return new PEPacket[] { pkMotion };
}
Also used : SetEntityMotionPacket(org.dragonet.net.packet.minecraft.SetEntityMotionPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket)

Example 19 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class HealthMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(HealthMessage packet) {
    int h = (int) packet.health;
    if (h <= 0) {
        //DEAD
        SetHealthPacket pk1 = new SetHealthPacket(h);
        RespawnPacket pk2 = new RespawnPacket();
        pk2.x = (float) getTranslator().getSession().getServer().getWorlds().get(0).getSpawnLocation().getX();
        pk2.y = (float) getTranslator().getSession().getServer().getWorlds().get(0).getSpawnLocation().getY();
        pk2.z = (float) getTranslator().getSession().getServer().getWorlds().get(0).getSpawnLocation().getZ();
        return new PEPacket[] { pk1, pk2 };
    } else {
        SetHealthPacket pk = new SetHealthPacket(h);
        return new PEPacket[] { pk };
    }
}
Also used : SetHealthPacket(org.dragonet.net.packet.minecraft.SetHealthPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) RespawnPacket(org.dragonet.net.packet.minecraft.RespawnPacket)

Example 20 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class MultiBlockChangeMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(MultiBlockChangeMessage packet) {
    UpdateBlockPacket pkBC = new UpdateBlockPacket();
    pkBC.records = new UpdateBlockPacket.UpdateBlockRecord[packet.records.size()];
    //PEPacket[] packets = new PEPacket[msgMBC.records.size()];
    int i = 0;
    for (BlockChangeMessage msgBC : packet.records) {
        //packets[i] = this.translateToPE(msgBC)[0];
        pkBC.records[i] = new UpdateBlockPacket.UpdateBlockRecord();
        pkBC.records[i].x = msgBC.x;
        pkBC.records[i].z = msgBC.z;
        pkBC.records[i].y = (byte) (msgBC.y & 0xFF);
        pkBC.records[i].block = (byte) (this.getTranslator().getItemTranslator().translateToPE(msgBC.type >> 4) & 0xFF);
        pkBC.records[i].meta = UpdateBlockPacket.FLAG_ALL_PRIORITY;
        i++;
    }
    return new PEPacket[] { pkBC };
}
Also used : PEPacket(org.dragonet.net.packet.minecraft.PEPacket) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) UpdateBlockPacket(org.dragonet.net.packet.minecraft.UpdateBlockPacket)

Aggregations

PEPacket (org.dragonet.net.packet.minecraft.PEPacket)22 MovePlayerPacket (org.dragonet.net.packet.minecraft.MovePlayerPacket)4 GlowPlayer (net.glowstone.entity.GlowPlayer)3 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)3 Entity (org.bukkit.entity.Entity)2 MoveEntitiesPacket (org.dragonet.net.packet.minecraft.MoveEntitiesPacket)2 PlayerListPacket (org.dragonet.net.packet.minecraft.PlayerListPacket)2 UpdateBlockPacket (org.dragonet.net.packet.minecraft.UpdateBlockPacket)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)1 SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)1 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)1 MultiBlockChangeMessage (net.glowstone.net.message.play.game.MultiBlockChangeMessage)1 CloseWindowMessage (net.glowstone.net.message.play.inv.CloseWindowMessage)1 Player (org.bukkit.entity.Player)1 PocketPotionEffect (org.dragonet.PocketPotionEffect)1 AddItemEntityPacket (org.dragonet.net.packet.minecraft.AddItemEntityPacket)1 AddPlayerPacket (org.dragonet.net.packet.minecraft.AddPlayerPacket)1 AnimatePacket (org.dragonet.net.packet.minecraft.AnimatePacket)1