Java Code Examples for net.minecraft.world.World#addParticle()

The following examples show how to use net.minecraft.world.World#addParticle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OxygenCollectorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
public void randomDisplayTick(BlockState blockState_1, World world, BlockPos pos, Random random_1) {
    BlockEntity blockEntity = world.getBlockEntity(pos);
    if (!(blockEntity instanceof OxygenCollectorBlockEntity)) {
        return;
    }

    OxygenCollectorBlockEntity collector = (OxygenCollectorBlockEntity) blockEntity;
    if (collector.collectionAmount > 0) {
        for (int particleCount = 0; particleCount < 10; particleCount++) {
            Random random = world.random;

            for (int int_1 = 0; int_1 < 32; ++int_1) {
                world.addParticle(
                        new DustParticleEffect(0.9f, 0.9f, 1.0f, 1.0F),
                        pos.getX() + 0.5D,
                        (random.nextFloat() - 0.5D) * 0.5D + /*random.nextDouble() * 2.0D*/ 0.5D,
                        pos.getZ() + 0.5D,
                        random.nextGaussian(),
                        0.0D,
                        random.nextGaussian());
            }
        }
    }
}
 
Example 2
Source File: CoalGeneratorBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Environment(EnvType.CLIENT)
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos blockPos_1, Random rand) {
    if (world.getBlockEntity(blockPos_1) instanceof CoalGeneratorBlockEntity && ((CoalGeneratorBlockEntity) world.getBlockEntity(blockPos_1)).status == CoalGeneratorBlockEntity.CoalGeneratorStatus.ACTIVE || ((CoalGeneratorBlockEntity) world.getBlockEntity(blockPos_1)).status == CoalGeneratorBlockEntity.CoalGeneratorStatus.WARMING) {
        double x = (double) blockPos_1.getX() + 0.5D;
        double y = blockPos_1.getY();
        double z = (double) blockPos_1.getZ() + 0.5D;
        if (rand.nextDouble() < 0.1D) {
            world.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
        }

        Direction direction_1 = state.get(FACING);
        Direction.Axis direction$Axis_1 = direction_1.getAxis();
        double d = rand.nextDouble() * 0.6D - 0.3D;
        double xo = direction$Axis_1 == Direction.Axis.X ? (double) direction_1.getOffsetX() * 0.52D : d;
        double yo = rand.nextDouble() * 6.0D / 16.0D;
        double zo = direction$Axis_1 == Direction.Axis.Z ? (double) direction_1.getOffsetZ() * 0.52D : d;
        world.addParticle(ParticleTypes.SMOKE, x + xo, y + yo, z + zo, 0.0D, 0.0D, 0.0D);
        world.addParticle(ParticleTypes.FLAME, x + xo, y + yo, z + zo, 0.0D, 0.0D, 0.0D);

    }
}
 
Example 3
Source File: WitchWaterFluid.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(World world, BlockPos blockPos, FluidState fluidState, Random random) {
	if (random.nextInt(10) == 0) {
		world.addParticle(ParticleTypes.BUBBLE_POP,
			(double) blockPos.getX() + 0.5D + (random.nextFloat() - 0.5F),
			(double) blockPos.getY() + (fluidState.getHeight(world, blockPos) * (1F / 7F)) + 1F,
			(double) blockPos.getZ() + 0.5D + (random.nextFloat() - 0.5F),
			0.0D, 0.0D, 0.0D
		);
	}
	
	if (random.nextInt(15) == 0) {
		world.addParticle(ParticleTypes.BUBBLE,
			(double) blockPos.getX() + 0.5D + (random.nextFloat() - 0.5F),
			(double) blockPos.getY() + (fluidState.getHeight(world, blockPos) * (1F / 7F)) + 1F,
			(double) blockPos.getZ() + 0.5D + (random.nextFloat() - 0.5F),
			0.0D, 0.0D, 0.0D
		);
	}
}
 
