Generating a (flat) circle of blocks..

Discussion in 'Plugin Development' started by Eballer48, Aug 13, 2012.

Not open for further replies.
1. Offline

Eballer48

How the hell do I do that..

#31
2. Offline

Splated

Heres how i did it.

You can add a for loop for y also and make spheres.

Code:

Block block = this.FenceCenter.getWorld().getBlockAt(this.FenceCenter);

Block b = block.getRelative(x, 1, z);
double d = this.FenceCenter.distance(b.getLocation());

if ((d > radius -1 ) && (d < radius +1 ))
b.setType(Material.FENCE);

}
}

#32
3. Offline

That's my method for generating cylinders:

Code:
public void createCyl(Location loc, int r, Material mat) {
int cx = loc.getBlockX();
int cy = loc.getBlockY();
int cz = loc.getBlockZ();
World w = loc.getWorld();
int rSquared = r * r;
for (int x = cx - r; x <= cx + r; x++) {
for (int z = cz - r; z <= cz + r; z++) {
if ((cx - x) * (cx - x) + (cz - z) * (cz - z) <= rSquared) {
Location cylBlock = new Location(w, x, cy, z);
w.getBlockAt(x, cy, z).setType(mat);
}
}
}
}

#33
4. Offline

Jnorr44

Here, I made a 3d sphere, just remove the Y loop, and you will have a 2d circle:
Code:
public class Sphere {//TODO annotations
private ArrayList<Block> sphere = new ArrayList<Block>();
private Location center;

public Sphere(Location center, int radius) {
this.center = center;
if(Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) {
Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ());
}
}
}
}
}

public Location getCenter() {
return center;
}

}

public ArrayList<Block> getBlocks() {
return sphere;
}

private boolean isInside(int X, int Y, int Z) {
return Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius;
}

public boolean overlaps(Sphere other) {
for (Block block : other.getBlocks())
if (contains(block.getLocation()))
return true;
return false;
}

public boolean contains(Location loc) {
return isInside(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
}

#34