I'm like my code simple and organized, and I want multiple keybindings but I'm not too happy with my current result.
Are there anyone here who has a good suggestion on how to do this more cleanly?
public class ModKeybindings {
public static MazKeyBind PowerKey;
public static MazKeyBind SomeKey;
public static void registerKeyBindings(){
boolean[] repeat = {false};
KeyBinding[] some = {new KeyBinding("SomeKey", Keyboard.KEY_NUMPAD5)};
SomeKey = new MazKeyBind(some, repeat);
KeyBindingRegistry.registerKeyBinding(SomeKey);
KeyBinding[] power = {new KeyBinding("Toggle Power", Keyboard.KEY_G)};
PowerKey = new MazKeyBind(power, repeat);
KeyBindingRegistry.registerKeyBinding(PowerKey);
}
As you can see it's quite bulky and ugly, I know I could have done it in some other ways but all I came up with earlier tonight was inefficient and bulky. Does you guys have any suggestions?
From what I can see, that is the cleanest way you can do it. That is the exact way I do it to
From what I can see, that is the cleanest way you can do it. That is the exact way I do it to
Yes, just change TickTypes to server. Keybinding is done client side so you need to be more specific in what you're doing if you want a better answer.
So i am making a keybind that changes a mode of a weapon. it works on a single player world but when i tried to run it on a server, it crashed. I tried to change it to TickTypes.SERVER but it didn't work. I did a little small search about this, i think you need to do something with packet.
So i am making a keybind that changes a mode of a weapon. it works on a single player world but when i tried to run it on a server, it crashed. I tried to change it to TickTypes.SERVER but it didn't work. I did a little small search about this, i think you need to do something with packet.
Yep, your research is right. I recommend working with packet handler, checking the forge wiki, and googling tutorials on packets.
Well your inheriting GuiScreen instead of KeyHandler so when call the super class it doesn't recognize the arguments because that is for the KeyHandler class constructor. I'm not sure why you're extending GuiScreen....
I kind of need help.
In my ItemFile i made it to where if you press G you go up in the air and if you press H it shoots Fireballs
i want it to be to where it only does that if i hold the item.
Cause even though it's defined in the Item###.java It works without the item being held
Which i don't like
I kind of need help.
In my ItemFile i made it to where if you press G you go up in the air and if you press H it shoots Fireballs
i want it to be to where it only does that if i hold the item.
Cause even though it's defined in the Item###.java It works without the item being held
Which i don't like
Why don't you call player.getHeldItem() in your key press:
if (player.getHeldItem() != null && player.getHeldItem().itemID == YourMod.yourItem.itemID) {
// shoot fireballs or whatever here
}
I wrote the code in the tutorial, But the error occurs.
Do you know how to solve?
Console:
java.lang.NoClassDefFoundError: atp
at com.Test.core.TestModContainer.init(TestModContainer.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:313)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:194)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:313)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:105)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:697)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:232)
at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:506)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:796)
at net.minecraft.client.main.Main.main(SourceFile:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:57)
at net.minecraft.launchwrapper.Launch.main(Launch.java:18)
Caused by: java.lang.ClassNotFoundException: atp
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 33 more
Caused by: java.lang.LinkageError: loader (instance of net/minecraft/launchwrapper/LaunchClassLoader): attempted duplicate class definition for name: "net/minecraft/client/settings/KeyBinding"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:171)
... 35 more
I wrote the code in the tutorial, But the error occurs.
Do you know how to solve?
Console:
java.lang.NoClassDefFoundError: atp
at com.Test.core.TestModContainer.init(TestModContainer.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:313)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:194)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:313)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:105)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:697)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:232)
at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:506)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:796)
at net.minecraft.client.main.Main.main(SourceFile:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:57)
at net.minecraft.launchwrapper.Launch.main(Launch.java:18)
Caused by: java.lang.ClassNotFoundException: atp
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 33 more
Caused by: java.lang.LinkageError: loader (instance of net/minecraft/launchwrapper/LaunchClassLoader): attempted duplicate class definition for name: "net/minecraft/client/settings/KeyBinding"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:171)
... 35 more
From what I can see, that is the cleanest way you can do it. That is the exact way I do it to
Yes, just change TickTypes to server. Keybinding is done client side so you need to be more specific in what you're doing if you want a better answer.
So i am making a keybind that changes a mode of a weapon. it works on a single player world but when i tried to run it on a server, it crashed. I tried to change it to TickTypes.SERVER but it didn't work. I did a little small search about this, i think you need to do something with packet.
Yep, your research is right. I recommend working with packet handler, checking the forge wiki, and googling tutorials on packets.
Those are a bit out of my league.
Once I learn about them i'll get a tutorial up.
Show me your code.
He has a life besides the forum and will respond when he has the time
and to Everyone:
This code and tutorial works for 1.6.X no need to ask him to update!
Well your inheriting GuiScreen instead of KeyHandler so when call the super class it doesn't recognize the arguments because that is for the KeyHandler class constructor. I'm not sure why you're extending GuiScreen....
Thank you mazetar!
In my ItemFile i made it to where if you press G you go up in the air and if you press H it shoots Fireballs
i want it to be to where it only does that if i hold the item.
Cause even though it's defined in the Item###.java It works without the item being held
Which i don't like
Follow me on twitter! @dreinsteinium
Why don't you call player.getHeldItem() in your key press:
Didn't know that method existed. Thanks.
Do you know how to solve?
Console:
at com.Test.core.TestModContainer.init(TestModContainer.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:313)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:194)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:313)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:105)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:697)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:232)
at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:506)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:796)
at net.minecraft.client.main.Main.main(SourceFile:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:57)
at net.minecraft.launchwrapper.Launch.main(Launch.java:18)
Caused by: java.lang.ClassNotFoundException: atp
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 33 more
Caused by: java.lang.LinkageError: loader (instance of net/minecraft/launchwrapper/LaunchClassLoader): attempted duplicate class definition for name: "net/minecraft/client/settings/KeyBinding"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:171)
... 35 more
Code:
No problem! Thanks for the great tutorial - I'll be trying it out soon
Hmm... Did you import the class correctly? The error means it can't find the KeyBinding Class. Make sure you imported the forge KeyBinding class
Yes.KeyBinding Class has been imported.
It will run correctly when run in Eclipce.
Error appears it from your compiled with MCP.
Hmm. I'm not really sure why this is happening. I'll look into it later.