Hello and welcome back to another episode in this episode we’re going to be covering keybinds so first in our init package let’s create a new class called keybinds init then let’s create a public static key binding and we need to make sure we import the net.minecraft.client.settings Let’s call it example key let’s create a public static void register and this is going to take a final fml client setup event event then let’s create a private static keybinding create with string name and int key and we’re going to return a new key binding where we’re going to return key dot And then we’re going to add our mod id and then once again we’re going to add dot and then the name then we pass in the key and then for the last bit we can pass in key dot category dot plus tutorial mod dot mod id now in our register function We need to create the example key so let’s do example key is equal to create and we pass in the name so in this case example underscore key and then we can do key events and now we can import java.awt.event and then we can give it the default Button so in my case this is going to be vkg which is the g key on the keyboard that we can add a semicolon and now we’re registering our example key now we need to add this to the client registry so let’s do client registry dot register key binding example key now We need to call this register function so we can do that by going in our client event bus subscriber and at the top we can do keybind init dot register and then pass in the event so next let’s create a new event class called input events and then we can copy the Event bus subscriber from the player events that we made last time but this time we’re going to do dist is equal to dist dot client however instead of dist it’s value now we need to create two events a at subscribe event for when a key is pressed so let’s do public static Void on key press and then we can do input event and we want to make sure to select the minecraft one dot key input event and let’s name this event so first of all let’s get the minecraft so let’s do minecraft mc is equal to minecraft dot Get instance then we’re going to check if mc.world is equal to null and if it is we’re just going to return and next we need to create a on input function let’s do a private static void on input and this is going to take a minecraft mc An int key and an int action so now under here we can call on input with mc event dot get key and event dot get action now we can copy this on key press and paste it down here and we’re going to change this to on mouse Click and then what we have to do is change this to dot mouse input event and change the get key to dot get button and now all we need to do is to fill out our input function so let’s check if our mc dot current screen Is equal to null and if it isn’t equal to null which is going to return and we’re going to check that the key is the keybind so we’re going to do keybinds init dot example key dot is pressed and if both of those are true that means Our example key has been pressed right now i’m just going to do system dot out dot print line i’m going to say example key press however we need to remember that this is happening on the client so if we want something to happen on the server we’re going to need to send a Packet something that i’ll cover in the next episode so now if we launch the game now if we go to controls and scroll down we can see our key mines however we haven’t set these values in our lang file so we can go to main resources assets tutorial mod Lang en underscore us.json and then we can add our things so in this case it’s going to be key dot category dot tutorial mod which is our mod id and we’re going to change this to tutorial mod and then i’m going to do key dot tutorial mod dot example Key which is going to be example key so now if we go into a game and press f3 and t and go to controls we can see that everything is named and if we go ahead and press g then you can see example key pressed But if we go to our inventory and press g then nothing happens that’s going to do it for this episode if you need help join the discord and i’ll see you next time when i’m going to be covering Packets Video Information
This video, titled ‘Minecraft Modding Tutorial 1.16 | 13.0 – Keybinds’, was uploaded by Cy4’s Modding on 2021-04-06 10:00:37. It has garnered 4481 views and 101 likes. The duration of the video is 00:05:10 or 310 seconds.
client to server packets in the next video! join discord below!
(ɔ◔‿◔)ɔ ♥ ~ expand me
C://Follow_Me/ Subscribe: https://www.youtube.com/channel/UCJIDXtGpf4wv1ybDzdTA_vQ/ Website: https://mcmodding.club/tutorials/
C://Help/ Discord: https://discord.gg/x9Mj63m4QG Or comment on this video!
C://Source_Code/ This Episode: https://github.com/Cy4Shot/ModdingTutorial1.16/tree/main/13.0-Keybinds All Episodes: https://github.com/Cy4Shot/ModdingTutorial1.16/