Example 4
Source File: ScorchedRockBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
    double x = (double) pos.getX() + random.nextDouble() * 0.10000000149011612D;
    double y = (double) pos.getY() + random.nextDouble();
    double z = (double) pos.getZ() + random.nextDouble();

    world.addParticle(ParticleTypes.LARGE_SMOKE, x, y, z, 0.0D, 0.0D, 0.0D);
}
 
Example 5
Source File: MoonBerryBushBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState blockState, World world, BlockPos blockPos, Random random) {
    if (blockState.get(AGE) == 3) {

        double x = blockPos.getX() + 0.5D + (random.nextFloat() - random.nextFloat());
        double y = blockPos.getY() + random.nextFloat();
        double z = blockPos.getZ() + 0.5D + (random.nextFloat() - random.nextFloat());
        int times = random.nextInt(4);

        for (int i = 0; i < times; i++) {
            world.addParticle(new DustParticleEffect(0.5f, 0.5f, 1.0f, 0.6f), x, y, z, 0.0D, 0.0D, 0.0D);
        }
    }
}
 
Example 6
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(World world, BlockPos blockPos, FluidState fluidState, Random random) {
    if (random.nextInt(10) == 0) {
        world.addParticle(GalacticraftParticles.DRIPPING_CRUDE_OIL_PARTICLE,
                (double) blockPos.getX() + 0.5D - random.nextGaussian() + random.nextGaussian(),
                (double) blockPos.getY() + 1.1F,
                (double) blockPos.getZ() + 0.5D - random.nextGaussian() + random.nextGaussian(),
                0.0D, 0.0D, 0.0D);
    }
}
 
Example 7
Source File: FuelFluid.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(World world, BlockPos blockPos, FluidState fluidState, Random random) {
    if (random.nextInt(10) == 0) {
        world.addParticle(GalacticraftParticles.DRIPPING_FUEL_PARTICLE,
                (double) blockPos.getX() + 0.5D - random.nextGaussian() + random.nextGaussian(),
                (double) blockPos.getY() + 1.1F,
                (double) blockPos.getZ() + 0.5D - random.nextGaussian() + random.nextGaussian(),
                0.0D, 0.0D, 0.0D);
    }
}
 
Example 8
Source File: TorchBlockMixin.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Deprecated
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean moved) {
    super.onBlockAdded(state, world, pos, oldState, moved);
    if (CelestialBodyType.getByDimType(world.getRegistryKey()).isPresent() && !CelestialBodyType.getByDimType(world.getRegistryKey()).get().getAtmosphere().getComposition().containsKey(AtmosphericGas.OXYGEN)) {
        if (state.getBlock() == Blocks.TORCH) {
            world.setBlockState(pos, GalacticraftBlocks.UNLIT_TORCH.getDefaultState());
        } else if (state.getBlock() == Blocks.WALL_TORCH) {
            world.setBlockState(pos, GalacticraftBlocks.UNLIT_WALL_TORCH.getDefaultState().with(WallTorchBlock.FACING, state.get(WallTorchBlock.FACING)));
        }
        world.addParticle(ParticleTypes.SMOKE, pos.getX(), pos.getY(), pos.getZ(), 0.0D, 0.0D, 0.0D);
        world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EXTINGUISH_FIRE, SoundCategory.BLOCKS, 1.0F, 0.9F, false);
    }
}
 
Example 9
Source File: HallowCharmItem.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void usageTick(World world, LivingEntity user, ItemStack stack, int ticksLeft) {
	Random random = new Random();
	BlockPos pos = user.getBlockPos();
	double x = pos.getX() + random.nextFloat();
	double y = pos.getY() + random.nextFloat();
	double z = pos.getZ() + random.nextFloat();
	double velX = (random.nextFloat() - 0.5D) * 0.5D;
	double velY = (random.nextFloat() - 0.5D) * 0.5D;
	double velZ = (random.nextFloat() - 0.5D) * 0.5D;
	world.addParticle(ParticleTypes.PORTAL, x, y, z, velX, velY, velZ);
}
 
