From 31163e7658bb927b0b451fdb161ec1e90c323353 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Tue, 19 Jan 2021 20:06:51 +0300 Subject: [PATCH] Fireflies, small fixes --- .../betterend/particle/FireflyParticle.java | 81 ++++++++++++++++++ .../ru/betterend/registry/EndParticles.java | 3 + .../world/biome/GlowingGrasslandsBiome.java | 2 + .../world/features/bushes/Lumecorn.java | 3 + .../materialmaps/particle/firefly.json | 3 + .../assets/betterend/particles/firefly.json | 5 ++ .../betterend/textures/particle/firefly.png | Bin 0 -> 1486 bytes 7 files changed, 97 insertions(+) create mode 100644 src/main/java/ru/betterend/particle/FireflyParticle.java create mode 100644 src/main/resources/assets/betterend/materialmaps/particle/firefly.json create mode 100644 src/main/resources/assets/betterend/particles/firefly.json create mode 100644 src/main/resources/assets/betterend/textures/particle/firefly.png diff --git a/src/main/java/ru/betterend/particle/FireflyParticle.java b/src/main/java/ru/betterend/particle/FireflyParticle.java new file mode 100644 index 00000000..5bb620f4 --- /dev/null +++ b/src/main/java/ru/betterend/particle/FireflyParticle.java @@ -0,0 +1,81 @@ +package ru.betterend.particle; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.particle.AnimatedParticle; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleFactory; +import net.minecraft.client.particle.SpriteProvider; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.particle.DefaultParticleType; +import net.minecraft.util.math.MathHelper; +import ru.betterend.util.MHelper; + +@Environment(EnvType.CLIENT) +public class FireflyParticle extends AnimatedParticle { + private double preVX; + private double preVY; + private double preVZ; + private double nextVX; + private double nextVY; + private double nextVZ; + + protected FireflyParticle(ClientWorld world, double x, double y, double z, SpriteProvider sprites, double r, double g, double b) { + super(world, x, y, z, sprites, 0); + setSprite(sprites.getSprite(random)); + this.maxAge = MHelper.randRange(150, 300, random); + this.scale = MHelper.randRange(0.05F, 0.15F, random); + this.setTargetColor(15916745); + this.setSpriteForAge(spriteProvider); + this.setColorAlpha(0); + + preVX = random.nextGaussian() * 0.02; + preVY = random.nextGaussian() * 0.02; + preVZ = random.nextGaussian() * 0.02; + + nextVX = random.nextGaussian() * 0.02; + nextVY = random.nextGaussian() * 0.02; + nextVZ = random.nextGaussian() * 0.02; + } + + @Override + public void tick() { + int ticks = this.age & 31; + if (ticks == 0) { + preVX = nextVX; + preVY = nextVY; + preVZ = nextVZ; + nextVX = random.nextGaussian() * 0.02; + nextVY = random.nextGaussian() * 0.02; + nextVZ = random.nextGaussian() * 0.02; + } + double delta = (double) ticks / 31.0; + + this.velocityX = MathHelper.lerp(delta, preVX, nextVX); + this.velocityY = MathHelper.lerp(delta, preVY, nextVY); + this.velocityZ = MathHelper.lerp(delta, preVZ, nextVZ); + + if (this.age <= 60) { + this.setColorAlpha(this.age / 60F); + } + else if (this.age > maxAge - 60) { + this.setColorAlpha((maxAge - this.age) / 60F); + } + + super.tick(); + } + + @Environment(EnvType.CLIENT) + public static class FireflyParticleFactory implements ParticleFactory { + private final SpriteProvider sprites; + + public FireflyParticleFactory(SpriteProvider sprites) { + this.sprites = sprites; + } + + @Override + public Particle createParticle(DefaultParticleType type, ClientWorld world, double x, double y, double z, double vX, double vY, double vZ) { + return new FireflyParticle(world, x, y, z, sprites, 1, 1, 1); + } + } +} \ No newline at end of file diff --git a/src/main/java/ru/betterend/registry/EndParticles.java b/src/main/java/ru/betterend/registry/EndParticles.java index d273cb29..05defbc7 100644 --- a/src/main/java/ru/betterend/registry/EndParticles.java +++ b/src/main/java/ru/betterend/registry/EndParticles.java @@ -7,6 +7,7 @@ import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; import net.minecraft.util.registry.Registry; import ru.betterend.BetterEnd; +import ru.betterend.particle.FireflyParticle; import ru.betterend.particle.InfusionParticle; import ru.betterend.particle.InfusionParticleType; import ru.betterend.particle.ParticleBlackSpore; @@ -29,6 +30,7 @@ public class EndParticles { public static final DefaultParticleType BLACK_SPORE = register("black_spore"); public static final DefaultParticleType TENANEA_PETAL = register("tenanea_petal"); public static final DefaultParticleType JUNGLE_SPORE = register("jungle_spore"); + public static final DefaultParticleType FIREFLY = register("firefly"); public static void register() { ParticleFactoryRegistry.getInstance().register(GLOWING_SPHERE, ParticleGlowingSphere.FactoryGlowingSphere::new); @@ -41,6 +43,7 @@ public class EndParticles { ParticleFactoryRegistry.getInstance().register(BLACK_SPORE, ParticleBlackSpore.FactoryBlackSpore::new); ParticleFactoryRegistry.getInstance().register(TENANEA_PETAL, ParticleTenaneaPetal.FactoryTenaneaPetal::new); ParticleFactoryRegistry.getInstance().register(JUNGLE_SPORE, ParticleJungleSpore.FactoryJungleSpore::new); + ParticleFactoryRegistry.getInstance().register(FIREFLY, FireflyParticle.FireflyParticleFactory::new); } private static DefaultParticleType register(String name) { diff --git a/src/main/java/ru/betterend/world/biome/GlowingGrasslandsBiome.java b/src/main/java/ru/betterend/world/biome/GlowingGrasslandsBiome.java index f878e85d..be5bdd10 100644 --- a/src/main/java/ru/betterend/world/biome/GlowingGrasslandsBiome.java +++ b/src/main/java/ru/betterend/world/biome/GlowingGrasslandsBiome.java @@ -3,6 +3,7 @@ package ru.betterend.world.biome; import net.minecraft.entity.EntityType; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; +import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndSounds; public class GlowingGrasslandsBiome extends EndBiome { @@ -10,6 +11,7 @@ public class GlowingGrasslandsBiome extends EndBiome { super(new BiomeDefinition("glowing_grasslands") .setFogColor(99, 228, 247) .setFogDensity(1.3F) + .setParticles(EndParticles.FIREFLY, 0.001F) .setMusic(EndSounds.MUSIC_OPENSPACE) .setSurface(EndBlocks.END_MOSS) .addFeature(EndFeatures.END_LAKE_RARE) diff --git a/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java b/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java index 5c823cb0..f9d6c5da 100644 --- a/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java +++ b/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java @@ -12,6 +12,7 @@ import net.minecraft.world.gen.feature.DefaultFeatureConfig; import ru.betterend.blocks.BlockProperties.LumecornShape; import ru.betterend.blocks.LumecornBlock; import ru.betterend.registry.EndBlocks; +import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; import ru.betterend.world.features.DefaultFeature; @@ -19,6 +20,8 @@ import ru.betterend.world.features.DefaultFeature; public class Lumecorn extends DefaultFeature { @Override public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) { + if (!world.getBlockState(pos.down()).getBlock().isIn(EndTags.END_GROUND)) return false; + int height = MHelper.randRange(3, 6, random); Mutable mut = new Mutable().set(pos); for (int i = 1; i < height; i++) { diff --git a/src/main/resources/assets/betterend/materialmaps/particle/firefly.json b/src/main/resources/assets/betterend/materialmaps/particle/firefly.json new file mode 100644 index 00000000..ab909d8e --- /dev/null +++ b/src/main/resources/assets/betterend/materialmaps/particle/firefly.json @@ -0,0 +1,3 @@ +{ + "material": "canvas:emissive_no_diffuse" +} \ No newline at end of file diff --git a/src/main/resources/assets/betterend/particles/firefly.json b/src/main/resources/assets/betterend/particles/firefly.json new file mode 100644 index 00000000..059552aa --- /dev/null +++ b/src/main/resources/assets/betterend/particles/firefly.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "betterend:firefly" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/betterend/textures/particle/firefly.png b/src/main/resources/assets/betterend/textures/particle/firefly.png new file mode 100644 index 0000000000000000000000000000000000000000..de0c2bc0ffdf9f1b4adedad3085dcf48737b0c19 GIT binary patch literal 1486 zcmbVMU1%Id9N#F$SR1AE!77N$#s|gj?ac1wE<0os<8Ab=cGGKm(D>H5nYp_qw>#V2 zx!xrrN#K-D`RH0aB?qe-dHMlT4U%&bNzyEL7 z*It@E@WcU4(`IW`e_hTqYRpW_|J6q?pO@1^N%fUX(;hy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