Skip to content

Commit

Permalink
Merge pull request #1959 from Vaern/master
Browse files Browse the repository at this point in the history
spent casings prrrrrr!!!
  • Loading branch information
HbmMods authored Feb 27, 2025
2 parents fa93b94 + e6aa3f2 commit 3ae27af
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/hbm/handler/CasingEjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public CasingEjector setAngleRange(float yaw, float pitch) {
@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);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/hbm/handler/guncfg/GunCannonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GunCannonFactory {
protected static SpentCasing CASINNG240MM;

static {
CASINNG240MM = new SpentCasing(CasingType.BOTTLENECK).setScale(7.5F).setBounceMotion(0.02F, 0.05F).setColor(SpentCasing.COLOR_CASE_BRASS).setupSmoke(1F, 0.5D, 60, 20);
CASINNG240MM = new SpentCasing(CasingType.BOTTLENECK).setScale(7.5F).setBounceMotion(0.5F, 0.5F).setColor(SpentCasing.COLOR_CASE_BRASS).setupSmoke(1F, 0.5D, 60, 20);
}

public static BulletConfiguration getShellConfig() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/hbm/handler/guncfg/GunDGKFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class GunDGKFactory {
public static final SpentCasing CASINGDGK;

static {
CASINGDGK = new SpentCasing(CasingType.STRAIGHT).setScale(1.5F).setBounceMotion(0.05F, 0.02F).setColor(SpentCasing.COLOR_CASE_BRASS).register("DGK").setupSmoke(0.02F, 0.5D, 60, 20).setMaxAge(60); //3 instead of 12 seconds
CASINGDGK = new SpentCasing(CasingType.STRAIGHT).setScale(1.5F).setBounceMotion(1F, 0.5F).setColor(SpentCasing.COLOR_CASE_BRASS).register("DGK").setupSmoke(0.02F, 0.5D, 60, 20).setMaxAge(60); //3 instead of 12 seconds
}

/*public static BulletConfiguration getDGKConfig() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/hbm/items/weapon/ItemAmmoArty.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public String getUnlocalizedName(ItemStack stack) {
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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GunFactory {

public static BulletConfig ammo_debug;

public static SpentCasing CASING44 = new SpentCasing(CasingType.STRAIGHT).setScale(1.5F, 1.0F, 1.5F).setBounceMotion(0.01F, 0.05F).setColor(SpentCasing.COLOR_CASE_44);
public static SpentCasing CASING44 = new SpentCasing(CasingType.STRAIGHT).setScale(1.5F, 1.0F, 1.5F).setColor(SpentCasing.COLOR_CASE_44);

public static void init() {

Expand Down
54 changes: 27 additions & 27 deletions src/main/java/com/hbm/items/weapon/sedna/factory/Orchestras.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/com/hbm/main/ResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ public class ResourceManager {
//Projectiles
public static final IModelCustom projectiles = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/projectiles/projectiles.obj"));
public static final IModelCustom leadburster = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/projectiles/leadburster.obj"));
public static final IModelCustom casings = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/effect/casings.obj"));
public static final IModelCustom casings = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/effect/casings.obj")).asVBO();

//Bomber
public static final IModelCustom dornier = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/dornier.obj"));
Expand Down
121 changes: 102 additions & 19 deletions src/main/java/com/hbm/particle/ParticleSpentCasing.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
Expand Down Expand Up @@ -49,8 +51,10 @@ public ParticleSpentCasing(TextureManager textureManager, World world, double x,
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;
Expand Down Expand Up @@ -85,26 +89,20 @@ public void onUpdate() {
}

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 = (float) (Math.floor(this.rotationPitch / 180F + 0.5F)) * 180F;
this.momentumYaw *= 0.7F;
this.onGround = false;
}

if(particleAge > maxSmokeGen && !smokeNodes.isEmpty())
smokeNodes.clear();

Expand All @@ -124,16 +122,101 @@ public void onUpdate() {
smokeNodes.add(new Pair<Vec3, Double>(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;

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) {
this.motionZ *= -0.25D;

if(Math.abs(momentumYaw) > 1e-7)
momentumYaw *= -0.75F;
else
momentumYaw = (float) rand.nextGaussian() * 10F * this.config.getBounceYaw();
}

this.worldObj.theProfiler.endSection();
}

/** Used for frame-perfect translation of smoke */
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/hbm/particle/SpentCasing.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private CasingType(String... names) {
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) {
Expand Down Expand Up @@ -86,6 +86,7 @@ public static SpentCasing fromName(String name) {
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;
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/com/hbm/particle/helper/CasingCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@

public class CasingCreator implements IParticleCreator {

/** Casing without smoke */
/** Default casing without smoke */
public static void composeEffect(World world, EntityLivingBase player, double frontOffset, double heightOffset, double sideOffset, double frontMotion, double heightMotion, double sideMotion, double motionVariance, String casing) {
composeEffect(world, player, frontOffset, heightOffset, sideOffset, frontMotion, heightMotion, sideMotion, motionVariance, casing, false, 0, 0, 0);
composeEffect(world, player, frontOffset, heightOffset, sideOffset, frontMotion, heightMotion, sideMotion, motionVariance, 5F, 10F, casing, false, 0, 0, 0);
}


/** Casing without smoke */
public static void composeEffect(World world, EntityLivingBase player, double frontOffset, double heightOffset, double sideOffset, double frontMotion, double heightMotion, double sideMotion, double motionVariance, float multPitch, float multYaw, String casing) {
composeEffect(world, player, frontOffset, heightOffset, sideOffset, frontMotion, heightMotion, sideMotion, motionVariance, multPitch, multYaw, casing, false, 0, 0, 0);
}

/** Default casing, but with smoke*/
public static void composeEffect(World world, EntityLivingBase player, double frontOffset, double heightOffset, double sideOffset, double frontMotion, double heightMotion, double sideMotion, double motionVariance, String casing, boolean smoking, int smokeLife, double smokeLift, int nodeLife) {
composeEffect(world, player, frontOffset, heightOffset, sideOffset, frontMotion, heightMotion, sideMotion, motionVariance, 5F, 10F, casing, false, 0, 0, 0);
}

public static void composeEffect(World world, EntityLivingBase player, double frontOffset, double heightOffset, double sideOffset, double frontMotion, double heightMotion, double sideMotion, double motionVariance, float mPitch, float mYaw, String casing, boolean smoking, int smokeLife, double smokeLift, int nodeLife) {

if(player.isSneaking()) heightOffset -= 0.075F;

Expand Down Expand Up @@ -51,6 +61,8 @@ public static void composeEffect(World world, EntityLivingBase player, double fr
data.setDouble("mZ", mZ);
data.setFloat("yaw", player.rotationYaw);
data.setFloat("pitch", player.rotationPitch);
data.setFloat("mPitch", mPitch);
data.setFloat("mYaw", mYaw);
data.setString("name", casing);
data.setBoolean("smoking", smoking);
data.setInteger("smokeLife", smokeLife);
Expand All @@ -71,11 +83,13 @@ public void makeParticle(World world, EntityPlayer player, TextureManager texman
double mZ = data.getDouble("mZ");
float yaw = data.getFloat("yaw");
float pitch = data.getFloat("pitch");
float mPitch = data.getFloat("mPitch");
float mYaw = data.getFloat("mYaw");
boolean smoking = data.getBoolean("smoking");
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, mPitch, mYaw, casingConfig, smoking, smokeLife, smokeLift, nodeLife);
casing.prevRotationYaw = casing.rotationYaw = yaw;
casing.prevRotationPitch = casing.rotationPitch = pitch;
Minecraft.getMinecraft().effectRenderer.addEffect(casing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public static void renderFireball(long lastShot) {
double lengthOffset = -1.125;
Minecraft.getMinecraft().renderEngine.bindTexture(flash_plume);
tess.startDrawingQuads();
tess.setBrightness(240);
tess.setNormal(0F, 1F, 0F);
tess.setColorRGBA_F(1F, 1F, 1F, 1F);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public static void renderFireball(long lastShot) {
double lengthOffset = -1.125;
Minecraft.getMinecraft().renderEngine.bindTexture(flash_plume);
tess.startDrawingQuads();
tess.setBrightness(240);
tess.setNormal(0F, 1F, 0F);
tess.setColorRGBA_F(1F, 1F, 1F, 1F);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ public static void renderMuzzleFlash(long lastShot, int duration, double l) {
double inset = 2;
Minecraft.getMinecraft().renderEngine.bindTexture(flash_plume);
tess.startDrawingQuads();
tess.setBrightness(240);
tess.setNormal(0F, 1F, 0F);
tess.setColorRGBA_F(1F, 1F, 1F, 1F);

Expand Down Expand Up @@ -379,6 +380,7 @@ public static void renderGapFlash(long lastShot) {
double lengthOffset = 0.125;
Minecraft.getMinecraft().renderEngine.bindTexture(flash_plume);
tess.startDrawingQuads();
tess.setBrightness(240);
tess.setNormal(0F, 1F, 0F);
tess.setColorRGBA_F(1F, 1F, 1F, 1F);

Expand Down

0 comments on commit 3ae27af

Please sign in to comment.