I'm making a mod with an Invisible Block. When the player presses 'V' I'd like it to become invisible, or re-visible again. I think I know how to actually change the texture of a block in-game. What I don't know how to do, and can't find anywhere, is how to react to a keypress. I've seen stuff about eventhandling and such but none if it really makes sense to me. Can somebody please explain it to me, and how to react to a keypress?
Thank you very much.
EDIT: I have everything working on singleplayer, but it crashes on server
@Override
public EnumSet<TickType> ticks()
{
return tickTypes;
}
}
and here is the crash I get:
[SEVERE] Encountered an unexpected exception LoaderException
cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cpw.mods.fml.common.LoadController.transition(LoadController.java:156)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:700)
at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:107)
at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:355)
at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:142)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cm.common.modCloneeskimod.load(modCloneeskimod.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:545)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:201)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:112)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:699)
... 5 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.settings.KeyBinding
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/settings/KeyBinding for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172)
... 35 more
[SEVERE] This crash report has been saved to: Z:\My Documents\Programming\Minecraft Modding\forge\mcp\jars\.\crash-reports\crash-2015-08-29_13.51.53-server.txt
Did you try searching 'Minecraft keybinding tutorial' with your favorite search engine? First result was this.
yes I have seen that page but when I follow it's exact steps, "KEY_G cannot be resolved or is not a field". Any ideas why?
EDIT: Was importing from the wrong area. fixed, thanks!
EDIT 2: However now I need help excactly changing the texture of a block. I have the keybind set up but I don't know how to change the actual texture of the block. How do I do this?
EDIT 3: Nevermind it works now on client but crashes on server.
@Override
public EnumSet<TickType> ticks()
{
return tickTypes;
}
}
and here is the crash I get:
[SEVERE] Encountered an unexpected exception LoaderException
cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cpw.mods.fml.common.LoadController.transition(LoadController.java:156)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:700)
at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:107)
at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:355)
at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:142)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cm.common.modCloneeskimod.load(modCloneeskimod.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:545)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:201)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:112)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:699)
... 5 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.settings.KeyBinding
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/settings/KeyBinding for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172)
... 35 more
[SEVERE] This crash report has been saved to: Z:\My Documents\Programming\Minecraft Modding\forge\mcp\jars\.\crash-reports\crash-2015-08-29_13.51.53-server.txt
Player input, e.g. via the keyboard, only happens on the client, so you cannot use it on the server for anything. You have to respond to the client input by sending a packet to the server with the information needed (e.g. which key was pressed or which action needs to be performed) for the server to process it correctly.
Player input, e.g. via the keyboard, only happens on the client, so you cannot use it on the server for anything. You have to respond to the client input by sending a packet to the server with the information needed (e.g. which key was pressed or which action needs to be performed) for the server to process it correctly.
I thought It might have to do with packets, everywhere else I found gave that answer as well. Thanks for confirming! Could you reference me to a good link or explain to me excactly how to do these packets?
I thought It might have to do with packets, everywhere else I found gave that answer as well. Thanks for confirming! Could you reference me to a good link or explain to me excactly how to do these packets?
For 1.6.4? You'll have to Google that, sorry. It's pretty old-school, and most implementations (in 1.6.4) are very messy...
I'm making a mod with an Invisible Block. When the player presses 'V' I'd like it to become invisible, or re-visible again. I think I know how to actually change the texture of a block in-game. What I don't know how to do, and can't find anywhere, is how to react to a keypress. I've seen stuff about eventhandling and such but none if it really makes sense to me. Can somebody please explain it to me, and how to react to a keypress?
Thank you very much.
EDIT: I have everything working on singleplayer, but it crashes on server
here is the keybinding class:
package cm.common;
import ibxm.Player;
import java.util.EnumSet;
import java.util.Iterator;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeChunkManager;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
class cmKeyBind extends KeyHandler
{
private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);
public cmKeyBind(KeyBinding[] keyBindings, boolean[] repeatings)
{
super(keyBindings, repeatings);
}
@Override
public String getLabel()
{
return "cmKeyBind";
}
@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
{
}
@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd)
{
cm.common.modCloneeskimod.artificialBarrier.canProvidePower();
System.out.println("V Released");
}
@Override
public EnumSet<TickType> ticks()
{
return tickTypes;
}
}
and here is the crash I get:
[SEVERE] Encountered an unexpected exception LoaderException
cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cpw.mods.fml.common.LoadController.transition(LoadController.java:156)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:700)
at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:107)
at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:355)
at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:142)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cm.common.modCloneeskimod.load(modCloneeskimod.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:545)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:201)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:112)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:699)
... 5 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.settings.KeyBinding
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/settings/KeyBinding for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172)
... 35 more
[SEVERE] This crash report has been saved to: Z:\My Documents\Programming\Minecraft Modding\forge\mcp\jars\.\crash-reports\crash-2015-08-29_13.51.53-server.txt
Did you try searching 'Minecraft keybinding tutorial' with your favorite search engine? First result was this.
yes I have seen that page but when I follow it's exact steps, "KEY_G cannot be resolved or is not a field". Any ideas why?
EDIT: Was importing from the wrong area. fixed, thanks!
EDIT 2: However now I need help excactly changing the texture of a block. I have the keybind set up but I don't know how to change the actual texture of the block. How do I do this?
EDIT 3: Nevermind it works now on client but crashes on server.
here is the keybinding class:
package cm.common;
import ibxm.Player;
import java.util.EnumSet;
import java.util.Iterator;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeChunkManager;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
class cmKeyBind extends KeyHandler
{
private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);
public cmKeyBind(KeyBinding[] keyBindings, boolean[] repeatings)
{
super(keyBindings, repeatings);
}
@Override
public String getLabel()
{
return "cmKeyBind";
}
@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
{
}
@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd)
{
cm.common.modCloneeskimod.artificialBarrier.canProvidePower();
System.out.println("V Released");
}
@Override
public EnumSet<TickType> ticks()
{
return tickTypes;
}
}
and here is the crash I get:
[SEVERE] Encountered an unexpected exception LoaderException
cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cpw.mods.fml.common.LoadController.transition(LoadController.java:156)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:700)
at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:107)
at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:355)
at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:142)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at cm.common.modCloneeskimod.load(modCloneeskimod.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:545)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:201)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:112)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:699)
... 5 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.settings.KeyBinding
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/settings/KeyBinding for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172)
... 35 more
[SEVERE] This crash report has been saved to: Z:\My Documents\Programming\Minecraft Modding\forge\mcp\jars\.\crash-reports\crash-2015-08-29_13.51.53-server.txt
Player input, e.g. via the keyboard, only happens on the client, so you cannot use it on the server for anything. You have to respond to the client input by sending a packet to the server with the information needed (e.g. which key was pressed or which action needs to be performed) for the server to process it correctly.
I thought It might have to do with packets, everywhere else I found gave that answer as well. Thanks for confirming! Could you reference me to a good link or explain to me excactly how to do these packets?
For 1.6.4? You'll have to Google that, sorry. It's pretty old-school, and most implementations (in 1.6.4) are very messy...