Block Inventorys

Discussion in 'Plugin Development' started by awesomer3, Jul 26, 2014.

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

    awesomer3

    Hello Fellow coders.

    I have been coding and i wanted to know how to make an inventory that saves for each piston extension block. I have the bit where it places the piston extension but i need to know how to make it have its own savable inventory like a chest but for a piston extension
     
  2. Offline

    Niknea

    awesomer3 Do you want to open up a GUI when a player right clicks a extended piston? If not, mind explaining it a bit better?
     
  3. Offline

    awesomer3

    Niknea
    Yes i want it to open a gui like a chest
     
  4. Offline

    fireblast709

    awesomer3 you can just place a chest and use sendBlockChange to change it to an extended piston for the client
     
  5. Offline

    awesomer3

    fireblast709
    when i do that i cant figure out how to make it know where the player places the chest meaning i can do player.getLocation but i cant get the location of the block and when you click the crate it turns back to a chest soo
     
  6. Offline

    fireblast709

    awesomer3 Cancel the interact and open the chest manually
     
  7. Offline

    awesomer3

    fireblast709 how do you open the chest manually would it be p.openInventory("? what inventory")
     
  8. Offline

    fireblast709

    awesomer3 Block -> BlockState -> Chest (this is a cast) -> Inventory
     
  9. Offline

    awesomer3

  10. Offline

    dsouzamatt

  11. Offline

    fireblast709

    awesomer3 it is pretty straight forward. You have the block already, I assume you already check the type, the rest is just using getters and casting.

    If you fail to find a method, there is always documentation
    http://jd.bukkit.org/dev/apidocs
     
  12. Offline

    awesomer3

    fireblast709 dsouzamatt why cant i just make an inventory for every piston extension and when you click it it opens the inventory for that block like using ubid (unique block id)
     
  13. Offline

    fireblast709

    awesomer3 you can, but you would need tot store inventories and such, and for persistance you would need tot serialize them (which is a tad messy)
     
  14. Offline

    GeorgeeeHD

    awesomer3 if u dont need the inventories to save thru reloads u can just make a HashMap of Location and Inventory and put the pistons Location as the key and the Inventory u want it to have as the value. but you could add code to make that save thru reloads but tbh im not sure how efficient this method is
     
  15. Offline

    awesomer3

    GeorgeeeHD i know what to do i just dont know how so can anyone help me
     
  16. Offline

    Dragonphase

    awesomer3

    You could handle a PlayerInteractEvent, check if the event's action is Action.RIGHT_CLICK_BLOCK and the material of the clicked block is Material.PISTON_EXTENSION. Then, create an inventory, and open it.

    I would give the inventory a custom name too, because you'll need to save the contents of the inventory somehow and it's much easier if you know what it is you're saving. Handle an InventoryCloseEvent and check whether the name of the inventory that was closed matches the name of the inventory you opened.
     
Thread Status:
Not open for further replies.

Share This Page