Search in sources :

Example 1 with BlockEntityUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket in project UniversalGraves by Patbox.

the class GravesLookType method sendHeadToPlayer.

public static void sendHeadToPlayer(ServerPlayerEntity player, BlockPos pos, NbtCompound compound) {
    if (compound != null) {
        compound.putString("id", "minecraft:skull");
        compound.putInt("x", pos.getX());
        compound.putInt("y", pos.getY());
        compound.putInt("z", pos.getZ());
        player.networkHandler.sendPacket(new BlockEntityUpdateS2CPacket(pos, 4, compound));
    }
}
Also used : BlockEntityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket)

Example 2 with BlockEntityUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket in project FastAsyncWorldEdit by IntellectualSites.

the class FabricPlayer method sendFakeBlock.

@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    World world = getWorld();
    if (!(world instanceof FabricWorld)) {
        return;
    }
    BlockPos loc = FabricAdapter.toBlockPos(pos);
    if (block == null) {
        final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket(((FabricWorld) world).getWorld(), loc);
        player.networkHandler.sendPacket(packetOut);
    } else {
        final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket();
        PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
        buf.writeBlockPos(loc);
        buf.writeVarInt(Block.getRawIdFromState(FabricAdapter.adapt(block.toImmutableState())));
        try {
            packetOut.read(buf);
        } catch (IOException e) {
            return;
        }
        player.networkHandler.sendPacket(packetOut);
        if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
            final BaseBlock baseBlock = (BaseBlock) block;
            final CompoundTag nbtData = baseBlock.getNbtData();
            if (nbtData != null) {
                player.networkHandler.sendPacket(new BlockEntityUpdateS2CPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
            }
        }
    }
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) BlockEntityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) CompoundTag(com.sk89q.jnbt.CompoundTag)

Aggregations

BlockEntityUpdateS2CPacket (net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket)2 CompoundTag (com.sk89q.jnbt.CompoundTag)1 World (com.sk89q.worldedit.world.World)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 IOException (java.io.IOException)1 BlockUpdateS2CPacket (net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket)1 PacketByteBuf (net.minecraft.util.PacketByteBuf)1 BlockPos (net.minecraft.util.math.BlockPos)1