Custom tile entities with material api?

Discussion in 'Plugin Development' started by Techy4198, Jan 15, 2014.

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

    Techy4198

    I have heard of the material api, and am thinking of using it for something in a plugin I'm working on.

    1.I need to know, if the custom material can be checked in a block click event, and if not, whether I can add a custom tile entity data to the block when placed.

    2. also I'm wondering, is there maybe a way I can create a custom item material and have it place a different custom block?
     
  2. Techy4198
    I assume you're talking about this MaterialAPI, and it looks like it supports a variety of events, though it is handled in a different way.

    Your questions are quite confusing, so would you mind elaborating them a bit?
     
  3. Offline

    Techy4198

    Assist
    Let's do this logically. here is what I need to achieve. I want to have it so witches have a random chance of dropping a certain item on death that looks like a cauldron item. I then want to have it so that if I place it, it will place a custom material that looks like a cauldron block, but when I click on it it opens an inventory with some items in, which I need to store, like a chest, not just temporary items in the inventory gui. then I want it to disappear when the inventory is closed, but only if there are no items left in it. I originally had most of that done with chests, but I didn't like the way that the cauldron shows up briefly before the server tells the client that it's actually placed a chest, not a cauldron. I also discovered that that method meant it was possible to make chests of more than 2 blocks in size. that is why I want single cauldrons to be placed, which shouldn't have any graphical issues or block placement issues. the only problems I have now are how do I tell if the cauldron is one of my custom ones, how do I make it open an inventory, and how do I make it store items.
     
  4. Techy4198
    Well this could all be done with the normal Bukkit API without using any external ones, just requires some logic. I haven't looked into the MaterialAPI yet, so I have no clue what all is possible with it.

    Here's my thinking:
    1. A witch dies, you roll a random number, and check if it is <= chance
    2. Witch drops a cauldron, you add this Item (capitalized I meaning the Item class, not an item in general) to an ArrayList<Item>
    3. You listen for PlayerPickupItemEvent(?), check if it is a cauldron, then check if your ArrayList contains it
    4. You store this cauldron ItemStack to an ArrayList<ItemStack>, or use some other way to make the plugin know it's special (such as adding custom display name)
    5. On BlockPlaceEvent, you check if the placed item is one of your special cauldrons by, for example, checking if your imaginary maybe-non-existant ArrayList contains it
    6. More storing, *hooray*. You store this placed Block to an ArrayList<Block>, or once again, use some other way to make it special (such as using Metadata)
    7. There's two ways to do the next part. InventoryOpenEvent or PlayerInteractEvent. InventoryOpenEvent is easier, so I'll use that
    8. On InventoryOpenEvent, you check if the inventory holder is a cauldron (Block), then check if it's one of your special cauldrons
    9. Cancel the event, and open a custom newly created inventory (Bukkit.createInventory(etc))
    10. And again, use some way to store the created Inventory. Should be clear by now how to do it
    11. On InventoryCloseEvent, check if the inventory is a special inventory, then check if it is empty (getContents().length == 0 should do it, as empty slots are null, not AIR)
    Then use some magic to remove all of the stuff relevant to that inventory. You'll probably want to store this whole process to a separate class, then just create new instances of it.

    This isn't meant to be a tutorial, this is just my way of doing it. might be the worst way, but meh. :D

    I'll probably turn this thinking into code tomorrow, and share it with you.
     
Thread Status:
Not open for further replies.

Share This Page