mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
eh
This commit is contained in:
parent
c64ca0d40c
commit
833ae407e5
@ -1,10 +1,8 @@
|
||||
package com.hbm.items.weapon.sedna;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.hbm.handler.HbmKeybinds.EnumKeybind;
|
||||
import com.hbm.util.Tuple.Triplet;
|
||||
import com.hbm.render.util.RenderScreenOverlay.Crosshair;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@ -13,6 +11,8 @@ 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;
|
||||
public int drawDuration = 0;
|
||||
public Crosshair crosshair;
|
||||
/** Lambda function that determines what receiver the gun should use when a keybind is hit */
|
||||
//public Function<Triplet<ItemStack, EnumKeybind, GunConfig>, Receiver> receiverDecider;
|
||||
/** Lambda functions for clicking shit */
|
||||
@ -26,21 +26,12 @@ public class GunConfig {
|
||||
public BiConsumer<ItemStack, GunConfig> onReleaseTertiary;
|
||||
public BiConsumer<ItemStack, GunConfig> onReleaseReload;
|
||||
|
||||
public float getDurability(ItemStack stack) {
|
||||
return durability;
|
||||
}
|
||||
|
||||
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; };
|
||||
}
|
||||
|
||||
@ -4,12 +4,16 @@ import com.hbm.handler.HbmKeybinds.EnumKeybind;
|
||||
import com.hbm.items.IKeybindReceiver;
|
||||
import com.hbm.util.EnumUtil;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemGunBase implements IKeybindReceiver {
|
||||
public class ItemGunBase extends Item implements IKeybindReceiver {
|
||||
|
||||
public static final String KEY_DRAWN = "drawn";
|
||||
public static final String KEY_TIMER = "timer";
|
||||
public static final String KEY_STATE = "state";
|
||||
public static final String KEY_PRIMARY = "mouse1";
|
||||
@ -25,6 +29,7 @@ public class ItemGunBase implements IKeybindReceiver {
|
||||
}
|
||||
|
||||
public static enum GunState {
|
||||
DRAWING, //initial delay after selecting
|
||||
IDLE, //gun can be fired or reloaded
|
||||
WINDUP, //fire button is down, added delay before fire
|
||||
JUST_FIRED, //gun has been fired, cooldown
|
||||
@ -36,16 +41,41 @@ public class ItemGunBase implements IKeybindReceiver {
|
||||
|
||||
GunConfig config = getConfig(stack);
|
||||
|
||||
if(keybind == EnumKeybind.GUN_PRIMARY && state && !getPrimary(stack)) { if(config.onPressPrimary != null) config.onPressPrimary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_PRIMARY && !state && getPrimary(stack)) { if(config.onReleasePrimary != null) config.onReleasePrimary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_SECONDARY && state && !getSecondary(stack)) { if(config.onPressSecondary != null) config.onPressSecondary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_SECONDARY && !state && getSecondary(stack)) { if(config.onReleaseSecondary != null) config.onReleaseSecondary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_TERTIARY && state && !getTertiary(stack)) { if(config.onPressTertiary != null) config.onPressTertiary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_TERTIARY && !state && getTertiary(stack)) { if(config.onReleaseTertiary != null) config.onReleaseTertiary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.RELOAD && state && !getReloadKey(stack)) { if(config.onPressReload != null) config.onPressReload.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.RELOAD && !state && getReloadKey(stack)) { if(config.onReleaseReload != null) config.onReleaseReload.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_PRIMARY && state && !getPrimary(stack)) { if(config.onPressPrimary != null) config.onPressPrimary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_PRIMARY && !state && getPrimary(stack)) { if(config.onReleasePrimary != null) config.onReleasePrimary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_SECONDARY && state && !getSecondary(stack)) { if(config.onPressSecondary != null) config.onPressSecondary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_SECONDARY && !state && getSecondary(stack)) { if(config.onReleaseSecondary != null) config.onReleaseSecondary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_TERTIARY && state && !getTertiary(stack)) { if(config.onPressTertiary != null) config.onPressTertiary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.GUN_TERTIARY && !state && getTertiary(stack)) { if(config.onReleaseTertiary != null) config.onReleaseTertiary.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.RELOAD && state && !getReloadKey(stack)) { if(config.onPressReload != null) config.onPressReload.accept(stack, config); return; }
|
||||
if(keybind == EnumKeybind.RELOAD && !state && getReloadKey(stack)) { if(config.onReleaseReload != null) config.onReleaseReload.accept(stack, config); return; }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) {
|
||||
if(world.isRemote) return;
|
||||
|
||||
GunConfig config = this.getConfig(stack);
|
||||
|
||||
if(!isHeld) {
|
||||
this.setState(stack, GunState.DRAWING);
|
||||
this.setTimer(stack, config.drawDuration);
|
||||
return;
|
||||
}
|
||||
|
||||
int timer = this.getTimer(stack);
|
||||
if(timer > 0) this.setTimer(stack, timer - 1);
|
||||
if(timer <= 1) nextState();
|
||||
}
|
||||
|
||||
public void nextState() {
|
||||
// run the decider
|
||||
}
|
||||
|
||||
// GUN DRAWN //
|
||||
public static boolean getIsDrawn(ItemStack stack) { return getValueBool(stack, KEY_DRAWN); }
|
||||
public static void setIsDrawn(ItemStack stack, boolean value) { setValueBool(stack, KEY_DRAWN, 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); }
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.hbm.items.weapon.sedna;
|
||||
|
||||
import com.hbm.handler.CasingEjector;
|
||||
import com.hbm.items.weapon.sedna.mags.IMagazine;
|
||||
|
||||
public class Receiver {
|
||||
@ -10,6 +11,7 @@ public class Receiver {
|
||||
protected boolean refireOnHold = false;
|
||||
protected int burstSize = 1;
|
||||
protected int delayAfterBurst;
|
||||
protected CasingEjector ejector = null;
|
||||
|
||||
protected IMagazine magazine;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user