gun jamming

This commit is contained in:
Bob 2024-09-25 21:47:45 +02:00
parent 0f277657db
commit eb157ea874
11 changed files with 2464 additions and 12 deletions

View File

@ -22,6 +22,7 @@ public class GunConfig {
public static final String F_DURABILITY = "F_DURABILITY";
public static final String I_DRAWDURATION = "I_DRAWDURATION";
public static final String I_INSPECTDURATION = "I_INSPECTDURATION";
public static final String I_JAMDURATION = "I_JAMDURATION";
public static final String O_CROSSHAIR = "O_CROSSHAIR";
public static final String B_DOESSMOKE = "B_DOESSMOKE";
public static final String B_RELOADANIMATIONSEQUENTIAL = "B_RELOADANIMATIONSEQUENTIAL";
@ -45,6 +46,7 @@ public class GunConfig {
protected float durability_DNA;
protected int drawDuration_DNA = 0;
protected int inspectDuration_DNA = 0;
protected int jamDuration_DNA = 0;
protected Crosshair crosshair_DNA;
protected boolean doesSmoke_DNA;
protected boolean reloadAnimationsSequential_DNA;
@ -72,6 +74,7 @@ public class GunConfig {
public float getDurability(ItemStack stack) { return WeaponUpgradeManager.eval(durability_DNA, stack, F_DURABILITY, this); }
public int getDrawDuration(ItemStack stack) { return WeaponUpgradeManager.eval(drawDuration_DNA, stack, I_DRAWDURATION, this); }
public int getInspectDuration(ItemStack stack) { return WeaponUpgradeManager.eval(inspectDuration_DNA, stack, I_INSPECTDURATION, this); }
public int getJamDuration(ItemStack stack) { return WeaponUpgradeManager.eval(jamDuration_DNA, stack, I_JAMDURATION, this); }
public Crosshair getCrosshair(ItemStack stack) { return WeaponUpgradeManager.eval(crosshair_DNA, stack, O_CROSSHAIR, this); }
public boolean getDoesSmoke(ItemStack stack) { return WeaponUpgradeManager.eval(doesSmoke_DNA, stack, B_DOESSMOKE, this); }
public boolean getReloadAnimSequential(ItemStack stack) { return WeaponUpgradeManager.eval(reloadAnimationsSequential_DNA, stack, B_RELOADANIMATIONSEQUENTIAL, this); }
@ -98,6 +101,7 @@ public class GunConfig {
public GunConfig dura(float dura) { this.durability_DNA = dura; return this; }
public GunConfig draw(int draw) { this.drawDuration_DNA = draw; return this; }
public GunConfig inspect(int inspect) { this.inspectDuration_DNA = inspect; return this; }
public GunConfig jam(int jam) { this.jamDuration_DNA = jam; return this; }
public GunConfig crosshair(Crosshair crosshair) { this.crosshair_DNA = crosshair; return this; }
public GunConfig smoke(boolean doesSmoke) { this.doesSmoke_DNA = doesSmoke; return this; }

View File

@ -55,6 +55,7 @@ public class GunFactory {
public static enum EnumAmmo {
STONE,
STONE_AP,
STONE_IRON,
STONE_SHOT,
}
}

View File

@ -8,6 +8,7 @@ import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.items.weapon.sedna.Receiver;
import com.hbm.items.weapon.sedna.ItemGunBaseNT.GunState;
import com.hbm.items.weapon.sedna.ItemGunBaseNT.LambdaContext;
import com.hbm.render.anim.HbmAnimations.AnimType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -22,6 +23,7 @@ public class GunStateDecider {
public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_DECIDER = (stack, ctx) -> {
GunState lastState = ItemGunBaseNT.getState(stack);
deciderStandardFinishDraw(stack, lastState);
deciderStandardClearJam(stack, lastState);
deciderStandardReload(stack, ctx, lastState, 0);
deciderAutoRefire(stack, ctx, lastState, 0, () -> { return ItemGunBaseNT.getPrimary(stack); });
};
@ -36,6 +38,16 @@ public class GunStateDecider {
}
}
/** Transitions the gun from DRAWING to IDLE */
public static void deciderStandardClearJam(ItemStack stack, GunState lastState) {
//transition to idle
if(lastState == GunState.JAMMED) {
ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBaseNT.setTimer(stack, 0);
}
}
/** Triggers a reload action on the first receiver. If the mag is not full and reloading is still possible, set to RELOADING, otherwise IDLE */
public static void deciderStandardReload(ItemStack stack, LambdaContext ctx, GunState lastState, int recIndex) {
@ -53,12 +65,25 @@ public class GunStateDecider {
ItemGunBaseNT.setTimer(stack, cfg.getReceivers(stack)[recIndex].getReloadDuration(stack));
//if no more reloading can be done, go idle
} else {
ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBaseNT.setTimer(stack, 0);
if(getStandardJamChance(stack, cfg) > player.getRNG().nextFloat()) {
ItemGunBaseNT.setState(stack, GunState.JAMMED);
ItemGunBaseNT.setTimer(stack, cfg.getJamDuration(stack));
ItemGunBaseNT.playAnimation(player, stack, AnimType.JAMMED);
} else {
ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBaseNT.setTimer(stack, 0);
}
}
}
}
public static float getStandardJamChance(ItemStack stack, GunConfig config) {
float percent = (float) ItemGunBaseNT.getWear(stack) / config.getDurability(stack);
if(percent < 0.66F) return 0F;
return Math.min((percent - 0.66F) * 4F, 1F);
}
/** Triggers a re-fire of the primary if the fire delay has expired, the left mouse button is down and re-firing is enabled, otherwise switches to IDLE */
public static void deciderAutoRefire(ItemStack stack, LambdaContext ctx, GunState lastState, int recIndex, BooleanSupplier refireCondition) {

View File

@ -53,18 +53,22 @@ public class Orchestras {
int timer = ItemGunBaseNT.getAnimTimer(stack);
if(type == AnimType.RELOAD) {
if(timer == 20) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.magSmallInsert", 1F, 1F);
if(timer == 24) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.magSmallInsert", 1F, 1F);
if(timer == 55) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.revolverSpin", 1F, 1F);
}
if(type == AnimType.CYCLE) {
if(timer == 21) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.revolverCock", 1F, 1F);
if(timer == 21) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.revolverCock", 1F, 0.6F);
}
if(type == AnimType.CYCLE_DRY) {
if(timer == 3) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.dryFireClick", 1F, 1F);
if(timer == 11) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.revolverCock", 1F, 1F);
if(timer == 2) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.dryFireClick", 1F, 0.8F);
if(timer == 11) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.revolverCock", 1F, 0.6F);
}
if(type == AnimType.INSPECT) {
if(timer == 3) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.revolverSpin", 1F, 1F);
}
if(type == AnimType.JAMMED) {
if(timer == 28) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.dryFireClick", 1F, 0.75F);
if(timer == 45) player.worldObj.playSoundAtEntity(player, "hbm:weapon.reload.dryFireClick", 1F, 0.6F);
}
};
}

View File

@ -23,14 +23,15 @@ public class XFactoryBlackPowder {
public static void init() {
BulletConfig stone = new BulletConfig().setItem(EnumAmmo.STONE).setSpread(0.025F).setRicochetAngle(15);
BulletConfig flint = new BulletConfig().setItem(EnumAmmo.STONE_AP).setSpread(0.01F).setRicochetAngle(5).setDoesPenetrate(true).setDamage(1.5F);
BulletConfig shot = new BulletConfig().setItem(EnumAmmo.STONE_SHOT).setSpread(0.1F).setRicochetAngle(45).setProjectiles(6, 6).setDamage(0.2F);
BulletConfig flint = new BulletConfig().setItem(EnumAmmo.STONE_AP).setSpread(0.01F).setRicochetAngle(5).setDoesPenetrate(true).setDamage(1.75F);
BulletConfig iron = new BulletConfig().setItem(EnumAmmo.STONE_IRON).setSpread(0F).setRicochetAngle(90).setRicochetCount(5).setDoesPenetrate(true).setDamageFalloutByPen(false).setDamage(2F);
BulletConfig shot = new BulletConfig().setItem(EnumAmmo.STONE_SHOT).setSpread(0.1F).setRicochetAngle(45).setProjectiles(6, 6).setDamage(0.5F);
ModItems.gun_pepperbox = new ItemGunBaseNT(new GunConfig()
.dura(300).draw(4).inspect(23).crosshair(Crosshair.L_CLASSIC).hud(Lego.HUD_COMPONENT_DURABILITY, Lego.HUD_COMPONENT_AMMO).smoke(true).orchestra(Orchestras.ORCHESTRA_PEPPERBOX)
.dura(300).draw(4).inspect(23).crosshair(Crosshair.CIRCLE).hud(Lego.HUD_COMPONENT_DURABILITY, Lego.HUD_COMPONENT_AMMO).smoke(true).orchestra(Orchestras.ORCHESTRA_PEPPERBOX)
.rec(new Receiver(0)
.dmg(5F).delay(27).reload(67).sound("hbm:weapon.fire.blackPowder", 1.0F, 1.0F)
.mag(new MagazineFullReload(0, 6).addConfigs(stone, flint, shot))
.mag(new MagazineFullReload(0, 6).addConfigs(stone, flint, iron, shot))
.canFire(Lego.LAMBDA_STANDARD_CAN_FIRE).fire(Lego.LAMBDA_STANDARD_FIRE))
.pp(Lego.LAMBDA_STANDARD_CLICK_PRIMARY) .pr(Lego.LAMBDA_STANDARD_RELOAD) .pt(Lego.LAMBDA_TOGGLE_AIM)
.decider(GunStateDecider.LAMBDA_STANDARD_DECIDER)
@ -60,7 +61,10 @@ public class XFactoryBlackPowder {
case INSPECT: return new BusAnimation()
.addBus("ROTATE", new BusAnimationSequence().addPos(-360 * 1, 0, 0, 750, IType.SIN_FULL))
.addBus("RECOIL", new BusAnimationSequence().addPos(-5, 0, 0, 200, IType.SIN_UP).addPos(0, 0, 0, 200, IType.SIN_DOWN));
case JAMMED: break;
case JAMMED: return new BusAnimation()
.addBus("ROTATE", new BusAnimationSequence().addPos(0, 0, 0, 1300).addPos(60, 0, 0, 500, IType.SIN_FULL).addPos(60, 0, 0, 400).addPos(0, 0, 0, 500, IType.SIN_FULL))
.addBus("TRANSLATE", new BusAnimationSequence().addPos(0, 0, 0, 500).addPos(0, -6, 0, 400, IType.SIN_FULL).addPos(0, -6, 0, 2000).addPos(0, 0, 0, 400, IType.SIN_FULL))
.addBus("RECOIL", new BusAnimationSequence().addPos(0, 0, 0, 500).addPos(45, 0, 0, 400, IType.SIN_FULL).addPos(45, 0, 0, 2000).addPos(0, 0, 0, 400, IType.SIN_FULL));
}
return null;

View File

@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack;
public class ItemRenderPepperbox extends ItemRenderWeaponBase {
@Override
protected float getTurnMagnitude(ItemStack stack) { return ItemGunBaseNT.getIsAiming(stack) ? 2.5F : -0.25F; }
protected float getTurnMagnitude(ItemStack stack) { return ItemGunBaseNT.getIsAiming(stack) ? 2.5F : -0.5F; }
@Override
protected void setupFirstPerson(ItemStack stack) {

View File

@ -1143,6 +1143,10 @@ item.ammo_shell.name=240mm Geschoss
item.ammo_shell_apfsds_du.name=240mm APFSDS-DU
item.ammo_shell_apfsds_t.name=240mm APFSDS-T
item.ammo_shell_explosive.name=240mm HE-Geschoss
item.ammo_standard.stone.name=Kugel und Pulver
item.ammo_standard.stone_ap.name=Feuerstein und Pulver
item.ammo_standard.stone_iron.name=Eisenkugel und Pulver
item.ammo_standard.stone_shot.name=Schrot und Pulver
item.ammo_stinger_rocket.name=Stinger-Rakete
item.ammo_stinger_rocket_he.name=Stinger-Rakete (HE)
item.ammo_stinger_rocket_incendiary.name=Stinger-Rakete (Brand)
@ -2106,6 +2110,7 @@ item.gun_moist_nugget.name=Mosin-Nagant
item.gun_mp.name=Maschinengewehr des Pazifisten
item.gun_mp40.name=Maschinenpistole
item.gun_mp40_ammo.name=SMG-Patrone (LEGACY)
item.gun_pepperbox.name=Bündelrevolver
item.gun_pm_ammo.name=Kleine treibmittellose MG-Patrone
item.gun_mymy.name=Nietes
item.gun_osipr.name=Standartausrüstung für Sicherheitskräfte

View File

@ -1866,6 +1866,10 @@ item.ammo_shell_apfsds_du.name=240mm APFSDS-DU
item.ammo_shell_apfsds_t.name=240mm APFSDS-T
item.ammo_shell_explosive.name=240mm HE Shell
item.ammo_shell_w9.name=240mm W9 Nuclear Shell
item.ammo_standard.stone.name=Ball and Powder
item.ammo_standard.stone_ap.name=Flint and Powder
item.ammo_standard.stone_iron.name=Iron Ball and Powder
item.ammo_standard.stone_shot.name=Shot and Powder
item.ammo_stinger_rocket.name=Stinger Rocket
item.ammo_stinger_rocket_he.name=Stinger Rocket (HE)
item.ammo_stinger_rocket_incendiary.name=Stinger Rocket (Incendiary)
@ -2915,6 +2919,7 @@ item.gun_moist_nugget.name=Mosin-Nagant
item.gun_mp.name=Pacifist's Machine Gun
item.gun_mp40.name=Submachine Gun
item.gun_mp40_ammo.name=Submachine Gun Round (LEGACY)
item.gun_pepperbox.name=Pepperbox
item.gun_pm_ammo.name=Small Propellantless Machine Gun Round
item.gun_mymy.name=Nietes
item.gun_osipr.name=Overwatch Standard Issue Pulse Rifle

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB