| 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.particles.SimpleParticleType;
|
| 7 | import net.minecraft.util.LightCoordsUtil;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 |
|
| 10 | @Environment(EnvType.CLIENT)
|
| 11 | public class GlowParticle extends SingleQuadParticle {
|
| 12 | private final SpriteSet sprites;
|
| 13 |
|
| 14 | private GlowParticle(
|
| 15 | final ClientLevel level, final double x, final double y, final double z, final double xa, final double ya, final double za, final SpriteSet sprites
|
| 16 | ) {
|
| 17 | super(level, x, y, z, xa, ya, za, sprites.first());
|
| 18 | this.friction = 0.96F;
|
| 19 | this.speedUpWhenYMotionIsBlocked = true;
|
| 20 | this.sprites = sprites;
|
| 21 | this.quadSize *= 0.75F;
|
| 22 | this.hasPhysics = false;
|
| 23 | this.setSpriteFromAge(sprites);
|
| 24 | }
|
| 25 |
|
| 26 | @Override
|
| 27 | public SingleQuadParticle.Layer getLayer() {
|
| 28 | return SingleQuadParticle.Layer.OPAQUE;
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | public int getLightCoords(final float a) {
|
| 33 | return LightCoordsUtil.addSmoothBlockEmission(super.getLightCoords(a), (this.age + a) / this.lifetime);
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | public void tick() {
|
| 38 | super.tick();
|
| 39 | this.setSpriteFromAge(this.sprites);
|
| 40 | }
|
| 41 |
|
| 42 | @Environment(EnvType.CLIENT)
|
| 43 | public static class ElectricSparkProvider implements ParticleProvider<SimpleParticleType> {
|
| 44 | private static final double SPEED_FACTOR = 0.25;
|
| 45 | private final SpriteSet sprite;
|
| 46 |
|
| 47 | public ElectricSparkProvider(final SpriteSet sprite) {
|
| 48 | this.sprite = sprite;
|
| 49 | }
|
| 50 |
|
| 51 | public Particle createParticle(
|
| 52 | final SimpleParticleType options,
|
| 53 | final ClientLevel level,
|
| 54 | final double x,
|
| 55 | final double y,
|
| 56 | final double z,
|
| 57 | final double xAux,
|
| 58 | final double yAux,
|
| 59 | final double zAux,
|
| 60 | final RandomSource random
|
| 61 | ) {
|
| 62 | GlowParticle glowParticle = new GlowParticle(level, x, y, z, 0.0, 0.0, 0.0, this.sprite);
|
| 63 | glowParticle.setColor(1.0F, 0.9F, 1.0F);
|
| 64 | glowParticle.setParticleSpeed(xAux * 0.25, yAux * 0.25, zAux * 0.25);
|
| 65 | int minLifespan = 2;
|
| 66 | int maxLifespan = 4;
|
| 67 | glowParticle.setLifetime(random.nextInt(2) + 2);
|
| 68 | return glowParticle;
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | @Environment(EnvType.CLIENT)
|
| 73 | public static class GlowSquidProvider implements ParticleProvider<SimpleParticleType> {
|
| 74 | private final SpriteSet sprite;
|
| 75 |
|
| 76 | public GlowSquidProvider(final SpriteSet sprite) {
|
| 77 | this.sprite = sprite;
|
| 78 | }
|
| 79 |
|
| 80 | public Particle createParticle(
|
| 81 | final SimpleParticleType options,
|
| 82 | final ClientLevel level,
|
| 83 | final double x,
|
| 84 | final double y,
|
| 85 | final double z,
|
| 86 | final double xAux,
|
| 87 | final double yAux,
|
| 88 | final double zAux,
|
| 89 | final RandomSource random
|
| 90 | ) {
|
| 91 | GlowParticle glowParticle = new GlowParticle(level, x, y, z, 0.5 - random.nextDouble(), yAux, 0.5 - random.nextDouble(), this.sprite);
|
| 92 | if (random.nextBoolean()) {
|
| 93 | glowParticle.setColor(0.6F, 1.0F, 0.8F);
|
| 94 | } else {
|
| 95 | glowParticle.setColor(0.08F, 0.4F, 0.4F);
|
| 96 | }
|
| 97 |
|
| 98 | glowParticle.yd *= 0.2F;
|
| 99 | if (xAux == 0.0 && zAux == 0.0) {
|
| 100 | glowParticle.xd *= 0.1F;
|
| 101 | glowParticle.zd *= 0.1F;
|
| 102 | }
|
| 103 |
|
| 104 | glowParticle.setLifetime((int)(8.0 / (random.nextDouble() * 0.8 + 0.2)));
|
| 105 | return glowParticle;
|
| 106 | }
|
| 107 | }
|
| 108 |
|
| 109 | @Environment(EnvType.CLIENT)
|
| 110 | public static class ScrapeProvider implements ParticleProvider<SimpleParticleType> {
|
| 111 | private static final double SPEED_FACTOR = 0.01;
|
| 112 | private final SpriteSet sprite;
|
| 113 |
|
| 114 | public ScrapeProvider(final SpriteSet sprite) {
|
| 115 | this.sprite = sprite;
|
| 116 | }
|
| 117 |
|
| 118 | public Particle createParticle(
|
| 119 | final SimpleParticleType options,
|
| 120 | final ClientLevel level,
|
| 121 | final double x,
|
| 122 | final double y,
|
| 123 | final double z,
|
| 124 | final double xAux,
|
| 125 | final double yAux,
|
| 126 | final double zAux,
|
| 127 | final RandomSource random
|
| 128 | ) {
|
| 129 | GlowParticle glowParticle = new GlowParticle(level, x, y, z, 0.0, 0.0, 0.0, this.sprite);
|
| 130 | if (random.nextBoolean()) {
|
| 131 | glowParticle.setColor(0.29F, 0.58F, 0.51F);
|
| 132 | } else {
|
| 133 | glowParticle.setColor(0.43F, 0.77F, 0.62F);
|
| 134 | }
|
| 135 |
|
| 136 | glowParticle.setParticleSpeed(xAux * 0.01, yAux * 0.01, zAux * 0.01);
|
| 137 | int minLifespan = 10;
|
| 138 | int maxLifespan = 40;
|
| 139 | glowParticle.setLifetime(random.nextInt(30) + 10);
|
| 140 | return glowParticle;
|
| 141 | }
|
| 142 | }
|
| 143 |
|
| 144 | @Environment(EnvType.CLIENT)
|
| 145 | public static class WaxOffProvider implements ParticleProvider<SimpleParticleType> {
|
| 146 | private static final double SPEED_FACTOR = 0.01;
|
| 147 | private final SpriteSet sprite;
|
| 148 |
|
| 149 | public WaxOffProvider(final SpriteSet sprite) {
|
| 150 | this.sprite = sprite;
|
| 151 | }
|
| 152 |
|
| 153 | public Particle createParticle(
|
| 154 | final SimpleParticleType options,
|
| 155 | final ClientLevel level,
|
| 156 | final double x,
|
| 157 | final double y,
|
| 158 | final double z,
|
| 159 | final double xAux,
|
| 160 | final double yAux,
|
| 161 | final double zAux,
|
| 162 | final RandomSource random
|
| 163 | ) {
|
| 164 | GlowParticle glowParticle = new GlowParticle(level, x, y, z, 0.0, 0.0, 0.0, this.sprite);
|
| 165 | glowParticle.setColor(1.0F, 0.9F, 1.0F);
|
| 166 | glowParticle.setParticleSpeed(xAux * 0.01 / 2.0, yAux * 0.01, zAux * 0.01 / 2.0);
|
| 167 | int minLifespan = 10;
|
| 168 | int maxLifespan = 40;
|
| 169 | glowParticle.setLifetime(random.nextInt(30) + 10);
|
| 170 | return glowParticle;
|
| 171 | }
|
| 172 | }
|
| 173 |
|
| 174 | @Environment(EnvType.CLIENT)
|
| 175 | public static class WaxOnProvider implements ParticleProvider<SimpleParticleType> {
|
| 176 | private static final double SPEED_FACTOR = 0.01;
|
| 177 | private final SpriteSet sprite;
|
| 178 |
|
| 179 | public WaxOnProvider(final SpriteSet sprite) {
|
| 180 | this.sprite = sprite;
|
| 181 | }
|
| 182 |
|
| 183 | public Particle createParticle(
|
| 184 | final SimpleParticleType options,
|
| 185 | final ClientLevel level,
|
| 186 | final double x,
|
| 187 | final double y,
|
| 188 | final double z,
|
| 189 | final double xAux,
|
| 190 | final double yAux,
|
| 191 | final double zAux,
|
| 192 | final RandomSource random
|
| 193 | ) {
|
| 194 | GlowParticle glowParticle = new GlowParticle(level, x, y, z, 0.0, 0.0, 0.0, this.sprite);
|
| 195 | glowParticle.setColor(0.91F, 0.55F, 0.08F);
|
| 196 | glowParticle.setParticleSpeed(xAux * 0.01 / 2.0, yAux * 0.01, zAux * 0.01 / 2.0);
|
| 197 | int minLifespan = 10;
|
| 198 | int maxLifespan = 40;
|
| 199 | glowParticle.setLifetime(random.nextInt(30) + 10);
|
| 200 | return glowParticle;
|
| 201 | }
|
| 202 | }
|
| 203 | }
|
| 204 |
|