Solved What can keep a chunk loaded

Discussion in 'Spigot Plugin Development' started by Stellrow, Mar 31, 2020.

  1. So everytime i join the server,a certain thing runned,wich is exclusivly set to only go if the chunk is loaded,is there a specific reason for a chunk to be loaded even if no players are near?
     
  2. Some chunks around the spawn are always loaded if I’m not wrong.
     
  3. It think i mistaken as i tested with a furnace to see,and it stopped cooking,strange.. even though i have in the code if(loc,getChunk().isLoaded())...
     
  4. Maybe people can help you better if they see your code. Just to better understand what kind of problem you are facing.
     
  5. drives_a_ford

    Moderator

    I'm fairly certain Location#getChunk simply loads the chunk if it was not previously loaded. It calls World#getChunkAt in the end.
    You'd be better off checking World#isChunkLoaded.

    PS. Make sure to use the chunk coordinates not the location coordinates in the method I linked to.
     
    • Useful Useful x 1
  6. Ahh so basically im loading the chunk to check if its loaded.. damn
     
  7. Will
    Code (Text):
    (loc.getWorld().getChunkAt(loc).isLoaded())
    do the job?
     
  8. drives_a_ford

    Moderator

    The job of what? Loading the chunk just as your last method? Sure.

     
  9. Would location.isWorldLoaded() do the same job as well?,afterall the final purpose is to know if that specific location is loaded(player near it or so..)
     
  10. drives_a_ford

    Moderator

    That one, like the method name suggests, only checks if the World is loaded.
     
  11. If you want to keep the chunk explicitly open you can add a plugin ticket to the chunk.
    To be honest, I don't think this works all the time, or the same way vanilla minecraft does, but anyways here's the link:
    https://hub.spigotmc.org/javadocs/s...ddPluginChunkTicket-org.bukkit.plugin.Plugin-
    The reason I say this, I have tried to add plugin tickets to the chunk where some entity enters a nether portal, and where they are going to end up, so that they do not despawn, or go wonky in some way, but they do. Vanilla Minecraft adds it's own "Portal Ticket" which doesn't despawn anything, but I am not sure how to access it even with reflection and NMS, (it is in there kind of deep).

    So anyways the plugin ticket will "keep the chunk loaded". Does it actually though? Who knows, I can't tell. Try it with your furnace, or whatever.
     
  12. The final outcome is knowing if a chunk is loaded(to do something),thanks to @drives_a_ford made it,hopefully the conversion is good
    Code (Text):
    int x = (int)Math.floor(loc.getBlockX()>>4);
                            int z = (int)Math.floor(loc.getBlockZ()>>4);
                            if(loc.getWorld().isChunkLoaded(x,z)) {
    }
     
  13. drives_a_ford

    Moderator

    The conversion should be handled much simpler. I.e
    Code (Java):
    int x = loc.getBlockX()>>4;
    int z = loc.getBlockZ()>>4;