Search in sources :

Example 1 with UpdateBlockPacket

use of org.dragonet.net.packet.minecraft.UpdateBlockPacket 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)

Example 2 with UpdateBlockPacket

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

the class UseItemPacketTranslator method handleSpecific.

@Override
public Message[] handleSpecific(UseItemPacket packet) {
    UseItemPacket pkUseItem = (UseItemPacket) packet;
    System.out.println("FACE=" + (pkUseItem.face & 0xFF) + ", ITEM=" + packet.item);
    if (pkUseItem.face == 0xFF) {
        // Air touch
        // Left click air
        PlayerSwingArmMessage msg = new PlayerSwingArmMessage();
        return new Message[] { msg };
    }
    if (!(pkUseItem.face >= 0 && pkUseItem.face < 6)) {
        return null;
    }
    // Check the slot
    ItemStack test_holding = this.getSession().getPlayer().getInventory().getItemInHand();
    if (packet.item.id != this.getTranslator().getItemTranslator().translateToPE(test_holding.getTypeId()) || packet.item.meta != test_holding.getDurability()) {
        // Not same, resend slot
        PlayerEquipmentPacket pkRet = new PlayerEquipmentPacket();
        pkRet.eid = this.getSession().getPlayer().getEntityId();
        pkRet.item = new PEInventorySlot((short) 0, (byte) 0, (short) 0);
        pkRet.item.id = (short) (this.getTranslator().getItemTranslator().translateToPE(test_holding.getTypeId()) & 0xFFFF);
        pkRet.item.count = (byte) (test_holding.getAmount() & 0xFF);
        pkRet.item.meta = test_holding.getDurability();
        pkRet.selectedSlot = this.getSession().getPlayer().getInventory().getHeldItemSlot();
        // Resend block
        UpdateBlockPacket pkUpdateBlock = new UpdateBlockPacket();
        UpdateBlockPacket.UpdateBlockRecord blockRec = new UpdateBlockPacket.UpdateBlockRecord();
        blockRec.x = packet.x;
        blockRec.z = packet.z;
        blockRec.y = (byte) (packet.y & 0xFF);
        blockRec.block = (byte) (this.getSession().getPlayer().getWorld().getBlockAt(pkUseItem.x, pkUseItem.y, pkUseItem.z).getTypeId() & 0xFF);
        blockRec.meta = (byte) (this.getSession().getPlayer().getWorld().getBlockAt(pkUseItem.x, pkUseItem.y, pkUseItem.z).getData() & 0xFF);
        pkUpdateBlock.records = new UpdateBlockPacket.UpdateBlockRecord[] { blockRec };
        getSession().send(pkRet);
        getSession().send(pkUpdateBlock);
        return null;
    }
    // Copied from Glowstone class BlockPlacementHandler
    new BlockPlacementHandler().handle(getSession(), new BlockPlacementMessage(packet.x, packet.y, packet.z, packet.face, test_holding, 0, 0, 0));
    return null;
}
Also used : BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) UseItemPacket(org.dragonet.net.packet.minecraft.UseItemPacket) Message(com.flowpowered.networking.Message) PlayerSwingArmMessage(net.glowstone.net.message.play.player.PlayerSwingArmMessage) BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) ItemStack(org.bukkit.inventory.ItemStack) PlayerSwingArmMessage(net.glowstone.net.message.play.player.PlayerSwingArmMessage) PlayerEquipmentPacket(org.dragonet.net.packet.minecraft.PlayerEquipmentPacket) BlockPlacementHandler(net.glowstone.net.handler.play.player.BlockPlacementHandler) PEInventorySlot(org.dragonet.inventory.PEInventorySlot) UpdateBlockPacket(org.dragonet.net.packet.minecraft.UpdateBlockPacket)

Example 3 with UpdateBlockPacket

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

the class BlockChangeMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(BlockChangeMessage packet) {
    UpdateBlockPacket pkBC = new UpdateBlockPacket();
    UpdateBlockPacket.UpdateBlockRecord rec = new UpdateBlockPacket.UpdateBlockRecord();
    rec.x = packet.x;
    rec.z = packet.z;
    rec.y = (byte) (packet.y & 0xFF);
    rec.block = (byte) (this.getTranslator().getItemTranslator().translateToPE(packet.type >> 4) & 0xFF);
    rec.meta = UpdateBlockPacket.FLAG_ALL;
    pkBC.records = new UpdateBlockPacket.UpdateBlockRecord[] { rec };
    return new PEPacket[] { pkBC };
}
Also used : PEPacket(org.dragonet.net.packet.minecraft.PEPacket) UpdateBlockPacket(org.dragonet.net.packet.minecraft.UpdateBlockPacket)

Aggregations

UpdateBlockPacket (org.dragonet.net.packet.minecraft.UpdateBlockPacket)3 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)2 Message (com.flowpowered.networking.Message)1 BlockPlacementHandler (net.glowstone.net.handler.play.player.BlockPlacementHandler)1 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)1 MultiBlockChangeMessage (net.glowstone.net.message.play.game.MultiBlockChangeMessage)1 BlockPlacementMessage (net.glowstone.net.message.play.player.BlockPlacementMessage)1 PlayerSwingArmMessage (net.glowstone.net.message.play.player.PlayerSwingArmMessage)1 ItemStack (org.bukkit.inventory.ItemStack)1 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)1 PlayerEquipmentPacket (org.dragonet.net.packet.minecraft.PlayerEquipmentPacket)1 UseItemPacket (org.dragonet.net.packet.minecraft.UseItemPacket)1