Search in sources :

Example 26 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class UpstreamSession method sendAllPackets.

public void sendAllPackets(PEPacket[] packets, boolean high_priority) {
    if (// <- this disable batched packets
    packets.length < 5 || true)
        for (PEPacket packet : packets) sendPacket(packet, high_priority);
    else {
        BatchPacket batchPacket = new BatchPacket();
        // System.out.println("BatchPacket :");
        for (PEPacket packet : packets) // System.out.println(" - " + packet.getClass().getSimpleName());
        if (high_priority) {
            batchPacket.packets.add(packet);
            break;
        }
        sendPacket(batchPacket, high_priority);
    }
}
Also used : BatchPacket(org.dragonet.protocol.packets.BatchPacket) PEPacket(org.dragonet.protocol.PEPacket)

Example 27 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PEPacketProcessor method onTick.

public void onTick() {
    int cnt = 0;
    Timings.playerNetworkReceiveTimer.startTiming();
    while (cnt < MAX_PACKETS_PER_CYCLE && !packets.isEmpty()) {
        cnt++;
        byte[] p = packets.pop();
        PEPacket[] packets;
        try {
            packets = Protocol.decode(p);
            if (packets == null || packets.length <= 0)
                continue;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        for (PEPacket decoded : packets) try (Timing timing = Timings.getReceiveDataPacketTiming(decoded)) {
            handlePacket(decoded);
        }
    }
    Timings.playerNetworkReceiveTimer.stopTiming();
}
Also used : PEPacket(org.dragonet.protocol.PEPacket) Timing(co.aikar.timings.Timing) JsonParseException(com.google.gson.JsonParseException)

Example 28 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class InventoryTranslatorRegister method sendPlayerInventory.

public static PEPacket[] sendPlayerInventory(UpstreamSession session) {
    CachedWindow win = session.getWindowCache().getPlayerInventory();
    // Translate and send
    InventoryContentPacket ret = new InventoryContentPacket();
    ret.windowId = ContainerId.INVENTORY.getId();
    ret.items = new Slot[40];
    // hotbar
    for (int i = 36; i < 45; i++) ret.items[i - 36] = ItemBlockTranslator.translateSlotToPE(win.slots[i]);
    // inventory
    for (int i = 9; i < 36; i++) // TODO: Add NBT support
    ret.items[i] = ItemBlockTranslator.translateSlotToPE(win.slots[i]);
    // armors
    for (int i = 5; i < 9; i++) ret.items[i + 31] = ItemBlockTranslator.translateSlotToPE(win.slots[i]);
    // TODO: Add armor support
    return new PEPacket[] { ret };
}
Also used : CachedWindow(org.dragonet.proxy.network.cache.CachedWindow) PEPacket(org.dragonet.protocol.PEPacket) InventoryContentPacket(org.dragonet.protocol.packets.InventoryContentPacket)

Aggregations

PEPacket (org.dragonet.protocol.PEPacket)28 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)14 Vector3F (org.dragonet.common.maths.Vector3F)8 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 BlockPosition (org.dragonet.common.maths.BlockPosition)4 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)3 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 Timing (co.aikar.timings.Timing)1 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 GameMode (com.github.steveice10.mc.protocol.data.game.entity.player.GameMode)1 ExplodedBlockRecord (com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord)1 BuiltinSound (com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound)1 TranslationMessage (com.github.steveice10.mc.protocol.data.message.TranslationMessage)1 ServerPlaySoundPacket (com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)1 JsonParseException (com.google.gson.JsonParseException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PocketPotionEffect (org.dragonet.common.data.PocketPotionEffect)1 PEEntityAttribute (org.dragonet.common.data.entity.PEEntityAttribute)1