Search in sources :

Example 1 with IParticleData

use of net.minecraft.particles.IParticleData in project AgriCraft by AgriCraft.

the class JsonPlant method spawnParticles.

@Override
public void spawnParticles(@Nonnull IAgriCrop crop, Random rand) {
    final int index = IncrementalGrowthLogic.getGrowthIndex(crop.getGrowthStage());
    final World world = crop.world();
    if (index == -1 || world == null) {
        return;
    }
    this.plant.getParticleEffects().stream().filter(effect -> effect.allowParticles(index)).forEach(effect -> {
        ParticleType<?> particle = ForgeRegistries.PARTICLE_TYPES.getValue(new ResourceLocation(effect.getParticle()));
        if (!(particle instanceof IParticleData)) {
            return;
        }
        for (int amount = 0; amount < 3; ++amount) {
            if (rand.nextDouble() < effect.getProbability()) {
                BlockPos pos = crop.getPosition();
                double x = pos.getX() + 0.5D + (rand.nextBoolean() ? 1 : -1) * effect.getDeltaX() * rand.nextDouble();
                double y = pos.getY() + 0.5D + effect.getDeltaY() * rand.nextDouble();
                double z = pos.getZ() + 0.5D + (rand.nextBoolean() ? 1 : -1) * effect.getDeltaZ() * rand.nextDouble();
                world.addParticle((IParticleData) particle, x, y, z, 0.0D, 0.0D, 0.0D);
            }
        }
    });
}
Also used : FluidState(net.minecraft.fluid.FluidState) java.util(java.util) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BiFunction(java.util.function.BiFunction) AgriSoilCondition(com.agricraft.agricore.plant.AgriSoilCondition) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) Direction(net.minecraft.util.Direction) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) AgriCore(com.agricraft.agricore.core.AgriCore) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) AgriGrowthRequirement(com.infinityraider.agricraft.impl.v1.requirement.AgriGrowthRequirement) IAgriFertilizer(com.infinityraider.agricraft.api.v1.fertilizer.IAgriFertilizer) com.infinityraider.agricraft.api.v1.requirement(com.infinityraider.agricraft.api.v1.requirement) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Fluids(net.minecraft.fluid.Fluids) AgriCraft(com.infinityraider.agricraft.AgriCraft) Entity(net.minecraft.entity.Entity) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IJsonPlantCallback(com.infinityraider.agricraft.api.v1.plant.IJsonPlantCallback) IncrementalGrowthLogic(com.infinityraider.agricraft.impl.v1.crop.IncrementalGrowthLogic) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) VanillaSeedConversionHandler(com.infinityraider.agricraft.handler.VanillaSeedConversionHandler) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) AgriPlantQuadGenerator(com.infinityraider.agricraft.render.plant.AgriPlantQuadGenerator) BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Consumer(java.util.function.Consumer) IParticleData(net.minecraft.particles.IParticleData) IAgriStatsMap(com.infinityraider.agricraft.api.v1.stat.IAgriStatsMap) AgriPlant(com.agricraft.agricore.plant.AgriPlant) ResourceLocation(net.minecraft.util.ResourceLocation) ParticleType(net.minecraft.particles.ParticleType) Fluid(net.minecraft.fluid.Fluid) ActionResultType(net.minecraft.util.ActionResultType) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) ModelResourceLocation(net.minecraft.client.renderer.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.model.ModelResourceLocation) IParticleData(net.minecraft.particles.IParticleData) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 2 with IParticleData

use of net.minecraft.particles.IParticleData in project AgriCraft by AgriCraft.

the class TileEntitySprinkler method spawnSprinklerParticles.

