Jump to content

Recommended Posts

Posted (edited)

I'm trying to make a mod that involves randomly rebinding vanilla controls without user input however I'm confused on the InputMappings.Input class . I'm trying to use an instance of KeyBindingMap like so: 

public static KeyBindingMap allBinds;

to change the mapping of vanilla controls. I get the vanilla binds like so:

Minecraft.getInstance().gameSettings.keyBindAttack

I then try to change the keybindings like so:

allBinds.addKey( ??? ,Minecraft.getInstance().gameSettings.keyBindAttack);

the first variable needs to be an instance of InputMappings.Input, but I'm very confused on how to use it. I'm not trying to record user input for this. I want to randomly switch around keyCodes from a predefined set of keys so that one event is done through a different key after the switch.

 

I've already tried removing all the keys in the map and then recreating them to randomly switch the keys, but that crashes the game since (I'm assuming from what I saw In the error logs) some Vanilla values can't be NULL.

Edited by Thigh Exercise
wrote something wrong
Posted

update: So I tried to get the keys like so:

public static InputMappings.Input[] allVanillaKeys = new InputMappings.Input[22];

 

allVanillaKeys[0] = Minecraft.getInstance().gameSettings.keyBindAttack.getKey();
allVanillaKeys[1] = Minecraft.getInstance().gameSettings.keyBindForward.getKey();

I then flipped the keys with each other

Minecraft.getInstance().gameSettings.keyBindAttack.bind(allVanillaKeys[1]);
Minecraft.getInstance().gameSettings.keyBindForward.bind(allVanillaKeys[0]);

But when I tried running it in game, the game couldn't save options and the game crashed due to a NullPointerException, so I guess switching the keys like that nullifys some stuff.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.