Solved Most efficient way to check 250x250x250 region for a certain block

Discussion in 'Plugin Development' started by feff890, Apr 29, 2019.

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

    feff890

    Hi,
    I'm looking for the most efficient way to check a 250x250x250 block region for a certain type of block (chest & enderchest) so that I can then modify them.
    I tried 3 for loops one for x, y and z and used world.getBlockAt(x,y,z) but the server timed out.
    I'm sure there is a more efficient way to do this, any support?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @feff890 What is the usage? Resetting a minigame?
     
  3. Offline

    feff890

    @timtower
    It's for a Survival Games plugin, it is run at the start of the game to find all chests in the map and randomise their loot.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @feff890 I would use the end of the match instead but that is not that important.
    Use a BukkitRunnable and handle a chunk per tick.
     
  5. Offline

    KarimAKL

    @feff890 Another way could be randomizing the loot when you open the chest, i think something like this would work.
    Code:Java
    1. private boolean started = false;
    2. private Set<Chest> opened = new HashSet<>();
    3.  
    4. public void startGame() {
    5. this.started = true;
    6. }
    7.  
    8. @EventHandler
    9. public void onOpen(InventoryOpenEvent e) {
    10. if (!(e.getInventory().getHolder() instanceof Chest)) return;
    11. if (!started) return;
    12. Chest chest = (Chest) e.getInventory().getHolder();
    13. if (opened.contains(chest)) return;
    14. opened.add(chest);
    15. randomizeLoot(chest);
    16. }
    17.  
    18. public void randomizeLoot(Chest chest) {
    19. // Code for randomizing the chest's loot
    20. }
    21.  
    22. public void resetChests() {
    23. opened.clear();
    24. }
     
Thread Status:
Not open for further replies.

Share This Page