第三方模组开发者指南
我们非常欢迎您对MadParticle作出主动或被动的支持。
被动兼容
只需要让您的粒子继承TextureSheetParticle,按常规路径走原版ParticleEngine的各种逻辑,MadParticle会自动地按照用户的设置进行接管。
主动兼容
在以上所述的被动兼容的基础上,您还可以主动向MadParticle告知您的粒子是否支持并行计算,以及是否支持实例化渲染。
info
如果您不确定您的粒子是否支持并行计算和实例化渲染:
- 只需要检查您的粒子
tick方法中的内容是否含有只能在主线程中执行的内容,例如对Minecraft对象的写操作; - 您的粒子是否含有特殊的渲染?比如具有固定旋转角度而不是常规billboard、材质不来源于
TextureAtlas.LOCATION_PARTICLES; 
MadParticle在Particle类中注入了类型为枚举TakeOver.TickType的madparticleTickType字段,以表示这个粒子是否支持并行计算。TickType的值可以是SYNC、ASYNC和UNKNOWN。对于没有主动赋值的第三方粒子,默认值是UNKNOWN。
MadParticle依靠Particle.getRenderType方法来判断粒子是否支持实例化渲染。如果你返回传统的PARTICLE_SHEET_TRANSLUCENT或PARTICLE_SHEET_OPAQUE,MadParticle会自动根据用户设置来决定是否进行实例化渲染。如果返回INSTANCED,则是显式指定总是进行实例化渲染。
以下是完整的参考代码:
public class YourParticle extends TextureSheetParticle {
    private @NotNull ParticleRenderType particleRenderType = ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
    public YourParticle(ClientLevel pLevel, double pX, double pY, double pZ, ParticleRenderType particleRenderType) {
        super(pLevel, pX, pY, pZ);
        if (ModList.get().isLoaded("madparticle")) {
            try {
                var madparticleTickType = this.getClass().getDeclaredField("madparticleTickType");
                madparticleTickType.setAccessible(true);
                var takeOver = Class.forName("cn.ussshenzhou.madparticle.particle.enums.TakeOver.TickType");
                var valueOf = takeOver.getMethod("valueOf", String.class);
                //SYNC ASYNC UNKNOWN
                var sync = valueOf.invoke(null, "SYNC");
                madparticleTickType.set(this, sync);
            } catch (NoSuchFieldException | ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
                     InvocationTargetException ignored) {
            }
            try {
                var madparticleModParticleRenderTypes = Class.forName("cn.ussshenzhou.madparticle.particle.ModParticleRenderTypes");
                var instance = madparticleModParticleRenderTypes.getField("INSTANCED");
                this.particleRenderType = (ParticleRenderType) instance.get(null);
            } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
            }
        }
    }
    /**
     * Do NOT put reflection or other logic here. This method should be as quick as possible.
     */
    @Override
    public @NotNull ParticleRenderType getRenderType() {
        return particleRenderType;
    }
}
info
这里利用了反射来避免在你的项目中引入MadParticle本身。如果你不太喜欢这样做,你也可以借助CurseMaven引入MadParticle。