protected void spawnSprinklerParticles() {
    if (this.getWorld() == null) {
        return;
    }
    boolean vapour = this.getWorld().getDimensionType().isUltrawarm();
    // 0 = all, 1 = decreased; 2 = minimal;
    int particleSetting = AgriCraft.instance.proxy().getParticleSetting();
    particleSetting += vapour ? 6 : 2;
    this.particleCounter = (this.particleCounter + 1) % particleSetting;
    if (this.particleCounter == 0) {
        double x = this.getPos().getX() + 0.5;
        double y = this.getPos().getY() + 0.35;
        double z = this.getPos().getZ() + 0.5;
        for (int i = 0; i < 4; i++) {
            float alpha = -(angle + 90 * i) * ((float) Math.PI) / 180;
            float cosA = MathHelper.cos(alpha);
            float sinA = MathHelper.sin(alpha);
            double xOffset = (4 * Constants.UNIT) * cosA;
            double zOffset = (4 * Constants.UNIT) * sinA;
            float radius = 0.35F;
            if (vapour) {
                IParticleData particle = ParticleTypes.CLOUD;
                this.getWorld().addParticle(particle, x + xOffset, y, z + zOffset, 0.15 * cosA, 0.25, 0.15 * sinA);
            } else {
                IParticleData particle = AgriCraft.instance.getModParticleRegistry().sprinkler.createParticleData(Fluids.WATER, 0.2F, 0.7F);
                for (int j = 0; j <= 4; j++) {
                    float beta = -j * ((float) Math.PI) / (8.0F);
                    this.getWorld().addParticle(particle, x + xOffset * (4 - j) / 4, y, z + zOffset * (4 - j) / 4, radius * cosA, radius * Math.sin(beta), radius * sinA);
                }
            }
        }
        if (vapour) {
            this.getWorld().playSound(AgriCraft.instance.getClientPlayer(), this.getPos(), SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (this.getWorld().getRandom().nextFloat() - this.getWorld().getRandom().nextFloat()) * 0.8F);
        }
    }
}
Also used : IParticleData(net.minecraft.particles.IParticleData)

Example 3 with IParticleData

use of net.minecraft.particles.IParticleData in project AgriCraft by AgriCraft.

the class JsonFertilizer method spawnParticles.

protected void spawnParticles(World world, BlockPos pos, String type, Random rand) {
    this.fertilizerEffect.getParticles(type).forEach(effect -> {
        ParticleType<?> particle = ForgeRegistries.PARTICLE_TYPES.getValue(new ResourceLocation(effect.getParticle()));
        if (!(particle instanceof IParticleData)) {
            return;
        }
        for (int amount = 0; amount < effect.getAmount(); ++amount) {
            double x = pos.getX() + 0.5D + (rand.nextBoolean() ? 1 : -1) * effect.getDeltaX() * rand.nextDouble();
            double y = pos.getY() + 0.5D + effect.getDeltaY() * rand.nextDouble();
            double z = pos.getZ() + 0.5D + (rand.nextBoolean() ? 1 : -1) * effect.getDeltaZ() * rand.nextDouble();
            world.addParticle((IParticleData) particle, x, y, z, 0.0D, 0.0D, 0.0D);
        }
    });
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IParticleData(net.minecraft.particles.IParticleData)

Aggregations

IParticleData (net.minecraft.particles.IParticleData)3 ResourceLocation (net.minecraft.util.ResourceLocation)2 AgriCore (com.agricraft.agricore.core.AgriCore)1 AgriPlant (com.agricraft.agricore.plant.AgriPlant)1 AgriSoilCondition (com.agricraft.agricore.plant.AgriSoilCondition)1 ImmutableList (com.google.common.collect.ImmutableList)1 AgriCraft (com.infinityraider.agricraft.AgriCraft)1 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 IAgriGrowthStage (com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)1 IAgriFertilizer (com.infinityraider.agricraft.api.v1.fertilizer.IAgriFertilizer)1 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)1 IJsonPlantCallback (com.infinityraider.agricraft.api.v1.plant.IJsonPlantCallback)1 com.infinityraider.agricraft.api.v1.requirement (com.infinityraider.agricraft.api.v1.requirement)1 IAgriStatsMap (com.infinityraider.agricraft.api.v1.stat.IAgriStatsMap)1 VanillaSeedConversionHandler (com.infinityraider.agricraft.handler.VanillaSeedConversionHandler)1 IncrementalGrowthLogic (com.infinityraider.agricraft.impl.v1.crop.IncrementalGrowthLogic)1 AgriGrowthRequirement (com.infinityraider.agricraft.impl.v1.requirement.AgriGrowthRequirement)1 AgriPlantQuadGenerator (com.infinityraider.agricraft.render.plant.AgriPlantQuadGenerator)1 java.util (java.util)1