Hello hello hello everybody and welcome back to another minecraft modding tutorial for version 1.19 in this tutorial we are going to be covering advanced items so this is where this part of the series gets a little more exciting and we can start to do something more than just basic stuff so Yes let’s get started with advanced items shall we so let’s just briefly explain what i am classifying as an advanced item so by advanced item i am meaning an item that has functionality other than just being an item pretty much so whether that be tool tips whether that be Doing something when you right click doing something when you left click etc etc there’s tons of different functionality you can add so we’re going to go through some of that today obviously not all of it because there’s millions of things you could do but we’ll cover some of the base things You might want to do so let’s just get started let’s come into our main package and we’re going to create a new package and we’re going to call this items and inside of here we’re going to want to create our item class so i’m just going to call this advanced item okay Now this class will need to extend item now you need to make sure that’s the correct item of course that’s net.minecraft.world.item and then we need to add the constructor here we have the properties which we can just shift f6 and change to properties then we can start doing whatever we want So before we continue with that let’s go ahead and register this item and get it ready so in our item in it we can come down below our armors and we can go actually we won’t do it down below our armors we’ll just do it up here so we’ll say public static final Registry objects and this will be of type advanced item and i’m just going to call this advanced item is equal items dot register advanced underscore item and then you have your supplier of a new advanced item and as usual that will take in your item properties which we created a method for Down here fantastic so that is now our advanced item okay inside this class we can do whatever we want so any functionality you would like to add to your item you can do it here so i’m briefly going to go through some of the methods you might want to override And just sort of what they do so the first and probably most common method you’re going to want to override is the use method now this method is called when you right click the item that’s that’s pretty much it so if when you right click the item in mid air This is sort of the method that will be called and yeah you can do any right click functionality functionality here the other method which you might want to use a lot is use on so this method is called when you right click on a block with this item Another method you might want to use is on left click entity so this is when you left click or punch an entity with this item and another one is i believe it is called entity uh no it’s not called there is an interact method interact living entity there you go so This happens when you right click a living entity and there are a few more but we’re just going to be using use in this episode and let’s rename some of these things so this for example is the level this is the player and this is the hand okay And we’re going to keep this return there and we’re going to do our functionality up here so yeah i mean you can do whatever you want all i’m going to do in this tutorial is make it send a message in the chat to the player So all you need to do for that is player dot send system message and this just takes in a component so a component is basically just um a piece of text pretty much so to make a component you do component dot and then you can create your different Components you can get an empty component a keybind component a literal component which is just a string mbt score selector translatable so if you want your component to be translatable then you can put a translation key in here for example um i could put tutorial mod dot mod id plus dot um Dot advanced underscore item dot um right under click and then in my lang file i could have something like tutorial mod dot advanced underscore item dot right and we’ll click and i could say that is equal to bins and then that can be translatable into any language that that is what you Should do another thing you can do is also just a literal so a literal it’s just a normal uh text component really nothing too special about it you can just put in whatever you want in this string and that won’t be translatable for the simplicity sake here i am going to use The little rule and i’m just going to say beans and there you go that will be the beans fantastic so now when you right click that will send a message to the player saying beans one thing you obviously might want to do here well i say obviously it’s not Obvious but you might want to check the hand so you might want to say only if the hand is equal interactionhand.mainhand then maybe you can do that and you could also do something like check if it’s client-side so you might want to say if it’s not client-side and it’s in the main hand Then we want to send a message like that okay the next thing i’m going to be showing you how to do in this tutorial is tool tips and i know that that will be um very very common among most people’s items so how do we add a tooltip now initially You might think there is just a method named tooltip however if you search for tooltip you’ll see there are two methods with tooltip in the name but they’re not helpful they’re not the ones we want what we actually want is a method called append hover text i know it’s a slightly weird name And let’s just rename some parameters first so this first one here is the item stack or i’m just going to name it stack then we have the level which i’m just going to name level then we have a list of component so these are the different components i’m Just going to call this components and then we have a tooltip flag which is basically whether it’s advanced or not i’m just going to name that flag okay so here we have the super which will just add everything that the super class wants to add we are going to leave that there And from there we basically can do whatever we want so we can do components.add and then you can add your component so component.translatable maybe it’s touringmod.mod id plus let’s say advanced underscore item.tooltip and you can put that in your lang and that will work now i’m going to be doing here is i’m Going to do something a little more advanced and i want to have a shift tooltip so when you press shift it will show a different tool tip so say press shift for more information when you press shift it shows the different tool tip and that is actually really easy to do however The issue is we don’t have a player here as you can see there is no access to a player so we can’t really check if the shift key is being pressed and that is slightly an issue here so one thing to note about this append hover text method is this is client only This method will only run on the client side and the issue is this item class is common so this item class is both client and server and that means we can’t have any client only code in here because this class is loaded on the server as well And that that sort of causes a bit of an issue because the only way that we can access the player is using the minecraft class and this class here is client only if you load this on the server it will crash because it doesn’t exist on the Server side so we have a slight little issue there luckily there is a fix for this and that is to make our own class so let’s come into our main package let’s create a new class now i’m going to call this class client access and this is basically going to be for Methods that we want to access only on the client side and these could be called for anywhere so this would just be basically a utility class if you will and what i’m going to put in here is i’m going to say public static void now i’m going to call this um check I’ll do advanced item tooltip that’s what i’ll call it okay and i’m going to pass in here a list of components not that type of component that type of component and i’ll call this components now we can actually say if minecraft dot get instance which as i was saying is client only Dot player dot is shift key down then we can say components dot add we can say component dot literal and then we can say um press shift for more information okay and what you can do to this is we can actually go ahead and color this if we want as well And we can do that using the minecraft color code so these are the minecraft color codes here and we need to use the motd codes this not the chat codes so i’m going to use purple here so let’s come back into here and let’s say before the shift we’ll put this one Make sure we get that right like that and then after the shift if we come back onto our color code website we can simply say grab the white close this site now because i don’t need that anymore and we can plug that in there here this jank that’s added and boom Now we have our two colors for it now if shift is not pressed we can say else components dot add component.literal and we can instead say um beams and we could do something like if we pass in the level as well so level level beams plus level dot um Wait is that past that’s not the right level okay we want to make sure we import the correct level here that’s the level we want we can just say level dot is reigning for example and that will just only say beans level is raining if the shift key is being pressed Now let’s come back into our glocks and you may think that we can just call client access you may think we can just do client access dot advanced tool tip level components however we can’t do that because we will still have the same issue that class is still going to be loaded Or at least theoretically might still be loaded so what we can do just to make sure that this is perfectly safe we can do dist executor dot unsafe run when on dist dot client and then we can do a i believe supplier let me just check what does it ask for A supplier of a runnable okay that’s what i thought so we can do a supplier of a runnable of client access dot advanced item tooltip level components and that absolute that absolutely ensures that nothing here is going to be loaded on the correct side nothing is going to be loaded on the Incorrect slide we don’t want anything to be loading on the server and yeah this will work perfectly fine now you could just risk it and leave the client access um this it might work however personally i don’t trust it and in my eyes there’s no reason not to make sure um The client and server interact with really weird ways sometimes you just want to make sure everything does work fine and that’s just how i like to do this now one thing i should mention here um in this use method you can actually return stuff other than the super if you Want something to happen so for example instead of returning the super here we could do interaction result holder dot and then you have some options here so you have whether it succeeded uh whether it failed whether it should pass whether it should succeed on a certain side etc etc and this just Allows the super to have some functionality when you go through and do all the super stuff that should be pretty much it um yeah that should be pretty much it our items should now work let’s just go ahead really quickly do the boring stuff that being the lang so advanced underscore item Advanced item and also obviously the item model let’s grab that as well advanced underscore item advanced underscore item and then finally making sure you have the texture which i actually named slightly different so i’ll just call that advanced item now obviously you wouldn’t name your item advanced item that is something i Should have mentioned earlier in this tutorial you would name it you know whatever your item is not advanced item that is a really dumb name that is the same with the class name don’t call this advanced item i beg you don’t do that people did that In my last tutorial series don’t do it it’s really bad name for a class call it what it is you know if it’s um a golden apple call it a golden apple item simple as that you know don’t call it an advanced item unless your item is literally just called advanced which Dumb name by the way but yeah i mean you get my point you you get my drift um but that is it for this tutorial let’s just go ahead and test it in the game and hope that everything will work okay so that didn’t work and i was Trying to figure out why for a little bit it turns out the methods i was using to check if the player is pressing shift do not work in g uis which is stupid um but essentially i have changed it around a little bit so we are now using screen dot hash shift Down much simpler method as well um i did i actually wasn’t aware this existed i was just looking through the minecraft code just to see why it wasn’t working and it turns out this is sort of what you’re meant to use for this kind of thing another thing i Did just change because i thought it was a little bit ugly is instead of having these literals straight in this string i am instead just making them constant and passing them in like this i think that’s just um a little bit cleaner and uh yeah much easier to read So if we go into the game we can see if i right click my item it says beans and it only says it once every time i click it says it once um fantastic if i go in my inventory we have our press shift for more information i press shift and it says False and if i do happen to do weather rain and then press shift it says true because it’s now raining and i’m just going to do weather clear because rain is bad and as you will see it now changed to pulse because it’s no longer raining And that’s it so yeah i know the texture is obviously awful um but yeah i hope you guys did find this tutorial useful if you did please do be sure to smash your face into that like button and subscribe if you really enjoyed or found it useful please do be Sure to share it around and uh yeah i’ll see you guys in the advanced block tutorial good bye oh you can’t come back here chicken sandwich Video Information
This video, titled ‘1.19 Minecraft Forge Modding Tutorial – Advanced Items’, was uploaded by TurtyWurty on 2022-07-29 16:30:07. It has garnered 2692 views and 67 likes. The duration of the video is 00:22:20 or 1340 seconds.
Hello everyone, in this video we will be creating an advanced item with special functionality such as tooltip and right click actions!
In the next video we will create an advanced block which we can right click to perform a function! Remember, if you have any problems, please join the discord that is linked below!
–Links– Patreon: https://www.patreon.com/turtywurty Discord: https://discord.gg/BAYB3A38wn Github: https://github.com/DaRealTurtyWurty/1.19TutorialMod Trello: WIP