Infusion particles
This commit is contained in:
parent
6dccc0bf32
commit
d9aa50fe1c
6 changed files with 193 additions and 17 deletions
63
src/main/java/ru/betterend/particle/InfusionParticle.java
Normal file
63
src/main/java/ru/betterend/particle/InfusionParticle.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package ru.betterend.particle;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
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;
|
||||
|
||||
public class InfusionParticle extends SpriteBillboardParticle {
|
||||
|
||||
private final SpriteProvider spriteProvider;
|
||||
|
||||
public InfusionParticle(ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ, float[] palette, SpriteProvider spriteProvider) {
|
||||
super(clientWorld, x, y, z, 0.0, 0.0, 0.0);
|
||||
this.setSpriteForAge(spriteProvider);
|
||||
this.spriteProvider = spriteProvider;
|
||||
this.setColor(palette[0], palette[1], palette[2]);
|
||||
this.setColorAlpha(palette[3]);
|
||||
this.velocityX = velocityX * 0.1D;
|
||||
this.velocityY = velocityY * 0.1D;
|
||||
this.velocityZ = velocityZ * 0.1D;
|
||||
this.maxAge = (int) (3.0F / (this.random.nextFloat() * 0.9F + 0.1F));
|
||||
this.scale *= 0.9F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.prevPosX = this.x;
|
||||
this.prevPosY = this.y;
|
||||
this.prevPosZ = this.z;
|
||||
if (this.age++ >= this.maxAge) {
|
||||
this.markDead();
|
||||
} else {
|
||||
this.setSpriteForAge(spriteProvider);
|
||||
double velocityX = 2.0D * this.velocityX * this.random.nextDouble();
|
||||
double velocityY = 3.0D * this.velocityY * this.random.nextDouble();
|
||||
double velocityZ = 2.0D * this.velocityZ * this.random.nextDouble();
|
||||
this.move(velocityX, velocityY, velocityZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class DefaultFactory implements ParticleFactory<InfusionParticleType> {
|
||||
private final SpriteProvider spriteProvider;
|
||||
|
||||
public DefaultFactory(SpriteProvider spriteProvider) {
|
||||
this.spriteProvider = spriteProvider;
|
||||
}
|
||||
|
||||
public Particle createParticle(InfusionParticleType particleType, ClientWorld clientWorld, double d, double e, double f, double g, double h, double i) {
|
||||
return new InfusionParticle(clientWorld, d, e, f, g, h, i, particleType.getPalette(), this.spriteProvider);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package ru.betterend.particle;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.serialization.Codec;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import net.minecraft.command.argument.ItemStackArgument;
|
||||
import net.minecraft.command.argument.ItemStringReader;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.particle.ParticleType;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import ru.betterend.registry.EndParticles;
|
||||
import ru.betterend.util.ColorUtil;
|
||||
|
||||
public class InfusionParticleType extends ParticleType<InfusionParticleType> implements ParticleEffect {
|
||||
public static final Codec<InfusionParticleType> CODEC = ItemStack.CODEC.xmap(itemStack -> {
|
||||
return new InfusionParticleType(EndParticles.INFUSION, itemStack);
|
||||
}, infusionParticleType -> {
|
||||
return infusionParticleType.itemStack;
|
||||
});
|
||||
public static final ParticleEffect.Factory<InfusionParticleType> PARAMETERS_FACTORY = new ParticleEffect.Factory<InfusionParticleType>() {
|
||||
public InfusionParticleType read(ParticleType<InfusionParticleType> particleType, StringReader stringReader) throws CommandSyntaxException {
|
||||
stringReader.expect(' ');
|
||||
ItemStringReader itemStringReader = new ItemStringReader(stringReader, false).consume();
|
||||
ItemStack itemStack = new ItemStackArgument(itemStringReader.getItem(), itemStringReader.getTag()).createStack(1, false);
|
||||
return new InfusionParticleType(particleType, itemStack);
|
||||
}
|
||||
|
||||
public InfusionParticleType read(ParticleType<InfusionParticleType> particleType, PacketByteBuf packetByteBuf) {
|
||||
return new InfusionParticleType(particleType, packetByteBuf.readItemStack());
|
||||
}
|
||||
};
|
||||
|
||||
private ParticleType<InfusionParticleType> type;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public InfusionParticleType(ParticleType<InfusionParticleType> particleType, ItemStack stack) {
|
||||
super(true, PARAMETERS_FACTORY);
|
||||
this.type = particleType;
|
||||
this.itemStack = stack;
|
||||
}
|
||||
|
||||
public InfusionParticleType(ItemStack stack) {
|
||||
this(EndParticles.INFUSION, stack);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public float[] getPalette() {
|
||||
int color = ColorUtil.extractColor(itemStack.getItem());
|
||||
return ColorUtil.toFloatArray(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleType<?> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf buffer) {
|
||||
buffer.writeItemStack(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Registry.PARTICLE_TYPE.getId(this).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<InfusionParticleType> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue