NOTICE: Due to continuing issues with the forum editor, I am no longer maintaining this page, but the same (and up-to-date with nicer formatting) tutorials can be found on Github (links below).
Here I will cover how to create an Item that stores an Inventory, like a backpack, as well as how to add additional inventory slots to the player, allowing you to have slots for things like amulets, rings, or whatever.
Edited to include notes in the Item class about using 'onItemRightClick' vs. 'onItemUse' to access the inventory, as 'onItemRightClick' ONLY works if you also set your item to have a max use duration. Otherwise, your gui will open but any changes you make will not be saved. This has to do with the way these 2 vanilla methods function. 'onItemUse' will always work correctly, so I suggest using that if you can.
EDIT: Actually, BOTH of these methods require you to override this method:
@Override
public int getMaxItemUseDuration(ItemStack itemstack)
{
return 1;
}
coolAlias, I just wanted to ask if you can make a tutorial about opening a item with a inventory but in a completely new GUI or if I can remove the player model and just make it bigger. Thanks for all these amazing tutorials
coolAlias, I just wanted to ask if you can make a tutorial about opening a item with a inventory but in a completely new GUI or if I can remove the player model and just make it bigger. Thanks for all these amazing tutorials
You're welcome
Are there not any gui tutorials? I haven't looked. Anyway, yes, you can just remove the player model - look at any tile entity based gui, such as furnace.
I'm pretty sure gui texture files are limited in that they must be a multiple of 256x256 pixels, but within that you can make it any size you want (up to the max of 256). Look at the inventory texture I provided and you'll see there's still plenty of room to expand it - it's only about 176x165 pixels. Delete the renderPlayerModel code from the Gui class and you can use that space, too.
Increasing the texture size to 512x512 or larger doesn't make the gui any larger, just higher resolution.
Updated to include instructions on how to make the Item multi-player compatible.
For those who don't want to read the whole tutorial again:
NOTE: Using 'Keyboard' works for single player but WILL crash on a multi-player server. To make your item multi-player-compatible, you will need to set up a custom KeyBinding and KeyHandler. See SoBiohazardous' tutorial on how to set that up, as well as my post there for some more advanced stuff.
New tutorial up on how to override the default player inventory screen with your own customized inventory with custom slots, such as a shield or amulet. Let me know if anything needs clarification
Updated to Forge 871. Only things that needed changing were in the Gui:
Three things you'll need to change in your GUI files:
1. I18n.func_135053_a() is now I18n.getString()
2. mc.func_110434_K() is now mc.renderEngine
3. renderEngine.func_110577_a() is now renderEngine.bindTexture()
Added Step 6 to "Inventory Item Tutorial", describing an improved method of saving Inventory contents without the need for onUpdate method. This will also allow you to interact with the inventory from outside of a Gui, so you can add items directly to your custom inventory.
Thanks to Country_Gamer for bringing up this issue.
EDIT: Ended up re-writing the tutorial as this method is so much better than using onUpdate. There is no longer a step 6, so I'll put the most important details here for those of you who don't want to reread the whole thing:
Things to ADD:
// Add a variable to InventoryItem to store the parent ItemStack:
private final ItemStack stack;
// Initialize it in the Constructor:
public InventoryItem(ItemStack itemstack)
{
this.stack = itemstack;
if (!this.stack.hasTagCompound()) { this.stack.setTagCompound(new NBTTagCompound()); }
readFromNBT(this.stack.getTagCompound());
}
// then just add this one line to the end of onInventoryChanged():
this.writeToNBT(this.stack.getTagCompound());
Things to REMOVE:
- onUpdate method in Item class, unless you use it to open the Gui with Keyboard (recommended to put that in a KeyHandler instead! Then you can still remove onUpdate safely)
- writeToNBT and slotClick methods in Container class
- needsUpdate and containerStack variables in Container class
I think that covers it all; if not, check the updated tutorial!
I have just tried working through the "InventoryItem" tutorial, and I keep getting errors in "readFromNBT", specifically "method tagCount() is undefined" and "method atTag() is undefined"
I'm using the Eclipse editor, and Forge 1.6.4-9.11.1.921
--------
Oops. My first post didn't show up until after I posted this one. Sorry.
I have just tried working through the "InventoryItem" tutorial, and I keep getting errors in "readFromNBT", specifically "method tagCount() is undefined" and "method atTag() is undefined"
I'm using the Eclipse editor, and Forge 1.6.4-9.11.1.921
--------
Oops. My first post didn't show up until after I posted this one. Sorry.
Those methods both belong to 'NBTTagList', did you import that class?
Those methods both belong to 'NBTTagList', did you import that class?
Yes, I did import that class, but I must have been looking at the wrong line when following the tutorial. I had miscast "items" as "NBTTagCompund". Got it fixed now.
@1froghog1 - I thought the example in the tutorial was pretty clear, but if you need more information, check out the Forge wiki article on packet handling. There's not really much else I can do to help you understand. If you have a specific question, you can post that, though.
NOTICE: Due to continuing issues with the forum editor, I am no longer maintaining this page, but the same (and up-to-date with nicer formatting) tutorials can be found on Github (links below).
Here I will cover how to create an Item that stores an Inventory, like a backpack, as well as how to add additional inventory slots to the player, allowing you to have slots for things like amulets, rings, or whatever.
Creating an Item that stores an Inventory
(such as a Backpack)
Github Link
Custom Player Inventory
Github Link
Be sure to check out my other tutorials as well (more in my profile!):
- Modding With APIs
- EventHandler and IExtendedEntityProperties
- Custom Inventories in Items and Players
- Multi-Input/Output Furnace
- Rendering Your Custom Item Texture
- Overriding shift-click in custom Containers
- Using Potions in Crafting Recipes
- Enchanted Books and Crafting Recipes
I would add a picture for the "final result", though.
Developer thing.
EDIT: Actually, BOTH of these methods require you to override this method:
You're welcome
Are there not any gui tutorials? I haven't looked. Anyway, yes, you can just remove the player model - look at any tile entity based gui, such as furnace.
I'm pretty sure gui texture files are limited in that they must be a multiple of 256x256 pixels, but within that you can make it any size you want (up to the max of 256). Look at the inventory texture I provided and you'll see there's still plenty of room to expand it - it's only about 176x165 pixels. Delete the renderPlayerModel code from the Gui class and you can use that space, too.
Increasing the texture size to 512x512 or larger doesn't make the gui any larger, just higher resolution.
For those who don't want to read the whole tutorial again:
NOTE: Using 'Keyboard' works for single player but WILL crash on a multi-player server. To make your item multi-player-compatible, you will need to set up a custom KeyBinding and KeyHandler. See SoBiohazardous' tutorial on how to set that up, as well as my post there for some more advanced stuff.
I'll be putting up a new tutorial on adding custom slots to the player inventory shortly. I'll split the OP into two sections.
Three things you'll need to change in your GUI files:
1. I18n.func_135053_a() is now I18n.getString()
2. mc.func_110434_K() is now mc.renderEngine
3. renderEngine.func_110577_a() is now renderEngine.bindTexture()
Thanks to Country_Gamer for bringing up this issue.
EDIT: Ended up re-writing the tutorial as this method is so much better than using onUpdate. There is no longer a step 6, so I'll put the most important details here for those of you who don't want to reread the whole thing:
Things to ADD:
Things to REMOVE:
- onUpdate method in Item class, unless you use it to open the Gui with Keyboard (recommended to put that in a KeyHandler instead! Then you can still remove onUpdate safely)
- writeToNBT and slotClick methods in Container class
- needsUpdate and containerStack variables in Container class
Using Eclipse, and Forge 1.6.4-9.11.1.921
I'm using the Eclipse editor, and Forge 1.6.4-9.11.1.921
--------
Oops. My first post didn't show up until after I posted this one. Sorry.
Those methods both belong to 'NBTTagList', did you import that class?
Yes, I did import that class, but I must have been looking at the wrong line when following the tutorial. I had miscast "items" as "NBTTagCompund". Got it fixed now.
Thanks for the help.
http://www.planetminecraft.com/mod/couple-of-new-mobs/
http://www.planetminecraft.com/mod/couple-of-new-mobs/