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
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumFrom 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.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYep, 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.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumShow me your code.
package Craftculator; import java.util.EnumSet; import java.util.Iterator; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.World; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.common.TickType; public class CraftculatorGui<TileEntityCraftculator> extends GuiScreen { private EnumSet tickTypes = EnumSet.of(TickType.CLIENT); public CraftculatorGui(KeyBinding[] keyBindings, boolean[] repeatings) { super(keyBindings, repeatings); } public String getLabel() { return "Craftculator"; } public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) { //what to do when key is pressed/down keyPressed = true; } public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) { //What to do when key is released/up keyPressed = false; } public EnumSet<TickType> ticks() { return tickTypes; } public static boolean keyPressed = false; }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!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWell 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!
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIn 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
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumFollow me on twitter! @dreinsteinium
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWhy 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 }-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDidn'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:
public void init(FMLInitializationEvent evt) { KeyBinding[] key = {new KeyBinding("GUIOpen", Keyboard.KEY_F6)}; // <- line 69 boolean[] repeat = {false}; KeyBindingRegistry.registerKeyBinding(new TestKeyHandler(cf.getGuiKeybind(), repeat)); TickRegistry.registerTickHandler(new TestTickHandler(), Side.CLIENT); }-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNo problem! Thanks for the great tutorial - I'll be trying it out soon
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumHmm... 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.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumHmm. I'm not really sure why this is happening. I'll look into it later.