Skip to content
LegendOnline edited this page Nov 5, 2018 · 10 revisions

You don't want to read all these Pages ? GOOD!
This is the perfect Page for you.
I will try to quickly sum up how to create an working, good looking inventory in a few lines of code!

This is what we want to achieve:

image

Code:

//firstly, we create a layout, this determines how our inventory should look like
ExactLayout layout = new ExactLayout("rrrgggrrr",
                                     "bbbgdgbbb", //you may recognize this code style from recipe initialization
                                     "rrrgggrrr");//every character represents one slot in your inventory
                                                  //the inventory size is automatically determined by the amount of characters
//now we have to link every char with the wanted item:
layout.set('r', new GUILabel("red", Material.STAINED_GLASS_PANE,(byte) 14)); //the GUILabel is just a normal, unmovable item with
layout.set('g', new GUILabel("gold", Material.GOLD_BLOCK));                    // a custom name (e.g. in swing JLabel.class)
layout.set('b', new GUILabel("black", Material.STAINED_GLASS_PANE,(byte) 15));//<- sub id of block STAINED_GLASS_PANE (e.g. black)
layout.set('d', new GUILabel("diamond", Material.DIAMOND_BLOCK));

//The McGui class represents an openable inventory with title "First Steps" and our previously created layout
McGui gui = new McGui(Test.plugin,"First Steps", layout);
gui.draw(player); //this makes the player open the inventory

Result:

Now we have an inventory that basically does.. nothing.. Nice!
By default all elements (items) are locked, so you cant move, click or shift them out of the inventory.
Remember: the inventory contents are not recomputed by calling .draw() because of performance reasons.
Next tutorial: Lock/Unlock & Events

Articles you might be interested in: