Search in sources :

Example 1 with BlockUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket 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)

Example 2 with BlockUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket in project BleachHack by BleachDrinker420.

the class ChunkProcessor method onReadPacket.

@BleachSubscribe
public void onReadPacket(EventPacket.Read event) {
    if (MinecraftClient.getInstance().world == null)
        return;
    if (updateBlockConsumer != null && event.getPacket() instanceof BlockUpdateS2CPacket) {
        BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.getPacket();
        executor.execute(() -> updateBlockConsumer.accept(packet.getPos(), packet.getState()));
    } else if (updateBlockConsumer != null && event.getPacket() instanceof ExplosionS2CPacket) {
        ExplosionS2CPacket packet = (ExplosionS2CPacket) event.getPacket();
        for (BlockPos pos : packet.getAffectedBlocks()) {
            executor.execute(() -> updateBlockConsumer.accept(pos, Blocks.AIR.getDefaultState()));
        }
    } else if (updateBlockConsumer != null && event.getPacket() instanceof ChunkDeltaUpdateS2CPacket) {
        ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.getPacket();
        packet.visitUpdates((pos, state) -> {
            BlockPos impos = /*ter*/
            pos.toImmutable();
            executor.execute(() -> updateBlockConsumer.accept(impos, state));
        });
    } else if (loadChunkConsumer != null && event.getPacket() instanceof ChunkDataS2CPacket) {
        ChunkDataS2CPacket packet = (ChunkDataS2CPacket) event.getPacket();
        ChunkPos cp = new ChunkPos(packet.getX(), packet.getZ());
        WorldChunk chunk = new WorldChunk(MinecraftClient.getInstance().world, cp, null);
        chunk.loadFromPacket(null, packet.getReadBuffer(), new NbtCompound(), packet.getVerticalStripBitmask());
        executor.execute(() -> loadChunkConsumer.accept(cp, chunk));
    } else if (unloadChunkConsumer != null && event.getPacket() instanceof UnloadChunkS2CPacket) {
        UnloadChunkS2CPacket packet = (UnloadChunkS2CPacket) event.getPacket();
        ChunkPos cp = new ChunkPos(packet.getX(), packet.getZ());
        WorldChunk chunk = MinecraftClient.getInstance().world.getChunk(cp.x, cp.z);
        executor.execute(() -> unloadChunkConsumer.accept(cp, chunk));
    }
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) ExplosionS2CPacket(net.minecraft.network.packet.s2c.play.ExplosionS2CPacket) NbtCompound(net.minecraft.nbt.NbtCompound) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkDataS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) UnloadChunkS2CPacket(net.minecraft.network.packet.s2c.play.UnloadChunkS2CPacket) ChunkDeltaUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 3 with BlockUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket in project Hypnotic-Client by Hypnotic-Development.

the class Search method receivePacket.

