more gun crap

This commit is contained in:
Bob 2024-09-03 22:45:18 +02:00
parent a3c56e0a11
commit d227c9d89b
8 changed files with 160 additions and 16 deletions

View File

@ -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,
}
}

View File

@ -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<BulletConfig> 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);
}
}

View File

@ -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<Triplet<ItemStack, EnumKeybind, GunConfig>, 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<Triplet<ItemStack, EnumKeybind, GunConfig>, Receiver> receiverDeciderSingle = (x) -> { return x.getY() == EnumKeybind.GUN_PRIMARY ? x.getZ().receivers[0] : null; };
public static Function<Triplet<ItemStack, EnumKeybind, GunConfig>, Receiver> receiverDeciderDouble = (x) -> { return x.getY() == EnumKeybind.GUN_PRIMARY ? x.getZ().receivers[0] : x.getY() == EnumKeybind.GUN_SECONDARY ? x.getZ().receivers[1] : null; };
}

View File

@ -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); }

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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<BulletConfig> 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); }
}

View File

@ -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.
*/