Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Climbing the interface ladder

From basic graphical interfaces to very advanced ones

Drop item in inventory?

  • 2014-01-18 20:27:47
    So I tried to do your code so that when the item is broken it drops the items in the inventory, but nothing happens when I break the block. It just drops the block, not the items that were inside of it? BTW, I'm in 1.6.4.
  • 2014-01-18 22:48:50
    Can you please pastebin your code for the block so we can see what's wrong.
  • 2014-01-20 23:11:01
  • 2014-01-20 23:41:45
    Considering that's the exact same code I'm using and it works fine for me. My guess is that the issue is in the TileEntity class, maybe the getStackInSlotOnClosing function is returning null
  • 2014-01-20 23:47:35
    I don't know why it would though, I'm leaving a custom item in items[0], breaking the block, and its not coming out. I have it set so that items[0] only can accept that particular item by the way, if that makes a difference.
  • 2014-01-20 23:48:41
    can I see your tile entity code?
  • 2014-01-21 00:29:58
  • 2014-01-21 00:40:24
    yea, see how in the breakBlock, you're dropping an entity corresponding to the itemstack from the getStackInSlotOnClosing method

    for (int i = 0; i < inventory.getSizeInventory(); i++) {
    ItemStack stack = inventory.getStackInSlotOnClosing(i);

    but in your tile entity you're just returning null

    public ItemStack getStackInSlotOnClosing(int i) {
    return null;

    So yea, it's just that method. Use this code instead:

    public ItemStack getStackInSlotOnClosing (int i)
        ItemStack stack = getStackInSlot(i);
        setInventorySlotContents(i, null);
        return stack;

    It's covered in one of the lectures somewhere
  • 2014-01-21 00:48:50
    Also, in your decrStackSize, call onInventoryChanged() after the itemstack = itemstack.splitStack(i); and also in your setInventorySlotContents method
  • 2014-01-21 01:44:26
    Thanks so much! It finally works! This has been bugging me for days, I owe you one.
  • Log in or sign up to reply to this thread