Solved Calculating with Modulo

Discussion in 'Spigot Plugin Development' started by ColorMyChicken, May 29, 2018.

  1. Hey, I have a method to spawn glowstone as corners around a location.
    But this only works if the coordinate x and z are positive.
    Anyone can fix it for negatives?

    Here are all coordinates positive:
    https://www.pic-upload.de/view-35397401/2018-05-29_10.01.00.png.html

    Here are is only one coordinate negative and I won't work:
    https://www.pic-upload.de/view-35397409/2018-05-29_10.02.46.png.html

    Code (Text):
    private int islandSize = 31;

    private void highlightIslandBorders(Location loc) {
            World world = loc.getWorld();

            int sx = loc.getBlockX();
            sx -= sx % islandSize;

            int sz = loc.getBlockZ();
            sz -= sz % islandSize;

            if ((sx < 0) || (sz < 0)) {
                return;
            }

            int ex = sx + islandSize - 1;
            int ez = sz + islandSize - 1;

            int y = loc.getBlockY() - 1;

            Material cornerMat = Material.GLOWSTONE;
            world.getBlockAt(sx, y, sz).setType(cornerMat);
            world.getBlockAt(ex, y, sz).setType(cornerMat);
            world.getBlockAt(sx, y, ez).setType(cornerMat);
            world.getBlockAt(ex, y, ez).setType(cornerMat);
        }
     
  2. Code (Text):
    int diameter = this.radius * 2;
            for (int x = 0; x < diameter; x++) {
    //Change y if you want
                for (int y = 0; y < 255; y++) {
                    for (int z = 0; z < diameter; z++) {
                        Location loc = location.clone();
                        loc.setX(loc.getX() + x - radius + 0.5);
                        loc.setY(y);
                        loc.setZ(loc.getZ() + z - radius + 0.5);
                        double d = distanceWithoutY(location, loc);
                        if (d >= radius) continue;
    //Change Material
                        if (loc.getBlock().getType() == Material.AIR) continue;
    //Adding to a map due that i want to break blocks with that modus in a certain time but u can do it otherwise.
                        add((int) d, loc);
                    }
                }
            }
     
  3. And radius is my islandSize but the half?
     
  4. test it its to long ago i used it :D
     
  5. I've tried it with the half and the whole value and it doesn't work :/
     
  6. well i must say this is just the method to get the blocks at distance (= radius) so u need to figure out how to get all blocks in that radius and not just the blocks at 10 9 8 etc. as i said i used it to destroy the blocks after time.
     
  7. So you just want to place glowstone at the corners of a square with a set radius(half side size) and a fixed location?
     
  8. Many thank to you but I could solve it a lot easier :D
    Here is the code:

    Code (Text):
    private int islandSize = 31;
    private void spawnRectangle(Location loc) {
            World world = loc.getWorld();

            int x = loc.getBlockX();
            int z = loc.getBlockZ();

            int r = islandSize / 2;

            Material cornerMat = Material.GLOWSTONE;
            world.getBlockAt(x + r, islandHeight, z + r).setType(cornerMat);
            world.getBlockAt(x + r, islandHeight, z - r).setType(cornerMat);
            world.getBlockAt(x - r, islandHeight, z - r).setType(cornerMat);
            world.getBlockAt(x - r, islandHeight, z + r).setType(cornerMat);
        }