Search in sources :

Example 1 with ContainerClosePacket

use of com.nukkitx.protocol.bedrock.packet.ContainerClosePacket in project Geyser by GeyserMC.

the class DoubleChestInventoryTranslator method closeInventory.

@Override
public void closeInventory(GeyserSession session, Inventory inventory) {
    if (((Container) inventory).isUsingRealBlock()) {
        // No need to reset a block since we didn't change any blocks
        // But send a container close packet because we aren't destroying the original.
        ContainerClosePacket packet = new ContainerClosePacket();
        packet.setId((byte) inventory.getId());
        // TODO needs to be changed in Protocol to "server-side" or something
        packet.setUnknownBool0(true);
        session.sendUpstreamPacket(packet);
        return;
    }
    Vector3i holderPos = inventory.getHolderPosition();
    int realBlock = session.getGeyser().getWorldManager().getBlockAt(session, holderPos);
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(holderPos);
    blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(realBlock));
    session.sendUpstreamPacket(blockPacket);
    holderPos = holderPos.add(Vector3i.UNIT_X);
    realBlock = session.getGeyser().getWorldManager().getBlockAt(session, holderPos);
    blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(holderPos);
    blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(realBlock));
    session.sendUpstreamPacket(blockPacket);
}
Also used : Container(org.geysermc.geyser.inventory.Container) ContainerClosePacket(com.nukkitx.protocol.bedrock.packet.ContainerClosePacket) Vector3i(com.nukkitx.math.vector.Vector3i) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 2 with ContainerClosePacket

use of com.nukkitx.protocol.bedrock.packet.ContainerClosePacket in project Geyser by GeyserMC.

the class BlockInventoryHolder method closeInventory.

@Override
public void closeInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
    if (((Container) inventory).isUsingRealBlock()) {
        // No need to reset a block since we didn't change any blocks
        // But send a container close packet because we aren't destroying the original.
        ContainerClosePacket packet = new ContainerClosePacket();
        packet.setId((byte) inventory.getId());
        // TODO needs to be changed in Protocol to "server-side" or something
        packet.setUnknownBool0(true);
        session.sendUpstreamPacket(packet);
        return;
    }
    Vector3i holderPos = inventory.getHolderPosition();
    Position pos = new Position(holderPos.getX(), holderPos.getY(), holderPos.getZ());
    int realBlock = session.getGeyser().getWorldManager().getBlockAt(session, pos.getX(), pos.getY(), pos.getZ());
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(holderPos);
    blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(realBlock));
    blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
    session.sendUpstreamPacket(blockPacket);
}
Also used : Container(org.geysermc.geyser.inventory.Container) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ContainerClosePacket(com.nukkitx.protocol.bedrock.packet.ContainerClosePacket) Vector3i(com.nukkitx.math.vector.Vector3i) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Aggregations

Vector3i (com.nukkitx.math.vector.Vector3i)2 ContainerClosePacket (com.nukkitx.protocol.bedrock.packet.ContainerClosePacket)2 UpdateBlockPacket (com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)2 Container (org.geysermc.geyser.inventory.Container)2 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1