@EventTarget
public void receivePacket(EventReceivePacket event) {
    if (event.getPacket() instanceof DisconnectS2CPacket || event.getPacket() instanceof GameJoinS2CPacket || event.getPacket() instanceof PlayerRespawnS2CPacket) {
        reset();
    } else if (event.getPacket() instanceof BlockUpdateS2CPacket) {
        BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.getPacket();
        queuedBlocks.add(Pair.of(packet.getPos(), packet.getState()));
    } else if (event.getPacket() instanceof ExplosionS2CPacket) {
        ExplosionS2CPacket packet = (ExplosionS2CPacket) event.getPacket();
        for (BlockPos pos : packet.getAffectedBlocks()) {
            queuedBlocks.add(Pair.of(pos, Blocks.AIR.getDefaultState()));
        }
    } else if (event.getPacket() instanceof ChunkDeltaUpdateS2CPacket) {
        ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.getPacket();
        packet.visitUpdates((pos, state) -> queuedBlocks.add(Pair.of(pos.toImmutable(), state)));
    } else if (event.getPacket() instanceof ChunkDataS2CPacket) {
        ChunkDataS2CPacket packet = (ChunkDataS2CPacket) event.getPacket();
        ChunkPos cp = new ChunkPos(packet.getX(), packet.getZ());
        queuedChunks.add(cp);
        queuedUnloads.remove(cp);
    } else if (event.getPacket() instanceof UnloadChunkS2CPacket) {
        UnloadChunkS2CPacket packet = (UnloadChunkS2CPacket) event.getPacket();
        queuedUnloads.add(new ChunkPos(packet.getX(), packet.getZ()));
    }
}
Also used : Color(java.awt.Color) ExplosionS2CPacket(net.minecraft.network.packet.s2c.play.ExplosionS2CPacket) Category(dev.hypnotic.module.Category) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) DisconnectS2CPacket(net.minecraft.network.packet.s2c.play.DisconnectS2CPacket) BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) EventTarget(dev.hypnotic.event.EventTarget) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Map(java.util.Map) PlayerRespawnS2CPacket(net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket) Chunk(net.minecraft.world.chunk.Chunk) BlockState(net.minecraft.block.BlockState) ExecutorService(java.util.concurrent.ExecutorService) ChunkDeltaUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket) EventRender3D(dev.hypnotic.event.events.EventRender3D) WorldUtils(dev.hypnotic.utils.world.WorldUtils) GameJoinS2CPacket(net.minecraft.network.packet.s2c.play.GameJoinS2CPacket) Set(java.util.Set) ChunkPos(net.minecraft.util.math.ChunkPos) VoxelShapes(net.minecraft.util.shape.VoxelShapes) BlockPos(net.minecraft.util.math.BlockPos) RenderUtils(dev.hypnotic.utils.render.RenderUtils) VoxelShape(net.minecraft.util.shape.VoxelShape) Executors(java.util.concurrent.Executors) Blocks(net.minecraft.block.Blocks) ExecutionException(java.util.concurrent.ExecutionException) UnloadChunkS2CPacket(net.minecraft.network.packet.s2c.play.UnloadChunkS2CPacket) EventReceivePacket(dev.hypnotic.event.events.EventReceivePacket) Entry(java.util.Map.Entry) Mod(dev.hypnotic.module.Mod) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) ChunkDataS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket) BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) ExplosionS2CPacket(net.minecraft.network.packet.s2c.play.ExplosionS2CPacket) PlayerRespawnS2CPacket(net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket) GameJoinS2CPacket(net.minecraft.network.packet.s2c.play.GameJoinS2CPacket) ChunkDataS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) UnloadChunkS2CPacket(net.minecraft.network.packet.s2c.play.UnloadChunkS2CPacket) ChunkDeltaUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket) DisconnectS2CPacket(net.minecraft.network.packet.s2c.play.DisconnectS2CPacket) EventTarget(dev.hypnotic.event.EventTarget)

Example 4 with BlockUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket in project Hypnotic-Client by Hypnotic-Development.

the class NewChunks method onReadPacket.

@EventTarget
public void onReadPacket(EventReceivePacket event) {
    Direction[] searchDirs = new Direction[] { Direction.EAST, Direction.NORTH, Direction.WEST, Direction.SOUTH, Direction.UP };
    if (event.getPacket() instanceof ChunkDeltaUpdateS2CPacket) {
        ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.getPacket();
        packet.visitUpdates((pos, state) -> {
            if (!state.getFluidState().isEmpty() && !state.getFluidState().isStill()) {
                ChunkPos chunkPos = new ChunkPos(pos);
                for (Direction dir : searchDirs) {
                    if (mc.world.getBlockState(pos.offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
                        newChunks.add(chunkPos);
                        return;
                    }
                }
            }
        });
    } else if (event.getPacket() instanceof BlockUpdateS2CPacket) {
        BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.getPacket();
        if (!packet.getState().getFluidState().isEmpty() && !packet.getState().getFluidState().isStill()) {
            ChunkPos chunkPos = new ChunkPos(packet.getPos());
            for (Direction dir : searchDirs) {
                if (mc.world.getBlockState(packet.getPos().offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
                    newChunks.add(chunkPos);
                    return;
                }
            }
        }
    }
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) ChunkPos(net.minecraft.util.math.ChunkPos) Direction(net.minecraft.util.math.Direction) ChunkDeltaUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket) EventTarget(dev.hypnotic.event.EventTarget)

Aggregations

BlockUpdateS2CPacket (net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket)4 ChunkDeltaUpdateS2CPacket (net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket)3 BlockPos (net.minecraft.util.math.BlockPos)3 ChunkPos (net.minecraft.util.math.ChunkPos)3 EventTarget (dev.hypnotic.event.EventTarget)2 ChunkDataS2CPacket (net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket)2 ExplosionS2CPacket (net.minecraft.network.packet.s2c.play.ExplosionS2CPacket)2 UnloadChunkS2CPacket (net.minecraft.network.packet.s2c.play.UnloadChunkS2CPacket)2 CompoundTag (com.sk89q.jnbt.CompoundTag)1 World (com.sk89q.worldedit.world.World)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 EventReceivePacket (dev.hypnotic.event.events.EventReceivePacket)1 EventRender3D (dev.hypnotic.event.events.EventRender3D)1 Category (dev.hypnotic.module.Category)1 Mod (dev.hypnotic.module.Mod)1 RenderUtils (dev.hypnotic.utils.render.RenderUtils)1 WorldUtils (dev.hypnotic.utils.world.WorldUtils)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1