Solved Help with Chunk Outline

Discussion in 'Plugin Development' started by Swissi, Jul 21, 2015.

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

    Swissi

    Hello ,

    I currently headaches of the many calculations , etc , etc , and need your help ...
    Possibly one of you knows what I do wrong : p

    So far I have the following :
    Code:
            if (p.isOp()){         
                 
                try {
                    Chunk chunki = getChunk();
                    int locx = (int) chunki.getX();
                    //Location chunkint = new Location(chunki.getBlock((int)p.getLocation().getX(), (int)p.getLocation().getY(), (int)p.getLocation().getZ()));
                    int locz = (int) chunki.getZ();
                 
                    for (int x = 0; x < 16; x++) {
                        for (int z = 0; z < 16; z++) {
                            if (z == 15 || z == 0 || x == 15 || x ==  0) {
                                    Location locr = new Location(Bukkit.getWorld(worldName), p.getLocation().getChunk().getX() + x, 0 ,p.getLocation().getChunk().getZ() + z);
                                    int inita = chunk.getWorld().getHighestBlockAt(locr).getY();
                                    Block changeblock = chunk.getBlock(x, inita, z);
                                    //Block b = chunk.getBlock(x, y, z);
                                    changeblock.getRelative(BlockFace.DOWN, 2);
                                    changeblock.getLocation().add(x,2,z);
                                    changeblock.setType(Material.GLOWSTONE);
                                    p.sendMessage("" + chunk.getWorld().getHighestBlockAt(p.getLocation().getChunk().getX() + x ,p.getLocation().getChunk().getZ() + z).getY());
                                }
                            }
                        }
                } catch (Exception ue){
                    ue.printStackTrace();
                }
            }
    So ... until then everything works , the blocks are placed only ... according to my ChunkBorder not on the Chunk :(
    It creates the square only with me on the " corner " point .
    My question .... How to make exactly the Chunk these blocks ?

    sry for bad English
     
    Last edited: Jul 21, 2015
  2. Offline

    tastybento

    So, you want to outline the chunk that the Op is in with glowstone?

    One problem is here:

    Code:
    Location locr = new Location(Bukkit.getWorld(worldName), p.getLocation().getChunk().getX() + x, 0 ,p.getLocation().getChunk().getZ() + z);
    The getChunk() method returns the chunk coordinates, not the location coordinates, so you need to multiply by 16:

    Code:
    Location locr = new Location(Bukkit.getWorld(worldName), p.getLocation().getChunk().getX()*16 + x, 0 ,p.getLocation().getChunk().getZ()*16 + z);
    I'm not sure why you are doing this:
    Code:
    changeblock.getRelative(BlockFace.DOWN, 2);
    changeblock.getLocation().add(x,2,z);
    Why not just do:

    Code:
    changeblock.getRelative(BlockFace.DOWN);
    Also, a tip - unless you really want to change the blocks to real GlowStone, you may want to use player.sendBlockChange(pos, block.getType(), block.getData()); instead because that will just make it visible to the Op only.
     
  3. Code:
    p.getLocation().getChunk().getX() + x, 0 ,p.getLocation().getChunk().getZ() + z
    I believe you want Chunk#getX() * 16, that should give you the world's exact coordinates
     
  4. Offline

    Zombie_Striker

    @Swissi
    Your naming is wierd, but thats not the problem. The getX/getZ methods are used to get the amount of chunkcs from the center they are (e.g. 160 blocks away is chunk 10). Multiply ChunkX and chunkZ by 16.

    Also. Why have you not debugged your code. That would have told you that your numbers are way off.
     
  5. Offline

    Swissi

    Thanks :) @tastybento works ;)
     
Thread Status:
Not open for further replies.

Share This Page