Search in sources :

Example 1 with UpdateBlockPacket

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

the class ItemFrameEntity method updateBlock.

/**
 * Updates the item frame as a block
 */
public void updateBlock(boolean force) {
    if (!changed && !force) {
        // Don't send a block update packet - nothing changed
        return;
    }
    UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
    updateBlockPacket.setDataLayer(0);
    updateBlockPacket.setBlockPosition(bedrockPosition);
    updateBlockPacket.setRuntimeId(bedrockRuntimeId);
    updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
    updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
    updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
    session.sendUpstreamPacket(updateBlockPacket);
    BlockEntityDataPacket blockEntityDataPacket = new BlockEntityDataPacket();
    blockEntityDataPacket.setBlockPosition(bedrockPosition);
    if (cachedTag != null) {
        blockEntityDataPacket.setData(cachedTag);
    } else {
        blockEntityDataPacket.setData(getDefaultTag());
    }
    session.sendUpstreamPacket(blockEntityDataPacket);
    changed = false;
}
Also used : BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 2 with UpdateBlockPacket

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

the class BlockInventoryHolder method prepareInventory.

@Override
public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
    // (This could be a virtual inventory that the player is opening)
    if (checkInteractionPosition(session)) {
        // Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
        int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
        String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
        if (isValidBlock(javaBlockString)) {
            // We can safely use this block
            inventory.setHolderPosition(session.getLastInteractionBlockPosition());
            ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
            setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
            return;
        }
    }
    // Otherwise, time to conjure up a fake block!
    Vector3i position = session.getPlayerEntity().getPosition().toInt();
    position = position.add(Vector3i.UP);
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(position);
    blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState));
    blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
    session.sendUpstreamPacket(blockPacket);
    inventory.setHolderPosition(position);
    setCustomName(session, position, inventory, defaultJavaBlockState);
}
Also used : Container(org.geysermc.geyser.inventory.Container) Vector3i(com.nukkitx.math.vector.Vector3i) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 3 with UpdateBlockPacket

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

the class ChunkUtils method sendEmptyChunk.

public static void sendEmptyChunk(GeyserSession session, int chunkX, int chunkZ, boolean forceUpdate) {
    LevelChunkPacket data = new LevelChunkPacket();
    data.setChunkX(chunkX);
    data.setChunkZ(chunkZ);
    data.setSubChunksLength(0);
    data.setData(EMPTY_CHUNK_DATA);
    data.setCachingEnabled(false);
    session.sendUpstreamPacket(data);
    if (forceUpdate) {
        Vector3i pos = Vector3i.from(chunkX << 4, 80, chunkZ << 4);
        UpdateBlockPacket blockPacket = new UpdateBlockPacket();
        blockPacket.setBlockPosition(pos);
        blockPacket.setDataLayer(0);
        blockPacket.setRuntimeId(1);
        session.sendUpstreamPacket(blockPacket);
    }
}
Also used : LevelChunkPacket(com.nukkitx.protocol.bedrock.packet.LevelChunkPacket) Vector3i(com.nukkitx.math.vector.Vector3i) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 4 with UpdateBlockPacket

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

the class FlowerPotBlockEntityTranslator method updateBlock.

@Override
public void updateBlock(GeyserSession session, int blockState, Vector3i position) {
    NbtMap tag = getTag(session, blockState, position);
    BlockEntityUtils.updateBlockEntity(session, tag, position);
    UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
    updateBlockPacket.setDataLayer(0);
    updateBlockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(blockState));
    updateBlockPacket.setBlockPosition(position);
    updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
    updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
    updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
    session.sendUpstreamPacket(updateBlockPacket);
    BlockEntityUtils.updateBlockEntity(session, tag, position);
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 5 with UpdateBlockPacket

use of com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket 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)

Aggregations

UpdateBlockPacket (com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)9 Vector3i (com.nukkitx.math.vector.Vector3i)5 Container (org.geysermc.geyser.inventory.Container)4 NbtMap (com.nukkitx.nbt.NbtMap)2 BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)2 ContainerClosePacket (com.nukkitx.protocol.bedrock.packet.ContainerClosePacket)2 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)1 LevelChunkPacket (com.nukkitx.protocol.bedrock.packet.LevelChunkPacket)1 ItemFrameEntity (org.geysermc.geyser.entity.type.ItemFrameEntity)1 SkullPlayerEntity (org.geysermc.geyser.entity.type.player.SkullPlayerEntity)1 DoubleChestValue (org.geysermc.geyser.level.block.DoubleChestValue)1 BedrockOnlyBlockEntity (org.geysermc.geyser.translator.level.block.entity.BedrockOnlyBlockEntity)1