From 61bba7974f0c52118bc26f2998090f27f9bd83ab Mon Sep 17 00:00:00 2001 From: Vaern Date: Sun, 23 Feb 2025 22:06:16 -0800 Subject: [PATCH] added rotational momentum, better bounces to spent casings turret's cases do not rotate for some reason! --- .../com/hbm/particle/ParticleSpentCasing.java | 131 +++++++++++++++--- .../java/com/hbm/particle/SpentCasing.java | 4 +- 2 files changed, 114 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/hbm/particle/ParticleSpentCasing.java b/src/main/java/com/hbm/particle/ParticleSpentCasing.java index a21aad162..95d09f6c0 100644 --- a/src/main/java/com/hbm/particle/ParticleSpentCasing.java +++ b/src/main/java/com/hbm/particle/ParticleSpentCasing.java @@ -13,14 +13,21 @@ import com.hbm.util.Tuple.Pair; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; +import net.minecraft.util.ReportedException; import net.minecraft.util.Vec3; import net.minecraft.world.World; @@ -49,8 +56,10 @@ public class ParticleSpentCasing extends EntityFX { this.momentumPitch = momentumPitch; this.momentumYaw = momentumYaw; this.config = config; - + this.particleMaxAge = config.getMaxAge(); + this.setSize(2 * dScale * Math.max(config.getScaleX(), config.getScaleZ()), dScale * config.getScaleY()); + this.yOffset = this.height / 2F; this.isSmoking = smoking; this.maxSmokeGen = smokeLife; @@ -85,26 +94,20 @@ public class ParticleSpentCasing extends EntityFX { } this.motionY -= 0.04D * (double) this.particleGravity; - double prevMotionY = this.motionY; this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.98D; this.motionY *= 0.98D; this.motionZ *= 0.98D; - + if(this.onGround) { this.motionX *= 0.7D; this.motionZ *= 0.7D; - } - - if(onGround) { - this.onGround = false; - motionY = prevMotionY * -0.5; - this.rotationPitch = 0; - //momentumPitch = (float) rand.nextGaussian() * config.getBouncePitch(); - //momentumYaw = (float) rand.nextGaussian() * config.getBounceYaw(); + this.rotationPitch = 0; + this.momentumYaw *= 0.7F; + this.onGround = false; } - + if(particleAge > maxSmokeGen && !smokeNodes.isEmpty()) smokeNodes.clear(); @@ -124,16 +127,106 @@ public class ParticleSpentCasing extends EntityFX { smokeNodes.add(new Pair(Vec3.createVectorHelper(0, 0, 0), smokeNodes.isEmpty() ? 0.0D : 1D)); } } - + prevRotationPitch = rotationPitch; prevRotationYaw = rotationYaw; - - if(onGround) { - rotationPitch = 0; - } else { - rotationPitch += momentumPitch; - rotationYaw += momentumYaw; + + rotationPitch += momentumPitch; + rotationYaw += momentumYaw; + } + + public void moveEntity(double motionX, double motionY, double motionZ) { + this.worldObj.theProfiler.startSection("move"); + this.ySize *= 0.4F; + + if (this.isInWeb) { + this.isInWeb = false; + motionX *= 0.25D; + motionY *= 0.05000000074505806D; + motionZ *= 0.25D; + this.motionX = 0.0D; + this.motionY = 0.0D; + this.motionZ = 0.0D; } + + //Handle block collision + double initMoX = motionX; + double initMoY = motionY; + double initMoZ = motionZ; + AxisAlignedBB axisalignedbb = this.boundingBox.copy(); + + List list = this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox.addCoord(motionX, motionY, motionZ)); + + for (int i = 0; i < list.size(); ++i) { + motionY = ((AxisAlignedBB)list.get(i)).calculateYOffset(this.boundingBox, motionY); + } + + this.boundingBox.offset(0.0D, motionY, 0.0D); + + int j; + + for (j = 0; j < list.size(); ++j) { + motionX = ((AxisAlignedBB)list.get(j)).calculateXOffset(this.boundingBox, motionX); + } + + this.boundingBox.offset(motionX, 0.0D, 0.0D); + + for (j = 0; j < list.size(); ++j) { + motionZ = ((AxisAlignedBB)list.get(j)).calculateZOffset(this.boundingBox, motionZ); + } + + this.boundingBox.offset(0.0D, 0.0D, motionZ); + + this.worldObj.theProfiler.endSection(); + this.worldObj.theProfiler.startSection("rest"); + this.posX = (this.boundingBox.minX + this.boundingBox.maxX) / 2.0D; + this.posY = this.boundingBox.minY + (double)this.yOffset - (double)this.ySize; + this.posZ = (this.boundingBox.minZ + this.boundingBox.maxZ) / 2.0D; + this.isCollidedHorizontally = initMoX != motionX || initMoZ != motionZ; + this.isCollidedVertically = initMoY != motionY; + this.onGround = initMoY != motionY && initMoY < 0.0D; + this.isCollided = this.isCollidedHorizontally || this.isCollidedVertically; + this.updateFallState(motionY, this.onGround); + + //Handles bounces + if (initMoX != motionX) { + this.motionX *= -0.25D; + + if(Math.abs(momentumYaw) > 1e-7) + momentumYaw *= -0.75F; + else + momentumYaw = (float) rand.nextGaussian() * 10F * this.config.getBounceYaw(); + } + + 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) + momentumPitch *= -0.75F; + } + + if (initMoZ != motionZ) { + this.motionZ *= -0.25D; + + if(Math.abs(momentumYaw) > 1e-7) + momentumYaw *= -0.75F; + else + momentumYaw = (float) rand.nextGaussian() * 10F * this.config.getBounceYaw(); + } + + try { + this.func_145775_I(); + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Checking entity block collision"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Entity being checked for collision"); + this.addEntityCrashInfo(crashreportcategory); + throw new ReportedException(crashreport); + } + + this.worldObj.theProfiler.endSection(); } /** Used for frame-perfect translation of smoke */ diff --git a/src/main/java/com/hbm/particle/SpentCasing.java b/src/main/java/com/hbm/particle/SpentCasing.java index 13f79ef89..d9fa1007f 100644 --- a/src/main/java/com/hbm/particle/SpentCasing.java +++ b/src/main/java/com/hbm/particle/SpentCasing.java @@ -40,8 +40,8 @@ public class SpentCasing implements Cloneable { private int[] colors; private CasingType type; private String bounceSound; - private float bounceYaw = 0F; - private float bouncePitch = 0F; + private float bounceYaw = 1F; + private float bouncePitch = 1F; private int maxAge = 240; public SpentCasing(CasingType type) {