Search in sources :

Example 1 with ContainerOpenPacket

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

the class CommandBlockMinecartEntity method interact.

@Override
public InteractionResult interact(Hand hand) {
    if (session.canUseCommandBlocks()) {
        // Client-side GUI required
        ContainerOpenPacket openPacket = new ContainerOpenPacket();
        openPacket.setBlockPosition(Vector3i.ZERO);
        openPacket.setId((byte) 1);
        openPacket.setType(ContainerType.COMMAND_BLOCK);
        openPacket.setUniqueEntityId(geyserId);
        session.sendUpstreamPacket(openPacket);
        return InteractionResult.SUCCESS;
    } else {
        return InteractionResult.PASS;
    }
}
Also used : ContainerOpenPacket(com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket)

Example 2 with ContainerOpenPacket

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

the class DoubleChestInventoryTranslator method openInventory.

@Override
public void openInventory(GeyserSession session, Inventory inventory) {
    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
    containerOpenPacket.setId((byte) inventory.getId());
    containerOpenPacket.setType(ContainerType.CONTAINER);
    containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
    containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
    session.sendUpstreamPacket(containerOpenPacket);
}
Also used : ContainerOpenPacket(com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket)

Example 3 with ContainerOpenPacket

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

the class BedrockInteractTranslator method translate.

@Override
public void translate(GeyserSession session, InteractPacket packet) {
    Entity entity;
    if (packet.getRuntimeEntityId() == session.getPlayerEntity().getGeyserId()) {
        // Player is not in entity cache
        entity = session.getPlayerEntity();
    } else {
        entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
    }
    if (entity == null)
        return;
    switch(packet.getAction()) {
        case INTERACT:
            if (session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) {
                break;
            }
            ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
            session.sendDownstreamPacket(interactPacket);
            break;
        case DAMAGE:
            ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
            session.sendDownstreamPacket(attackPacket);
            break;
        case LEAVE_VEHICLE:
            ServerboundPlayerCommandPacket sneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
            session.sendDownstreamPacket(sneakPacket);
            break;
        case MOUSEOVER:
            // Handle the buttons for mobile - "Mount", etc; and the suggestions for console - "ZL: Mount", etc
            if (packet.getRuntimeEntityId() != 0) {
                Entity interactEntity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
                session.setMouseoverEntity(interactEntity);
                if (interactEntity == null) {
                    return;
                }
                interactEntity.updateInteractiveTag();
            } else {
                if (session.getMouseoverEntity() != null) {
                    // No interactive tag should be sent
                    session.setMouseoverEntity(null);
                    session.getPlayerEntity().getDirtyMetadata().put(EntityData.INTERACTIVE_TAG, "");
                    session.getPlayerEntity().updateBedrockMetadata();
                }
            }
            break;
        case OPEN_INVENTORY:
            if (session.getOpenInventory() == null) {
                Entity ridingEntity = session.getPlayerEntity().getVehicle();
                if (ridingEntity instanceof AbstractHorseEntity) {
                    if (ridingEntity.getFlag(EntityFlag.TAMED)) {
                        // We should request to open the horse inventory instead
                        ServerboundPlayerCommandPacket openHorseWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_HORSE_INVENTORY);
                        session.sendDownstreamPacket(openHorseWindowPacket);
                    }
                } else {
                    session.setOpenInventory(session.getPlayerInventory());
                    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
                    containerOpenPacket.setId((byte) 0);
                    containerOpenPacket.setType(ContainerType.INVENTORY);
                    containerOpenPacket.setUniqueEntityId(-1);
                    containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
                    session.sendUpstreamPacket(containerOpenPacket);
                }
            }
            break;
    }
}
Also used : AbstractHorseEntity(org.geysermc.geyser.entity.type.living.animal.horse.AbstractHorseEntity) AbstractHorseEntity(org.geysermc.geyser.entity.type.living.animal.horse.AbstractHorseEntity) Entity(org.geysermc.geyser.entity.type.Entity) ServerboundInteractPacket(com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket) ServerboundPlayerCommandPacket(com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket) ContainerOpenPacket(com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket)

Example 4 with ContainerOpenPacket

use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project JukeboxMC by LucGamesYT.

the class ContainerInventory method addViewer.

public void addViewer(Player player, Vector position, byte windowId) {
    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
    containerOpenPacket.setUniqueEntityId(this.holderId);
    containerOpenPacket.setId(windowId);
    containerOpenPacket.setType(this.getWindowTypeId());
    containerOpenPacket.setBlockPosition(position.toVector3i());
    player.sendPacket(containerOpenPacket);
    super.addViewer(player);
    this.onOpen(player);
}
Also used : ContainerOpenPacket(com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket)

Example 5 with ContainerOpenPacket

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

the class Generic3X3InventoryTranslator method openInventory.

@Override
public void openInventory(GeyserSession session, Inventory inventory) {
    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
    containerOpenPacket.setId((byte) inventory.getId());
    // Required for opening the real block - otherwise, if the container type is incorrect, it refuses to open
    containerOpenPacket.setType(((Generic3X3Container) inventory).isDropper() ? com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DROPPER : com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DISPENSER);
    containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
    containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
    session.sendUpstreamPacket(containerOpenPacket);
}
Also used : Generic3X3Container(org.geysermc.geyser.inventory.Generic3X3Container) ContainerOpenPacket(com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket)

Aggregations

ContainerOpenPacket (com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket)7 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 BlockEntityType (com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType)1 ServerboundInteractPacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket)1 ServerboundPlayerCommandPacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket)1 Entity (org.geysermc.geyser.entity.type.Entity)1 AbstractHorseEntity (org.geysermc.geyser.entity.type.living.animal.horse.AbstractHorseEntity)1 Generic3X3Container (org.geysermc.geyser.inventory.Generic3X3Container)1 BlockEntityTranslator (org.geysermc.geyser.translator.level.block.entity.BlockEntityTranslator)1 RequiresBlockState (org.geysermc.geyser.translator.level.block.entity.RequiresBlockState)1 SkullBlockEntityTranslator (org.geysermc.geyser.translator.level.block.entity.SkullBlockEntityTranslator)1