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);
}
}
});
}
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);
}
}
}
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);
}
});
}
Aggregations