ItemMeta lost when ItemStack is placed -> Block

Discussion in 'Plugin Development' started by Kuuichi, Jul 27, 2013.

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

    Kuuichi

    So, when you set the display name of the ItemStack of a Block(or any itemmeta for that matter), it all seems to go away when the ItemStack is placed(thus converted into a Block). This is a problem, because when you retrieve the block later by breaking it, the ItemStack dropped no longer has the itemmeta it had before.

    I could just store the info in some file or database, but I'd like to stay away from storing and loading if possible, and let Bukkit handle it.

    Is there anything else I could possibly do?
     
  2. Offline

    CubieX

    No. Blocks don't have persistant MetaData like ItemStacks have.
    This is why it's called "ItemMeta". ;)
    You can add metadata to a block on placement,
    but you'll have to save this data with the blocks location to a file, in order to survive restarts
    or transfer the data on blockbreak to the dropping ItemStack.
     
  3. Offline

    iFamasssxD

    You could save the itemMeta to a HashMap with the location of the placed block onBlockPlace. Then on disable write it to a file and onEnable write it back to the hashmap. Then onBlockBreak go through the hashMap and if its one of the blocks set the drops to null and create your own item on drop.
     
  4. Offline

    Kuuichi


    I understand the problem, and the non-persistence (;)), I was just wondering if there were any other methods that would prevent me from having to use files and databases.

    I.E. when BlockPlaceEvent is called, you can still get the ItemStack of the Block placed - I thought you could maybe change the drop of the block to the ItemStack. (Block drops persist throughout a restart... right?)
     
  5. Offline

    CubieX

    Not as far as I know.
    Code:
    getDrops().clear()
    and
    Code:
    block.getDrops().add(...)
    can be used.
    But the problem is, you can only alter the returned list. But you cannot apply this new list to the block again.
    And there is no "setDrops()" method, unfortunately.
    I tried it some moments ago. And the drop did not change by using these methods.

    Perharps someone other has a solution for this. But I don't know if this is possible right now.
    My last informatuion was, it's not.
     
Thread Status:
Not open for further replies.

Share This Page