| 1 | package net.minecraft.client.particle;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.particles.ParticleTypes;
|
| 8 | import net.minecraft.core.particles.SimpleParticleType;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 | import net.minecraft.world.level.Level;
|
| 11 | import net.minecraft.world.level.block.entity.PotentSulfurBlockEntity;
|
| 12 | import net.minecraft.world.phys.Vec3;
|
| 13 | import org.jspecify.annotations.Nullable;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class NoxiousGasCloudParticle extends NoRenderParticle {
|
| 17 | private static final int PARTICLE_TICKS = 2;
|
| 18 |
|
| 19 | protected NoxiousGasCloudParticle(final ClientLevel level, final double x, final double y, final double z) {
|
| 20 | super(level, x, y, z);
|
| 21 | this.lifetime = 20;
|
| 22 | }
|
| 23 |
|
| 24 | @Override
|
| 25 | public void tick() {
|
| 26 | super.tick();
|
| 27 | if (this.age % 2 == 0) {
|
| 28 | BlockPos sourceBlock = BlockPos.containing(this.x, this.y, this.z);
|
| 29 | Vec3 particlePos = pickRandomParticleSpawnPoint(this.level, sourceBlock);
|
| 30 | if (PotentSulfurBlockEntity.canBeReachedByNoxiousGas(this.level, sourceBlock, particlePos)) {
|
| 31 | spawnNoxiousGasParticle(this.level, particlePos);
|
| 32 | }
|
| 33 | }
|
| 34 | }
|
| 35 |
|
| 36 | private static Vec3 pickRandomParticleSpawnPoint(final Level level, final BlockPos centerBlock) {
|
| 37 | RandomSource random = level.getRandom();
|
| 38 | Vec3 horizontalDirection = new Vec3(random.nextFloat() - 0.5F, 0.0, random.nextFloat() - 0.5F).normalize();
|
| 39 | float distance = random.nextFloat() * 3.0F;
|
| 40 | return Vec3.atCenterOf(centerBlock).add(horizontalDirection.scale(distance)).subtract(0.0, 0.25, 0.0);
|
| 41 | }
|
| 42 |
|
| 43 | private static void spawnNoxiousGasParticle(final Level level, final Vec3 pos) {
|
| 44 | level.addAlwaysVisibleParticle(ParticleTypes.NOXIOUS_GAS, pos.x, pos.y, pos.z, 0.0, 0.0, 0.0);
|
| 45 | }
|
| 46 |
|
| 47 | @Environment(EnvType.CLIENT)
|
| 48 | public static class Provider implements ParticleProvider<SimpleParticleType> {
|
| 49 | public @Nullable Particle createParticle(
|
| 50 | final SimpleParticleType options,
|
| 51 | final ClientLevel level,
|
| 52 | final double x,
|
| 53 | final double y,
|
| 54 | final double z,
|
| 55 | final double xAux,
|
| 56 | final double yAux,
|
| 57 | final double zAux,
|
| 58 | final RandomSource random
|
| 59 | ) {
|
| 60 | return new NoxiousGasCloudParticle(level, x, y, z);
|
| 61 | }
|
| 62 | }
|
| 63 | }
|
| 64 |
|