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. I already have this code: 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
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++) { result.add(new Location(world, x, minY, z)); result.add(new Location(world, x, maxY, z)); } } // 2 sides (front & back) for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { result.add(new Location(world, x, y, minZ)); result.add(new Location(world, x, y, maxZ)); } } // 2 sides (left & right) for (int z = minZ; z <= maxZ; z++) { for (int y = minY; y <= maxY; y++) { result.add(new Location(world, minX, y, z)); result.add(new Location(world, maxX, y, z)); } } return result; } Janhektor
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
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) { result.add(new Location(world, x, minY, z)); result.add(new Location(world, x, maxY, z)); } } // 2 sides (front & back) for (double x = minX; x <= maxX; x+=0.2D) { for (double y = minY; y <= maxY; y+=0.2D) { result.add(new Location(world, x, y, minZ)); result.add(new Location(world, x, y, maxZ)); } } // 2 sides (left & right) for (double z = minZ; z <= maxZ; z+=0.2D) { for (double y = minY; y <= maxY; y+=0.2D) { result.add(new Location(world, minX, y, z)); result.add(new Location(world, maxX, y, z)); } } return result; }
Now it looks like this: But how to remove the walls between the outlines of the cube so I can get this?
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.
@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.
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) { result.add(new Location(world, x, y, z)); } } } } return result; }
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
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); corners.add(point); corners.add(new Point3D(point2.getX(), point.getY(), point.getZ())); corners.add(new Point3D(point.getX(), point2.getY(), point.getZ())); corners.add(new Point3D(point.getX(), point.getY(), point2.getZ())); corners.add(new Point3D(point2.getX(), point2.getY(), point.getZ())); corners.add(new Point3D(point2.getX(), point.getY(), point2.getZ())); corners.add(new Point3D(point.getX(), point2.getY(), point2.getZ())); corners.add(point2); 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) { points.add(new Point3D(x1, y1, z1)); } } while (x1 > x2) { x1 -= step; if (x1 > x2) { points.add(new Point3D(x1, y1, z1)); } } while (y1 < y2) { y1 += step; if (y1 < y2) { points.add(new Point3D(x1, y1, z1)); } } while (y1 > y2) { y1 -= step; if (y1 > y2) { points.add(new Point3D(x1, y1, z1)); } } while (z1 < z2) { z1 += step; if (z1 < z2) { points.add(new Point3D(x1, y1, z1)); } } while (z1 > z2) { z1 -= step; if (z1 > z2) { points.add(new Point3D(x1, y1, z1)); } } } } } return Collections.unmodifiableCollection(points); }
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) { result.add(new Location(world, x, y, z)); } } } } return result; } Try to call this method with 0.2 or 0.25 for particle distance. It may look better. // EDIT: Sorry @Qatell I hadn't seen your post.