Search in sources :

Example 6 with ContainerOpenPacket

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

the class BlockInventoryHolder method openInventory.

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

Example 7 with ContainerOpenPacket

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

the class JavaBlockEntityDataTranslator method translate.

@Override
public void translate(GeyserSession session, ClientboundBlockEntityDataPacket packet) {
    final BlockEntityType type = packet.getType();
    if (type == null) {
        return;
    }
    BlockEntityTranslator translator = BlockEntityUtils.getBlockEntityTranslator(type);
    // The Java block state is used in BlockEntityTranslator.translateTag() to make up for some inconsistencies
    // between Java block states and Bedrock block entity data
    int blockState;
    if (translator instanceof RequiresBlockState) {
        blockState = session.getGeyser().getWorldManager().getBlockAt(session, packet.getPosition());
    } else {
        blockState = BlockStateValues.JAVA_AIR_ID;
    }
    Position position = packet.getPosition();
    BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(type, position.getX(), position.getY(), position.getZ(), packet.getNbt(), blockState), packet.getPosition());
    // Check for custom skulls.
    if (session.getPreferencesCache().showCustomSkulls() && packet.getNbt() != null && packet.getNbt().contains("SkullOwner")) {
        SkullBlockEntityTranslator.spawnPlayer(session, packet.getNbt(), position.getX(), position.getY(), position.getZ(), blockState);
    }
    // TODO 1.18 re-test
    if (type == BlockEntityType.COMMAND_BLOCK && session.getOpPermissionLevel() >= 2 && session.getGameMode() == GameMode.CREATIVE && packet.getNbt() != null && packet.getNbt().size() > 5) {
        ContainerOpenPacket openPacket = new ContainerOpenPacket();
        openPacket.setBlockPosition(Vector3i.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
        openPacket.setId((byte) 1);
        openPacket.setType(ContainerType.COMMAND_BLOCK);
        openPacket.setUniqueEntityId(-1);
        session.sendUpstreamPacket(openPacket);
    }
}
Also used : BlockEntityType(com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) SkullBlockEntityTranslator(org.geysermc.geyser.translator.level.block.entity.SkullBlockEntityTranslator) BlockEntityTranslator(org.geysermc.geyser.translator.level.block.entity.BlockEntityTranslator) RequiresBlockState(org.geysermc.geyser.translator.level.block.entity.RequiresBlockState) 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