# Create particles in cube outline shape

Discussion in 'Spigot Plugin Development' started by Arthurhoeke, May 14, 2015.

1. ### Arthurhoeke

Hi,
I want to create a shape of a cube, and then just the outlines of the cupe. So no walls between the outlines, and no particles inside.
Code (Text):
Material material = Material.DIRT;

for (int x = 0; x < 3; x++) {
for (int z = 0; z < 3; z++) {
for (int y = 0; y <= 2; y++) {
Location loc1 = new Location(world, startX + x, startY + y, startZ + z);
if (y != 3 && y!=0) {
if ((x >= 0 && z == 0) || (x >= 0 && z == 2) ||( x == 0 && z >= 0) || (x == 2 && z >= 0))
loc1.getBlock().setType(material);
} else {
loc1.getBlock().setType(material);
}
}
}
But this just generates a cube of dirt, and I need it to be particles (Just replace setmaterial with particle spawning, got that working) but I have to remove the particles in the middle etc.
Does anyone have a method for this? Or can help me? Thanks!

Example what I want:

Go to 2:21

#1
Last edited: May 14, 2015
• Funny x 1
• Friendly x 1
2. ### Janhektor

Hey,

I wrote a method for you. It returns a list of locations; you can loop this list and spawn a particle on every location.
Try this:
Code (Text):
public List<Location> getHollowCube(Location corner1, Location corner2) {
List<Location> result = new ArrayList<Location>();
World world = corner1.getWorld();
int minX = Math.min(corner1.getBlockX(), corner2.getBlockX());
int minY = Math.min(corner1.getBlockY(), corner2.getBlockY());
int minZ = Math.min(corner1.getBlockZ(), corner2.getBlockZ());
int maxX = Math.max(corner1.getBlockX(), corner2.getBlockX());
int maxY = Math.max(corner1.getBlockY(), corner2.getBlockY());
int maxZ = Math.max(corner1.getBlockZ(), corner2.getBlockZ());

// 2 areas
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
}
}

// 2 sides (front & back)
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
}
}

// 2 sides (left & right)
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
}
}

return result;
}
Janhektor

• Useful x 1
3. ### Arthurhoeke

Thanks! It works, but there is 1 problem, I want that it is like in the video, so that in the middle has no particles in it.

So the particles in the middle, 4 particles needs to be removed

4. ### Janhektor

Okay.
Maybe the distance between the calculated locations is too big. I improved this method a little bit. Try this:
Code (Text):
public List<Location> getHollowCube(Location corner1, Location corner2) {
List<Location> result = new ArrayList<Location>();
World world = corner1.getWorld();
double minX = Math.min(corner1.getX(), corner2.getX());
double minY = Math.min(corner1.getY(), corner2.getY());
double minZ = Math.min(corner1.getZ(), corner2.getZ());
double maxX = Math.max(corner1.getX(), corner2.getX());
double maxY = Math.max(corner1.getY(), corner2.getY());
double maxZ = Math.max(corner1.getZ(), corner2.getZ());

// 2 areas
for (double x = minX; x <= maxX; x+=0.2D) {
for (double z = minZ; z <= maxZ; z+=0.2D) {
}
}

// 2 sides (front & back)
for (double x = minX; x <= maxX; x+=0.2D) {
for (double y = minY; y <= maxY; y+=0.2D) {
}
}

// 2 sides (left & right)
for (double z = minZ; z <= maxZ; z+=0.2D) {
for (double y = minY; y <= maxY; y+=0.2D) {
}
}

return result;
}

5. ### Arthurhoeke

Now it looks like this:

But how to remove the walls between the outlines of the cube so I can get this?

6. ### Janhektor

Ahh, now I know what you want.
First of all, I thought you want to spawn the only the areas, inside empty.
I try to write a method. If I get it, I'll write a response here.

• Like x 1
7. ### Arthurhoeke

Thanks! Appreciate it

8. ### DarkSeraphim

@Arthurhoeke you need to display particles at all coordinates where at least 2 out of 3 components (x, y and z) are either the min or max of the cube.

Assuming a cube from 0,0,0 to 1,1,1:
• 0, 0, [0 - 1]
• 0, [0 - 1], 0
• [0 - 1], 0, 0
• 1, 1, [0 - 1]
• 1, [0 - 1], 1
• [0 - 1], 1, 1
The rest is just a bunch of for loops and actually displaying the particles.

