|
1 | 1 | package top.zoyn.particlelib.pobject; |
2 | 2 |
|
| 3 | +import com.google.common.collect.Lists; |
3 | 4 | import org.bukkit.Location; |
4 | 5 | import org.bukkit.util.Vector; |
5 | 6 |
|
| 7 | +import java.util.List; |
| 8 | + |
6 | 9 | public class Grid extends ParticleObject { |
7 | 10 |
|
8 | 11 | private final double gridLength; |
@@ -39,6 +42,82 @@ public Grid(Location minimumLocation, Location maximumLocation, double gridLengt |
39 | 42 | this.gridLength = gridLength; |
40 | 43 | } |
41 | 44 |
|
| 45 | + @Override |
| 46 | + public List<Location> calculateLocations() { |
| 47 | + List<Location> points = Lists.newArrayList(); |
| 48 | + // 为防止给定的最小和最高点出现反向的情况, 这里做了个查找操作 |
| 49 | + Location minLocation = findMinimumLocation(); |
| 50 | + Location maxLocation = findMaximumLocation(); |
| 51 | + |
| 52 | + double height; |
| 53 | + double width; |
| 54 | + |
| 55 | + // 在Y平面下有点不一样 |
| 56 | + if (isYDimension) { |
| 57 | + height = Math.abs(minLocation.getX() - maxLocation.getX()); |
| 58 | + width = Math.abs(minLocation.getZ() - maxLocation.getZ()); |
| 59 | + } else { |
| 60 | + height = Math.abs(maximumLocation.getY() - minimumLocation.getY()); |
| 61 | + if (isXDimension) { |
| 62 | + width = Math.abs(maximumLocation.getX() - minimumLocation.getX()); |
| 63 | + } else { |
| 64 | + width = Math.abs(maximumLocation.getZ() - minimumLocation.getZ()); |
| 65 | + } |
| 66 | + } |
| 67 | + int heightSideLine = (int) (height / gridLength); |
| 68 | + int widthSideLine = (int) (width / gridLength); |
| 69 | + |
| 70 | + if (isYDimension) { |
| 71 | + for (int i = 1; i <= heightSideLine; i++) { |
| 72 | + Vector vector = maxLocation.clone().subtract(minLocation).toVector(); |
| 73 | + vector.setZ(0).normalize(); |
| 74 | + |
| 75 | + Location start = minLocation.clone().add(0, 0, i * gridLength); |
| 76 | + for (double j = 0; j < width; j += 0.2) { |
| 77 | + points.add(start.clone().add(vector.clone().multiply(j))); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + for (int i = 1; i <= widthSideLine; i++) { |
| 82 | + Vector vector = maxLocation.clone().subtract(minLocation).toVector(); |
| 83 | + vector.setX(0).normalize(); |
| 84 | + Location start = minLocation.clone().add(i * gridLength, 0, 0); |
| 85 | + |
| 86 | + for (double j = 0; j < height; j += 0.2) { |
| 87 | + points.add(start.clone().add(vector.clone().multiply(j))); |
| 88 | + } |
| 89 | + } |
| 90 | + return points; |
| 91 | + } |
| 92 | + |
| 93 | + for (int i = 1; i <= heightSideLine; i++) { |
| 94 | + Vector vector = maxLocation.clone().subtract(minLocation).toVector(); |
| 95 | + vector.setY(0).normalize(); |
| 96 | + |
| 97 | + Location start = minLocation.clone().add(0, i * gridLength, 0); |
| 98 | + for (double j = 0; j < width; j += 0.2) { |
| 99 | + points.add(start.clone().add(vector.clone().multiply(j))); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + for (int i = 1; i <= widthSideLine; i++) { |
| 104 | + Vector vector = maxLocation.clone().subtract(minLocation).toVector(); |
| 105 | + Location start; |
| 106 | + if (isXDimension) { |
| 107 | + vector.setX(0).normalize(); |
| 108 | + start = minLocation.clone().add(i * gridLength, 0, 0); |
| 109 | + } else { |
| 110 | + vector.setZ(0).normalize(); |
| 111 | + start = minLocation.clone().add(0, 0, i * gridLength); |
| 112 | + } |
| 113 | + |
| 114 | + for (double j = 0; j < height; j += 0.2) { |
| 115 | + points.add(start.clone().add(vector.clone().multiply(j))); |
| 116 | + } |
| 117 | + } |
| 118 | + return points; |
| 119 | + } |
| 120 | + |
42 | 121 | @Override |
43 | 122 | public void show() { |
44 | 123 | // 为防止给定的最小和最高点出现反向的情况, 这里做了个查找操作 |
|
0 commit comments