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.
EDIT: Forget that, I figured it out Just sent another packet.
Alright, it works for the most part. On single player, it can access the data correctly, both moving the player and subtracting ExtendedPlayer properties. However, on a server it doesn't do it. Would getting rid of the "Side.CLIENT" part of the if statement just cause it to crash in this?
Please help somebody!
My keybind not work on server!
How to send packets?
I followed subiohazardous tutorial.
Basically in my tickhandler it detect what item in your hand is and when you press the key it changes it.
I tryed to change TickType to Player and in TickHandler register i changed te side to Client.
I also put my key register into client proxy because in the load method it crash te server.
I want to release my mod but i can't because of thet.
If a get a code snipet it will work for me!
Try reading through many other replies. this has been stated a few times.
I know but if you mean coolAlias Packet Handler it not wokr for me.
If somebody can clearly write down how to get it working on a server theres will be no more question about this.
If you can write to the main post for "how to get it work on server".
Thank you!
You shouldn't be handling your keys in a Tick Handler; they can all be handled from the KeyHandler class itself, and you can send packets as needed from there. You can build a custom packet to contain anything you need; check out the Packet Handling tutorial on the Forge wiki.
If the tutorial and supplementary material doesn't make sense to you, post your code and ask questions, but don't just say 'it doesn't work'. The posted code clearly works for many people.
Hi, great tutorial by the way. I am trying to use your keyhandler to activate skills stored within an extended player. This all works fine thanks to coolAlias's great tutorial. My only problem is that I am using F1-F12 to activate skills, do you know of any way to stop minecraft from using its default functions seeing as they are not assigned to any keys in controls without editing the base class(or if you know which class contains those, could you point me in that direction to try to find my own way to stop them from running). Thanks in advance!After searching alot of minecraft classes I came upon this after running a search in eclipse:
Its in the Minecraft.class so I can grab an instance of minecraft to be able to call those functions with other keys, any idea of how to cancel/overrite that without directly changing it? Sorry if this is somewhat offtopic
There is a way to intercept default keys; check this blog post by The Grey Ghost, and in there you'll find this link to his example. TGG has all sorts of great information there, and you can often find him over at the Minecraft Forge Forums if you have some more specific questions. He and many of the other people there are quite experienced modders.
Thanks you very much for a reply and the link provided, I'm so used to making games from scratch that I can just change things whenever that having to conform to this work style so to speak makes it harder on me. Anyways thanks again!
From what I can tell from reading his/her blog is that the only way to intercept a key is if it already exists as a keybind. The function keys are hardcoded and aren't assigned a key bind as it appears and it doesn't look like it can be changed. Tell me if I read it incorrectly, thanks for the the info though.
From what I can tell from reading his/her blog is that the only way to intercept a key is if it already exists as a keybind. The function keys are hardcoded and aren't assigned a key bind as it appears and it doesn't look like it can be changed. Tell me if I read it incorrectly, thanks for the the info though.
That very much looks to be the case... I guess your only other option is to learn ASM and inject your code in to intercept the hard-coded keys that way. Sorry I haven't actually done any of that before, but it should be possible.
We'll looking at ASM it seems do able, however I will most likely just use the number pad and if players do not have a number pad it is a keybind so they can change it accordingly. Maybe forge will implement them as keybinds in 1.7.2 seeing as minecraft adds F2, F5, and F8 as keybinds however it doesn't add F1 or F3. Anyways thanks for all the help.
Is it possible to apply it to potion effects? Like if you have an effect you can use that key?
Anything that can be done in Java can be done with a key in Minecraft. Whenever a key is pressed, a method gets called, and from within that method you can do anything you want limited only by your coding skills.
Regarding your question more specifically, you need to send a packet to the server when the key is pressed and add the potion effect from the server side. There are lots of examples of both packets and adding potion effects if you search here in the tutorial section and in the modification development subforum.
Anything that can be done in Java can be done with a key in Minecraft. Whenever a key is pressed, a method gets called, and from within that method you can do anything you want limited only by your coding skills.
Regarding your question more specifically, you need to send a packet to the server when the key is pressed and add the potion effect from the server side. There are lots of examples of both packets and adding potion effects if you search here in the tutorial section and in the modification development subforum.
I meant that If you have a certain potion effect you can have access to the input
Rollback Post to RevisionRollBack
"A delayed game is eventually good, but a rushed game is forever bad."
~Shigeru Miyamoto
Also, do you know how to make it launch entitys when you put in the input? I'm starting out a statement, but I can't complete the whole thing(I don't know every minecraft value yet like isPotionActive)
Rollback Post to RevisionRollBack
"A delayed game is eventually good, but a rushed game is forever bad."
~Shigeru Miyamoto
Not too much has changed; in fact, it's simpler now, as everything is done within the KeyBinding class (KeyHandler has been removed).
public class KeyHandler // note that before we extended KeyHandler, but that class no longer exists
{
/** Key index for easy handling */
public static final int CUSTOM_INV = 0;
/** Key descriptions; use a language file to localize the description later */
private static final String[] desc = {"key.tut_inventory.desc"};
/** Default key values */
private static final int[] keyValues = {Keyboard.KEY_P};
private final KeyBinding[] keys;
public KeyHandler() {
keys = new KeyBinding[desc.length];
for (int i = 0; i < desc.length; ++i) {
keys[i] = new KeyBinding(desc[i], keyValues[i], "key.tutorial.category");
ClientRegistry.registerKeyBinding(keys[i]);
}
}
/**
* KeyInputEvent is in the FML package, so we must register to the FML event bus
*/
@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
// FMLClientHandler.instance().getClient().inGameHasFocus
if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) {
if (keys[CUSTOM_INV].isPressed()) {
TutorialMain.packetPipeline.sendToServer(new OpenGuiPacket(TutorialMain.GUI_CUSTOM_INV));
}
}
}
}
Not too much has changed; in fact, it's simpler now, as everything is done within the KeyBinding class (KeyHandler has been removed).
public class KeyHandler // note that before we extended KeyHandler, but that class no longer exists
{
/** Key index for easy handling */
public static final int CUSTOM_INV = 0;
/** Key descriptions; use a language file to localize the description later */
private static final String[] desc = {"key.tut_inventory.desc"};
/** Default key values */
private static final int[] keyValues = {Keyboard.KEY_P};
private final KeyBinding[] keys;
public KeyHandler() {
keys = new KeyBinding[desc.length];
for (int i = 0; i < desc.length; ++i) {
keys[i] = new KeyBinding(desc[i], keyValues[i], "key.tutorial.category");
ClientRegistry.registerKeyBinding(keys[i]);
}
}
/**
* KeyInputEvent is in the FML package, so we must register to the FML event bus
*/
@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
// FMLClientHandler.instance().getClient().inGameHasFocus
if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) {
if (keys[CUSTOM_INV].isPressed()) {
TutorialMain.packetPipeline.sendToServer(new OpenGuiPacket(TutorialMain.GUI_CUSTOM_INV));
}
}
}
}
EDIT: Forget that, I figured it out Just sent another packet.
Alright, it works for the most part. On single player, it can access the data correctly, both moving the player and subtracting ExtendedPlayer properties. However, on a server it doesn't do it. Would getting rid of the "Side.CLIENT" part of the if statement just cause it to crash in this?
Bleach Mod
Try reading through many other replies. this has been stated a few times.
You shouldn't be handling your keys in a Tick Handler; they can all be handled from the KeyHandler class itself, and you can send packets as needed from there. You can build a custom packet to contain anything you need; check out the Packet Handling tutorial on the Forge wiki.
If the tutorial and supplementary material doesn't make sense to you, post your code and ask questions, but don't just say 'it doesn't work'. The posted code clearly works for many people.
There is a way to intercept default keys; check this blog post by The Grey Ghost, and in there you'll find this link to his example. TGG has all sorts of great information there, and you can often find him over at the Minecraft Forge Forums if you have some more specific questions. He and many of the other people there are quite experienced modders.
That very much looks to be the case... I guess your only other option is to learn ASM and inject your code in to intercept the hard-coded keys that way. Sorry I haven't actually done any of that before, but it should be possible.
~Shigeru Miyamoto
Anything that can be done in Java can be done with a key in Minecraft. Whenever a key is pressed, a method gets called, and from within that method you can do anything you want limited only by your coding skills.
Regarding your question more specifically, you need to send a packet to the server when the key is pressed and add the potion effect from the server side. There are lots of examples of both packets and adding potion effects if you search here in the tutorial section and in the modification development subforum.
I meant that If you have a certain potion effect you can have access to the input
~Shigeru Miyamoto
Do you mean that the key is only fired when under a potion effect? Like:
Yeah exactly like that.
~Shigeru Miyamoto
~Shigeru Miyamoto
Try it in 1.7.2, It should work!
It does not. A whole heck of a lot has changed!
Not too much has changed; in fact, it's simpler now, as everything is done within the KeyBinding class (KeyHandler has been removed).
Thanks again coolAlias, for your bounds of help!