Let’s hit some buttons and add custom keybinds to minecraft oh all right we found this back intelligent once more and in this tutorial we’re going to be adding custom keybinds to minecraft now this is going to be a very interesting thing indeed and this is also part of a four part tutorial series Of adding a custom thirst system to minecraft so first of all of course in this tutorial we’re going to be adding the custom key bindings in the next tutorial we’re going to be talking about custom networking then after that we’re going to be talking about saving data on The player with some capabilities and then last but not least we’re going to make a custom hut element on the basically the head up display or the player now first and foremost i want to say that while we’re implementing a fully functioning thirst system here you Should not use this system in your mod you shouldn’t just copy it over and use it just like that in your own mod because number one there are still things that are not quite working right and then secondly also this really is just an example to show you how you Could implement such a thing i very much recommend not just copying it over especially if you’re just a beginner do not just copy it over and put it into your mod that way lies madness all right and one thing that is actually quite important that you need to note and that Is the version of forge you’re using so currently i’m using 41096 now this particular tutorial will definitely not be compatible with anything that’s 41 0 63 and lower and it might also not be compatible with anything 41 0 64. so keep that in mind you will probably have to update i did This in the last tutorial i very much suggest you update as well otherwise some of the things that we’re discussing in the next few tutorials and you know and the rest of the series basically will probably not be compatible with these versions so keep that in mind and That should be pretty much all that you need to do but whatever the case may be let’s start with the keybinds first and foremost we’ll first of all start by making a new packet in our tutorial mode package and that’s going to be called the util package and instead of there We’re going to make a new java class called the key binding class now to be honest where this key binding class goes you know you can put it into the util package you could also put it into a into a separate client package i personally will just put it into the Youtube package that’s gonna be fine and that’s gonna be okay here we’re actually gonna have three different fields the first one is gonna be a public static final string key called key underscore category underscore tutorial now this is going to be the translation key key dot category dot tutorial mod dot tutorial This is going to be the translation key for our category that we’re going to basically put our keys under and then we’re going to have another string right here which is going to be the key underscore drink underscore water and that’s gonna be the key dot tutorial mod dot drink underscore water And that is the name of the key that we’re going to basically create just now so this is going to be a public static final e mapping from net minecraft client over there and we’re going to call this the drinking underscore key and that’s going To be equal to a new key mapping first passing in the key drink water string this is going to be the translation key of the actual you know thing we’re going to be pressing then we’re going to do the key conflict context dot in game that is the second parameter then we’re Going to say input constants type and then use the key as here and then do glfw dot glfw key glfw underscored key underscore oh let’s say so we’re gonna press the o key and then the last parameter is going to be the key category tutorial and that Should be all that we need to do right here this is the way to do it so this one right here would make it so that it’s looking for a key to input and then this of course makes it so that’s looking for a mouse to input should be Fairly self-explanatory and in this case we’re choosing the o key so you can see there actually are you know pretty much all of the keys that you could ever press are on here now we want to press the o key and that is basically the default key for this keybind let’s Actually immediately translate those names over here so that’s going to be happening in the enr school use json well of course so we can basically just copy this over and just add this here right so this is of course going to be the translation and the translation for This is just going to be the tutorial mod you could also call this tutorial mode category or something similar to that but that is going to be fine and then the actual name of the key that we’re having is going to be just the drink water key so it’s just Going to be called drink water and that is pretty much what we need to do i highly recommend always adding your mod id into the translation key over here otherwise there might be some conflicts there and of course that’s not quite what we want now this has now added a Key mapping of course nothing right now happens when we press this and therefore we actually need another class and then it’s going to be in the event package we’re going to right click new java class called client events we’re actually going to make an inner class so There’s going to be a public static class called client forge events and this is going to have two different methods public static void the first one is the on e register method with a register e mappings event called event we’re going to fill this in just a Moment and the second one is a public static void on key input method with the input event dot key called event let’s just type this out and then let’s import this alt and enter and there you go so now we have the two methods over here and that Should be fine right so let’s first of all start with the actual class we want to add a mod over here so let’s just do mod and then delete the parentheses dot eventbus subscriber we can add the parentheses again we want to do mod id equals tutorialmod.mod id then we also Want to say value equals dist.client let’s just write this and then we can go in here and actually import the disks as well then over the two methods we want to say add subscribe event very important that we add this otherwise it will not work and then we should be fine Now for the registration event here it’s actually going to be very very straightforward event dot register e-binding that drinking key there you go and that is all that we need to do now our key is actually registered and it should appear in the options menu under our tutorial mode category but once Again nothing happens at the moment when we actually press this that is what the key input method is for so we’re going to say if keybinding dot drinking key dot consume click right so if this particular key has been clicked then we want to do something right so in this Case what we’re going to do is we’re just going to be outputting something from the player into the chat that is literally all that we’re doing right now we’re not going to be sending any packets or anything like that because that is something we’re going to discuss In the next tutorial so we can say here is we can say minecraft.getinstance.player and then we can just send a message so send system message component dot literal and we’re just going to say rest a key now why can we do you know the craziness of a minecraft get instance Well because this particular method will ever only be called on the client so we know there only is one player right even if we’re on a server your client is still only you and that is basically the reason so we can actually take a look at This key event and we should be able to see if we go up all the way if we get go all the way up we can actually see it is in the client package that is one indication basically also that that is the case but also i believe so it should Ever only happen for the client you know keybinds actually don’t exist on the server therefore this should basically always be on the client therefore we can do this now once again this is just one example once we actually implemented some networking then we’re going to be Sending a packet over here but for the time being we’re just going to output something just so that we know that our key actually works hello future common draw here to tell you that there was a little bit of a mistake in the placement of this particular method this actually Goes into another class so we actually have to create a second static class over here which is going to be called the client mod bus events and then what we can do is we can just completely cut this out put it in here let’s also add The add mod event bus over here and then here we also want to say bus equals mod bus dot mod there you go now the reason for this is if we actually go into the registered key mappings event you can see this is an imod bus event meaning That this has to happen with the modbus and this basically happens for forge events therefore we actually need to split it up otherwise if we don’t do this then the key mapping will not appear in the options menu so that’s very important and now we can go in and See if it works or we found those in minecraft and let’s first of all go into the options menu controls keybinds and at the very bottom there we go the tutorial mode category with the drink water key being oh there you go so the water key has been properly registered Let’s also see if i press it if we get a output in the chat and indeed we do press a key and we can do it again and do it again we can even hold it down it should you know just continue to go up basically and i mean this is pretty Awesome already now of course you know we’re not doing anything particularly interesting yet but just having added a custom keybind already pretty freaking awesome so to properly do something with a custom keybind you basically always are going to need networking so this is going to be perfect for the next Tutorial displayed right here once it’s available hope to see you there so yeah Video Information
This video, titled ‘Minecraft 1.19 Forge Modding Tutorial | CUSTOM KEYBINDINGS | #14’, was uploaded by Modding by Kaupenjoe on 2022-07-26 13:59:46. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
In this Minecraft Modding Tutorial, we are are adding CUSTOM KEYBINDINGS to Minecraft 1.19 with Forge 🙂 == MINECRAFT …