getChunk().getX() is wrong?

Discussion in 'Plugin Development' started by johnny_boy, Jul 8, 2018.

Thread Status:
Not open for further replies.
  1. I'm making a crop hopper plugin, currently testing it with just a normal hopper, however i always get an NPE when trying to get my x value of the chunk (because it's not the same as what I'm trying to do, read my code comments). I think it's different for some reason?!
    Code:Java
    1.  
    2.  
    3. int chunkX = e.getEntity().getLocation().getChunk().getX(); // this is different to the other x
    4. int chunkZ = e.getEntity().getLocation().getChunk().getZ(); // however this is the same
    5.  
    6. String hopperData = String.valueOf(chunkX) + String.valueOf(chunkZ);
    7.  
    8.  
    9. if (plugin.config.get("hopperdata." + hopperData) == null) {
    10. Bukkit.broadcastMessage(hopperData);
    11. Bukkit.broadcastMessage(plugin.config.get("hopperdata." + hopperData + ".x").toString());
    12.  
    13. Bukkit.broadcastMessage("hello gai2s");
    14. return;
    15. }
    16.  


    Code:Java
    1.  
    2. int x = e.getBlockPlaced().getX();
    3. int y = e.getBlockPlaced().getY();
    4. int z = e.getBlockPlaced().getZ();
    5.  
    6. int chunkX = e.getBlockPlaced().getChunk().getX(); // different to other x
    7. int chunkZ = e.getBlockPlaced().getChunk().getZ(); // the same?!
    8.  
    9. String hopperData = String.valueOf(chunkX) + String.valueOf(chunkZ);
    10.  
    11. plugin.config.set("hopperdata." + hopperData + "." + "x", x);
    12. plugin.config.set("hopperdata." + hopperData + "." + "y", y);
    13. plugin.config.set("hopperdata." + hopperData + "." + "z", z);
    14.  
    15. plugin.config.set("hopperdata." + hopperData + "." + "chunkX", chunkX);
    16. plugin.config.set("hopperdata." + hopperData + "." + "chunkZ", chunkZ);
    17. plugin.config.set("hopperdata." + hopperData + "." + "world", e.getBlockPlaced().getWorld().getName());
    18.  


    EDIT: After a bit of testing it's inconsistent, both values are usually wrong.
     
    Last edited: Jul 8, 2018
  2. Offline

    MightyOne

    Chunk coordinates are 1/16 of real coordinates. So if you want get the location where your chunk starts you need to Chunk#getX() >> 4
     
Thread Status:
Not open for further replies.

Share This Page