Ye Olde Double Cheste

Discussion in 'Plugin Development' started by SycoPrime, May 1, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    SycoPrime

    So double chests are causing my plugin to crash, and I'm not entirely sure why.
    Single chests work fine.
    The plugin is relocating chests to a new world location, and crashes when the player attempts to access the contents of the relocated chest.

    I have seen two solutions for this. The first was to add in CraftBukkit or Minecraft (I forget which) as a dependancy, and use, I think, IInventory? Some odd non-API call. The other, it looked like, was to deal with each of the chests individually, but I think there was something more complicated to it than that which I'm missing.

    The blocks are being looped and handled one at a time. Single chests still report an inventory size of zero, and items are being placed in chests in a manner that looks compatible to how they're being taken out.
    This is the code that stores the information temporarily before moving it to the new block:
    Code:
    Inventory inventory = null;
    ...
    Chest chest = ((Chest)theBlock.getState());
    inventory = chest.getInventory();
    ...
                    for(int slot = 0; slot < inventory.getSize(); slot++) {
                        if(inventory.getItem(slot).getTypeId() != 0) {
                            complexBlock.setItem(slot, inventory.getItem(slot));
                            inventory.setItem(slot, new ItemStack(0));
                        }
                    }
    ComplexBlock is a custom type of block. The items variable in it is this:
    Code:
    private ItemStack[] items = new ItemStack[27];
    And this is the code that restores that information to the blocks (inventory variable is declared as above):
    Code:
                   for(int slot = 0; slot < inventory.getSize(); slot++){
                        if(complexBlock.items[slot] != null && complexBlock.items[slot].getTypeId() != 0) {
                            inventory.setItem(slot, complexBlock.items[slot]);
                        }
                    }   
    Any help would be appreciated. Thanks.
     
  2. Offline

    Acrobot

    ItemStack(0) crashes the client.
    Set it to null instead.

    Also, free slot is considered as null.
     
    SycoPrime likes this.
  3. Offline

    SycoPrime

    ItemStack(0) only appeared once in the code, I changed "new ItemStack(0)" to "null".

    Edit: Fixed it. Hooray!
     
Thread Status:
Not open for further replies.

Share This Page