Skip to content

Commit

Permalink
basic ring smoke particle
Browse files Browse the repository at this point in the history
  • Loading branch information
iron431 committed Dec 21, 2023
1 parent 615adf1 commit 427e453
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ dependencies {
compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-common-api:${jei_version}")
compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-forge-api:${jei_version}")
runtimeOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-forge:${jei_version}")
runtimeOnly fg.deobf("curse.maven:just-enough-effect-descriptions-jeed-532286:4599099")
//runtimeOnly fg.deobf("curse.maven:just-enough-effect-descriptions-jeed-532286:4599099")

// CURIOS *****************************************************************************************************
implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.redspace.ironsspellbooks.entity.spells.AbstractConeProjectile;
import io.redspace.ironsspellbooks.registries.EntityRegistry;
import io.redspace.ironsspellbooks.api.spells.SchoolType;
import io.redspace.ironsspellbooks.registries.ParticleRegistry;
import io.redspace.ironsspellbooks.util.ParticleHelper;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.EntityType;
Expand All @@ -30,26 +31,29 @@ public void spawnParticles() {
return;
}
Vec3 rotation = owner.getLookAngle().normalize();
var pos = owner.position().add(rotation.scale(1.6));
var pos = owner.position().add(rotation.scale(1.5));

double x = pos.x;
double y = pos.y + owner.getEyeHeight() * .9f;
double z = pos.z;

double speed = random.nextDouble() * .4 + .45;
for (int i = 0; i < 25; i++) {
for (int i = 0; i < 5; i++) {
double offset = .25;
double ox = Math.random() * 2 * offset - offset;
double oy = Math.random() * 2 * offset - offset;
double oz = Math.random() * 2 * offset - offset;

double angularness = .8;
Vec3 randomVec = new Vec3(Math.random() * 2 * angularness - angularness, Math.random() * 2 * angularness - angularness, Math.random() * 2 * angularness - angularness).normalize();
Vec3 randomVec = new Vec3(Math.random() * 2 * angularness - angularness, Math.random() * 2 * angularness - angularness, Math.random() * 2 * angularness - angularness).normalize();
Vec3 result = (rotation.scale(3).add(randomVec)).normalize().scale(speed);
level.addParticle(Math.random() > .05 ? ParticleTypes.SNOWFLAKE : ParticleHelper.SNOWFLAKE, x + ox, y + oy, z + oz, result.x, result.y, result.z);
}


}
if (tickCount % 10 == 0) {
var forward = rotation.scale(.175f);
level.addParticle(ParticleRegistry.RING_SMOKE_PARTICLE.get(), x, y, z, forward.x, forward.y, forward.z);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package io.redspace.ironsspellbooks.particle;

import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import com.sun.jna.platform.win32.Dxva2;
import io.redspace.ironsspellbooks.IronsSpellbooks;
import io.redspace.ironsspellbooks.api.util.Utils;
import net.minecraft.Util;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.util.Mth;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import java.util.function.Consumer;

public class RingSmokeParticle extends TextureSheetParticle {
//private static final Vector3f ROTATION_VECTOR = Util.make(new Vector3f(0.5F, 0.5F, 0.5F), Vector3f::normalize);
private static final Vector3f ROTATION_VECTOR = new Vector3f(0F, 0F, 0F);
private static final Vector3f TRANSFORM_VECTOR = new Vector3f(-1.0F, -1.0F, 0.0F);
private final float targetSize;
private final boolean isFullbright;
private float rx;
private float ry;

RingSmokeParticle(ClientLevel pLevel, double pX, double pY, double pZ, double xd, double yd, double zd/*, IShockwaveParticleOptions options*/) {
super(pLevel, pX, pY, pZ, 0, 0, 0);

this.xd = xd;
this.yd = yd;
this.zd = zd;
rx = /*heading.x;*/(float) -Math.asin(yd / new Vec3(xd, yd, zd).length());
ry = /*heading.y;*/ Mth.HALF_PI - (float) Mth.atan2(zd, xd);

this.targetSize = 2;//options.getScale();
this.quadSize = 0;
this.lifetime = (int) (20 + targetSize * 20);
this.gravity = 0f;

float f = random.nextFloat() * 0.14F + 0.85F;
this.rCol = 1;//options.color().x() * f;
this.gCol = 1;//options.color().y() * f;
this.bCol = 1;//options.color().z() * f;
this.friction = 1;
this.isFullbright = false;//options.isFullbright();
}

@Override
public float getQuadSize(float partialTick) {
var f = (partialTick + this.age) / (float) this.lifetime;
return Mth.lerp(f/*1 - (1 - f) * (1 - f)*/, .15f, targetSize);
}

@Override
public void tick() {
this.xo = this.x;
this.yo = this.y;
this.zo = this.z;
if (this.age++ >= this.lifetime) {
//IronsSpellbooks.LOGGER.debug("Removing shockwave particle {}/{} ({}/{})", age, lifetime, getQuadSize(0), targetSize);
this.remove();
} else {
this.move(this.xd, this.yd, this.zd);
this.yd *= .99f;
this.xd *= .99f;
this.zd *= .99f;
}
}

@Override
public void render(VertexConsumer buffer, Camera camera, float partialticks) {
// IronsSpellbooks.LOGGER.debug("RingSmokeParticle.render heading: ({},{})", heading.x * Mth.RAD_TO_DEG, heading.y * Mth.RAD_TO_DEG);
this.alpha = 1.0F - Mth.clamp((this.age + partialticks) / (float) this.lifetime, 0, 1F);
//Quaternion rot = new Quaternion(rx, ry, 0, false);
this.renderRotatedParticle(buffer, camera, partialticks, (quaternion) -> {
//quaternion.mul(Vector3f.XP.rotation(-degrees90));
quaternion.mul(Vector3f.YP.rotation(ry));
quaternion.mul(Vector3f.XP.rotation(rx));
// quaternion.mul(rot);
// quaternion.mul(rot);

});
//back face
this.renderRotatedParticle(buffer, camera, partialticks, (quaternion) -> {
quaternion.mul(Vector3f.YP.rotation(ry));
quaternion.mul(Vector3f.XP.rotation(Mth.PI));
quaternion.mul(Vector3f.XP.rotation(rx));
//quaternion.mul(Vector3f.YP.rotation(-(ry - degrees90)));
});
}

private void renderRotatedParticle(VertexConsumer pConsumer, Camera camera, float partialTick, Consumer<Quaternion> pQuaternion) {
/*
Copied from Shriek Particle
*/
Vec3 vec3 = camera.getPosition();
float f = (float) (Mth.lerp(partialTick, this.xo, this.x) - vec3.x());
float f1 = (float) (Mth.lerp(partialTick, this.yo, this.y) - vec3.y());
float f2 = (float) (Mth.lerp(partialTick, this.zo, this.z) - vec3.z());
Quaternion quaternion = new Quaternion(ROTATION_VECTOR, 0.0F, true);

pQuaternion.accept(quaternion);
//TRANSFORM_VECTOR.transform(quaternion);
Vector3f[] avector3f = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)};
float f3 = this.getQuadSize(partialTick);

for (int i = 0; i < 4; ++i) {
Vector3f vector3f = avector3f[i];
vector3f.transform(quaternion);
vector3f.mul(f3);
vector3f.add(f, f1, f2);
}

int j = this.getLightColor(partialTick);
this.makeCornerVertex(pConsumer, avector3f[0], this.getU1(), this.getV1(), j);
this.makeCornerVertex(pConsumer, avector3f[1], this.getU1(), this.getV0(), j);
this.makeCornerVertex(pConsumer, avector3f[2], this.getU0(), this.getV0(), j);
this.makeCornerVertex(pConsumer, avector3f[3], this.getU0(), this.getV1(), j);
}

private void makeCornerVertex(VertexConsumer pConsumer, Vector3f pVec3f, float p_233996_, float p_233997_, int p_233998_) {
pConsumer.vertex(pVec3f.x(), pVec3f.y(), pVec3f.z()).uv(p_233996_, p_233997_).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(p_233998_).endVertex();
}

@NotNull
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}

