粒子
第一个粒子
最近有了些想法,于是乎,重新开始了模组开发的学习。
本文主要用于记录开发过程的问题,留下学习的记录。
基于此教程
与此教程不同的是,这里将更大篇幅的记录粒子开发
而不是浅尝辄止
版本为1.16.5
WindParticle–粒子效果类
没什么可说的,只有一些变量名称的变化
public class WindParticle extends SpriteTexturedParticle {
protected WindParticle(ClientWorld world, double x, double y, double z, Vector3d speed, Color color, float diameter) {
super(world, x, y, z, speed.x, speed.y, speed.z);
this.lifetime=100;//最大生命周期
Random rand = new Random();
this.xd = rand.nextDouble() * 0.2 - 0.1;//x速度
this.yd = rand.nextDouble() * 0.1;
this.zd = rand.nextDouble() * 0.2 - 0.1;
setColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F);
this.setAlpha(color.getAlpha());//透明度
final float PARTICLE_SCALE_FOR_ONE_METRE = 0.5F;//大小
this.scale(PARTICLE_SCALE_FOR_ONE_METRE * diameter);
hasPhysics = true;//碰撞
}
@Override
public IParticleRenderType getRenderType() {
return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;//渲染方式
}
}
如果不设置速度,默认是随机速度
继承了SpriteTexturedParticle意思是将使用一张材质作为粒子效果的显示
WindData–使用接口IParticleData存放和处理这些创建例子效果的数据
注意方法名的变化
public class WindData implements IParticleData {
public WindData(Vector3d speed, Color color, float diameter) {
this.speed = speed;
this.color = color;
this.diameter = diameter;
}
private final Vector3d speed;
private final Color color;
private final float diameter;
public static final IDeserializer<WindData> DESERIALIZER = new IDeserializer<WindData