Search in sources :

Example 1 with ParticlesMode

use of net.minecraft.client.options.ParticlesMode in project Biome-Makeover by Lemonszz.

the class S2C_DoLightningBottleParticles method receive.

@Override
public void receive(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
    final boolean doBottleBreak = buf.readBoolean();
    BlockPos pos = buf.readBlockPos();
    client.execute(() -> {
        Vec3d dir = Vec3d.ofBottomCenter(pos);
        Random random = client.world.random;
        World world = client.world;
        if (doBottleBreak) {
            for (int i = 0; i < 8; ++i) {
                world.addParticle(new ItemStackParticleEffect(ParticleTypes.ITEM, new ItemStack(BMItems.LIGHTNING_BOTTLE)), dir.x, dir.y, dir.z, random.nextGaussian() * 0.15D, random.nextDouble() * 0.2D, random.nextGaussian() * 0.15D);
            }
            world.playSound(null, pos, SoundEvents.ENTITY_SPLASH_POTION_BREAK, SoundCategory.NEUTRAL, 1.0F, random.nextFloat() * 0.1F + 0.9F);
        }
        ParticleEffect particleEffect = BMEffects.LIGHTNING_SPARK;
        ParticlesMode mode = MinecraftClient.getInstance().options.particles;
        int particleCount = mode == ParticlesMode.ALL ? 100 : mode == ParticlesMode.DECREASED ? 50 : 10;
        for (int i = 0; i < particleCount; ++i) {
            double direction = random.nextDouble() * 4.0D;
            double ac = random.nextDouble() * Math.PI * 2.0D;
            double xVel = (Math.cos(ac) * direction) * 0.1D;
            double yVel = 0.01D + random.nextDouble() * 0.5D;
            double zVel = (Math.sin(ac) * direction) * 0.1D;
            Particle particle = ClientUtil.spawnParticle(particleEffect, particleEffect.getType().shouldAlwaysSpawn(), true, dir.x + xVel * 0.01D, dir.y + 0.3D, dir.z + zVel * 0.01D, xVel, yVel, zVel);
            if (particle != null) {
                particle.move((float) direction);
            }
        }
    });
}
Also used : ParticleEffect(net.minecraft.particle.ParticleEffect) ItemStackParticleEffect(net.minecraft.particle.ItemStackParticleEffect) Particle(net.minecraft.client.particle.Particle) Random(java.util.Random) ItemStackParticleEffect(net.minecraft.particle.ItemStackParticleEffect) BlockPos(net.minecraft.util.math.BlockPos) ParticlesMode(net.minecraft.client.options.ParticlesMode) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Random (java.util.Random)1 ParticlesMode (net.minecraft.client.options.ParticlesMode)1 Particle (net.minecraft.client.particle.Particle)1 ItemStack (net.minecraft.item.ItemStack)1 ItemStackParticleEffect (net.minecraft.particle.ItemStackParticleEffect)1 ParticleEffect (net.minecraft.particle.ParticleEffect)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1