Keep A Chunk loaded

Discussion in 'Plugin Development' started by LordManegane, Feb 15, 2014.

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

    LordManegane

    How i can keep a chunk loaded? So can manage entities and everything like spawnchunks?
    I tried location.getChunk().load(); but i throw items, get away but they doesnt despawn!

    bumpity bump

    .

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

    masshuu

    Possibly try this, I have not tested it.

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onChunkUnloadE(ChunkUnloadEvent event){
    3. if(event.getChunk().getX()==0 && event.getChunk().getZ() ==0)
    4. event.setCancelled(true);
    5.  
    6. }
    7.  
     
  3. Offline

    LordManegane

    masshuu Doesnt seems to be working
     
  4. Offline

    masshuu

    I just tested it and it appears to work for me. I set it to 99 for x and y and setup a command block which broadcasts a message every few seconds, still broadcasting when i leave. Stops if i change the x/y
     
  5. Offline

    LordManegane

    I tested it with blocks despawning. And still there.
     
  6. Offline

    masshuu

    What is your current code
     
  7. Offline

    LordManegane

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public static void unLoad(ChunkUnloadEvent e){
    3. Location location = new Location(e.getChunk().getWorld(), 2000, 1, 2000);
    4. if(e.getChunk().getX()==2000 && e.getChunk().getZ() ==2000){
    5. e.setCancelled(true);
    6.  
    7. }
    8.  
    9. }
     
  8. Offline

    Cirno

    Try new Location(e.getChunk().getWorld(), 32000, 1, 32000);
     
  9. Offline

    masshuu

    I would also check F3 window to be sure what chunk you are in. I originally setup as 100 but whenever I checked F3 I realized I had moved into chunks 99,99
     
  10. Offline

    LordManegane

    masshuu
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public static void unLoad(ChunkUnloadEvent e){
    3. Location location = new Location(e.getChunk().getWorld(), 2000, 1, 2000);
    4. if(e.getChunk().getX()==2000 && e.getChunk().getZ() ==2000){
    5. e.setCancelled(true);
    6.  
    7. }
    8.  
    9. }


    masshuu pfff doesnt works

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

    desht

    Pay attention to what Cirno said. Chunk co-ordinates and block co-ordinates are not the same thing; e.g. block (2000,1,2000) is in chunk (125,125) - a chunk's X/Z co-ordinates are the block's X/Z co-ordinates divided by 16 (and rounded down).
     
  12. Offline

    xize

    I'm not sure if it works but what if you do getWorld().refreshChunk(x, z); on the chunk axises on the ChunkUnloadEvent? maybe I'm wrong and its to resource active though but anyways I also thought it automatic already loads whenever you call getChunk(); again not sure.

    but the question is why would you prevent chunks from unloading?
     
  13. Offline

    LordManegane

    desht I tried with chunks coords, but the items didn't despawn

    bum:p

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

    desht

    Just noticed that you declared your event handler static. No wonder it's not working :)

    Event handlers can't be static methods.
     
  15. Offline

    LordManegane

    desht doesnt works. Even if i remove the static
     
Thread Status:
Not open for further replies.

Share This Page