Tenanea petals

This commit is contained in:
paulevsGitch 2020-12-14 13:47:35 +03:00
parent ae172a1517
commit 022260e51e
8 changed files with 149 additions and 1 deletions

View file

@ -1,5 +1,9 @@
package ru.betterend.blocks;
import java.util.Random;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.item.ItemColorProvider;
@ -7,8 +11,10 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockVine;
import ru.betterend.interfaces.IColorProvider;
import ru.betterend.registry.EndParticles;
import ru.betterend.util.MHelper;
public class BlockTenaneaFlowers extends BlockVine implements IColorProvider {
@ -52,6 +58,17 @@ public class BlockTenaneaFlowers extends BlockVine implements IColorProvider {
return false;
}
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
if (random.nextInt(32) == 0) {
double x = (double) pos.getX() + random.nextGaussian() + 0.5;
double z = (double) pos.getZ() + random.nextGaussian() + 0.5;
double y = (double) pos.getY() + random.nextDouble();
world.addParticle(EndParticles.TENANEA_PETAL, x, y, z, 0, 0, 0);
}
}
static {
COLORS = new Vec3i[] {
new Vec3i(250, 111, 222),

View file

@ -0,0 +1,119 @@
package ru.betterend.particle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.particle.SpriteBillboardParticle;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import ru.betterend.interfaces.IColorProvider;
import ru.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper;
@Environment(EnvType.CLIENT)
public class ParticleTenaneaPetal extends SpriteBillboardParticle {
private static BlockColorProvider provider;
private double preVX;
private double preVY;
private double preVZ;
private double nextVX;
private double nextVY;
private double nextVZ;
private float angleSpeed;
protected ParticleTenaneaPetal(ClientWorld world, double x, double y, double z, double r, double g, double b, SpriteProvider sprites) {
super(world, x, y, z, r, g, b);
setSprite(sprites);
if (provider == null) {
IColorProvider block = (IColorProvider) EndBlocks.TENANEA_FLOWERS;
provider = block.getProvider();
}
int color = provider.getColor(null, null, new BlockPos(x, y, z), 0);
this.colorRed = ((color >> 16) & 255) / 255F;
this.colorGreen = ((color >> 8) & 255) / 255F;
this.colorBlue = ((color) & 255) / 255F;
this.maxAge = MHelper.randRange(120, 200, random);
this.scale = MHelper.randRange(0.05F, 0.15F, random);
this.setColorAlpha(0);
this.angle = 0.1F;//random.nextFloat() * MHelper.PI2;
preVX = 0;
preVY = 0;
preVZ = 0;
nextVX = random.nextGaussian() * 0.02;
nextVY = -random.nextDouble() * 0.02 - 0.02;
nextVZ = random.nextGaussian() * 0.02;
angleSpeed = random.nextFloat() * 0.0001F + 0.0001F;
if (random.nextBoolean()) {
angleSpeed = -angleSpeed;
}
}
@Override
public int getColorMultiplier(float tint) {
return 15728880;
}
@Override
public void tick() {
int ticks = this.age & 63;
if (ticks == 0) {
preVX = nextVX;
preVY = nextVY;
preVZ = nextVZ;
nextVX = random.nextGaussian() * 0.02;
nextVY = -random.nextDouble() * 0.02 - 0.02;
nextVZ = random.nextGaussian() * 0.02;
}
double delta = (double) ticks / 63.0;
if (this.age <= 40) {
this.setColorAlpha(this.age / 40F);
}
else if (this.age >= this.maxAge - 40) {
this.setColorAlpha((this.maxAge - this.age) / 40F);
}
if (this.age >= this.maxAge) {
this.markDead();
}
this.velocityX = MathHelper.lerp(delta, preVX, nextVX);
this.velocityY = MathHelper.lerp(delta, preVY, nextVY);
this.velocityZ = MathHelper.lerp(delta, preVZ, nextVZ);
//this.angle += angleSpeed;
super.tick();
}
@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
}
@Environment(EnvType.CLIENT)
public static class FactoryTenaneaPetal implements ParticleFactory<DefaultParticleType> {
private final SpriteProvider sprites;
public FactoryTenaneaPetal(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 ParticleTenaneaPetal(world, x, y, z, 1, 1, 1, sprites);
}
}
}

View file

@ -14,6 +14,7 @@ import ru.betterend.particle.ParticleGeyser;
import ru.betterend.particle.ParticleGlowingSphere;
import ru.betterend.particle.ParticleSnowflake;
import ru.betterend.particle.ParticleSulphur;
import ru.betterend.particle.ParticleTenaneaPetal;
import ru.betterend.particle.PaticlePortalSphere;
public class EndParticles {
@ -25,6 +26,7 @@ public class EndParticles {
public static final DefaultParticleType SNOWFLAKE = register("snowflake");
public static final DefaultParticleType AMBER_SPHERE = register("amber_sphere");
public static final DefaultParticleType BLACK_SPORE = register("black_spore");
public static final DefaultParticleType TENANEA_PETAL = register("tenanea_petal");
public static void register() {
ParticleFactoryRegistry.getInstance().register(GLOWING_SPHERE, ParticleGlowingSphere.FactoryGlowingSphere::new);
@ -35,6 +37,7 @@ public class EndParticles {
ParticleFactoryRegistry.getInstance().register(SNOWFLAKE, ParticleSnowflake.FactorySnowflake::new);
ParticleFactoryRegistry.getInstance().register(AMBER_SPHERE, ParticleGlowingSphere.FactoryGlowingSphere::new);
ParticleFactoryRegistry.getInstance().register(BLACK_SPORE, ParticleBlackSpore.FactoryBlackSpore::new);
ParticleFactoryRegistry.getInstance().register(TENANEA_PETAL, ParticleTenaneaPetal.FactoryTenaneaPetal::new);
}
private static DefaultParticleType register(String name) {

View file

@ -201,7 +201,7 @@ public class MHelper {
}
}
return ALPHA | red << 16 | green << 8 | blue << 0;
return ALPHA | red << 16 | green << 8 | blue;
}
public static float[] fromRGBtoHSB(int r, int g, int b) {

View file

@ -0,0 +1,3 @@
{
"material": "canvas:emissive_no_diffuse"
}

View file

@ -0,0 +1,6 @@
{
"textures": [
"betterend:tenanea_petal_0",
"betterend:tenanea_petal_1"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB