more gun code

This commit is contained in:
Boblet 2024-09-04 16:48:58 +02:00
parent d227c9d89b
commit c64ca0d40c
8 changed files with 98 additions and 35 deletions

View File

@ -893,7 +893,6 @@ public class ModBlocks {
public static Block watz_element;
public static Block watz_cooler;
public static Block watz_end;
public static Block watz_conductor;
public static Block balefire;
public static Block fire_digamma;
@ -1997,7 +1996,6 @@ public class ModBlocks {
watz_element = new BlockPillar(Material.iron, RefStrings.MODID + ":watz_element_top").setBlockName("watz_element").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":watz_element_side");
watz_cooler = new BlockPillar(Material.iron, RefStrings.MODID + ":watz_cooler_top").setBlockName("watz_cooler").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":watz_cooler_side");
watz_end = new BlockToolConversion(Material.iron).addVariant("_bolted").setBlockName("watz_end").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":watz_casing");
watz_conductor = new BlockCableConnect(Material.iron).setBlockName("watz_conductor").setHardness(5.0F).setResistance(10.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":watz_conductor_top");
watz = new Watz().setBlockName("watz").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":block_steel");
watz_pump = new WatzPump().setBlockName("watz_pump").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":block_steel");
@ -3310,6 +3308,12 @@ public class ModBlocks {
GameRegistry.registerBlock(plasma, ItemBlockLore.class, plasma.getUnlocalizedName());
GameRegistry.registerBlock(iter, iter.getUnlocalizedName());
GameRegistry.registerBlock(plasma_heater, plasma_heater.getUnlocalizedName());
register(watz_element);
register(watz_cooler);
register(watz_end);
register(watz);
register(watz_pump);
register(machine_icf_press);
register(icf_laser_component);
@ -3317,13 +3321,6 @@ public class ModBlocks {
register(icf_block);
register(icf_component);
register(icf);
GameRegistry.registerBlock(watz_element, watz_element.getUnlocalizedName());
GameRegistry.registerBlock(watz_cooler, watz_cooler.getUnlocalizedName());
register(watz_end);
GameRegistry.registerBlock(watz_conductor, watz_conductor.getUnlocalizedName());
GameRegistry.registerBlock(watz, watz.getUnlocalizedName());
GameRegistry.registerBlock(watz_pump, watz_pump.getUnlocalizedName());
//E
GameRegistry.registerBlock(balefire, balefire.getUnlocalizedName());

View File

@ -1,7 +1,6 @@
package com.hbm.handler;
import com.hbm.inventory.gui.GUICalculator;
import com.hbm.items.IKeybindReceiver;
import cpw.mods.fml.common.FMLCommonHandler;
import org.lwjgl.input.Keyboard;
@ -15,8 +14,6 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class HbmKeybinds {
@ -25,10 +22,14 @@ public class HbmKeybinds {
public static KeyBinding calculatorKey = new KeyBinding(category + ".calculator", Keyboard.KEY_N, category);
public static KeyBinding jetpackKey = new KeyBinding(category + ".toggleBack", Keyboard.KEY_C, category);
public static KeyBinding hudKey = new KeyBinding(category + ".toggleHUD", Keyboard.KEY_V, category);
public static KeyBinding reloadKey = new KeyBinding(category + ".reload", Keyboard.KEY_R, category);
public static KeyBinding dashKey = new KeyBinding(category + ".dash", Keyboard.KEY_LSHIFT, category);
public static KeyBinding trainKey = new KeyBinding(category + ".trainInv", Keyboard.KEY_R, category);
public static KeyBinding reloadKey = new KeyBinding(category + ".reload", Keyboard.KEY_R, category);
public static KeyBinding gunPrimaryKey = new KeyBinding(category + ".gunPrimary", -100, category);
public static KeyBinding gunSecondaryKey = new KeyBinding(category + ".gunSecondary", -99, category);
public static KeyBinding gunTertiaryKey = new KeyBinding(category + ".gunTertitary", -98, category);
public static KeyBinding craneUpKey = new KeyBinding(category + ".craneMoveUp", Keyboard.KEY_UP, category);
public static KeyBinding craneDownKey = new KeyBinding(category + ".craneMoveDown", Keyboard.KEY_DOWN, category);
public static KeyBinding craneLeftKey = new KeyBinding(category + ".craneMoveLeft", Keyboard.KEY_LEFT, category);
@ -39,10 +40,14 @@ public class HbmKeybinds {
ClientRegistry.registerKeyBinding(calculatorKey);
ClientRegistry.registerKeyBinding(jetpackKey);
ClientRegistry.registerKeyBinding(hudKey);
ClientRegistry.registerKeyBinding(reloadKey);
ClientRegistry.registerKeyBinding(dashKey);
ClientRegistry.registerKeyBinding(trainKey);
ClientRegistry.registerKeyBinding(reloadKey);
ClientRegistry.registerKeyBinding(gunPrimaryKey);
ClientRegistry.registerKeyBinding(gunSecondaryKey);
ClientRegistry.registerKeyBinding(gunTertiaryKey);
ClientRegistry.registerKeyBinding(craneUpKey);
ClientRegistry.registerKeyBinding(craneDownKey);
ClientRegistry.registerKeyBinding(craneLeftKey);
@ -68,19 +73,6 @@ public class HbmKeybinds {
}
}
}
public static void onPressedServer(EntityPlayer player, EnumKeybind key, boolean state) {
// EXTPROP HANDLING
HbmPlayerProps props = HbmPlayerProps.getData(player);
props.setKeyPressed(key, state);
// ITEM HANDLING
ItemStack held = player.getHeldItem();
if(held != null && held.getItem() instanceof IKeybindReceiver) {
((IKeybindReceiver) held.getItem()).handleKeybind(player, held, key, state);
}
}
public static enum EnumKeybind {
JETPACK,
@ -96,7 +88,7 @@ public class HbmKeybinds {
GUN_PRIMARY,
GUN_SECONDARY,
GUN_TERITARY,
GUN_TERTIARY,
RELOAD,
}
}

View File

@ -0,0 +1,25 @@
package com.hbm.handler;
import com.hbm.extprop.HbmPlayerProps;
import com.hbm.handler.HbmKeybinds.EnumKeybind;
import com.hbm.items.IKeybindReceiver;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class HbmKeybindsServer {
/** Can't put this in HbmKeybinds because it's littered with clientonly stuff */
public static void onPressedServer(EntityPlayer player, EnumKeybind key, boolean state) {
// EXTPROP HANDLING
HbmPlayerProps props = HbmPlayerProps.getData(player);
props.setKeyPressed(key, state);
// ITEM HANDLING
ItemStack held = player.getHeldItem();
if(held != null && held.getItem() instanceof IKeybindReceiver) {
((IKeybindReceiver) held.getItem()).handleKeybind(player, held, key, state);
}
}
}

View File

@ -1,5 +1,6 @@
package com.hbm.items.weapon.sedna;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.hbm.handler.HbmKeybinds.EnumKeybind;
@ -13,23 +14,33 @@ public class GunConfig {
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 Function<Triplet<ItemStack, EnumKeybind, GunConfig>, Receiver> receiverDecider;
/** Lambda functions for clicking shit */
public BiConsumer<ItemStack, GunConfig> onPressPrimary;
public BiConsumer<ItemStack, GunConfig> onPressSecondary;
public BiConsumer<ItemStack, GunConfig> onPressTertiary;
public BiConsumer<ItemStack, GunConfig> onPressReload;
/** Lambda functions for releasing the aforementioned shit */
public BiConsumer<ItemStack, GunConfig> onReleasePrimary;
public BiConsumer<ItemStack, GunConfig> onReleaseSecondary;
public BiConsumer<ItemStack, GunConfig> onReleaseTertiary;
public BiConsumer<ItemStack, GunConfig> onReleaseReload;
public GunConfig setReceivers(Receiver... receivers) {
this.receivers = receivers;
return this;
}
public Receiver getReceiver(ItemStack stack, EnumKeybind keybind) {
/*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; };
//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,6 +12,17 @@ public class ItemGunBase implements IKeybindReceiver {
public static final String KEY_TIMER = "timer";
public static final String KEY_STATE = "state";
public static final String KEY_PRIMARY = "mouse1";
public static final String KEY_SECONDARY = "mouse2";
public static final String KEY_TERTIARY = "mouse3";
public static final String KEY_RELOAD = "reload";
/** NEVER ACCESS DIRECTLY - USE GETTER */
private GunConfig config_DNA;
public GunConfig getConfig(ItemStack stack) {
return config_DNA;
}
public static enum GunState {
IDLE, //gun can be fired or reloaded
@ -23,6 +34,16 @@ public class ItemGunBase implements IKeybindReceiver {
@Override
public void handleKeybind(EntityPlayer player, ItemStack stack, EnumKeybind keybind, boolean state) {
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; }
}
// GUN STATE TIMER //
@ -33,6 +54,16 @@ public class ItemGunBase implements IKeybindReceiver {
public static GunState getState(ItemStack stack) { return EnumUtil.grabEnumSafely(GunState.class, getValueByte(stack, KEY_STATE)); }
public static void setState(ItemStack stack, GunState value) { setValueByte(stack, KEY_STATE, (byte) value.ordinal()); }
// BUTTON STATES //
public static boolean getPrimary(ItemStack stack) { return getValueBool(stack, KEY_PRIMARY); }
public static void setPrimary(ItemStack stack, boolean value) { setValueBool(stack, KEY_PRIMARY, value); }
public static boolean getSecondary(ItemStack stack) { return getValueBool(stack, KEY_SECONDARY); }
public static void setSecondary(ItemStack stack, boolean value) { setValueBool(stack, KEY_SECONDARY, value); }
public static boolean getTertiary(ItemStack stack) { return getValueBool(stack, KEY_TERTIARY); }
public static void setTertiary(ItemStack stack, boolean value) { setValueBool(stack, KEY_TERTIARY, value); }
public static boolean getReloadKey(ItemStack stack) { return getValueBool(stack, KEY_RELOAD); }
public static void setReloadKey(ItemStack stack, boolean value) { setValueBool(stack, KEY_RELOAD, value); }
/// UTIL ///
public static int getValueInt(ItemStack stack, String name) { if(stack.hasTagCompound()) stack.getTagCompound().getInteger(name); return 0; }
@ -40,4 +71,7 @@ public class ItemGunBase implements IKeybindReceiver {
public static byte getValueByte(ItemStack stack, String name) { if(stack.hasTagCompound()) stack.getTagCompound().getByte(name); return 0; }
public static void setValueByte(ItemStack stack, String name, byte value) { if(!stack.hasTagCompound()) stack.stackTagCompound = new NBTTagCompound(); stack.getTagCompound().setByte(name, value); }
public static boolean getValueBool(ItemStack stack, String name) { if(stack.hasTagCompound()) stack.getTagCompound().getBoolean(name); return false; }
public static void setValueBool(ItemStack stack, String name, boolean value) { if(!stack.hasTagCompound()) stack.stackTagCompound = new NBTTagCompound(); stack.getTagCompound().setBoolean(name, value); }
}

View File

@ -2110,6 +2110,9 @@ public class ClientProxy extends ServerProxy {
case CRANE_LEFT: return HbmKeybinds.craneLeftKey.getIsKeyPressed();
case CRANE_RIGHT: return HbmKeybinds.craneRightKey.getIsKeyPressed();
case CRANE_LOAD: return HbmKeybinds.craneLoadKey.getIsKeyPressed();
case GUN_PRIMARY: return HbmKeybinds.gunPrimaryKey.getIsKeyPressed();
case GUN_SECONDARY: return HbmKeybinds.gunSecondaryKey.getIsKeyPressed();
case GUN_TERTIARY: return HbmKeybinds.gunTertiaryKey.getIsKeyPressed();
}
return false;

View File

@ -1422,6 +1422,7 @@ public class MainRegistry {
ignoreMappings.add("hbm:item.gas7");
ignoreMappings.add("hbm:item.gas8");
ignoreMappings.add("hbm:tile.brick_forgotten");
ignoreMappings.add("hbm:tile.watz_conductor");
/// REMAP ///
remapItems.put("hbm:item.gadget_explosive8", ModItems.early_explosive_lenses);

View File

@ -1,7 +1,7 @@
package com.hbm.packet.toserver;
import com.hbm.handler.HbmKeybinds;
import com.hbm.handler.HbmKeybinds.EnumKeybind;
import com.hbm.handler.HbmKeybindsServer;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
@ -39,7 +39,7 @@ public class KeybindPacket implements IMessage {
public IMessage onMessage(KeybindPacket m, MessageContext ctx) {
EntityPlayer p = ctx.getServerHandler().playerEntity;
HbmKeybinds.onPressedServer(p, EnumKeybind.values()[m.key], m.pressed);
HbmKeybindsServer.onPressedServer(p, EnumKeybind.values()[m.key], m.pressed);
return null;
}