• 0

    posted a message on [Tutorial] Making Inventories
    oops, this is messed up, entityplayer.isDead not entityplayer.isDead(), it's a property not a void, sorry. And can you post the error report for the write to NTB?
    Posted in: Tutorials
  • 0

    posted a message on [Tutorial] Making Inventories
    updated, found the cause of the problem, which makes me really surprised that this worked for me because I was missing two full methods, canInteractWith() and onInventoryChange(). Also I accidentally left the super.onInventoryChange() there from the chest class, which isn't actually in my script, it must have gotten mixed when I was making the tutorial.
    Posted in: Tutorials
  • 0

    posted a message on [Tutorial] Making Inventories
    once again, strange, and as I posted above, I'm looking into it. I am getting no errors however so that's why I'm confused...
    Posted in: Tutorials
  • 0

    posted a message on [ModLoader]Zid's Tutorials - Not Just ModLoader[12/04/2011]
    Quote from daesora

    im getting errors in eclipse and when recompiling im trying to get my ore to generate

    == MCP v4.3 ==
    > Recompiling client...
    "C:\Program Files (x86)\Java\jdk1.6.0_25\bin\javac.exe" -g -verbose -classpath "
    lib/;lib/*;jars/bin/minecraft.jar;jars/bin/jinput.jar;jars/bin/lwjgl.jar;jars/bi
    n/lwjgl_util.jar" -sourcepath src/minecraft -d bin/minecraft src/minecraft\net\m
    inecraft\client\*.java src/minecraft\net\minecraft\isom\*.java src/minecraft\net
    \minecraft\src\*.java conf/patches/*.java failed.
    Return code : 1

    == ERRORS FOUND ==

    src\minecraft\net\minecraft\src\mod_Oil.java:19: illegal start of expression
    public void GenerateSurface; World world; Random rand; int chunkX; int chunkZ;
    ^

    src\minecraft\net\minecraft\src\mod_Oil.java:19: illegal start of expression
    public void GenerateSurface; World world; Random rand; int chunkX; int chunkZ;
    ^

    2 errors
    ==================

    > Done in 1.50 seconds
    > Recompiling server...
    > Done in 5.92 seconds
    Press any key to continue . . .

    and in eclipse it says

    void is an invalid type for variable GenerateSurface

    heres the code

    public void GenerateSurface; World world; Random rand; int chunkX; int chunkZ;
    {
    for(int i = 0; i < (13); i++)
    {
    int randPosX = chunkX + rand.nextInt(16);
    int randPosY = rand.nextInt(32);
    int randPosZ = chunkZ + rand.nextInt(16);
    (new WorldGenMinable(mod_Oil.oilore.blockID, 5)).generate(world, rand, randPosX, randPosY, randPosZ);

    can anyone help please :smile.gif:

    lol, I wonder why... :wink.gif: you are defineing that entirely wrong, what is with all the ";", GenerateSurface is the method name, world rand chunk x and chunk y and its arguments, the go inside () and seperated by , not ;

    public void GenerateSurface(World world, Random rand, int chunkX, int chunkZ)
    {
        for(int i = 0; i < (13); i++)
        {
            int randPosX = chunkX + rand.nextInt(16);
            int randPosY = rand.nextInt(32);
            int randPosZ = chunkZ + rand.nextInt(16);
            (new WorldGenMinable(mod_Oil.oilore.blockID, 5)).generate(world, rand, randPosX, randPosY, randPosZ);
        }           
    }


    see the difference?
    Posted in: Tutorials
  • 0

    posted a message on [Tutorial] Making Inventories
    hmm, I'll look into it but I get no errors..
    Posted in: Tutorials
  • 0

    posted a message on [Creating Mods] Chewy2014's Modding Tutorials
    um, the healing part is only 1 line:

    entityplayer.heal(amount)

    the rest was making it use one of the items, like if you had 4 healing items you'd then have 3.
    Posted in: Tutorials
  • 0

    posted a message on [Tutorial] Making Inventories
    um, that's more difficult, you'd want to look into the player classes and stuff to find the method used to do stuff like open the inventory. There is a line in the EntityPlayerSP that says:

    movementInput.checkKeyForMovementInput(int key, boolean flag), well, it would not be movement but we could certainly go in there and add a line. Open up MovementInput.java and you'll find it's empty for the method checkKeyForMovementInput, meaning that a subclass must have it's content, look in MovementInputFromOptions.java and we see this:

    public void checkKeyForMovementInput(int i, boolean flag)
        {
            byte byte0 = -1;
            if(i == gameSettings.keyBindForward.keyCode)
            {
                byte0 = 0;
            }
            if(i == gameSettings.keyBindBack.keyCode)
            {
                byte0 = 1;
            }
            if(i == gameSettings.keyBindLeft.keyCode)
            {
                byte0 = 2;
            }
            if(i == gameSettings.keyBindRight.keyCode)
            {
                byte0 = 3;
            }
            if(i == gameSettings.keyBindJump.keyCode)
            {
                byte0 = 4;
            }
            if(i == gameSettings.keyBindSneak.keyCode)
            {
                byte0 = 5;
            }
            if(byte0 >= 0)
            {
                movementKeyStates[byte0] = flag;
            }
        }


    all you need to do is look up ASII Key Codes to find out the integer value for whatever key you want and add a line:

    if(i == yourinteger){
        runSomeVoidOnYourClass();
    }
    Posted in: Tutorials
  • 0

    posted a message on [Creating Mods] Chewy2014's Modding Tutorials
    Quote from jbond98

    Can you please make a tutorial for making a new smeltable item and a new healing item? :iapprove: Oh, and take these: :Diamond: :Diamond: :Diamond: :Diamond: :Diamond:

    do the same thing as this tutorial, only instead of CraftingManager go to FurnaceRecipes and it should be fairly self explanitory:

    addSmelting(ID_of_item_or_block_you_put_above_coal, new ItemStack(Item_Or_Block_you_get_as_reward));


    for healing you could make the item class and use this method inside the class

    public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l){
        entityplayer.heal(SOME_NUMBER_OUT_OF_20);
        itemstack.stackSize--;
        return true;
    }
    Posted in: Tutorials
  • 0

    posted a message on [ModLoader]Zid's Tutorials - Not Just ModLoader[12/04/2011]
    Quote from Blueberry

    Help me please! I have one error. I don't know if you know how to work with achievements, but this is my error:
    2011-07-10 16:13 -    commands.recompile - ERROR - "C:\Program Files\Java\jdk1.6.0_26\bin\javac.exe" -g -verbose -classpath "lib/;lib/*;jars/bin/minecraft.jar;jars/bin/jinput.jar;jars/bin/lwjgl.jar;jars/bin/lwjgl_util.jar" -sourcepath src/minecraft -d bin/minecraft src/minecraft\net\minecraft\client\*.java src/minecraft\net\minecraft\isom\*.java src/minecraft\net\minecraft\src\*.java  conf/patches/*.java failed.
    2011-07-10 16:13 -    commands.recompile - ERROR - Return code : 1
    2011-07-10 16:13 -    commands.recompile - ERROR - 
    2011-07-10 16:13 -    commands.recompile - ERROR - == ERRORS FOUND ==
    2011-07-10 16:13 -    commands.recompile - ERROR - 
    2011-07-10 16:13 -    commands.recompile - ERROR - src\minecraft\net\minecraft\src\mod_Emeralds.java:73: incomparable types: int and net.minecraft.src.Block
    2011-07-10 16:13 -    commands.recompile - ERROR - if(itemstack.itemID == emeraldOre)
    2011-07-10 16:13 -    commands.recompile - ERROR - ^
    2011-07-10 16:13 -    commands.recompile - ERROR - 
    2011-07-10 16:13 -    commands.recompile - ERROR - 1 error
    2011-07-10 16:13 -    commands.recompile - ERROR - ==================
    2011-07-10 16:13 -    commands.recompile - ERROR - 
    2011-07-10 16:13 -    commands.checksources - WARNING - !! Can not find server sources !!



    it's because Block and intiger can not be compared, what you need to do is the following:

    if(itemstack.itemID == emeraldOre.blockID)
    Posted in: Tutorials
  • 0

    posted a message on [ModLoader]Zid's Tutorials - Not Just ModLoader[12/04/2011]
    Quote from LethalComboFilms

    I fixed the string version to 1.7_03, but still get the same error. Help!

    um... as seeing the error came from Block.java:

    Caused by: java.lang.ArrayIndexOutOfBoundsException: 2007
    at net.minecraft.src.Block.<init>(Block.java:46)

    could you please post Block.java?

    EDIT, exactly as said above, the max id is 255 anything above belongs to items. you can chane all that though, but it would take some more editing. you are fine to put your blocks at like 140 -149 etc, you can use 97-255 because most likely they are free unless used by other mods.
    Posted in: Tutorials
  • 0

    posted a message on [Tutorial] Making Inventories
    it doesn't take awesomeness, it just takes time... sometimes more that you want... anyway, thank you for your comment. I have however realized some errors in my tutorial that I will fix in a few minutes, small, but fairly important.
    Posted in: Tutorials
  • 0

    posted a message on [Misc] How to grow a big tree [10/7/11]
    it does work, however I'm still getting a lot of trees that grow right through the collar
    Posted in: Tutorials
  • 0

    posted a message on [Tutorial] Making Inventories
    Quote from Stronghold257

    Thanks man. Is there a way for it to be put in an inventory spot(designated spot in inventory, not you actual inventory space)? I was planning on it being on your back in game, and once in that spot, o(for example) to open it.

    Edit:
    Wouldn't you need to open Item.java and CraftingManager.java?


    yes, it could be possible, but it would take a lot more modding, I would need to modify the main inventory and stuff, and how would you open it, I sort of just had the idea that you could have like 5 backpacks in your inventory so you can have like 5 times the normal space in 5 slots.

    Quote from telecaster

    Could you do one for a new furnace like thing too? Thanks :smile.gif:


    Um sure, I'll make one later today or tomorrow. This one was written in 1.5 hours.

    EDIT! Wow, making a new furnace type or etc will be extremely harder than this tutorial. And I mean exponentially harder, we'd be getting into new rendering and Gui displays and all sorts of stuff. It may take a while to get this tutorial up.
    Posted in: Tutorials
  • 0

    posted a message on [Creating Mods] Chewy2014's Modding Tutorials
    Quote from DreadKyller

    I think some tutorial on this should be done. haven't found one anywhere.

    I think I've figured it out, let you know if it works.


    Ok, tutorial is posted. Tell me if it's helpful at all.
    Posted in: Tutorials
  • 2

    posted a message on [Tutorial] Making Inventories
    Making inventories.

    Making inventories is a very advanced modding and required modification of several classes. This tutorial is meant for only people who have general knowledge of setting up the MCP and making new blocks.

    In this tutorial we are going to be looking at 3 classes:

    BlockChest (for example)
    IInventory
    InventoryLargeChest (for example)

    we will be making a backpack item, this item will be held in the players hand and when right clicked will open up it’s inventory, you can have more backpacks, but we will be making the max stack size one. each backpack will take 1 slot in the inventory. And we will be using the small chest inventory image.

    Look at BlockChest.java and find the following lines:

    public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
        {
            Object obj = (TileEntityChest)world.getBlockTileEntity(i, j, k);
            if(world.func_28100_h(i, j + 1, k))
            {
                return true;
            }
            if(world.getBlockId(i - 1, j, k) == blockID && world.func_28100_h(i - 1, j + 1, k))
            {
                return true;
            }
            if(world.getBlockId(i + 1, j, k) == blockID && world.func_28100_h(i + 1, j + 1, k))
            {
                return true;
            }
            if(world.getBlockId(i, j, k - 1) == blockID && world.func_28100_h(i, j + 1, k - 1))
            {
                return true;
            }
            if(world.getBlockId(i, j, k + 1) == blockID && world.func_28100_h(i, j + 1, k + 1))
            {
                return true;
            }
            if(world.getBlockId(i - 1, j, k) == blockID)
            {
                obj = new InventoryLargeChest("Large chest", (TileEntityChest)world.getBlockTileEntity(i - 1, j, k), ((IInventory) (obj)));
            }
            if(world.getBlockId(i + 1, j, k) == blockID)
            {
                obj = new InventoryLargeChest("Large chest", ((IInventory) (obj)), (TileEntityChest)world.getBlockTileEntity(i + 1, j, k));
            }
            if(world.getBlockId(i, j, k - 1) == blockID)
            {
                obj = new InventoryLargeChest("Large chest", (TileEntityChest)world.getBlockTileEntity(i, j, k - 1), ((IInventory) (obj)));
            }
            if(world.getBlockId(i, j, k + 1) == blockID)
            {
                obj = new InventoryLargeChest("Large chest", ((IInventory) (obj)), (TileEntityChest)world.getBlockTileEntity(i, j, k + 1));
            }
            if(world.multiplayerWorld)
            {
                return true;
            } else
            {
                entityplayer.displayGUIChest(((IInventory) (obj)));
                return true;
            }
        }


    This is the script that runs on the chest when the block is right clicked. I’m not going to go over everything. But I’ll give a quick rundown on what this does.

    obj is initially set the just the chest that was clicked, then as it goes through a lot of ifs, which check to see if the blocks to the side are chests as well. So it starts off as a single chests and then checks all 4 sides. It checks 2 times for each side, why? The first check tells if there is a block above the clicked chest. If so the boolean returns true. the next 4 checks check to see if there is a chest next to the clicked one and if there is a block above that chest. If so it also ends the script by returning a value of true.

    Once it’s checked to make sure that none of the sides that have chests have blocks over them it then goes through and starts combining the chests using a class called InventoryLargeChest, which basically takes two classes that extend IInventory and store them in two properties. Then when the class is called it uses both stored inventories to determine the max size and the items in which slot. If there were no chests to the side of the one that was clicked the object remains only a single IInventory class and has only half the storage.

    The last step, and really the only step we will actually need is displaying the inventory. entityplayer.displayGUIChest(Class extends IInventory).

    This method in total checks to see the size of the passed inventory and chooses the right GUI for the chest and displays it. during this point anything put into the inventory will change the inventory content and anything removed will also change it, so the actual storage is taken care of already, no need to script it.

    So we can start making out class. Our class will not need to extend IInventory because we will be using a reference to an IInventory class.

    Make a new class called something like ItemBackpack and make it extend Item

    package net.minecraft.src;
    
    import java.util.HashMap;
    
    public class ItemBackpack extends Item{
    
    	protected ItemBackpack(int ID) {
    		super(ID);
    	}
    }


    Now assuming you know enough about items to register this item and set it’s texture you should be all set. If not please take a break from this tutorial to look at one about making new items and adding the recipes. This is the time for you to be creative with how your backpack works.

    We now need to add an IInventory property to our class. As seeing making a single IInventory property in the class will make all backpack items have the same inventory, we need to use something in java called a HashMap.

    A HashMap is basically a set of data that is sorted by keys, you can assign different keys a value and then retrive the value by getting it based on a key. For example we could assign ItemStacks a IInventory instance and then when we use our script we will just get the inventory corresponding to the item in the hand, to use it, as seeing it's not a class in the same package "net.minecraft.src" we need to import it in order to use it, more on this later, but for now please rework your class to this:

    package net.minecraft.src;
    
    import java.util.HashMap;
    
    public class ItemBackpack extends Item{
    	
    	private HashMap<ItemStack, InventoryBackpack> inv;
    	
    	protected ItemBackpack(int ID) {
    		super(ID);
    	}
    }


    Also real quick let's make sure that our item can only have 1 per stack, to do this add a simple line to your script.

    package net.minecraft.src;
    
    import java.util.HashMap;
    
    public class ItemBackpack extends Item{
    	
    	private HashMap<ItemStack, InventoryBackpack> inv;
    	
    	protected ItemBackpack(int ID) {
    		super(ID);
    		maxStackSize=1;
    	}
    }


    now we could reference an IInventory object, unfortunately it’s null, meaning nothing would happen except errors. inside the constructor we are going to set it to a new InventoryBackpack which of course does not exist yet, but we will make it.

    package net.minecraft.src;
    
    public class ItemBackpack extends Item{
    	
    	private HashMap<ItemStack, InventoryBackpack> inv;
    	
    	protected ItemBackpack(int ID) {
    		super(ID);
    		maxStackSize=1;
    		inv = new HashMap<ItemStack, InventoryBackpack>();
    	}
    }


    You will get an error if using eclipse or NetBeans however that error is because the class InventoryBackpack does not exist, even if not using Eclipse or NetBeans we need to now make the class, once again here is a large chunk of code, I’ll explain it one at a time:

    package net.minecraft.src;
    
    public class InventoryBackpack implements IInventory
    {
    
        public InventoryBackpack()
        {
            packContents = new ItemStack[36];
        }
    
        public int getSizeInventory()
        {
            return 27;
        }
        
        public boolean canInteractWith(EntityPlayer entityplayer)
        {
            return !entityplayer.isDead;
        }
    
        public void onInventoryChanged()
        {
        }
        
        public ItemStack getStackInSlot(int i)
        {
            return packContents[i];
        }
    
        public ItemStack decrStackSize(int i, int j)
        {
            if(packContents[i] != null)
            {
                if(packContents[i].stackSize <= j)
                {
                    ItemStack itemstack = packContents[i];
                    packContents[i] = null;
                    onInventoryChanged();
                    return itemstack;
                }
                ItemStack itemstack1 = packContents[i].splitStack(j);
                if(packContents[i].stackSize == 0)
                {
                    packContents[i] = null;
                }
                onInventoryChanged();
                return itemstack1;
            } else
            {
                return null;
            }
        }
    
        public void setInventorySlotContents(int i, ItemStack itemstack)
        {
            packContents[i] = itemstack;
            if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
            {
                itemstack.stackSize = getInventoryStackLimit();
            }
            onInventoryChanged();
        }
    
        public String getInvName()
        {
            return "Backpack";
        }
    
        public void readFromNBT(NBTTagCompound nbttagcompound)
        {
            NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
            packContents = new ItemStack[getSizeInventory()];
            for(int i = 0; i < nbttaglist.tagCount(); i++)
            {
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
                int j = nbttagcompound1.getByte("Slot") & 0xff;
                if(j >= 0 && j < packContents.length)
                {
                    packContents[j] = new ItemStack(nbttagcompound1);
                }
            }
    
        }
    
        public void writeToNBT(NBTTagCompound nbttagcompound)
        {
            NBTTagList nbttaglist = new NBTTagList();
            for(int i = 0; i < packContents.length; i++)
            {
                if(packContents[i] != null)
                {
                    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                    nbttagcompound1.setByte("Slot", (byte)i);
                    packContents[i].writeToNBT(nbttagcompound1);
                    nbttaglist.setTag(nbttagcompound1);
                }
            }
    
            nbttagcompound.setTag("Items", nbttaglist);
        }
    
        public int getInventoryStackLimit()
        {
            return 64;
        }
        private ItemStack packContents[];
    }


    WOW, that’s fairly large! But it’s not that hard to understand.

    public InventoryBackpack()
        {
            packContents = new ItemStack[36];
        }


    This is the constructor, when a new InventoryBackpack is made it will set a ItemStack array to a new array with a maximum amount of items as 36.

    public int getSizeInventory()
        {
            return 27;
        }


    This int returns the amount of slots the inventory shows. as for the reason the max index is 35 and the number of slots shown is 27 I have no idea, most likely something to deal with the players inventory.

    public boolean canInteractWith(EntityPlayer entityplayer)
        {
            return !entityplayer.isDead();
        }


    this returns whether or not the inventory can be used

    public void onInventoryChanged()
        {
        }


    does absolutely nothing, but as seeing we are implementing an interface with abstract methods, we need to have this in our class.

    public ItemStack getStackInSlot(int i)
        {
            return packContents[i];
        }


    This returns the ItemStack stored inside the array at the specified slot index.

    public ItemStack decrStackSize(int i, int j)
        {
            if(packContents[i] != null)
            {
                if(packContents[i].stackSize <= j)
                {
                    ItemStack itemstack = packContents[i];
                    packContents[i] = null;
                    onInventoryChanged();
                    return itemstack;
                }
                ItemStack itemstack1 = packContents[i].splitStack(j);
                if(packContents[i].stackSize == 0)
                {
                    packContents[i] = null;
                }
                onInventoryChanged();
                return itemstack1;
            } else
            {
                return null;
            }
        }


    This will take the item stack at index i and decrease it by the amount j, if the amount it items in that stack is less than the amount wanted set the item stack to null because there are no items left in that slot, it’s empty.

    public void setInventorySlotContents(int i, ItemStack itemstack)
        {
            packContents[i] = itemstack;
            if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
            {
                itemstack.stackSize = getInventoryStackLimit();
            }
            onInventoryChanged();
        }


    This will change the item stored inside a specific slot of the inventory. If the itemstack that was stored in the inventory is not null and has more items that the maximum allowed, the size will be set to the max. This then triggers the onInventoryChanged(), which will be explained.

    public String getInvName()
        {
            return "Backpack";
        }


    This tells mine craft what text will appear at the top of the inventory, like a Chest displays “Chest” our backpack will display “Backpack”

    public void readFromNBT(NBTTagCompound nbttagcompound)
        {
            NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
            packContents = new ItemStack[getSizeInventory()];
            for(int i = 0; i < nbttaglist.tagCount(); i++)
            {
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
                int j = nbttagcompound1.getByte("Slot") & 0xff;
                if(j >= 0 && j < packContents.length)
                {
                    packContents[j] = new ItemStack(nbttagcompound1);
                }
            }
    
        }


    This is used during the loading process for the world, this will set the contents of the chest.

    public void writeToNBT(NBTTagCompound nbttagcompound)
        {
            NBTTagList nbttaglist = new NBTTagList();
            for(int i = 0; i < packContents.length; i++)
            {
                if(packContents[i] != null)
                {
                    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                    nbttagcompound1.setByte("Slot", (byte)i);
                    packContents[i].writeToNBT(nbttagcompound1);
                    nbttaglist.setTag(nbttagcompound1);
                }
            }
    
            nbttagcompound.setTag("Items", nbttaglist);
        }


    This is used during the saving process, this saves the chests inventory so it can be loaded by the readFromNBT above. We will not get into much about either of these.

    public int getInventoryStackLimit()
        {
            return 64;
        }


    This returns the maximum stack size allowed, this will however not have any effect if the max stack size for the specific item is lower than the max size for the inventory. Meaning you will not be able to store 64 fish in this inventory.

    private ItemStack packContents[];


    This defines a null ItemStack array in which we set in the constructor.


    Now that we have our Backpack class complete the error on your ItemBackpack.java should no longer be there. If so make sure you have the class names correct.

    We have our item storing a fully working inventory class, however, we have nothing allowing us to open it. To know when a player right clicks with our backpack item we need to add one feature to our ItemBackpack, NOT the InventoryBackpack.

    public ItemStack onItemUse(ItemStack itemstack, World world,EntityPlayer entityplayer){
    	entityplayer.displayGUIChest(inv.get(itemstack));
    	return itemstack;
    }


    Now if you have added your item to the Item.java and added a recipe in CraftingManager.java you can now go ingame and use your new backpack!

    One last problem you NEED TO ADDRESS!!!!! what if an item has not ever been used before? then getting that itemstack will return null, and that will raise errors and crash the game. so let's put a little checking and initalizing

    public ItemStack onItemUse(ItemStack itemstack, World world, EntityPlayer entityplayer){
        if(!inv.containsKey(itemstack)){
            inv.put(itemstack, new InventoryBackpack());
        }
        entityplayer.displayGUIChest(inv.get(itemstack));
        return itemstack;
    }


    What this is for: We check to see if the hashmap contains the key we are looking for, if it does not contain the itemstack then it will make a new key with that item stack and assign it to a blank inventory, as seeing it's obviously not been used yet. There is one thing that will not work. The inventories will not save, as seeing the hashmap does not. you could easilly add your own saving script to InventoryBackpack's Write/ReadTo/FromNBT using ObjectOutputStream and ObjectInputStream if you found a way to pass the ItemBackpack class into it, maybe when making a new InventoryBackpack make the constructor take a new parameter. This will be added to the tutorial at some point.

    If you get any problems or if I've made a reply please reply. I will try and help.

    Q&A:

    Q: Why do we set the max items in the stack to 1?
    A: You can set it to what you want, it's risky though, certain changes to the stack will cause it to be considered a completely different item, therefore it will not be found while searching for saved inventories and this may cause you to lose anything you may have put into the backpack. 1 is recommended.

    Q: Why does InventoryBackpack implement IInventory and not extend it?
    A: You can not extend an interface. An interface is a blank slate, it holds a bunch of methods that must be defined in any class that implements it. When you implement an interface you are assigning all of the methods inside the interface. Interfaces are used so you can make a completely new class that follows the same idea as the class it implements, think of it this way, you are implementing the interfaces methods in your own class. When using a class you use extend, classes can not be implemented, extend can be used to make a subclass of a superclass, the superclass may be something called abstract, if the class is abstract it may have a type of method called an abstract method, like
    public abstract void something();
    when defining an abstract method you must end it with ; and not { because abstract methods do not have any content, they are meant to be over written so that the information about what they are supposed to do can be filled in. A class can have abstract methods and normal methods, all abstract methods MUST be filled in in the subclasses, any other method that is not abstract can be overwritten but is not nessesary.

    Q: What does the [] do in this statment? private ItemStack packContents[];
    A: [] creates an array, which is a list of items of a certain type that can be retrived by an index, the index is the number of the item you want to get, the first item in an array is an index of 0, so subtract everything by 1, example to get the 5'th item in an array use 5-1=4, 4 will be the 5'th item. To assign an item to a specific index do it in opposite of retriving it:
    To Retrieve:
    ItemStack item = packContents[index];

    Setting:
    packContents[index] = item;


    There are several ways to create an array, both these do the same thing:
    public ItemStack contents[];
    public ItemStack[] contents;


    Thanks @Stronghold257 @Ruze_ and @MbD-1337 for bug reporting.
    Posted in: Tutorials
  • To post a comment, please .