diff --git a/src/main/java/com/hbm/handler/HbmKeybinds.java b/src/main/java/com/hbm/handler/HbmKeybinds.java index 1c2e4483b..ee460eda8 100644 --- a/src/main/java/com/hbm/handler/HbmKeybinds.java +++ b/src/main/java/com/hbm/handler/HbmKeybinds.java @@ -86,13 +86,17 @@ public class HbmKeybinds { JETPACK, TOGGLE_JETPACK, TOGGLE_HEAD, - RELOAD, DASH, TRAIN, CRANE_UP, CRANE_DOWN, CRANE_LEFT, CRANE_RIGHT, - CRANE_LOAD + CRANE_LOAD, + + GUN_PRIMARY, + GUN_SECONDARY, + GUN_TERITARY, + RELOAD, } } diff --git a/src/main/java/com/hbm/items/weapon/sedna/BulletConfig.java b/src/main/java/com/hbm/items/weapon/sedna/BulletConfig.java index 4d1be717c..ce49ad85d 100644 --- a/src/main/java/com/hbm/items/weapon/sedna/BulletConfig.java +++ b/src/main/java/com/hbm/items/weapon/sedna/BulletConfig.java @@ -1,20 +1,32 @@ package com.hbm.items.weapon.sedna; +import java.util.ArrayList; +import java.util.List; + import com.hbm.inventory.RecipesCommon.ComparableStack; public class BulletConfig { + public static List configs = new ArrayList(); + + public final int id; + public ComparableStack ammo; public int ammoCount = 1; public float velocity = 5F; public float spread = 0F; public float wear = 1F; - public int projectilesMin; - public int projectilesMax; + public int projectilesMin = 1; + public int projectilesMax = 1; public float damageMult = 1.0F; public float headshotMult = 1.0F; public double gravity = 0; public int expires = 100; + + public BulletConfig() { + this.id = configs.size(); + configs.add(this); + } } diff --git a/src/main/java/com/hbm/items/weapon/sedna/GunConfig.java b/src/main/java/com/hbm/items/weapon/sedna/GunConfig.java index 02edce2a9..51fe69541 100644 --- a/src/main/java/com/hbm/items/weapon/sedna/GunConfig.java +++ b/src/main/java/com/hbm/items/weapon/sedna/GunConfig.java @@ -1,5 +1,35 @@ package com.hbm.items.weapon.sedna; +import java.util.function.Function; + +import com.hbm.handler.HbmKeybinds.EnumKeybind; +import com.hbm.util.Tuple.Triplet; + +import net.minecraft.item.ItemStack; + public class GunConfig { - // ??? + + /** List of receivers used by the gun, primary and secondary are usually indices 0 and 1 respectively, if applicable */ + public Receiver[] receivers; + public float durability; + /** Lambda function that determines what receiver the gun should use when a keybind is hit */ + public Function, Receiver> receiverDecider; + + public GunConfig setReceivers(Receiver... receivers) { + this.receivers = receivers; + return this; + } + + public Receiver getReceiver(ItemStack stack, EnumKeybind keybind) { + + if(receiverDecider != null) { + return receiverDecider.apply(new Triplet(stack, keybind, this)); + } + + return null; + } + + /* Standard implementations for receiver deciders */ + public static Function, Receiver> receiverDeciderSingle = (x) -> { return x.getY() == EnumKeybind.GUN_PRIMARY ? x.getZ().receivers[0] : null; }; + public static Function, Receiver> receiverDeciderDouble = (x) -> { return x.getY() == EnumKeybind.GUN_PRIMARY ? x.getZ().receivers[0] : x.getY() == EnumKeybind.GUN_SECONDARY ? x.getZ().receivers[1] : null; }; } diff --git a/src/main/java/com/hbm/items/weapon/sedna/ItemGunBase.java b/src/main/java/com/hbm/items/weapon/sedna/ItemGunBase.java index 666c92bde..d094b5fe3 100644 --- a/src/main/java/com/hbm/items/weapon/sedna/ItemGunBase.java +++ b/src/main/java/com/hbm/items/weapon/sedna/ItemGunBase.java @@ -12,8 +12,6 @@ public class ItemGunBase implements IKeybindReceiver { public static final String KEY_TIMER = "timer"; public static final String KEY_STATE = "state"; - public static final String KEY_MAG_COUNT = "magcount"; - public static final String KEY_MAG_TYPE = "magtype"; public static enum GunState { IDLE, //gun can be fired or reloaded @@ -27,15 +25,6 @@ public class ItemGunBase implements IKeybindReceiver { } - //TODO: move into the IMagazine impl - /*// MAG TYPE // - public static int getMagType(ItemStack stack, int index) { return getValueInt(stack, KEY_MAG_TYPE + index); } - public static void setMagType(ItemStack stack, int index, int value) { setValueInt(stack, KEY_MAG_TYPE + index, value); } - - // MAG COUNT // - public static int getMagCount(ItemStack stack, int index) { return getValueInt(stack, KEY_MAG_COUNT + index); } - public static void setMagCount(ItemStack stack, int index, int value) { setValueInt(stack, KEY_MAG_COUNT + index, value); }*/ - // GUN STATE TIMER // public static int getTimer(ItemStack stack) { return getValueInt(stack, KEY_TIMER); } public static void setTimer(ItemStack stack, int value) { setValueInt(stack, KEY_TIMER, value); } diff --git a/src/main/java/com/hbm/items/weapon/sedna/Receiver.java b/src/main/java/com/hbm/items/weapon/sedna/Receiver.java new file mode 100644 index 000000000..d74f88ca8 --- /dev/null +++ b/src/main/java/com/hbm/items/weapon/sedna/Receiver.java @@ -0,0 +1,20 @@ +package com.hbm.items.weapon.sedna; + +import com.hbm.items.weapon.sedna.mags.IMagazine; + +public class Receiver { + + protected float baseDamage; + protected int delayAfterFire; + protected int roundsPerCycle = 1; + protected boolean refireOnHold = false; + protected int burstSize = 1; + protected int delayAfterBurst; + + protected IMagazine magazine; + + public Receiver setMag(IMagazine magazine) { + this.magazine = magazine; + return this; + } +} diff --git a/src/main/java/com/hbm/items/weapon/sedna/mags/IMagazine.java b/src/main/java/com/hbm/items/weapon/sedna/mags/IMagazine.java index 85998ca8f..1a0aeaeec 100644 --- a/src/main/java/com/hbm/items/weapon/sedna/mags/IMagazine.java +++ b/src/main/java/com/hbm/items/weapon/sedna/mags/IMagazine.java @@ -1,5 +1,19 @@ package com.hbm.items.weapon.sedna.mags; +import net.minecraft.item.ItemStack; + public interface IMagazine { + /** What ammo is loaded currently */ + public Object getType(ItemStack stack); + /** How much ammo this mag can carry */ + public int getCapacity(ItemStack stack); + /** How much ammo is currently loaded */ + public int getAmount(ItemStack stack); + /** Sets the mag's ammo level */ + public void setAmount(ItemStack stack, int amount); + /** The action done at the end of one reload cycle, either loading one shell or replacing the whole mag */ + public void reloadAction(ItemStack stack); + /** The stack that should be displayed for the ammo HUD */ + public ItemStack getIcon(ItemStack stack); } diff --git a/src/main/java/com/hbm/items/weapon/sedna/mags/MagazineStandardBase.java b/src/main/java/com/hbm/items/weapon/sedna/mags/MagazineStandardBase.java new file mode 100644 index 000000000..09875ffe5 --- /dev/null +++ b/src/main/java/com/hbm/items/weapon/sedna/mags/MagazineStandardBase.java @@ -0,0 +1,51 @@ +package com.hbm.items.weapon.sedna.mags; + +import java.util.ArrayList; +import java.util.List; + +import com.hbm.items.weapon.sedna.BulletConfig; +import com.hbm.items.weapon.sedna.ItemGunBase; +import com.hbm.items.weapon.sedna.Receiver; + +import net.minecraft.item.ItemStack; + +/** Base class for typical magazines, i.e. ones that hold bullets, shells, grenades, etc, any ammo item */ +public abstract class MagazineStandardBase implements IMagazine { + + public static final String KEY_MAG_COUNT = "magcount"; + public static final String KEY_MAG_TYPE = "magtype"; + + protected List acceptedBullets = new ArrayList(); + + /** A number so the gun tell multiple mags apart */ + public int index; + /** How much ammo this mag can hold */ + public int capacity; + public Receiver parent; + + public MagazineStandardBase(int index, int capacity) { + this.index = index; + this.capacity = capacity; + } + + @Override + public Object getType(ItemStack stack) { + int type = getMagType(stack, index); + if(type >= 0 && type < BulletConfig.configs.size()) { + return BulletConfig.configs.get(type); + } + return null; + } + + @Override public int getCapacity(ItemStack stack) { return capacity; } + @Override public int getAmount(ItemStack stack) { return getMagCount(stack, index); } + @Override public void setAmount(ItemStack stack, int amount) { setMagCount(stack, index, amount); } + + // MAG TYPE // + public static int getMagType(ItemStack stack, int index) { return ItemGunBase.getValueInt(stack, KEY_MAG_TYPE + index); } + public static void setMagType(ItemStack stack, int index, int value) { ItemGunBase.setValueInt(stack, KEY_MAG_TYPE + index, value); } + + // MAG COUNT // + public static int getMagCount(ItemStack stack, int index) { return ItemGunBase.getValueInt(stack, KEY_MAG_COUNT + index); } + public static void setMagCount(ItemStack stack, int index, int value) { ItemGunBase.setValueInt(stack, KEY_MAG_COUNT + index, value); } +} diff --git a/src/main/java/com/hbm/items/weapon/sedna/package-info.java b/src/main/java/com/hbm/items/weapon/sedna/package-info.java new file mode 100644 index 000000000..a23713eca --- /dev/null +++ b/src/main/java/com/hbm/items/weapon/sedna/package-info.java @@ -0,0 +1,24 @@ +/** + * + */ +/** + * @author hbm + * + */ +package com.hbm.items.weapon.sedna; + +/* + +The MK2 unified gun system SEDNA + +ItemGunBase - NBT, timer, keybind handling + | GunConfig (1) - durability and sights + | Receiver (n) - base damage, fire modes + | Magazine (1) - NBT, reload management + | BulletConfig (n) - ammo stats + +Based on this system, alt fire that should logically use the same receiver actually use two different receivers, and +by extension two different mag fields. In this case, make sure to use the same mag instance (or an identical one) +on either receiver to ensure that both receivers access the same ammo pool and accept the same ammo types. + +*/ \ No newline at end of file