Search in sources :

Example 1 with VFXScaleFunction

use of hellfirepvp.astralsorcery.client.effect.function.VFXScaleFunction in project AstralSorcery by HellFirePvP.

the class EntityShootingStar method spawnEffects.

@OnlyIn(Dist.CLIENT)
private void spawnEffects() {
    float maxRenderPosDist = 96F;
    VFXRenderOffsetFunction<FXFacingParticle> renderFn = (fx, iPos, pTicks) -> {
        PlayerEntity pl = Minecraft.getInstance().player;
        if (pl == null) {
            return iPos;
        }
        Vector3 v = fx.getPosition().clone().subtract(Vector3.atEntityCorner(pl));
        if (v.length() <= maxRenderPosDist) {
            return iPos;
        }
        return Vector3.atEntityCorner(pl).add(v.normalize().multiply(maxRenderPosDist));
    };
    VFXScaleFunction<EntityVisualFX> scaleFn = (fx, scaleIn, pTicks) -> {
        PlayerEntity pl = Minecraft.getInstance().player;
        if (pl == null) {
            return scaleIn;
        }
        Vector3 v = fx.getPosition().clone().subtract(Vector3.atEntityCorner(pl));
        float mul = v.length() <= maxRenderPosDist ? 1 : (float) (maxRenderPosDist / (v.length()));
        return (scaleIn * 0.25F) + ((mul * scaleIn) - (scaleIn * 0.25F));
    };
    Vector3 thisPosition = Vector3.atEntityCorner(this);
    for (int i = 0; i < 4; i++) {
        if (rand.nextFloat() > 0.75F)
            continue;
        Vector3 dir = new Vector3(this.getMotion()).clone().multiply(rand.nextFloat() * -0.6F);
        dir.setX(dir.getX() + rand.nextFloat() * 0.008 * (rand.nextBoolean() ? 1 : -1));
        dir.setZ(dir.getZ() + rand.nextFloat() * 0.008 * (rand.nextBoolean() ? 1 : -1));
        EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).spawn(thisPosition).color(VFXColorFunction.WHITE).setMotion(dir).setAlphaMultiplier(0.85F).setScaleMultiplier(1.2F + rand.nextFloat() * 0.5F).scale(VFXScaleFunction.SHRINK.andThen(scaleFn)).alpha(VFXAlphaFunction.FADE_OUT).renderOffset(renderFn).setMaxAge(90 + rand.nextInt(40));
    }
    float scale = 4F + rand.nextFloat() * 3F;
    int age = 5 + rand.nextInt(2);
    Random effectSeed = new Random(this.getEffectSeed());
    EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).spawn(thisPosition).color(VFXColorFunction.constant(Color.getHSBColor(effectSeed.nextFloat() * 360F, 1F, 1F))).setScaleMultiplier(scale).scale(VFXScaleFunction.SHRINK.andThen(scaleFn)).renderOffset(renderFn).alpha(VFXAlphaFunction.FADE_OUT).setMaxAge(age);
    EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).spawn(thisPosition).color(VFXColorFunction.WHITE).setScaleMultiplier(scale * 0.6F).scale(VFXScaleFunction.SHRINK.andThen(scaleFn)).renderOffset(renderFn).alpha(VFXAlphaFunction.FADE_OUT).setMaxAge(Math.round(age * 1.5F));
}
Also used : EntityType(net.minecraft.entity.EntityType) EntityDataManager(net.minecraft.network.datasync.EntityDataManager) EntityTypesAS(hellfirepvp.astralsorcery.common.lib.EntityTypesAS) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) VFXScaleFunction(hellfirepvp.astralsorcery.client.effect.function.VFXScaleFunction) Random(java.util.Random) Dist(net.minecraftforge.api.distmarker.Dist) EffectTemplatesAS(hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS) Minecraft(net.minecraft.client.Minecraft) IPacket(net.minecraft.network.IPacket) VFXRenderOffsetFunction(hellfirepvp.astralsorcery.client.effect.function.VFXRenderOffsetFunction) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) FXFacingParticle(hellfirepvp.astralsorcery.client.effect.vfx.FXFacingParticle) VFXAlphaFunction(hellfirepvp.astralsorcery.client.effect.function.VFXAlphaFunction) ASDataSerializers(hellfirepvp.astralsorcery.common.util.data.ASDataSerializers) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) DataParameter(net.minecraft.network.datasync.DataParameter) EffectHelper(hellfirepvp.astralsorcery.client.effect.handler.EffectHelper) java.awt(java.awt) Vector3d(net.minecraft.util.math.vector.Vector3d) VFXColorFunction(hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction) MathHelper(net.minecraft.util.math.MathHelper) EntityVisualFX(hellfirepvp.astralsorcery.client.effect.EntityVisualFX) Random(java.util.Random) FXFacingParticle(hellfirepvp.astralsorcery.client.effect.vfx.FXFacingParticle) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) EntityVisualFX(hellfirepvp.astralsorcery.client.effect.EntityVisualFX) PlayerEntity(net.minecraft.entity.player.PlayerEntity) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

EntityVisualFX (hellfirepvp.astralsorcery.client.effect.EntityVisualFX)1 VFXAlphaFunction (hellfirepvp.astralsorcery.client.effect.function.VFXAlphaFunction)1 VFXColorFunction (hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction)1 VFXRenderOffsetFunction (hellfirepvp.astralsorcery.client.effect.function.VFXRenderOffsetFunction)1 VFXScaleFunction (hellfirepvp.astralsorcery.client.effect.function.VFXScaleFunction)1 EffectHelper (hellfirepvp.astralsorcery.client.effect.handler.EffectHelper)1 FXFacingParticle (hellfirepvp.astralsorcery.client.effect.vfx.FXFacingParticle)1 EffectTemplatesAS (hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS)1 EntityTypesAS (hellfirepvp.astralsorcery.common.lib.EntityTypesAS)1 ASDataSerializers (hellfirepvp.astralsorcery.common.util.data.ASDataSerializers)1 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)1 java.awt (java.awt)1 Random (java.util.Random)1 Minecraft (net.minecraft.client.Minecraft)1 EntityType (net.minecraft.entity.EntityType)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)1 IPacket (net.minecraft.network.IPacket)1 DataParameter (net.minecraft.network.datasync.DataParameter)1 EntityDataManager (net.minecraft.network.datasync.EntityDataManager)1