Example 10
Source File: MinersLight.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
    double d0 = (double) pos.getX() + 0.5D;
    double d1 = (double) pos.getY() + 0.5D;
    double d2 = (double) pos.getZ() + 0.5D;
    worldIn.addParticle(ModParticles.LIGHT_PARTICLE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
    //worldIn.addParticle(ParticleTypes.FLAME, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
 
Example 11
Source File: MiningGadget.java    From MiningGadgets with MIT License 5 votes vote down vote up
private void spawnFreezeParticle(PlayerEntity player, BlockPos sourcePos, World world, ItemStack stack) {
    float randomPartSize = 0.05f + (0.125f - 0.05f) * rand.nextFloat();
    double randomTX = rand.nextDouble();
    double randomTY = rand.nextDouble();
    double randomTZ = rand.nextDouble();
    double alpha = -0.5f + (1.0f - 0.5f) * rand.nextDouble(); //rangeMin + (rangeMax - rangeMin) * r.nextDouble();
    Vec3d playerPos = player.getPositionVec().add(0, player.getEyeHeight(), 0);
    Vec3d look = player.getLookVec(); // or getLook(partialTicks)
    int range = MiningProperties.getBeamRange(stack);
    BlockRayTraceResult lookAt = VectorHelper.getLookingAt(player, RayTraceContext.FluidMode.NONE, range);
    Vec3d lookingAt = lookAt.getHitVec();
    //The next 3 variables are directions on the screen relative to the players look direction. So right = to the right of the player, regardless of facing direction.
    Vec3d right = new Vec3d(-look.z, 0, look.x).normalize();
    Vec3d forward = look;
    Vec3d backward = look.mul(-1, 1, -1);
    Vec3d down = right.crossProduct(forward);

    //These are used to calculate where the particles are going. We want them going into the laser, so we move the destination right, down, and forward a bit.
    right = right.scale(0.65f);
    forward = forward.scale(0.85f);
    down = down.scale(-0.35);
    backward = backward.scale(0.05);

    //Take the player's eye position, and shift it to where the end of the laser is (Roughly)
    Vec3d laserPos = playerPos.add(right);
    laserPos = laserPos.add(forward);
    laserPos = laserPos.add(down);
    lookingAt = lookingAt.add(backward);
    PlayerParticleData data = PlayerParticleData.playerparticle("ice", sourcePos.getX() + randomTX, sourcePos.getY() + randomTY, sourcePos.getZ() + randomTZ, randomPartSize, 1f, 1f, 1f, 120, true);
    //Change the below laserPos to lookingAt to have it emit from the laser gun itself
    world.addParticle(data, laserPos.x, laserPos.y, laserPos.z, 0.025, 0.025f, 0.025);
}
 
Example 12
Source File: SawmillBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
    if (stateIn.get(POWERED))
    {
        Direction enumfacing = stateIn.get(FACING);
        double x = (double) pos.getX() + 0.5D;
        double y = (double) pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
        double z = (double) pos.getZ() + 0.5D;
        double d4 = rand.nextDouble() * 0.6D - 0.3D;

        if (rand.nextDouble() < 0.1D)
        {
            worldIn.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
        }

        switch (enumfacing)
        {
            case WEST:
                z += d4;
                x -= 0.52D;
                break;
            case EAST:
                z += d4;
                x += 0.52D;
                break;
            case NORTH:
                x += d4;
                z -= 0.52D;
                break;
            case SOUTH:
                x += d4;
                z += 0.52D;
        }

        worldIn.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0D, 0.0D, 0.0D);
        worldIn.addParticle(ParticleTypes.FLAME, x, y, z, 0.0D, 0.0D, 0.0D);
    }
}