Edited my post above to include an alternative way of getting your key bindings to process only once per key press, in addition to the other code on using a config file and keeping multiple keybindings as compact as possible.
Edited again to add information on how to send packets for opening server-side gui elements.
You have to call the minecraft key bind. I forgot how to do this, but if i figure it out i'll let you know.
it's a start, at least now I know what to look for, thanks!
=======edited===========
after hours searching, didn't find a way to to this, but i realized that this is more complicated. If I could put a new key into minecraft default control settings gui, and if the user change my key, i'll need to save it into my config file right?
I did the trick using a generalTickHandlers and a code inside like this:
public class generalTickHandler implements ITickHandler {
private static final Minecraft mc = FMLClientHandler.instance().getClient();
private static boolean keydown = false;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
//To change body of implemented methods use File | Settings | File Templates.
if (Keyboard.isKeyDown(ConfigurationSettings.jumpKey)) {
if (!keydown) {
keydown = true;
if (mc.thePlayer != null && mc.currentScreen == null && !mc.ingameGUI.getChatGUI().getChatOpen()) {
if (mc.thePlayer.ridingEntity instanceof EntitySpiderMother) {
PacketDispatcher.sendPacketToServer(new jumpPacket().makePacket());
}
}
}
} else
keydown = false;
}
Of course, doing this way I don't have a gui for editing the key, but this is not a problem, I just want to know if this is secure to do. Can I leave my mod working this way? Anybody knows?
You should both check out my post on the last page, here. It shows how to use a configuration file and, if you wanted, you could easily set your key to use a vanilla key binding, but then you'd need to let users know to change their key settings so as not to overlap.
It also addresses the issue of multiple outputs from each press by handling all the processing in the KeyHandler itself rather than in any outside classes.
@GnRSlashSP - That should work, but using 'Keyboard' will crash the game once you try it on a server. If you're just trying to get your custom entity to jump higher or something, you don't even need a key binding; use an EventHandler to handle a LivingJumpEvent, check if it's your custom entity there and do whatever you want to do. Check this tutorial for how to do that, if you need help.
How would I make it so it does something when I am wearing my special armor?
Normally you are at client side when you detect keystrokes. So, you need to check if your special key was pressed. When it happens, you will need to check if the player is wearing your armor.
You can check if player is wearing something using thePlayer instance at client side.
FMLClientHandler.instance().getClient().thePlayer
Does anyone actually know how to get this to work on servers? Keyboard stuff is all clientside, so I have no idea how to get it to translate. If I'm not referencing the player, it works fine. However, my keybind needs to take a stat from the player. Since they're saved serverside (I assume) it returns 0 no matter what I do. Can anyone help me solve this dilemma?
Thanks,
LittleBreadLoaf
Does anyone actually know how to get this to work on servers? Keyboard stuff is all clientside, so I have no idea how to get it to translate. If I'm not referencing the player, it works fine. However, my keybind needs to take a stat from the player. Since they're saved serverside (I assume) it returns 0 no matter what I do. Can anyone help me solve this dilemma?
Thanks,
LittleBreadLoaf
You get it to work on servers by not doing anything client side other than sending a packet to the server telling which key was pressed. The server handles the rest. So if you get a packet saying 'player X hit key Y', the server checks what key 'Y' needs from the player and does whatever needs doing.
You get it to work on servers by not doing anything client side other than sending a packet to the server telling which key was pressed. The server handles the rest. So if you get a packet saying 'player X hit key Y', the server checks what key 'Y' needs from the player and does whatever needs doing.
Alright... How do I get it to reference the player without using thePlayer (clientside). I'm also using your awesome extended player tutorial I had my keybind reference mc.thePlayer, then on to ExtendedPlayer which sent the packet... However it doesn't work Sooo how would I send a packet straight from the keybind, so that it can refer to the player's ExtendedPlayer?
Alright... How do I get it to reference the player without using thePlayer (clientside). I'm also using your awesome extended player tutorial I had my keybind reference mc.thePlayer, then on to ExtendedPlayer which sent the packet... However it doesn't work Sooo how would I send a packet straight from the keybind, so that it can refer to the player's ExtendedPlayer?
Look at my post here. You already have the player in onCustomData in your packet handler. That's the player you use to get the ExtendedPlayer.
The Grey Coder just made a new addition to his dissection of minecraft's code base.
This one is about getting input from the user's mouse and keyboard, I thought it could be useful for anyone who is interested in this tutorial
Edited again to add information on how to send packets for opening server-side gui elements.
Its just some simple tick logic in your keyDown method.
When I bind a key already binded (minecraft default key), the minecraft key stops working.
I saw that Mo's Creatures didi this!
Thanks!
Want real chalenge and cool mods? My mods:
Amazing Minecraft Mods
†GnR† Slash - Can one man truly make a difference?
You have to call the minecraft key bind. I forgot how to do this, but if i figure it out i'll let you know.
Because it ticks twice as the button is held down. You will have to follow the "button doesn't send a constant stream" tutorial.
it's a start, at least now I know what to look for, thanks!
=======edited===========
after hours searching, didn't find a way to to this, but i realized that this is more complicated. If I could put a new key into minecraft default control settings gui, and if the user change my key, i'll need to save it into my config file right?
I did the trick using a generalTickHandlers and a code inside like this:
Of course, doing this way I don't have a gui for editing the key, but this is not a problem, I just want to know if this is secure to do. Can I leave my mod working this way? Anybody knows?
thanks!
Want real chalenge and cool mods? My mods:
Amazing Minecraft Mods
†GnR† Slash - Can one man truly make a difference?
How or Where?
You should both check out my post on the last page, here. It shows how to use a configuration file and, if you wanted, you could easily set your key to use a vanilla key binding, but then you'd need to let users know to change their key settings so as not to overlap.
It also addresses the issue of multiple outputs from each press by handling all the processing in the KeyHandler itself rather than in any outside classes.
@GnRSlashSP - That should work, but using 'Keyboard' will crash the game once you try it on a server. If you're just trying to get your custom entity to jump higher or something, you don't even need a key binding; use an EventHandler to handle a LivingJumpEvent, check if it's your custom entity there and do whatever you want to do. Check this tutorial for how to do that, if you need help.
My modding project, just credit me and let me know if you borrow my code: https://github.com/FinalKill9175/WSBIM-NEW/
Normally you are at client side when you detect keystrokes. So, you need to check if your special key was pressed. When it happens, you will need to check if the player is wearing your armor.
You can check if player is wearing something using thePlayer instance at client side.
FMLClientHandler.instance().getClient().thePlayer
Want real chalenge and cool mods? My mods:
Amazing Minecraft Mods
†GnR† Slash - Can one man truly make a difference?
Thanks,
LittleBreadLoaf
Bleach Mod
You get it to work on servers by not doing anything client side other than sending a packet to the server telling which key was pressed. The server handles the rest. So if you get a packet saying 'player X hit key Y', the server checks what key 'Y' needs from the player and does whatever needs doing.
Alright... How do I get it to reference the player without using thePlayer (clientside). I'm also using your awesome extended player tutorial I had my keybind reference mc.thePlayer, then on to ExtendedPlayer which sent the packet... However it doesn't work Sooo how would I send a packet straight from the keybind, so that it can refer to the player's ExtendedPlayer?
Bleach Mod
Look at my post here. You already have the player in onCustomData in your packet handler. That's the player you use to get the ExtendedPlayer.
Thanks for helping out man!
This one is about getting input from the user's mouse and keyboard, I thought it could be useful for anyone who is interested in this tutorial
http://greyminecraftcoder.blogspot.com.au/2013/10/user-input.html