How to make chest array and, in chest: items array.. ?

How to make array in array ?

I want to:

chest variables:

chest X, chest Y, chestInventoryW, chestInventoryH

item variables:

itemPlace, itemId, itemCount

and the chest must have its items with variables.

the variables must be the same as I write here, you only need some example to see.

Here is example of Minecraft system...

howToChestAndInventoryAndItemsArray

Tagged:

Answers

  • edited October 2017
    class Item {
      int id;
      int count;
      Item(){
        // ...
      }
    }
    
    class Chest {
      Item[][] contents = new Item[4][9];
      Chest(){
        // ...
      }
    }
    
    Chest chest1 = new Chest();
    Chest chest2 = new Chest();
    Chest chests = new Chest[3];
    
    chests[2].contents[2][1] = new Item();
    
  • Not working :/

  • Could you be a bit more specific? What is not working? Post your current code. Tell us what doesn't work. Tell us what you expected it to do. Tell us what it does instead.

    The only answer we can give you to "It doesn't work." is "Then fix it."!

  • but i dont have any code... i want to only array on array :D

  • edited November 2017

    What does that even mean? What is an "array on array"? You want an array OF arrays? You want two arrays of the same length? You want an array of objects, and the object has a member that is an array? Or a 2D array member?

    Do you understand the code I posted above?

  • edited November 2017

    @GeorgeJava:

    It might be technically possible to model a Minecraft chest with a shovel in an array of arrays of arrays of arrays of arrays of arrays.

    int[][][][] things;

    ...so println(things[2][12][40][1]) prints "98":

    Chest 2, Object Slot 12, which is a Object Type 40 (Diamond Shovel), which has a grit (Parameter 1) of 98.

    ...but this is a terrible, terrible, terrible idea. Don't do this. Instead: DO use objects and classes. This is exactly what objects and classes are for.

Sign In or Register to comment.