-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fragmentation grenade 'wave' particle
- Loading branch information
1 parent
01dba31
commit be9d6f3
Showing
7 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...cts/pswg_gadgets/src/client/java/dev/pswg/particles/FragmentationGrenadeWaveParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package dev.pswg.particles; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.particle.*; | ||
import net.minecraft.client.render.Camera; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.particle.SimpleParticleType; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.util.math.random.Random; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.joml.Quaternionf; | ||
import org.joml.Vector3f; | ||
|
||
@Environment(value = EnvType.CLIENT) | ||
public class FragmentationGrenadeWaveParticle extends SpriteBillboardParticle | ||
{ | ||
private float scaleX = 1; | ||
private float scaleY = 1; | ||
|
||
protected FragmentationGrenadeWaveParticle(ClientWorld clientWorld, double x, double y, double z, double vX, double vY, double vZ, SpriteProvider spriteProvider) | ||
{ | ||
super(clientWorld, x, y, z); | ||
setBoundingBoxSpacing(0.25f, 0.25f); | ||
this.collidesWithWorld = false; | ||
velocityX = vX; | ||
velocityY = vY + (double)(random.nextFloat() / 500.0f); | ||
velocityZ = vZ; | ||
this.maxAge = 20; | ||
this.scale = 1; | ||
this.setSprite(spriteProvider); | ||
this.setColor(Random.create().nextBetween(0, 2) / 2f + 0.98f, Random.create().nextBetween(0, 2) / 2f + 0.98f, 1); | ||
} | ||
|
||
private void updateShape(float age) | ||
{ | ||
if (age <= 10) | ||
{ | ||
this.alpha = 1; | ||
|
||
this.scaleX = 2 * (1 + 2 * (float)Math.max(4 * Math.pow(age / 10 - 0.5f, 3), 0)); | ||
this.scaleY = 2 * (1 - (float)Math.pow((age - 4) / 6, 2)); | ||
} | ||
else | ||
{ | ||
this.scaleX = this.scaleY = 1; | ||
this.scale = (float)Math.pow(age / 10, 6); | ||
this.alpha = (float)(Math.max(1 - (Math.pow(age / 20, 3) * 2), 0.001f)); | ||
} | ||
} | ||
|
||
@Override | ||
public ParticleTextureSheet getType() | ||
{ | ||
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; | ||
} | ||
|
||
@Override | ||
public void render(VertexConsumer vertexConsumer, Camera camera, float tickDelta) | ||
{ | ||
updateShape(this.age + tickDelta); | ||
|
||
Vec3d vec3d = camera.getPos(); | ||
float f = (float)(MathHelper.lerp((double)tickDelta, this.prevPosX, this.x) - vec3d.getX()); | ||
float g = (float)(MathHelper.lerp((double)tickDelta, this.prevPosY, this.y) - vec3d.getY()); | ||
float h = (float)(MathHelper.lerp((double)tickDelta, this.prevPosZ, this.z) - vec3d.getZ()); | ||
|
||
Quaternionf quaternionf = new Quaternionf(); | ||
this.getRotator().setRotation(quaternionf, camera, tickDelta); | ||
if (this.angle != 0.0F) | ||
{ | ||
quaternionf.rotateZ(MathHelper.lerp(tickDelta, this.prevAngle, this.angle)); | ||
} | ||
|
||
Vector3f[] corners = 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 size = this.getSize(tickDelta); | ||
|
||
for (int j = 0; j < 4; ++j) | ||
{ | ||
Vector3f vector3f = corners[j]; | ||
vector3f.mul(scaleX, scaleY, 1); | ||
vector3f.rotate(new Quaternionf(camera.getRotation().rotateZ((float)Math.toRadians(180d)))); | ||
vector3f.mul(size); | ||
vector3f.add(f, g, h); | ||
} | ||
|
||
float k = this.getMinU(); | ||
float l = this.getMaxU(); | ||
float m = this.getMinV(); | ||
float n = this.getMaxV(); | ||
int o = this.getBrightness(tickDelta); | ||
vertexConsumer.vertex(corners[0].x(), corners[0].y(), corners[0].z()) | ||
.texture(l, n) | ||
.color(this.red, this.green, this.blue, this.alpha) | ||
.light(o); | ||
vertexConsumer.vertex(corners[1].x(), corners[1].y(), corners[1].z()) | ||
.texture(l, m) | ||
.color(this.red, this.green, this.blue, this.alpha) | ||
.light(o); | ||
vertexConsumer.vertex(corners[2].x(), corners[2].y(), corners[2].z()) | ||
.texture(k, m) | ||
.color(this.red, this.green, this.blue, this.alpha) | ||
.light(o); | ||
vertexConsumer.vertex(corners[3].x(), corners[3].y(), corners[3].z()) | ||
.texture(k, n) | ||
.color(this.red, this.green, this.blue, this.alpha) | ||
.light(o); | ||
} | ||
|
||
@Environment(value = EnvType.CLIENT) | ||
public static class Factory implements ParticleFactory<SimpleParticleType> | ||
{ | ||
private final SpriteProvider spriteProvider; | ||
|
||
public Factory(SpriteProvider spriteProvider) | ||
{ | ||
this.spriteProvider = spriteProvider; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Particle createParticle(SimpleParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) | ||
{ | ||
FragmentationGrenadeWaveParticle fragmentationGrenadeParticle = new FragmentationGrenadeWaveParticle(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider); | ||
fragmentationGrenadeParticle.setSprite(spriteProvider); | ||
return fragmentationGrenadeParticle; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
..._gadgets/src/main/resources/assets/pswg_gadgets/particles/fragmentation_grenade_wave.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"textures": [ | ||
"pswg_gadgets:fragmentation_grenade_wave" | ||
] | ||
} |
Binary file added
BIN
+562 Bytes
.../resources/assets/pswg_gadgets/textures/particle/fragmentation_grenade_wave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.