keybind bullshittery

This commit is contained in:
Bob 2024-09-10 21:40:39 +02:00
parent 699a8759a7
commit 00f5e8e279
16 changed files with 194 additions and 54 deletions

View File

@ -1,9 +1,10 @@
package com.hbm.items; package com.hbm.items;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public interface IEquipReceiver { public interface IEquipReceiver {
public void onEquip(EntityPlayer player); public void onEquip(EntityPlayer player, ItemStack stack);
} }

View File

@ -36,7 +36,7 @@ import com.hbm.items.weapon.ItemCustomMissilePart.*;
import com.hbm.items.weapon.ItemMissile.MissileFormFactor; import com.hbm.items.weapon.ItemMissile.MissileFormFactor;
import com.hbm.items.weapon.ItemMissile.MissileFuel; import com.hbm.items.weapon.ItemMissile.MissileFuel;
import com.hbm.items.weapon.ItemMissile.MissileTier; import com.hbm.items.weapon.ItemMissile.MissileTier;
import com.hbm.items.weapon.sedna.GunFactory; import com.hbm.items.weapon.sedna.factory.GunFactory;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.potion.HbmPotion; import com.hbm.potion.HbmPotion;

View File

@ -34,7 +34,7 @@ public class ItemCrucible extends ItemSwordAbility implements IEquipReceiver {
} }
@Override @Override
public void onEquip(EntityPlayer player) { public void onEquip(EntityPlayer player, ItemStack stack) {
if(!(player instanceof EntityPlayerMP)) if(!(player instanceof EntityPlayerMP))
return; return;

View File

@ -801,7 +801,7 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
} }
@Override @Override
public void onEquip(EntityPlayer player) { public void onEquip(EntityPlayer player, ItemStack stack) {
if(!mainConfig.equipSound.isEmpty() && !player.worldObj.isRemote) { if(!mainConfig.equipSound.isEmpty() && !player.worldObj.isRemote) {
player.worldObj.playSoundAtEntity(player, mainConfig.equipSound, 1, 1); player.worldObj.playSoundAtEntity(player, mainConfig.equipSound, 1, 1);
} }

View File

@ -1,8 +1,11 @@
package com.hbm.items.weapon.sedna; package com.hbm.items.weapon.sedna;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import com.hbm.items.weapon.sedna.ItemGunBase.LambdaContext; import com.hbm.items.weapon.sedna.ItemGunBaseNT.LambdaContext;
import com.hbm.render.anim.BusAnimation;
import com.hbm.render.anim.HbmAnimations.AnimType;
import com.hbm.render.util.RenderScreenOverlay.Crosshair; import com.hbm.render.util.RenderScreenOverlay.Crosshair;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -16,6 +19,7 @@ public class GunConfig {
protected float durability; protected float durability;
protected int drawDuration = 0; protected int drawDuration = 0;
protected Crosshair crosshair; protected Crosshair crosshair;
protected boolean reloadAnimationsSequential;
/** Lambda functions for clicking shit */ /** Lambda functions for clicking shit */
protected BiConsumer<ItemStack, LambdaContext> onPressPrimary; protected BiConsumer<ItemStack, LambdaContext> onPressPrimary;
protected BiConsumer<ItemStack, LambdaContext> onPressSecondary; protected BiConsumer<ItemStack, LambdaContext> onPressSecondary;
@ -28,13 +32,16 @@ public class GunConfig {
protected BiConsumer<ItemStack, LambdaContext> onReleaseReload; protected BiConsumer<ItemStack, LambdaContext> onReleaseReload;
/** The engine for the state machine that determines the gun's overall behavior */ /** The engine for the state machine that determines the gun's overall behavior */
protected BiConsumer<ItemStack, LambdaContext> decider; protected BiConsumer<ItemStack, LambdaContext> decider;
/** Lambda that returns the relevant animation for the given params */
protected BiFunction<ItemStack, AnimType, BusAnimation> animations;
/* GETTERS */ /* GETTERS */
public Receiver[] getReceivers(ItemStack stack) { return receivers; } public Receiver[] getReceivers(ItemStack stack) { return receivers; }
public float getDurability(ItemStack stack) { return durability; } public float getDurability(ItemStack stack) { return durability; }
public int getDrawDuration(ItemStack stack) { return drawDuration; } public int getDrawDuration(ItemStack stack) { return drawDuration; }
public Crosshair getCrosshair(ItemStack stack) { return crosshair; } public Crosshair getCrosshair(ItemStack stack) { return crosshair; }
public boolean getReloadAnimSequential(ItemStack stack) { return reloadAnimationsSequential; }
public BiConsumer<ItemStack, LambdaContext> getPressPrimary(ItemStack stack) { return this.onPressPrimary; } public BiConsumer<ItemStack, LambdaContext> getPressPrimary(ItemStack stack) { return this.onPressPrimary; }
public BiConsumer<ItemStack, LambdaContext> getPressSecondary(ItemStack stack) { return this.onPressSecondary; } public BiConsumer<ItemStack, LambdaContext> getPressSecondary(ItemStack stack) { return this.onPressSecondary; }
@ -48,6 +55,8 @@ public class GunConfig {
public BiConsumer<ItemStack, LambdaContext> getDecider(ItemStack stack) { return this.decider; } public BiConsumer<ItemStack, LambdaContext> getDecider(ItemStack stack) { return this.decider; }
public BiFunction<ItemStack, AnimType, BusAnimation> getAnims(ItemStack stack) { return this.animations; }
/* SETTERS */ /* SETTERS */
public GunConfig rec(Receiver... receivers) { this.receivers = receivers; return this; } public GunConfig rec(Receiver... receivers) { this.receivers = receivers; return this; }
@ -69,4 +78,7 @@ public class GunConfig {
//decider //decider
public GunConfig decider(BiConsumer<ItemStack, LambdaContext> lambda) { this.decider = lambda; return this; } public GunConfig decider(BiConsumer<ItemStack, LambdaContext> lambda) { this.decider = lambda; return this; }
//anims
public GunConfig anim(BiFunction<ItemStack, AnimType, BusAnimation> lambda) { this.animations = lambda; return this; }
} }

View File

@ -1,19 +1,29 @@
package com.hbm.items.weapon.sedna; package com.hbm.items.weapon.sedna;
import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.handler.HbmKeybinds.EnumKeybind;
import com.hbm.interfaces.IItemHUD;
import com.hbm.items.IEquipReceiver;
import com.hbm.items.IKeybindReceiver; import com.hbm.items.IKeybindReceiver;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toclient.GunAnimationPacket;
import com.hbm.render.anim.HbmAnimations.AnimType;
import com.hbm.render.util.RenderScreenOverlay;
import com.hbm.util.EnumUtil; import com.hbm.util.EnumUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
public class ItemGunBase extends Item implements IKeybindReceiver { public class ItemGunBaseNT extends Item implements IKeybindReceiver, IEquipReceiver, IItemHUD {
public static final String KEY_DRAWN = "drawn"; public static final String KEY_DRAWN = "drawn";
public static final String KEY_AIMING = "aiming"; public static final String KEY_AIMING = "aiming";
@ -34,7 +44,7 @@ public class ItemGunBase extends Item implements IKeybindReceiver {
return config_DNA; return config_DNA;
} }
public ItemGunBase(GunConfig cfg) { public ItemGunBaseNT(GunConfig cfg) {
this.setMaxStackSize(1); this.setMaxStackSize(1);
this.config_DNA = cfg; this.config_DNA = cfg;
} }
@ -68,6 +78,11 @@ public class ItemGunBase extends Item implements IKeybindReceiver {
if(keybind == EnumKeybind.RELOAD && !newState && getReloadKey(stack)) { if(config.getReleaseReload(stack) != null) config.getReleaseReload(stack).accept(stack, ctx); this.setReloadKey(stack, newState); return; } if(keybind == EnumKeybind.RELOAD && !newState && getReloadKey(stack)) { if(config.getReleaseReload(stack) != null) config.getReleaseReload(stack).accept(stack, ctx); this.setReloadKey(stack, newState); return; }
} }
@Override
public void onEquip(EntityPlayer player, ItemStack stack) {
if(player instanceof EntityPlayerMP) PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.EQUIP.ordinal()), (EntityPlayerMP) player);
}
@Override @Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) { public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isHeld) {
@ -152,4 +167,14 @@ public class ItemGunBase extends Item implements IKeybindReceiver {
this.player = player; this.player = player;
} }
} }
@Override
public void renderHUD(Pre event, ElementType type, EntityPlayer player, ItemStack stack) {
if(type == ElementType.CROSSHAIRS) {
event.setCanceled(true);
if(aimingProgress >= 1F) return;
ItemGunBaseNT gun = (ItemGunBaseNT) stack.getItem();
RenderScreenOverlay.renderCustomCrosshairs(event.resolution, Minecraft.getMinecraft().ingameGUI, gun.getConfig(stack).getCrosshair(stack));
}
}
} }

View File

@ -4,7 +4,7 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import com.hbm.handler.CasingEjector; import com.hbm.handler.CasingEjector;
import com.hbm.items.weapon.sedna.ItemGunBase.LambdaContext; import com.hbm.items.weapon.sedna.ItemGunBaseNT.LambdaContext;
import com.hbm.items.weapon.sedna.mags.IMagazine; import com.hbm.items.weapon.sedna.mags.IMagazine;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;

View File

@ -1,8 +1,10 @@
package com.hbm.items.weapon.sedna; package com.hbm.items.weapon.sedna.factory;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.items.weapon.sedna.factory.GunStateDecider; import com.hbm.items.weapon.sedna.BulletConfig;
import com.hbm.items.weapon.sedna.factory.Lego; import com.hbm.items.weapon.sedna.GunConfig;
import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.items.weapon.sedna.Receiver;
import com.hbm.items.weapon.sedna.mags.MagazineRevolverDrum; import com.hbm.items.weapon.sedna.mags.MagazineRevolverDrum;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
@ -18,7 +20,7 @@ public class GunFactory {
BulletConfig ammo_debug = new BulletConfig().setItem(ModItems.ammo_debug); BulletConfig ammo_debug = new BulletConfig().setItem(ModItems.ammo_debug);
ModItems.gun_debug = new ItemGunBase(new GunConfig() ModItems.gun_debug = new ItemGunBaseNT(new GunConfig()
.dura(600).draw(15).crosshair(Crosshair.L_CLASSIC) .dura(600).draw(15).crosshair(Crosshair.L_CLASSIC)
.rec(new Receiver() .rec(new Receiver()
.dmg(10F).delay(10).mag(new MagazineRevolverDrum(0, 6).addConfigs(ammo_debug)) .dmg(10F).delay(10).mag(new MagazineRevolverDrum(0, 6).addConfigs(ammo_debug))
@ -27,6 +29,7 @@ public class GunFactory {
.pp(Lego.LAMBDA_STANDARD_FIRE) .pp(Lego.LAMBDA_STANDARD_FIRE)
.pt(Lego.LAMBDA_TOGGLE_AIM) .pt(Lego.LAMBDA_TOGGLE_AIM)
.decider(GunStateDecider.LAMBDA_STANDARD_DECIDER) .decider(GunStateDecider.LAMBDA_STANDARD_DECIDER)
.anim(Lego.LAMBDA_DEBUG_ANIMS)
).setUnlocalizedName("gun_debug").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_darter"); ).setUnlocalizedName("gun_debug").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_darter");
} }
} }

View File

@ -4,10 +4,10 @@ import java.util.function.BiConsumer;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import com.hbm.items.weapon.sedna.GunConfig; import com.hbm.items.weapon.sedna.GunConfig;
import com.hbm.items.weapon.sedna.ItemGunBase; import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.items.weapon.sedna.Receiver; import com.hbm.items.weapon.sedna.Receiver;
import com.hbm.items.weapon.sedna.ItemGunBase.GunState; import com.hbm.items.weapon.sedna.ItemGunBaseNT.GunState;
import com.hbm.items.weapon.sedna.ItemGunBase.LambdaContext; import com.hbm.items.weapon.sedna.ItemGunBaseNT.LambdaContext;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -20,10 +20,10 @@ public class GunStateDecider {
* It supports draw delays as well as semi and auto fire * It supports draw delays as well as semi and auto fire
*/ */
public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_DECIDER = (stack, ctx) -> { public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_DECIDER = (stack, ctx) -> {
GunState lastState = ItemGunBase.getState(stack); GunState lastState = ItemGunBaseNT.getState(stack);
deciderStandardFinishDraw(stack, lastState); deciderStandardFinishDraw(stack, lastState);
deciderStandardReload(stack, ctx, lastState, 0); deciderStandardReload(stack, ctx, lastState, 0);
deciderAutoRefire(stack, ctx, lastState, 0, () -> { return ItemGunBase.getPrimary(stack); }); deciderAutoRefire(stack, ctx, lastState, 0, () -> { return ItemGunBaseNT.getPrimary(stack); });
}; };
/** Transitions the gun from DRAWING to IDLE */ /** Transitions the gun from DRAWING to IDLE */
@ -31,8 +31,8 @@ public class GunStateDecider {
//transition to idle //transition to idle
if(lastState == GunState.DRAWING) { if(lastState == GunState.DRAWING) {
ItemGunBase.setState(stack, GunState.IDLE); ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBase.setTimer(stack, 0); ItemGunBaseNT.setTimer(stack, 0);
} }
} }
@ -49,12 +49,12 @@ public class GunStateDecider {
//if after reloading the gun can still reload, assume a tube mag and resume reloading //if after reloading the gun can still reload, assume a tube mag and resume reloading
if(cfg.getReceivers(stack)[recIndex].getMagazine(stack).canReload(stack, player)) { if(cfg.getReceivers(stack)[recIndex].getMagazine(stack).canReload(stack, player)) {
ItemGunBase.setState(stack, GunState.RELOADING); ItemGunBaseNT.setState(stack, GunState.RELOADING);
ItemGunBase.setTimer(stack, cfg.getReceivers(stack)[recIndex].getReloadDuration(stack)); ItemGunBaseNT.setTimer(stack, cfg.getReceivers(stack)[recIndex].getReloadDuration(stack));
//if no more reloading can be done, go idle //if no more reloading can be done, go idle
} else { } else {
ItemGunBase.setState(stack, GunState.IDLE); ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBase.setTimer(stack, 0); ItemGunBaseNT.setTimer(stack, 0);
} }
} }
} }
@ -72,17 +72,17 @@ public class GunStateDecider {
//if there's a bullet loaded, fire again //if there's a bullet loaded, fire again
if(rec.getCanFire(stack).apply(stack, ctx)) { if(rec.getCanFire(stack).apply(stack, ctx)) {
rec.getOnFire(stack).accept(stack, ctx); rec.getOnFire(stack).accept(stack, ctx);
ItemGunBase.setState(stack, GunState.JUST_FIRED); ItemGunBaseNT.setState(stack, GunState.JUST_FIRED);
ItemGunBase.setTimer(stack, rec.getDelayAfterFire(stack)); ItemGunBaseNT.setTimer(stack, rec.getDelayAfterFire(stack));
//if not, revert to idle //if not, revert to idle
} else { } else {
ItemGunBase.setState(stack, GunState.IDLE); ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBase.setTimer(stack, 0); ItemGunBaseNT.setTimer(stack, 0);
} }
//if not, go idle //if not, go idle
} else { } else {
ItemGunBase.setState(stack, GunState.IDLE); ItemGunBaseNT.setState(stack, GunState.IDLE);
ItemGunBase.setTimer(stack, 0); ItemGunBaseNT.setTimer(stack, 0);
} }
} }
} }

View File

@ -3,11 +3,17 @@ package com.hbm.items.weapon.sedna.factory;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import com.hbm.items.weapon.sedna.ItemGunBase; import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.items.weapon.sedna.ItemGunBase.GunState; import com.hbm.items.weapon.sedna.ItemGunBaseNT.GunState;
import com.hbm.items.weapon.sedna.ItemGunBase.LambdaContext; import com.hbm.items.weapon.sedna.ItemGunBaseNT.LambdaContext;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toclient.GunAnimationPacket;
import com.hbm.render.anim.BusAnimation;
import com.hbm.render.anim.BusAnimationSequence;
import com.hbm.render.anim.HbmAnimations.AnimType;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
/** /**
@ -21,9 +27,9 @@ public class Lego {
* If IDLE and the mag of receiver 0 can be loaded, set state to RELOADING. Used by keybinds. */ * If IDLE and the mag of receiver 0 can be loaded, set state to RELOADING. Used by keybinds. */
public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_RELOAD = (stack, ctx) -> { public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_RELOAD = (stack, ctx) -> {
if(ItemGunBase.getState(stack) == GunState.IDLE && ctx.config.getReceivers(stack)[0].getMagazine(stack).canReload(stack, ctx.player)) { if(ItemGunBaseNT.getState(stack) == GunState.IDLE && ctx.config.getReceivers(stack)[0].getMagazine(stack).canReload(stack, ctx.player)) {
ItemGunBase.setState(stack, GunState.RELOADING); ItemGunBaseNT.setState(stack, GunState.RELOADING);
ItemGunBase.setTimer(stack, ctx.config.getReceivers(stack)[0].getReloadDuration(stack)); ItemGunBaseNT.setTimer(stack, ctx.config.getReceivers(stack)[0].getReloadDuration(stack));
} }
}; };
@ -31,15 +37,15 @@ public class Lego {
* If IDLE and ammo is loaded, fire and set to JUST_FIRED. */ * If IDLE and ammo is loaded, fire and set to JUST_FIRED. */
public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_FIRE = (stack, ctx) -> { public static BiConsumer<ItemStack, LambdaContext> LAMBDA_STANDARD_FIRE = (stack, ctx) -> {
if(ItemGunBase.getState(stack) == GunState.IDLE && ctx.config.getReceivers(stack)[0].getCanFire(stack).apply(stack, ctx)) { if(ItemGunBaseNT.getState(stack) == GunState.IDLE && ctx.config.getReceivers(stack)[0].getCanFire(stack).apply(stack, ctx)) {
ItemGunBase.setState(stack, GunState.JUST_FIRED); ItemGunBaseNT.setState(stack, GunState.JUST_FIRED);
ItemGunBase.setTimer(stack, ctx.config.getReceivers(stack)[0].getDelayAfterFire(stack)); ItemGunBaseNT.setTimer(stack, ctx.config.getReceivers(stack)[0].getDelayAfterFire(stack));
ctx.config.getReceivers(stack)[0].getOnFire(stack).accept(stack, ctx); ctx.config.getReceivers(stack)[0].getOnFire(stack).accept(stack, ctx);
} }
}; };
/** Toggles isAiming. Used by keybinds. */ /** Toggles isAiming. Used by keybinds. */
public static BiConsumer<ItemStack, LambdaContext> LAMBDA_TOGGLE_AIM = (stack, ctx) -> { ItemGunBase.setIsAiming(stack, !ItemGunBase.getIsAiming(stack)); }; public static BiConsumer<ItemStack, LambdaContext> LAMBDA_TOGGLE_AIM = (stack, ctx) -> { ItemGunBaseNT.setIsAiming(stack, !ItemGunBaseNT.getIsAiming(stack)); };
/** Returns true if the mag has ammo in it. Used by keybind functions on whether to fire, and deciders on whether to trigger a refire, */ /** Returns true if the mag has ammo in it. Used by keybind functions on whether to fire, and deciders on whether to trigger a refire, */
public static BiFunction<ItemStack, LambdaContext, Boolean> LAMBDA_STANDARD_CAN_FIRE = (stack, ctx) -> { return ctx.config.getReceivers(stack)[0].getMagazine(stack).getAmount(stack) > 0; }; public static BiFunction<ItemStack, LambdaContext, Boolean> LAMBDA_STANDARD_CAN_FIRE = (stack, ctx) -> { return ctx.config.getReceivers(stack)[0].getMagazine(stack).getAmount(stack) > 0; };
@ -53,5 +59,26 @@ public class Lego {
public static BiConsumer<ItemStack, LambdaContext> LAMBDA_DEBUG_FIRE = (stack, ctx) -> { public static BiConsumer<ItemStack, LambdaContext> LAMBDA_DEBUG_FIRE = (stack, ctx) -> {
EntityPlayer player = ctx.player; EntityPlayer player = ctx.player;
player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:weapon.shotgunShoot", 1F, 1F); player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:weapon.shotgunShoot", 1F, 1F);
if(player instanceof EntityPlayerMP) PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
};
public static BiFunction<ItemStack, AnimType, BusAnimation> LAMBDA_DEBUG_ANIMS = (stack, type) -> {
switch(type) {
case CYCLE:
return new BusAnimation()
.addBus("RECOIL", new BusAnimationSequence().addKeyframePosition(0, 0, 0, 50).addKeyframePosition(0, 0, -3, 50).addKeyframePosition(0, 0, 0, 250))
.addBus("HAMMER", new BusAnimationSequence().addKeyframePosition(0, 0, 1, 50).addKeyframePosition(0, 0, 1, 300).addKeyframePosition(0, 0, 0, 200))
.addBus("DRUM", new BusAnimationSequence().addKeyframePosition(0, 0, 1, 50));
case CYCLE_EMPTY: break;
case ALT_CYCLE: break;
case EQUIP: return new BusAnimation().addBus("ROTATE", new BusAnimationSequence().addKeyframePosition(-360, 0, 0, 350));
case RELOAD: break;
case RELOAD_CYCLE: break;
case RELOAD_EMPTY: break;
case RELOAD_END: break;
case SPINDOWN: break;
case SPINUP: break;
}
return null;
}; };
} }

View File

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.hbm.items.weapon.sedna.BulletConfig; import com.hbm.items.weapon.sedna.BulletConfig;
import com.hbm.items.weapon.sedna.ItemGunBase; import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -49,10 +49,10 @@ public abstract class MagazineStandardBase implements IMagazine {
@Override public void setAmount(ItemStack stack, int amount) { setMagCount(stack, index, amount); } @Override public void setAmount(ItemStack stack, int amount) { setMagCount(stack, index, amount); }
// MAG TYPE // // MAG TYPE //
public static int getMagType(ItemStack stack, int index) { return ItemGunBase.getValueInt(stack, KEY_MAG_TYPE + index); } public static int getMagType(ItemStack stack, int index) { return ItemGunBaseNT.getValueInt(stack, KEY_MAG_TYPE + index); }
public static void setMagType(ItemStack stack, int index, int value) { ItemGunBase.setValueInt(stack, KEY_MAG_TYPE + index, value); } public static void setMagType(ItemStack stack, int index, int value) { ItemGunBaseNT.setValueInt(stack, KEY_MAG_TYPE + index, value); }
// MAG COUNT // // MAG COUNT //
public static int getMagCount(ItemStack stack, int index) { return ItemGunBase.getValueInt(stack, KEY_MAG_COUNT + index); } public static int getMagCount(ItemStack stack, int index) { return ItemGunBaseNT.getValueInt(stack, KEY_MAG_COUNT + index); }
public static void setMagCount(ItemStack stack, int index, int value) { ItemGunBase.setValueInt(stack, KEY_MAG_COUNT + index, value); } public static void setMagCount(ItemStack stack, int index, int value) { ItemGunBaseNT.setValueInt(stack, KEY_MAG_COUNT + index, value); }
} }

View File

@ -475,7 +475,7 @@ public class ModEventHandler {
&& (prevArmor[0] == null || prevArmor[0].getItem() != event.entityLiving.getHeldItem().getItem()) && (prevArmor[0] == null || prevArmor[0].getItem() != event.entityLiving.getHeldItem().getItem())
&& event.entityLiving.getHeldItem().getItem() instanceof IEquipReceiver) { && event.entityLiving.getHeldItem().getItem() instanceof IEquipReceiver) {
((IEquipReceiver)event.entityLiving.getHeldItem().getItem()).onEquip((EntityPlayer) event.entityLiving); ((IEquipReceiver)event.entityLiving.getHeldItem().getItem()).onEquip((EntityPlayer) event.entityLiving, event.entityLiving.getHeldItem());
} }
for(int i = 1; i < 5; i++) { for(int i = 1; i < 5; i++) {

View File

@ -24,6 +24,7 @@ import com.hbm.handler.ArmorModHandler;
import com.hbm.handler.GunConfiguration; import com.hbm.handler.GunConfiguration;
import com.hbm.handler.HTTPHandler; import com.hbm.handler.HTTPHandler;
import com.hbm.handler.HazmatRegistry; import com.hbm.handler.HazmatRegistry;
import com.hbm.handler.HbmKeybinds;
import com.hbm.handler.ImpactWorldHandler; import com.hbm.handler.ImpactWorldHandler;
import com.hbm.hazard.HazardSystem; import com.hbm.hazard.HazardSystem;
import com.hbm.interfaces.IHoldableWeapon; import com.hbm.interfaces.IHoldableWeapon;
@ -43,6 +44,7 @@ import com.hbm.items.machine.ItemDepletedFuel;
import com.hbm.items.machine.ItemFluidDuct; import com.hbm.items.machine.ItemFluidDuct;
import com.hbm.items.machine.ItemRBMKPellet; import com.hbm.items.machine.ItemRBMKPellet;
import com.hbm.items.weapon.ItemGunBase; import com.hbm.items.weapon.ItemGunBase;
import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.packet.PacketDispatcher; import com.hbm.packet.PacketDispatcher;
@ -103,6 +105,7 @@ import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -1076,6 +1079,24 @@ public class ModEventHandlerClient {
} }
} }
} }
boolean gunKey = keyCode == HbmKeybinds.gunPrimaryKey.getKeyCode() || keyCode == HbmKeybinds.gunSecondaryKey.getKeyCode() ||
keyCode == HbmKeybinds.gunTertiaryKey.getKeyCode() || keyCode == HbmKeybinds.reloadKey.getKeyCode();
/* Shoot in favor of attacking */
if(gunKey && keyCode == mc.gameSettings.keyBindAttack.getKeyCode()) {
mc.gameSettings.keyBindAttack.pressed = false;
mc.gameSettings.keyBindAttack.pressTime = 0;
}
EntityPlayer player = mc.thePlayer;
if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemGunBaseNT) {
if(gunKey && keyCode == mc.gameSettings.keyBindPickBlock.getKeyCode()) {
mc.gameSettings.keyBindPickBlock.pressed = false;
mc.gameSettings.keyBindPickBlock.pressTime = 0;
}
}
} }
} }

View File

@ -1,6 +1,10 @@
package com.hbm.packet.toclient; package com.hbm.packet.toclient;
import java.util.function.BiFunction;
import com.hbm.items.weapon.ItemGunBase; import com.hbm.items.weapon.ItemGunBase;
import com.hbm.items.weapon.sedna.GunConfig;
import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.render.anim.BusAnimation; import com.hbm.render.anim.BusAnimation;
import com.hbm.render.anim.HbmAnimations; import com.hbm.render.anim.HbmAnimations;
import com.hbm.render.anim.HbmAnimations.AnimType; import com.hbm.render.anim.HbmAnimations.AnimType;
@ -51,6 +55,10 @@ public class GunAnimationPacket implements IMessage {
if(stack == null) if(stack == null)
return null; return null;
if(stack.getItem() instanceof com.hbm.items.weapon.sedna.ItemGunBaseNT) {
handleSedna(player, stack, slot, AnimType.values()[m.type]);
}
if(!(stack.getItem() instanceof ItemGunBase)) if(!(stack.getItem() instanceof ItemGunBase))
return null; return null;
@ -81,5 +89,27 @@ public class GunAnimationPacket implements IMessage {
return null; return null;
} }
public static void handleSedna(EntityPlayer player, ItemStack stack, int slot, AnimType type) {
ItemGunBaseNT gun = (ItemGunBaseNT) stack.getItem();
GunConfig config = gun.getConfig(stack);
BiFunction<ItemStack, AnimType, BusAnimation> anims = config.getAnims(stack);
BusAnimation animation = anims.apply(stack, type);
if(animation == null && type == AnimType.RELOAD_EMPTY) {
animation = anims.apply(stack, AnimType.RELOAD);
}
if(animation == null && (type == AnimType.ALT_CYCLE || type == AnimType.CYCLE_EMPTY)) {
animation = anims.apply(stack, AnimType.CYCLE);
}
if(animation != null) {
Minecraft.getMinecraft().entityRenderer.itemRenderer.resetEquippedProgress();
Minecraft.getMinecraft().entityRenderer.itemRenderer.itemToRender = stack;
boolean isReloadAnimation = type == AnimType.RELOAD || type == AnimType.RELOAD_CYCLE || type == AnimType.RELOAD_EMPTY;
HbmAnimations.hotbar[slot] = new Animation(stack.getItem().getUnlocalizedName(), System.currentTimeMillis(), animation, isReloadAnimation && config.getReloadAnimSequential(stack));
}
}
} }
} }

View File

