From 16f710450c83f00417885c58896f85562304d3c1 Mon Sep 17 00:00:00 2001 From: 70000hp <105080577+70000hp@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:43:59 -0400 Subject: [PATCH] actual burst fire logic also adds burst fire to josh --- .../com/hbm/handler/GunConfiguration.java | 4 +- .../hbm/handler/guncfg/Gun50BMGFactory.java | 13 +++++- .../com/hbm/items/weapon/ItemGunBase.java | 45 +++++++++++++++---- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/hbm/handler/GunConfiguration.java b/src/main/java/com/hbm/handler/GunConfiguration.java index 1763ad83a..dd8e20796 100644 --- a/src/main/java/com/hbm/handler/GunConfiguration.java +++ b/src/main/java/com/hbm/handler/GunConfiguration.java @@ -25,6 +25,8 @@ public class GunConfiguration implements Cloneable { public int rateOfFire; //amount of bullets fired per delay passed public int roundsPerCycle; + /** Amount of rounds per burst, irrelevant if not a burst fire weapon**/ + public int roundsPerBurst; //0 = normal, 1 = release, 2 = both public int gunMode; //0 = manual, 1 = automatic @@ -46,7 +48,7 @@ public class GunConfiguration implements Cloneable { //how long the reload animation will play //MUST BE GREATER THAN ZERO ! ! ! public int reloadDuration; - //duration of every animation cycle + //duration of every animation cycle, used also for how quickly a burst fire rifle can fire public int firingDuration; //sound path to the reload sound public String reloadSound = ""; diff --git a/src/main/java/com/hbm/handler/guncfg/Gun50BMGFactory.java b/src/main/java/com/hbm/handler/guncfg/Gun50BMGFactory.java index 5da9631d2..189ad105e 100644 --- a/src/main/java/com/hbm/handler/guncfg/Gun50BMGFactory.java +++ b/src/main/java/com/hbm/handler/guncfg/Gun50BMGFactory.java @@ -157,7 +157,18 @@ public class Gun50BMGFactory { return config; } - + + public static GunConfiguration getAR15BurstConfig(){ + GunConfiguration config = getAR15Config(); + config.rateOfFire = 4; + config.roundsPerBurst = 3; + config.firingDuration = 2; + config.gunMode = GunConfiguration.MODE_NORMAL; + config.firingMode = GunConfiguration.FIRE_BURST; + + return config; + } + public static GunConfiguration getM2Config() { GunConfiguration config = getAR15Config(); diff --git a/src/main/java/com/hbm/items/weapon/ItemGunBase.java b/src/main/java/com/hbm/items/weapon/ItemGunBase.java index e2b428c7e..0bd0611f8 100644 --- a/src/main/java/com/hbm/items/weapon/ItemGunBase.java +++ b/src/main/java/com/hbm/items/weapon/ItemGunBase.java @@ -55,7 +55,8 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu public boolean m1;// = false; @SideOnly(Side.CLIENT) public boolean m2;// = false; - + + public int burstDuration = 0; public ItemGunBase(GunConfiguration config) { mainConfig = config; this.setMaxStackSize(1); @@ -131,13 +132,26 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu if(getIsMouseDown(stack) && !(player.getHeldItem() == stack)) { setIsMouseDown(stack, false); } - + + if(burstDuration > 0) { + if(altConfig == null) { + if (world.getWorldTime() % mainConfig.firingDuration == 0 && tryShoot(stack, world, player, true)) { + fire(stack, world, player); + } + } else { + boolean canFire = altConfig.firingDuration == 1 || world.getWorldTime() % altConfig.firingDuration == 0; + if (canFire && tryShoot(stack, world, player, false)) { + altFire(stack, world, player); + } + } + + if(--burstDuration == 0) setDelay(stack, mainConfig.rateOfFire); + } if(getIsAltDown(stack) && !isCurrentItem) { setIsAltDown(stack, false); } if(GeneralConfig.enableGuns && mainConfig.firingMode == 1 && getIsMouseDown(stack) && tryShoot(stack, world, player, isCurrentItem)) { - fire(stack, world, player); setDelay(stack, mainConfig.rateOfFire); } @@ -284,17 +298,32 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu //called on click (server side, called by mouse packet) for semi-automatics and specific events public void startAction(ItemStack stack, World world, EntityPlayer player, boolean main) { - if(mainConfig.firingMode == mainConfig.FIRE_MANUAL && main && tryShoot(stack, world, player, main)) { - fire(stack, world, player); - setDelay(stack, mainConfig.rateOfFire); + boolean validConfig = mainConfig.firingMode == GunConfiguration.FIRE_MANUAL || mainConfig.firingMode == GunConfiguration.FIRE_BURST; + + if(validConfig && main && tryShoot(stack, world, player, main)) { + + if(mainConfig.firingMode == GunConfiguration.FIRE_BURST){ + if(burstDuration <= 0) + burstDuration = mainConfig.firingDuration * mainConfig.roundsPerBurst; + } else { + fire(stack, world, player); + setDelay(stack, mainConfig.rateOfFire); + } + //setMag(stack, getMag(stack) - 1); //useUpAmmo(player, stack, main); //player.inventoryContainer.detectAndSendChanges(); } if(!main && altConfig != null && tryShoot(stack, world, player, main)) { - altFire(stack, world, player); - setDelay(stack, altConfig.rateOfFire); + + if(altConfig.firingMode == GunConfiguration.FIRE_BURST && burstDuration <= 0){ + burstDuration = altConfig.firingDuration * altConfig.roundsPerBurst; + } else { + altFire(stack, world, player); + setDelay(stack, altConfig.rateOfFire); + } + //useUpAmmo(player, stack, main); //player.inventoryContainer.detectAndSendChanges(); }