From c5c6beb45382d814c2f57d6843253309a46044e0 Mon Sep 17 00:00:00 2001 From: Vaern Date: Mon, 24 Feb 2025 23:47:48 -0800 Subject: [PATCH] Finished casing physics added initial momentums as a test --- src/main/java/com/hbm/handler/CasingEjector.java | 2 +- .../java/com/hbm/items/weapon/ItemAmmoArty.java | 2 +- .../com/hbm/particle/ParticleSpentCasing.java | 15 ++++++++++----- src/main/java/com/hbm/particle/SpentCasing.java | 1 + .../com/hbm/particle/helper/CasingCreator.java | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hbm/handler/CasingEjector.java b/src/main/java/com/hbm/handler/CasingEjector.java index 321aa8d71..5c27ac673 100644 --- a/src/main/java/com/hbm/handler/CasingEjector.java +++ b/src/main/java/com/hbm/handler/CasingEjector.java @@ -94,7 +94,7 @@ public class CasingEjector implements Cloneable { @SideOnly(Side.CLIENT) public void spawnCasing(TextureManager textureManager, SpentCasing config, World world, double x, double y, double z, float pitch, float yaw, boolean crouched) { Vec3 rotatedMotionVec = rotateVector(getMotion(), pitch + (float) rand.nextGaussian() * getPitchFactor(), yaw + (float) rand.nextGaussian() * getPitchFactor(), getPitchFactor(), getPitchFactor()); - ParticleSpentCasing casing = new ParticleSpentCasing(textureManager, world, x, y, z, rotatedMotionVec.xCoord, rotatedMotionVec.yCoord, rotatedMotionVec.zCoord, (float) (getPitchFactor() * rand.nextGaussian()), (float) (getYawFactor() * rand.nextGaussian()), config, false, 0, 0, 0); + ParticleSpentCasing casing = new ParticleSpentCasing(textureManager, world, x, y, z, rotatedMotionVec.xCoord, rotatedMotionVec.yCoord, rotatedMotionVec.zCoord, (float) (world.rand.nextGaussian() * 5F), (float) (world.rand.nextGaussian() * 10F), config, false, 0, 0, 0); offsetCasing(casing, getOffset(), pitch, yaw, crouched); diff --git a/src/main/java/com/hbm/items/weapon/ItemAmmoArty.java b/src/main/java/com/hbm/items/weapon/ItemAmmoArty.java index 0014cb736..f1c10ff91 100644 --- a/src/main/java/com/hbm/items/weapon/ItemAmmoArty.java +++ b/src/main/java/com/hbm/items/weapon/ItemAmmoArty.java @@ -184,7 +184,7 @@ public class ItemAmmoArty extends Item { return "item." + itemTypes[Math.abs(stack.getItemDamage()) % itemTypes.length].name; } - protected static SpentCasing SIXTEEN_INCH_CASE = new SpentCasing(CasingType.STRAIGHT).setScale(15F, 15F, 10F).setupSmoke(1F, 1D, 200, 60).setMaxAge(300); + protected static SpentCasing SIXTEEN_INCH_CASE = new SpentCasing(CasingType.STRAIGHT).setScale(15F, 15F, 10F).setupSmoke(1F, 1D, 200, 60).setMaxAge(300).setBounceMotion(1F, 0.5F); public abstract class ArtilleryShell { diff --git a/src/main/java/com/hbm/particle/ParticleSpentCasing.java b/src/main/java/com/hbm/particle/ParticleSpentCasing.java index 95d09f6c0..5def153ba 100644 --- a/src/main/java/com/hbm/particle/ParticleSpentCasing.java +++ b/src/main/java/com/hbm/particle/ParticleSpentCasing.java @@ -9,6 +9,7 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import com.hbm.main.ResourceManager; +import com.hbm.util.BobMathUtil; import com.hbm.util.Tuple.Pair; import cpw.mods.fml.relauncher.Side; @@ -103,7 +104,7 @@ public class ParticleSpentCasing extends EntityFX { this.motionX *= 0.7D; this.motionZ *= 0.7D; - this.rotationPitch = 0; + this.rotationPitch = (float) (Math.floor(this.rotationPitch / 180F + 0.5F)) * 180F; this.momentumYaw *= 0.7F; this.onGround = false; } @@ -201,11 +202,15 @@ public class ParticleSpentCasing extends EntityFX { if (initMoY != motionY) { this.motionY *= -0.5D; - if(momentumPitch == 0 && this.motionY > 1e-7) { - momentumPitch = (float) rand.nextGaussian() * 10F * this.config.getBouncePitch(); - momentumYaw = (float) rand.nextGaussian() * 10F * this.config.getBounceYaw(); - } else if(Math.abs(momentumPitch) > 1e-7) + boolean rotFromSpeed = Math.abs(this.motionY) > 0.04; + if(rotFromSpeed || Math.abs(momentumPitch) > 1e-7) { momentumPitch *= -0.75F; + if(rotFromSpeed) { + float mult = (float) BobMathUtil.safeClamp(initMoY / 0.2F, -1F, 1F); + momentumPitch += rand.nextGaussian() * 10F * this.config.getBouncePitch() * mult; + momentumYaw += (float) rand.nextGaussian() * 10F * this.config.getBounceYaw() * mult; + } + } } if (initMoZ != motionZ) { diff --git a/src/main/java/com/hbm/particle/SpentCasing.java b/src/main/java/com/hbm/particle/SpentCasing.java index d9fa1007f..23cbfab93 100644 --- a/src/main/java/com/hbm/particle/SpentCasing.java +++ b/src/main/java/com/hbm/particle/SpentCasing.java @@ -86,6 +86,7 @@ public class SpentCasing implements Cloneable { return casingMap.get(name); } + /** Multiplier for default standard deviation of 10deg per tick, per bounce w/ full y speed */ public SpentCasing setBounceMotion(float yaw, float pitch) { this.bounceYaw = yaw; this.bouncePitch = pitch; diff --git a/src/main/java/com/hbm/particle/helper/CasingCreator.java b/src/main/java/com/hbm/particle/helper/CasingCreator.java index 967f6a381..cc8274079 100644 --- a/src/main/java/com/hbm/particle/helper/CasingCreator.java +++ b/src/main/java/com/hbm/particle/helper/CasingCreator.java @@ -75,7 +75,7 @@ public class CasingCreator implements IParticleCreator { int smokeLife = data.getInteger("smokeLife"); double smokeLift = data.getDouble("smokeLift"); int nodeLife = data.getInteger("nodeLife"); - ParticleSpentCasing casing = new ParticleSpentCasing(texman, world, x, y, z, mX, mY, mZ, 0, 0, casingConfig, smoking, smokeLife, smokeLift, nodeLife); + ParticleSpentCasing casing = new ParticleSpentCasing(texman, world, x, y, z, mX, mY, mZ, (float) (world.rand.nextGaussian() * 10F), (float) (world.rand.nextGaussian() * 5F), casingConfig, smoking, smokeLife, smokeLift, nodeLife); casing.prevRotationYaw = casing.rotationYaw = yaw; casing.prevRotationPitch = casing.rotationPitch = pitch; Minecraft.getMinecraft().effectRenderer.addEffect(casing);