Hello and welcome to your ninth minecraft mounting tutorial in the soil will be covering adding and removing items stacks from the players inventory this could be useful for like for the situation that we’re going to use it for when you right click on an item it will Remove an item for the players inventory and then also add an item to the players inventory so let’s get started first thing you import something but import net minecraft client dot minecraft i won’t explain this it basically imports minecraft Java which we’re going to use Right now so put when you create a new minecraft variable or object so put mine craft MC equals modloader get minecraft instance in Minecraft Java there’s like everything it includes you can get to the players inventory the player the world everything like that it’s very useful to have one of these you’ll see How it’s used in this tutorial oh and by the way this is a item file I created item emerald staff i also created it in my mod underscore file so i didn’t want you guys have to sit through me creating them anyways let’s get to the tutorial Now we need to create a method called on item right click so put public item stack on item right click cheese failure at spelling anyways it has to be capitalized exactly like this now for the arguments put itemstack itemstack world burp world world cheese I’m failure Today anyways world world then end the T player and steep player again make sure they are capitalized exactly like this or it will not work so add some room inside here and as you can see eclipse is whining because since this mess method is of the type itemstack it needs To return an item stack so we do now is put return item stack no capitals this is the built-in object for this method as you can see when the arguments is itemstack itemstack this is it’s basically nothing it just returns nothing at all which is exactly what we Want since we will be doing this ourselves and it only works or as far as I can tell it works if you do it by yourself if you don’t do it by yourself it does some weird stuff so now we need to do this but MC dot the player dot Inventory dot add itemstack to inventory what this is is it’s minecraft variable the player which is the player it’s like an entity player object inventory the players inventory in inventory player object dot itemstack or dot add item stack inventory it adds and I’m stack to the players inventory so now when you Decide what we want to add so put this new itemstack and inside the parameters put the item or block you want to be returned when you right click on the item so we’ll put mod underscore emeralds dot emerald item and then the quantity one so right now What you what this will do is if you right click on an emerald staff it will add emerald item to your inventory so this will work in everything but we want to do one more thing we want to remove an item from the players inventory so This is also this is a similar thing what we do is put em c dot the player dot inventory dot now we’ve put consume inventory item what this do is it will remove or consume or delete or whatever you want to call it a certain item from a player’s inventory it scans through All the slots in your inventory until it finds the item that you specified then deletes the whole itemstack it doesn’t delete just one item it deletes the whole stack of items so if you have 64 of this item it was still delete it so Now what you do is put the item you want to be consumed obviously so put mod underscore emeralds dot emerald staff dot shifted index since consume inventory items arguments is an int area believe the dot shifted index at the end so right now what this will do is it Will consume the inventory item and also add an item stack two players inventory so now we’re going to test this in games see you guys then so we’re here in game and as you can see I have my emerald stay I made listen now we’re going to right Click on it and it adds an emerald to your inventory pretty cool is it you see doing as many times you want I’ll just keep on and stuff even if you have a full stack it’ll add to the new stack like that so yeah pretty cool i think Next tutorial we’ll be covering how to change the world time with all an item right click so we’ll see you guys then but so now i want to add one thing that probably should have been saying just to help my channel grow and more people to find these tutorials because oh no i Think they’re pretty good if i had these when I was in New be they would have helped a lot Sheamus advertising but if this helped you please like the video and if you want to see more tutorials please subscribe because I guarantee you more will be coming out these are pretty Fun with me I love helping people so see you guys in the next tutorial see Video Information
This video, titled ‘Minecraft Modding Tutorial 10 – Adding and removing items using onItemRightClick (modloader)’, was uploaded by Zac Wood on 2011-08-14 21:54:16. It has garnered 2505 views and 14 likes. The duration of the video is 00:07:18 or 438 seconds.
sorry, i messed up the numbering 😛