Search in sources :

Example 66 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project pingspam by BasiqueEvangelist.

the class PingSpamPackets method register.

public static void register() {
    ServerPlayNetworking.registerGlobalReceiver(PULL_PERMISSIONS, (server, player, handler, buf, responseSender) -> {
        PacketByteBuf newBuf = PacketByteBufs.create();
        newBuf.writeBoolean(Permissions.check(player, "pingspam.ping.everyone", 2));
        newBuf.writeBoolean(Permissions.check(player, "pingspam.ping.online", 2));
        newBuf.writeBoolean(Permissions.check(player, "pingspam.ping.offline", 2));
        newBuf.writeBoolean(Permissions.check(player, "pingspam.ping.player", true));
        responseSender.sendPacket(PULL_PERMISSIONS, newBuf);
    });
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 67 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project wildmod by Osmiooo.

the class SculkShriekerBlock method sendGargleParticles.

public static void sendGargleParticles(World world, BlockPos blockPos) {
    if (!world.isClient) {
        PacketByteBuf buf = PacketByteBufs.create();
        buf.writeBlockPos(blockPos);
        int decider = UniformIntProvider.create(0, 1).get(world.getRandom());
        // Radius is cut from 32 to 12 in order to slightly help performance/bandwidth since this is kinda spamming tbh
        for (ServerPlayerEntity player : PlayerLookup.around((ServerWorld) world, blockPos, 12)) {
            if (decider > 0.5) {
                ServerPlayNetworking.send(player, RegisterAccurateSculk.SHRIEKER_GARGLE1_PACKET, buf);
            } else if (decider < 0.5) {
                ServerPlayNetworking.send(player, RegisterAccurateSculk.SHRIEKER_GARGLE2_PACKET, buf);
            }
        }
    }
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 68 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project wildmod by Osmiooo.

the class SculkShriekerBlock method sendParticles.

public static void sendParticles(World world, BlockPos blockPos, int direction) {
    if (!world.isClient) {
        PacketByteBuf buf = PacketByteBufs.create();
        buf.writeBlockPos(blockPos);
        buf.writeInt(direction);
        for (ServerPlayerEntity player : PlayerLookup.around((ServerWorld) world, blockPos, 32)) {
            ServerPlayNetworking.send(player, RegisterAccurateSculk.SHRIEKER_SHRIEK_PACKET, buf);
        }
    }
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 69 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project KiwiClient by TangyKiwi.

the class PlayerInteractEntityC2SUtils method getEntity.

public static Entity getEntity(PlayerInteractEntityC2SPacket packet) {
    PacketByteBuf packetBuf = new PacketByteBuf(Unpooled.buffer());
    packet.write(packetBuf);
    return MinecraftClient.getInstance().world.getEntityById(packetBuf.readVarInt());
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 70 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project VisualOverhaul by TeamMidnightDust.

the class MixinBrewingStandBlockEntity method tick.

@Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, BrewingStandBlockEntity blockEntity, CallbackInfo ci) {
    if (!world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) {
        Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
        PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
        passedData.writeBlockPos(pos);
        passedData.writeItemStack(blockEntity.getStack(0));
        passedData.writeItemStack(blockEntity.getStack(1));
        passedData.writeItemStack(blockEntity.getStack(2));
        passedData.writeItemStack(blockEntity.getStack(3));
        passedData.writeItemStack(blockEntity.getStack(4));
        watchingPlayers.forEach(player -> ServerSidePacketRegistryImpl.INSTANCE.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData));
        invUpdate = false;
    }
    playerUpdate = world.getPlayers().size();
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PacketByteBuf (net.minecraft.network.PacketByteBuf)117 PlayerEntity (net.minecraft.entity.player.PlayerEntity)21 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)14 Identifier (net.minecraft.util.Identifier)8 NbtCompound (net.minecraft.nbt.NbtCompound)7 Environment (net.fabricmc.api.Environment)5 CustomPayloadC2SPacket (net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket)5 CustomPayloadS2CPacket (net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket)4 Nullable (org.jetbrains.annotations.Nullable)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 JSONSource (de.modprog.blockmeter.util.JSONSource)2 Map (java.util.Map)2 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)2 LivingEntity (net.minecraft.entity.LivingEntity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ParticleType (net.minecraft.particle.ParticleType)2 LiteralText (net.minecraft.text.LiteralText)2