Mobs disappearing on chunk reload

Discussion in 'Plugin Development' started by Schwarzer Zylinder, Jan 23, 2012.

Thread Status:
Not open for further replies.
  1. Hey,
    I am using mobs for one of my plugins. The problem is, that hey are disappearing when you teleport away and then back.
    I made a test by printing out the status if a chunk is loaded, and it says me every time true, even if I am 200 hundred blocks away.
    I can not use chunk events either, because If i compare the x and z values from the mobs chunk with every new loaded, it says me false every time.
    So the problem is, that the mobs that I spawned disappear and I need an event or something else to know when I have to respawn them.
     
  2. Offline

    Zacherl

    I guess u dont use the chunk events correctly. How do you compare the coordinates? Chunk.getX() and Chunk.getZ() are not equal to Block.getX() and Block.getZ().
     
  3. Code:java
    1. public void deleteGuardsInChunk(Chunk chunk) {
    2. for(Guard guard : guardsList) {
    3. if(chunkMatch(guard.getLocation().getChunk(), chunk)) {guard.removeCreature();System.out.println("b");}
    4. }
    5. }
    6.  
    7. public void reloadGuardsInChunk(Chunk chunk) {
    8. for(Guard guard : guardsList) {
    9. //If a guard is in the chunk
    10. if(chunkMatch(guard.getLocation().getChunk(), chunk)) {guard.reloadCreature();System.out.println("c");}
    11. }
    12. }
    13.  
    14. private boolean chunkMatch(Chunk chunk1, Chunk chunk2) {
    15. return chunk1.getX() == chunk2.getX() && chunk1.getZ() == chunk2.getZ();
    16. }
     
Thread Status:
Not open for further replies.

Share This Page