Search in sources :

Example 1 with BlockEntityDataPacket

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

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

the class BlockEntityUtils method updateBlockEntity.

public static void updateBlockEntity(GeyserSession session, @Nonnull NbtMap blockEntity, Vector3i position) {
    BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket();
    blockEntityPacket.setBlockPosition(position);
    blockEntityPacket.setData(blockEntity);
    session.sendUpstreamPacket(blockEntityPacket);
}
Also used : BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)

Example 3 with BlockEntityDataPacket

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

the class BlockEntitySign method updateBlockEntitySign.

public void updateBlockEntitySign() {
    BlockEntityDataPacket blockEntityDataPacket = new BlockEntityDataPacket();
    blockEntityDataPacket.setBlockPosition(this.block.getLocation().toVector3i());
    blockEntityDataPacket.setData(this.toCompound().build());
    this.block.getWorld().sendDimensionPacket(blockEntityDataPacket, this.block.getLocation().getDimension());
}
Also used : BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)

Example 4 with BlockEntityDataPacket

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

the class BlockEntitySign method updateBlockEntitySign.

public void updateBlockEntitySign(NbtMap nbt, Player player) {
    String text = nbt.getString("Text", "");
    String[] splitLine = text.split("\n");
    ArrayList<String> lineList = new ArrayList<>();
    Collections.addAll(lineList, splitLine);
    BlockSignChangeEvent blockSignChangeEvent = new BlockSignChangeEvent(this.block, player, lineList);
    Server.getInstance().getPluginManager().callEvent(blockSignChangeEvent);
    if (blockSignChangeEvent.isCancelled()) {
        return;
    }
    this.lines.clear();
    this.lines.addAll(blockSignChangeEvent.getLines());
    BlockEntityDataPacket blockEntityDataPacket = new BlockEntityDataPacket();
    blockEntityDataPacket.setBlockPosition(this.block.getLocation().toVector3i());
    blockEntityDataPacket.setData(this.toCompound().build());
    this.block.getWorld().sendDimensionPacket(blockEntityDataPacket, this.block.getLocation().getDimension());
}
Also used : ArrayList(java.util.ArrayList) BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket) BlockSignChangeEvent(org.jukeboxmc.event.block.BlockSignChangeEvent)

Example 5 with BlockEntityDataPacket

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

the class BlockEntity method spawn.

public BlockEntity spawn() {
    World world = this.block.getWorld();
    Vector location = this.block.getLocation();
    BlockEntityDataPacket blockEntityDataPacket = new BlockEntityDataPacket();
    blockEntityDataPacket.setBlockPosition(location.toVector3i());
    blockEntityDataPacket.setData(this.toCompound().build());
    world.sendDimensionPacket(blockEntityDataPacket, location.getDimension());
    world.setBlockEntity(location, this, location.getDimension());
    return this;
}
Also used : BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket) World(org.jukeboxmc.world.World) Vector(org.jukeboxmc.math.Vector)

Aggregations

BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)9 Vector3i (com.nukkitx.math.vector.Vector3i)2 NbtMap (com.nukkitx.nbt.NbtMap)2 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)2 UpdateBlockPacket (com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)2 ArrayList (java.util.ArrayList)1 BeaconContainer (org.geysermc.geyser.inventory.BeaconContainer)1 Container (org.geysermc.geyser.inventory.Container)1 DoubleChestValue (org.geysermc.geyser.level.block.DoubleChestValue)1 BlockSignChangeEvent (org.jukeboxmc.event.block.BlockSignChangeEvent)1 Vector (org.jukeboxmc.math.Vector)1 World (org.jukeboxmc.world.World)1