Search in sources :

Example 1 with ClientboundSectionBlocksUpdatePacket

use of net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket in project NotQuests by AlessioGr.

the class PacketInjector method spawnBeaconBeam.

public void spawnBeaconBeam(Player player, Location location) {
    // Prepare Data
    Connection connection = getConnection(getServerPlayer(player).connection);
    location = location.clone();
    BlockPos blockPos = new BlockPos(location.getX(), location.getY(), location.getZ());
    Chunk chunk = location.getChunk();
    CraftChunk craftChunk = (CraftChunk) chunk;
    LevelChunk levelChunk = craftChunk.getHandle();
    World world = location.getWorld();
    CraftWorld craftWorld = (CraftWorld) world;
    ServerLevel serverLevel = craftWorld.getHandle();
    // 
    BlockState blockState = location.getBlock().getState();
    blockState.setType(Material.BEACON);
    SectionPos sectionPos = SectionPos.of((int) location.getX(), (int) location.getY(), (int) location.getZ());
    ShortSet positions = ShortSet.of((short) 0);
    // PalettedContainer<BlockState> pcB = new PalettedContainer<>();
    // net.minecraft.world.level.block.state.BlockState[] presetBlockStates = serverLevel.chunkPacketBlockController.getPresetBlockStates(world, chunkPos, b0 << 4);
    // PalettedContainer<BlockState> datapaletteblock = new PalettedContainer<>(net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES, presetBlockStates);
    LevelChunkSection section = levelChunk.getHighestSection();
    ClientboundSectionBlocksUpdatePacket clientboundSectionBlocksUpdatePacket = new ClientboundSectionBlocksUpdatePacket(sectionPos, positions, section, true);
    main.sendMessage(player, "<main>Sending packet...");
    connection.send(clientboundSectionBlocksUpdatePacket);
    main.sendMessage(player, "<success>Packet sent!");
// ClientboundBlockUpdatePacket clientboundBlockUpdatePacket = new ClientboundBlockUpdatePacket(blockPos, BlockState.);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Connection(net.minecraft.network.Connection) ClientboundSectionBlocksUpdatePacket(net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) Chunk(org.bukkit.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) World(org.bukkit.World) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) CraftBlockState(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState) BlockState(org.bukkit.block.BlockState) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) ShortSet(it.unimi.dsi.fastutil.shorts.ShortSet) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) SectionPos(net.minecraft.core.SectionPos) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk)

Example 2 with ClientboundSectionBlocksUpdatePacket

use of net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket in project MechanicsMain by WeaponMechanics.

the class Block_1_17_R1 method getMultiBlockMaskPacket.

private ClientboundSectionBlocksUpdatePacket getMultiBlockMaskPacket(List<Block> blocks, @Nullable BlockState mask) {
    BlockPos position = ((CraftBlock) blocks.get(0)).getPosition();
    // Setup default information
    short[] locations = new short[blocks.size()];
    BlockState[] data = new BlockState[blocks.size()];
    for (int i = 0; i < locations.length; i++) {
        Block block = blocks.get(i);
        int x = block.getX() & 0xF;
        int y = block.getY() & 0xF;
        int z = block.getZ() & 0xF;
        short shortLocation = (short) (x << 8 | z << 4 | y);
        locations[i] = shortLocation;
        data[i] = mask;
    }
    ClientboundSectionBlocksUpdatePacket packet = new ClientboundSectionBlocksUpdatePacket(SectionPos.of(position), new ShortArraySet(0), null, false);
    ReflectionUtil.setField(multiBlockChangeB, packet, locations);
    ReflectionUtil.setField(multiBlockChangeC, packet, data);
    return packet;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) CraftBlockState(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState) ShortArraySet(it.unimi.dsi.fastutil.shorts.ShortArraySet) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) Block(org.bukkit.block.Block) ClientboundSectionBlocksUpdatePacket(net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket) BlockPos(net.minecraft.core.BlockPos) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock)