@Override
protected int getLightColor(float pPartialTick) {
if (isFullbright) {
return LightTexture.FULL_BRIGHT;
}
BlockPos blockpos = new BlockPos(this.x, this.y, this.z).above();
return this.level.hasChunkAt(blockpos) ? LevelRenderer.getLightColor(this.level, blockpos) : 0;
}

@OnlyIn(Dist.CLIENT)
public static class Provider implements ParticleProvider<SimpleParticleType> {
private final SpriteSet sprite;

public Provider(SpriteSet pSprite) {
this.sprite = pSprite;
}

public Particle createParticle(@NotNull SimpleParticleType options, @NotNull ClientLevel pLevel, double pX, double pY, double pZ, double pXSpeed, double pYSpeed, double pZSpeed) {
RingSmokeParticle shriekparticle = new RingSmokeParticle(pLevel, pX, pY, pZ, pXSpeed, pYSpeed, pZSpeed/*, options*/);
shriekparticle.pickSprite(this.sprite);
shriekparticle.setAlpha(1.0F);
return shriekparticle;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void register(IEventBus eventBus) {
public static final RegistryObject<SimpleParticleType> SIPHON_PARTICLE = PARTICLE_TYPES.register("spell", () -> new SimpleParticleType(false));
public static final RegistryObject<SimpleParticleType> ACID_PARTICLE = PARTICLE_TYPES.register("acid", () -> new SimpleParticleType(false));
public static final RegistryObject<SimpleParticleType> ACID_BUBBLE_PARTICLE = PARTICLE_TYPES.register("acid_bubble", () -> new SimpleParticleType(false));
public static final RegistryObject<SimpleParticleType> RING_SMOKE_PARTICLE = PARTICLE_TYPES.register("ring_smoke", () -> new SimpleParticleType(false));
public static final RegistryObject<ParticleType<FogParticleOptions>> FOG_PARTICLE = PARTICLE_TYPES.register("fog", () -> new ParticleType<FogParticleOptions>(true, FogParticleOptions.DESERIALIZER) {
public Codec<FogParticleOptions> codec() {
return FogParticleOptions.CODEC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public static void registerParticles(RegisterParticleProvidersEvent event) {
event.register(ParticleRegistry.ACID_BUBBLE_PARTICLE.get(), AcidBubbleParticle.Provider::new);
event.register(ParticleRegistry.ZAP_PARTICLE.get(), ZapParticle.Provider::new);
event.register(ParticleRegistry.FIREFLY_PARTICLE.get(), FireflyParticle.Provider::new);
event.register(ParticleRegistry.RING_SMOKE_PARTICLE.get(), RingSmokeParticle.Provider::new);
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"irons_spellbooks:shockwave"
]
}

0 comments on commit 427e453

Please sign in to comment.