added rotational momentum, better bounces to spent casings

turret's cases do not rotate for some reason!
This commit is contained in:
Vaern 2025-02-23 22:06:16 -08:00
parent 0ccf81443a
commit 61bba7974f
2 changed files with 114 additions and 21 deletions

View File

@ -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;
@ -51,6 +58,8 @@ public class ParticleSpentCasing extends EntityFX {
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,7 +94,6 @@ 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;
@ -94,15 +102,10 @@ public class ParticleSpentCasing extends EntityFX {
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.momentumYaw *= 0.7F;
this.onGround = false;
}
if(particleAge > maxSmokeGen && !smokeNodes.isEmpty())
@ -128,12 +131,102 @@ public class ParticleSpentCasing extends EntityFX {
prevRotationPitch = rotationPitch;
prevRotationYaw = rotationYaw;
if(onGround) {
rotationPitch = 0;
} else {
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 */

View File

@ -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) {