Chest-Like Enderchests

Discussion in 'Plugin Development' started by The Fancy Whale, Jul 17, 2014.

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

    The Fancy Whale

    I am working on a plugin where I need to make ender chests that refill, but are universal. I have the refill method but I am not sure how to make ender chests universal. I want to make it so rather then clicking on an ender chest and getting a personal menu, you get a universal one. Any ideas?
    **Please don't spoonfeed!
     
  2. Offline

    fireblast709

  3. Offline

    The Fancy Whale

    I tried that but had some issues. So what i did was when you right click an ender chest it would add the ender chest to a list. Then it would open up the refilled inventory, if it wasn't on the list. However, that didn't allow for people to take some/no items. The inventory would just be empty the next time.
     
  4. Offline

    Onlineids

  5. Offline

    The Fancy Whale

    I feel like that's not all that realistic. This is for a survival games plugin where ender chests have some different items then normal chests, but the ender chests need to act like normal chests.
     
  6. Offline

    Onlineids

  7. Offline

    The Fancy Whale

    Essentially yes.
     
  8. Offline

    Onlineids

    The Fancy Whale Theres a very hacky way to do this that involves prot lib
     
  9. Offline

    guitargun

    The Fancy Whale, did you try storing the content somewhere and when a player tries to open the chest it opens the stored inventory?

    If not try to look at the Bukkit.create inventory and just use player.openinventory
    Fill it and you should be fine
     
  10. Offline

    fireblast709

  11. Offline

    JuicyDev

    Can't you just get a fake player for every ender chest named by the coordinates, then when a player tries to open the chest cancel it and grab the ender chest of the fake offline player and player the chest opening effect on the ender chest. If you make sure that the inventory that you open for the player is the fake offline player's then the changes would be universal.
     
  12. Offline

    Deleted user

    The Fancy Whale
    So you want a chest that looks like an EnderChest.

    You could either listen to PlayerInteractEvent, or you could go really deep and override PlayerInteractManager's interact method.

    The first is preferable though :p

    JuicyDev
    Well, with the PlayerInteractManager thing, it'll also be a real enderchest. The server will just process it differently.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 8, 2022
  13. Offline

    JuicyDev

    Though, the OfflinePlayer doesn't have a get ender chest method so that ideas out of the window.

    Here is what is probably best in my opinion:
    • Load all the inventories from a file, maybe with help from this https://gist.github.com/aadnk/8138186, into a map against a location string (eg. world;x;y;z) or similar method for later recall
    • Listen to the player interact event and check if the block is an ender chest, if not ignore it.
    • Cancel the event and check the map, or whatever you used earlier, opening the corresponding inventory (this way the changes made to the inventory will be universal
    • If you want the changes to be permanent then you can save the changed inventory back into the file

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  14. Offline

    fireblast709

    JuicyDev JuicyDev The Fancy Whale since the only real difference is what it fills, just use the method I mentioned before. You use a regular chest, which means you already have the same inventory for all players, already saved by MC. Thus pretty much no hassle for you aside deciding which chest is special.
     
  15. Offline

    JuicyDev

    fireblast709
    That is probably the best idea, I didn't notice because I was replying to a few threads at once.
     
  16. Offline

    The Fancy Whale

    fireblast709 guitargun JuicyDev zombiekiller753 This is what I tried. No errors, but it still opens up a normal ender chest
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent event){
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK){
    4. if (event.getClickedBlock().getType() == Material.ENDER_CHEST){
    5. //should i try cancelling the event or closing their inventory?
    6. event.getPlayer().sendBlockChange(event.getClickedBlock().getLocation(), Material.CHEST, (byte) 0);
    7. }
    8. }
    9. }
     
  17. Offline

    fireblast709

    The Fancy Whale the block should be a chest, and the sendBlockChange should send Material.ENDER_CHEST. (Also you might want to call that method earlier than the event)
     
  18. Offline

    Deleted user

  19. Offline

    JuicyDev

    The block should be a regular chest and you should send a block change update making it into an ender chest, that way it looks like an ender chest but is actually a regular chest.
     
  20. Offline

    Deleted user

    fireblast709
    Well, OP wants enderchests to act like regular chests, right?

    ---------

    lol in between writing this reply and reading the thread again, I finally understand what you're trying to do.

    However, it still won't work because the client will see the chest as a chest, then when they open it, it transforms into an enderchest. To make your solution work, you'd need to update as the client renders, etc. Complicated
     
  21. Offline

    The Fancy Whale

    fireblast709 zombiekiller753 JuicyDev So I wouldn't send the block change on interact. I'd send it when they teleport to the same world as the chest. Also, is the (byte) 0 correct? Wasn't sure what number to put there.
     
  22. Offline

    fireblast709

    The Fancy Whale try the same data as the chest, since it is most likely rotation
     
  23. Offline

    JuicyDev

  24. Offline

    fireblast709

  25. Offline

    JuicyDev

    Yeah, the data effects the orientation so make the data byte the same as the chest's
     
Thread Status:
Not open for further replies.

Share This Page