Creating custom items in your spigot plugins is actually fairly simple if you’re new to java then you might struggle to follow along with my minecraft tutorials don’t worry though i have a complete java course that you can watch for free by signing up for a free trial of skillshare this course has Around 50 videos and nearly 4 hours of content that are all designed for the beginner so if you’re new to java then this is the perfect place to start go ahead and click on the link in the description or in the pinned comment to sign up for free i’m first going to Start off by creating a new handler which is going to listen for whenever a player joins the server so i can right click and make a new java class this will be called player handler and this class is going to implement listener and then i can create a constructor so Public player handler and within here i’m going to register the events similar to what i did in the previous torch handler video so bucket.getpluginmanager.registerevents we also need access to the one off keys commands tutorial which is just my actual plugin that i created obviously you would use whatever the name is of Your main class so in my case it is one of case tutorial i’ll call this plugin then here i can say bucket.getpluginmanager.registerevents passing in this and then plugin now within this class i can listen for whenever a player joins a server that way i can give them items whenever they First join and to do that i can first say that this is going to be an event handler then i can create a method called on player join and within here i can now specify the player joint event and now i can access the player who Joined the server so i can create a player object and assign this equal to event dot get player i now want to create something known as an item stack which is basically an item within minecraft and i can then give that to this player so i can say item stack with A capital i and a capital s you could either call this i s or item or whatever you want i’m going to use item and i’m going to assign this equal to a new item stack now we can specify what type of item this is for example material which Is an enum that has every single material in the game we can specify material.grass diamond block diamond basically anything you want we can also specify how many of these are going to be for example i could specify 10. now i can access the player’s inventory and Add this item to it so here i can create an inventory i’m going to call this inv and assign this equal to player dot get inventory i can then say in dot add item which will add this item to the next empty spot if we wanted to we can add it To a very specific spot for example in dot set item here we can pass in an index and the item let’s say eight and then here we can pass in the item if we go into minecraft and i open my inventory the first nine rows down here Are going to be the index zero through eight so the very first item spot right here is going to be index zero and the very last one is going to be index 8. index 9 is going to be at the top left of the upper inventory and it’s going to Keep increasing for the full size of the inventory so index 8 is going to put this at the end of our hotbar and of course we’re also going to add it to the next available spot which will be index 1 in this case index 0 already has a Stick in it so the graph is going to go on the next available spot so let’s go ahead and initialize this class right in my main file i can say new player handler i can pass in this because it is expecting an instance of my plug-in one-off keys tutorial and i can now Compile this and then restart my server so logging back in i now have some graphs in my inventory and this is probably not what you expected to see you probably expected to see an actual grass block and that’s one thing i want to mention is that you have to be very Clear whenever you’re using the material enum for example here we have grass and grass block there’s also tall grass sea grass and a few other types of grass so you want to always double check that you’re going to use the correct item but for demonstration purposes this still Worked perfectly fine here the grass was added to the next available spot and also it was added to the eighth inventory spot which is at the end of the hot bar so i’ve rejoined and in my inventory i now have 20 grass on the next available spot and then 10 grass Still on the eighth spot why is that exactly well here on line 25 we’re going to add this item to the inventory as if we basically just picked up 10 grass from the ground but on line 26 we are going to assign a specific item stack with all of its details including the Names of the items the amount of items and any other details to that specific index so that means even if we have diamond blocks in here or we have nothing or we have existing grass it’s going to completely replace that with the item stack that we created right Here on line 22. but again adding the item right here which is what is affecting this slot right here is the same thing as me picking them up from the ground now there’s a lot more things you can do with item stacks once they’re already created for example i could say Item.set here we just have the amount the data the type the item meta which is actually pretty important let me briefly show you what is available in the item meta so here i can say item meta i can call this meta i can assign this equal To item dot get item meta now if i say meta dot set here we can set the attribute modifiers we can set the custom model data the display name the lore which is the text under the display name and we have a couple other options As well we can also get all those same attributes and a few more things let me quickly show you how to rename an item so i can say meta dot set display name i’m going to call this testing i can then say item dot set item meta and pass In the meta again i can then build this and restart my server so i’ve now reconnected to my server here we see the initial graphs that i originally had and here we see new grass which is on a different item spot that’s because the name is different so therefore the Entire item stack is technically different so it will not combine these two in fact if i try it’s just going to make me swap between the two in my hand as if there are two completely different items and here we see testing just as usual because of course we are assigning That complete item stack to this inventory slot thanks for watching the video if you want to download the source code gain early access to new videos as well as get your own linux vps then consider becoming a youtube member by clicking on the join button directly below this video Video Information
This video, titled ‘Custom Items – Minecraft Plugin Development Ep. 5 (2022)’, was uploaded by Worn Off Keys on 2022-06-07 14:59:50. It has garnered 12800 views and 261 likes. The duration of the video is 00:05:45 or 345 seconds.
Learn to create your own custom items in your Spigot plugins. 🧠 Free Java course ➡ https://wornoffkeys.com/java-for-free
🙋♂️ Need help? Ask in our Discord community: https://wornoffkeys.com/discord
📺 Watch more Discord.JS videos here: https://wornoffkeys.com/playlist/spigot
💡 Have an idea for a video or course? Request it here: https://wornoffkeys.com/content-request
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
#minecraft #spigot #wornoffkeys
FTC Legal Disclaimer – Some links found in my video descriptions might be affiliate links, meaning I will make commission on sales you make through my link. This is at no extra cost to you and it helps support the channel so I can make more free YouTube videos.