@ -2,8 +2,9 @@ package com.hbm.render.item.weapon.sedna;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import com.hbm.items.weapon.sedna.ItemGunBase; import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.main.ResourceManager; import com.hbm.main.ResourceManager;
import com.hbm.render.anim.HbmAnimations;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -11,7 +12,7 @@ import net.minecraft.item.ItemStack;
public class ItemRenderDebug extends ItemRenderWeaponBase { public class ItemRenderDebug extends ItemRenderWeaponBase {
@Override @Override
protected float getTurnMagnitude(ItemStack stack) { return ItemGunBase.getIsAiming(stack) ? 2.5F : -0.25F; } protected float getTurnMagnitude(ItemStack stack) { return ItemGunBaseNT.getIsAiming(stack) ? 2.5F : -0.25F; }
@Override @Override
protected void setupFirstPerson(ItemStack stack) { protected void setupFirstPerson(ItemStack stack) {
@ -30,14 +31,34 @@ public class ItemRenderDebug extends ItemRenderWeaponBase {
GL11.glScaled(scale, scale, scale); GL11.glScaled(scale, scale, scale);
GL11.glRotated(90, 0, 1, 0); GL11.glRotated(90, 0, 1, 0);
double[] equipSpin = HbmAnimations.getRelevantTransformation("ROTATE");
GL11.glRotated(equipSpin[0], 0, 0, 1);
double[] recoil = HbmAnimations.getRelevantTransformation("RECOIL");
GL11.glTranslated(recoil[0], recoil[1], recoil[2]);
GL11.glRotated(recoil[2] * 10, 0, 0, 1);
GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glShadeModel(GL11.GL_SMOOTH);
Minecraft.getMinecraft().renderEngine.bindTexture(ResourceManager.debug_gun_tex); Minecraft.getMinecraft().renderEngine.bindTexture(ResourceManager.debug_gun_tex);
ResourceManager.lilmac.renderPart("Gun"); ResourceManager.lilmac.renderPart("Gun");
GL11.glPushMatrix();
ResourceManager.lilmac.renderPart("Pivot");
GL11.glTranslated(0, 1.75, 0);
GL11.glRotated(HbmAnimations.getRelevantTransformation("DRUM")[2] * -60, 1, 0, 0);
GL11.glTranslated(0, -1.75, 0);
ResourceManager.lilmac.renderPart("Cylinder"); ResourceManager.lilmac.renderPart("Cylinder");
ResourceManager.lilmac.renderPart("Bullets"); ResourceManager.lilmac.renderPart("Bullets");
ResourceManager.lilmac.renderPart("Casings"); ResourceManager.lilmac.renderPart("Casings");
ResourceManager.lilmac.renderPart("Pivot"); GL11.glPopMatrix();
GL11.glPushMatrix(); /// HAMMER ///
GL11.glTranslated(4, 1.25, 0);
GL11.glRotated(-30 + 30 * HbmAnimations.getRelevantTransformation("HAMMER")[2], 0, 0, 1);
GL11.glTranslated(-4, -1.25, 0);
ResourceManager.lilmac.renderPart("Hammer"); ResourceManager.lilmac.renderPart("Hammer");
GL11.glPopMatrix();
GL11.glShadeModel(GL11.GL_FLAT); GL11.glShadeModel(GL11.GL_FLAT);
} }

View File

@ -4,7 +4,7 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
import org.lwjgl.util.glu.Project; import org.lwjgl.util.glu.Project;
import com.hbm.items.weapon.sedna.ItemGunBase; import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -220,7 +220,7 @@ public abstract class ItemRenderWeaponBase implements IItemRenderer {
public abstract void renderOther(ItemStack stack, ItemRenderType type); public abstract void renderOther(ItemStack stack, ItemRenderType type);
public static void standardAimingTransform(ItemStack stack, double sX, double sY, double sZ, double aX, double aY, double aZ) { public static void standardAimingTransform(ItemStack stack, double sX, double sY, double sZ, double aX, double aY, double aZ) {
float aimingProgress = ItemGunBase.prevAimingProgress + (ItemGunBase.aimingProgress - ItemGunBase.prevAimingProgress) * interp; float aimingProgress = ItemGunBaseNT.prevAimingProgress + (ItemGunBaseNT.aimingProgress - ItemGunBaseNT.prevAimingProgress) * interp;
double x = sX + (aX - sX) * aimingProgress; double x = sX + (aX - sX) * aimingProgress;
double y = sY + (aY - sY) * aimingProgress; double y = sY + (aY - sY) * aimingProgress;
double z = sZ + (aZ - sZ) * aimingProgress; double z = sZ + (aZ - sZ) * aimingProgress;