9. ### Arthurhoeke

I have no experience with creating shapes like this, really don't know how to do it :l

10. ### Janhektor

Good idea.

I wrote a code; we can try it:
Code (Text):
public List<Location> getHollowCube(Location corner1, Location corner2) {
List<Location> result = new ArrayList<Location>();
World world = corner1.getWorld();
double minX = Math.min(corner1.getX(), corner2.getX());
double minY = Math.min(corner1.getY(), corner2.getY());
double minZ = Math.min(corner1.getZ(), corner2.getZ());
double maxX = Math.max(corner1.getX(), corner2.getX());
double maxY = Math.max(corner1.getY(), corner2.getY());
double maxZ = Math.max(corner1.getZ(), corner2.getZ());

for (double x = minX; x <= maxX; x++) {
for (double y = minY; y <= maxY; y++) {
for (double z = minZ; z <= maxZ; z++) {
int components = 0;
if (x == minX || x == maxX) components++;
if (y == minY || y == maxY) components++;
if (z == minZ || z == maxZ) components++;
if (components >= 2) {
}
}
}
}

return result;
}

• Useful x 1
11. ### Arthurhoeke

Works fine! Only thing is that it does not set alot of points / locations for the particles to spawn, so there are not alot of particles

12. ### Qatell

Here's a simple sketchup, but I had a better idea which I'm going to improve this code with now.

Code (Text):

public static Collection<Point3D> gatherPoints(Point3D point, Point3D point2, double step) {
List<Point3D> corners = new ArrayList<Point3D>(8);
List<Point3D> points = new ArrayList<Point3D>();
for (Point3D corner : corners) {
for (Point3D corner2 : corners) {
if (corner == corner2) {
continue;
}
int matches = 0;
if (corner.getX() == corner2.getX()) {
matches++;
}
if (corner.getY() == corner2.getY()) {
matches++;
}
if (corner.getZ() == corner2.getZ()) {
matches++;
}
if (matches == 2) {
double x1 = corner.getX();
double x2 = corner2.getX();
double y1 = corner.getY();
double y2 = corner2.getY();
double z1 = corner.getZ();
double z2 = corner2.getZ();
while (x1 < x2) {
x1 += step;
if (x1 < x2) {
}
}
while (x1 > x2) {
x1 -= step;
if (x1 > x2) {
}
}
while (y1 < y2) {
y1 += step;
if (y1 < y2) {
}
}
while (y1 > y2) {
y1 -= step;
if (y1 > y2) {
}
}
while (z1 < z2) {
z1 += step;
if (z1 < z2) {
}
}
while (z1 > z2) {
z1 -= step;
if (z1 > z2) {
}
}
}
}
}
return Collections.unmodifiableCollection(points);
}

• Useful x 1
13. ### Janhektor

Nice, I changed some lines:
Code (Text):
public List<Location> getHollowCube(Location corner1, Location corner2, double particleDistance) {
List<Location> result = new ArrayList<Location>();
World world = corner1.getWorld();
double minX = Math.min(corner1.getX(), corner2.getX());
double minY = Math.min(corner1.getY(), corner2.getY());
double minZ = Math.min(corner1.getZ(), corner2.getZ());
double maxX = Math.max(corner1.getX(), corner2.getX());
double maxY = Math.max(corner1.getY(), corner2.getY());
double maxZ = Math.max(corner1.getZ(), corner2.getZ());

for (double x = minX; x <= maxX; x+=particleDistance) {
for (double y = minY; y <= maxY; y+=particleDistance) {
for (double z = minZ; z <= maxZ; z+=particleDistance) {
int components = 0;
if (x == minX || x == maxX) components++;
if (y == minY || y == maxY) components++;
if (z == minZ || z == maxZ) components++;
if (components >= 2) {
}
}
}
}

return result;
}
Try to call this method with 0.2 or 0.25 for particle distance.
It may look better.

• Useful x 3
14. ### Qatell

No worries, whatever gets him a working version fastest.

• Useful x 1
15. ### fujiboy4

That's really intense.... all those command blocs to run it...

16. ### Arthurhoeke

Works perfecly! Thanks for the help guys, really appreciate it