#sphere generation for blocks
1 messages ยท Page 1 of 1 (latest)
hello, if anyone joins/reads this and you're good at math, or spigot devleopment pls read
i've been trying to make a sphere generator, for some build utilities, i just dont want to use worldedit because... its not that lightweight of a plugin, right
so i got some code offline and i editted it a bit, however... after my edit i realized that the code would skip certain blocks
public static List<Block> getSphere(Location loc, boolean hollow, int radius, int height){
List<Block> blocks = new ArrayList<Block>();
int bx = loc.getBlockX();
int by = loc.getBlockY();
int bz = loc.getBlockZ();
for(int x = bx - radius; x <= bx + radius; x++){
for(int y = by - height; y <= by + height; y++){
for(int z = bz - radius; z <= bz + radius; z++){
double distance = ((bx-x) * (bx-x) + ((bz-z) * (bz-z)) + ((by-y) * (by-y)));
if(distance < height * radius && !(hollow && distance < ((height - 1) * (radius - 1)))) blocks.add(new Location(loc.getWorld(), x, y, z).getBlock());
}
}
}
return blocks;
}
``` code (i added 'int height')
and heres what happens when i use radius 15, height 5
ignore the giant sphere in the background XD
and im not 1000% sure how threads work, so just ping me if you answer
then how does worldedit do it?
wait WE is open source, 2 seconds
you can set a height in WE?
if you can provide a height I'd expect it to be a scalar
ie, you reduce the radius for bx by the scalar
yeah isnt it //sphere block width height
then thats not a radius
and im really not sure how to do that, im gonna continue google research ๐ง
also fair
wtffff
i wonder how they do it https://www.plotz.co.uk/plotz-model.php?model=Ellipsoid
Plan, view and make ellipsoids, domes and hollow oval spheres of any width, height and depth.
expanding any one dimension is not hard, so long as you don;t go below the radius
im not too sure how to expand by one dimension, is google my best answer for that?
you can go radius + a scalar, but not under the radius
its + radius + scalar
or height if you like
2 dimensions have to be the same (radius) the thrird can expand
okay
its already a nightmare :pepeWhy:
๐
ok for starters, change to using a Set instead of a List, and store the Blocks not locations
nah you use Locations blocks.add(new Location(loc.getWorld(), x, y, z).getBlock());
oh you do getBlock ๐
Set will not allow duplicates
ahh
also change your loops to use double instead of ints
then you can change your granularity
currently you are jumping a full block at a time. which means as you expand height its going to miss blocks
@sand ice This is the code they use https://paste.md-5.net/ilusiyehuk.js
yikes
but that does include all the rendering
yeah
ahh @solar ingot here's this
radius radius radius
x,y,z
length,height,length basicaly
if only the host was working ๐คฌ