跳转至

基本信息

自 2.0.4

开发 Maven

repositories {
    maven { url = "https://maven.firstdark.dev/snapshots" } // LDLib2, Photon2
}

dependencies {
    // LDLib2
    implementation("com.lowdragmc.ldlib2:ldlib2-neoforge-${minecraft_version}:${ldlib2_version}:all") { transitive = false }
    compileOnly("org.appliedenergistics.yoga:yoga:1.0.0")

    // Photon2
    implementation("com.lowdragmc.photon:photon-neoforge-${minecraft_version}:${photon2_version}") { transitive = false }
}

最新版本

ldlib2 maven photon maven


如何加载和使用效果文件?

FX fx = FXHelper.getFX(ResourceLocation.parse("photon:fire"));
// 绑定到一个方块
new BlockEffectExecutor(fx, level, pos).start();
// 绑定到一个实体
new EntityEffectExecutor(fx, level, entity, AutoRotate.NONE).start();

实现你自己的 IEffectExecutor 来管理 Photon 效果的生命周期。

有时候,你想用额外的逻辑来控制你的效果。 你可以实现 IEffectExecutor 并做你想做的事。

public interface IEffectExecutor {

    Level getLevel();

    /**
     * 在 FX 对象持续时间内的每一 tick 更新。在这里执行低频逻辑。
     * <br>
     * 例如:清除粒子
     * @param fxObject fx 对象
     */
    default void updateFXObjectTick(IFXObject fxObject) {
    }

    /**
     * 在渲染期间每帧更新每个 FX 对象。在这里执行高频逻辑。
     * <br>
     * 例如:更新发射器位置、旋转、缩放
     * @param fxObject fx 对象
     * @param partialTicks partialTicks
     */
    default void updateFXObjectFrame(IFXObject fxObject, float partialTicks) {

    }

    default RandomSource getRandomSource() {
        return getLevel().random;
    }
}
public class ExampleExecutor extends IEffectExecutor {
    public final FX fx;
    @Getter
    public final Level level;
    // 运行时
    @Nullable
    private FXRuntime fxRuntime;

    public ExampleExecutor(FX fx, Level level) {
        this.fx = fx;
        this.level = level;
    }

    public void emit() {
        kill();
        fxRuntime = fx.createRuntime(); // (1)
        fxRuntime.emmit(this);
    }

    public void kill() {
        if (fxRuntime == null) return;
        fxRuntime.destory(true);
        fxRuntime = null;
    }
}
  1. 如果你想修改配置数据,请使用 fx.createRuntime(true)

查看 ExampleExecutor 了解它是如何工作的。

FX fx = FXHelper.getFX(ResourceLocation.parse("photon:fire"));
var executor = new ExampleExecutor(fx, level);
executor.emit();