Example 3 with ClientboundSectionBlocksUpdatePacket

use of net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket in project MechanicsMain by WeaponMechanics.

the class Block_1_18_R1 method getMultiBlockMaskPacket.

private ClientboundSectionBlocksUpdatePacket getMultiBlockMaskPacket(List<Block> blocks, @Nullable BlockState mask) {
    BlockPos position = ((CraftBlock) blocks.get(0)).getPosition();
    // Setup default information
    short[] locations = new short[blocks.size()];
    BlockState[] data = new BlockState[blocks.size()];
    for (int i = 0; i < locations.length; i++) {
        Block block = blocks.get(i);
        int x = block.getX() & 0xF;
        int y = block.getY() & 0xF;
        int z = block.getZ() & 0xF;
        short shortLocation = (short) (x << 8 | z << 4 | y);
        locations[i] = shortLocation;
        data[i] = mask;
    }
    ClientboundSectionBlocksUpdatePacket packet = new ClientboundSectionBlocksUpdatePacket(SectionPos.of(position), new ShortArraySet(0), null, false);
    ReflectionUtil.setField(multiBlockChangeB, packet, locations);
    ReflectionUtil.setField(multiBlockChangeC, packet, data);
    return packet;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) CraftBlockState(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState) ShortArraySet(it.unimi.dsi.fastutil.shorts.ShortArraySet) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) Block(org.bukkit.block.Block) ClientboundSectionBlocksUpdatePacket(net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket) BlockPos(net.minecraft.core.BlockPos) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock)

Example 4 with ClientboundSectionBlocksUpdatePacket

use of net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket in project MechanicsMain by WeaponMechanics.

the class Block_1_18_R2 method getMultiBlockMaskPacket.

private ClientboundSectionBlocksUpdatePacket getMultiBlockMaskPacket(List<Block> blocks, @Nullable BlockState mask) {
    BlockPos position = ((CraftBlock) blocks.get(0)).getPosition();
    // Setup default information
    short[] locations = new short[blocks.size()];
    BlockState[] data = new BlockState[blocks.size()];
    for (int i = 0; i < locations.length; i++) {
        Block block = blocks.get(i);
        int x = block.getX() & 0xF;
        int y = block.getY() & 0xF;
        int z = block.getZ() & 0xF;
        short shortLocation = (short) (x << 8 | z << 4 | y);
        locations[i] = shortLocation;
        data[i] = mask;
    }
    ClientboundSectionBlocksUpdatePacket packet = new ClientboundSectionBlocksUpdatePacket(SectionPos.of(position), new ShortArraySet(0), null, false);
    ReflectionUtil.setField(multiBlockChangeB, packet, locations);
    ReflectionUtil.setField(multiBlockChangeC, packet, data);
    return packet;
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState) BlockState(net.minecraft.world.level.block.state.BlockState) ShortArraySet(it.unimi.dsi.fastutil.shorts.ShortArraySet) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) ClientboundSectionBlocksUpdatePacket(net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket) BlockPos(net.minecraft.core.BlockPos) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)

Aggregations

BlockPos (net.minecraft.core.BlockPos)4 ClientboundSectionBlocksUpdatePacket (net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket)4 ShortArraySet (it.unimi.dsi.fastutil.shorts.ShortArraySet)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 Block (org.bukkit.block.Block)3 CraftBlockState (org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState)2 ShortSet (it.unimi.dsi.fastutil.shorts.ShortSet)1 SectionPos (net.minecraft.core.SectionPos)1 Connection (net.minecraft.network.Connection)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)1 LevelChunkSection (net.minecraft.world.level.chunk.LevelChunkSection)1 Chunk (org.bukkit.Chunk)1 World (org.bukkit.World)1 BlockState (org.bukkit.block.BlockState)1 CraftBlock (org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock)1 CraftBlockState (org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState)1 CraftBlock (org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock)1 CraftBlockState (org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState)1 CraftChunk (org.bukkit.craftbukkit.v1_18_R2.CraftChunk)1