Skip to content

Commit 2a17b76

Browse files
committed
更新: 给粒子特效的 calculateLocations 兼容 Matrix 和 Increment 的参数
1 parent b4746ee commit 2a17b76

21 files changed

Lines changed: 420 additions & 29 deletions

src/main/java/top/zoyn/particlelib/pobject/Arc.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.Lists;
44
import org.bukkit.Location;
55
import org.bukkit.scheduler.BukkitRunnable;
6+
import org.bukkit.util.Vector;
67
import top.zoyn.particlelib.ParticleLib;
78

89
import java.util.List;
@@ -75,7 +76,17 @@ public List<Location> calculateLocations() {
7576
double radians = Math.toRadians(i);
7677
double x = radius * Math.cos(radians);
7778
double z = radius * Math.sin(radians);
78-
points.add(getOrigin().clone().add(x, 0, z));
79+
80+
Location showLocation = getOrigin().clone().add(x, 0, z);
81+
if (hasMatrix()) {
82+
Vector vector = new Vector(x, 0, z);
83+
Vector changed = getMatrix().applyVector(vector);
84+
85+
showLocation = getOrigin().clone().add(changed);
86+
}
87+
88+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
89+
points.add(showLocation);
7990
}
8091
return points;
8192
}

src/main/java/top/zoyn/particlelib/pobject/Astroid.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.Lists;
44
import org.bukkit.Location;
55
import org.bukkit.scheduler.BukkitRunnable;
6+
import org.bukkit.util.Vector;
67
import top.zoyn.particlelib.ParticleLib;
78

89
import java.util.List;
@@ -53,7 +54,16 @@ public List<Location> calculateLocations() {
5354
double x = Math.pow(this.radius * Math.cos(radians), 3.0D);
5455
double z = Math.pow(this.radius * Math.sin(radians), 3.0D);
5556

56-
points.add(getOrigin().clone().add(x, 0, z));
57+
Location showLocation = getOrigin().clone().add(x, 0, z);
58+
if (hasMatrix()) {
59+
Vector vector = new Vector(x, 0, z);
60+
Vector changed = getMatrix().applyVector(vector);
61+
62+
showLocation = getOrigin().clone().add(changed);
63+
}
64+
65+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
66+
points.add(showLocation);
5767
}
5868
return points;
5969
}

src/main/java/top/zoyn/particlelib/pobject/Cube.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import top.zoyn.particlelib.utils.VectorUtils;
77

88
import java.util.List;
9+
import java.util.stream.Collectors;
910

1011
/**
1112
* 表示一个立方体特效
@@ -112,13 +113,26 @@ public List<Location> calculateLocations() {
112113
for (double j = 0; j < length; j += step) {
113114
Location spawnLoc = newOrigin.clone().add(vector.clone().multiply(j));
114115
points.add(spawnLoc);
115-
points.add(spawnLoc.add(0, height, 0));
116+
points.add(spawnLoc.clone().add(0, height, 0));
116117
}
117118
// 获取结束时的坐标
118119
newOrigin = newOrigin.clone().add(vector.clone().multiply(length));
119120
vector = VectorUtils.rotateAroundAxisY(vector, 90D);
120121
}
121-
return points;
122+
123+
// 做一个对 Matrix 和 Increment 的兼容
124+
return points.stream().map(location -> {
125+
Location showLocation = location;
126+
if (hasMatrix()) {
127+
Vector v = new Vector(location.getX() - getOrigin().getX(), location.getY() - getOrigin().getY(), location.getZ() - getOrigin().getZ());
128+
Vector changed = getMatrix().applyVector(v);
129+
130+
showLocation = getOrigin().clone().add(changed);
131+
}
132+
133+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
134+
return showLocation;
135+
}).collect(Collectors.toList());
122136
}
123137

124138
@Override

src/main/java/top/zoyn/particlelib/pobject/FilledCircle.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.Location;
44
import org.bukkit.scheduler.BukkitRunnable;
5+
import org.bukkit.util.Vector;
56
import top.zoyn.particlelib.ParticleLib;
67

78
import java.util.ArrayList;
@@ -59,8 +60,18 @@ public List<Location> calculateLocations() {
5960
double x = radius * r * Math.cos(theta);
6061
double z = radius * r * Math.sin(theta);
6162

62-
Location spawnLocation = getOrigin().clone().add(x, 0, z);
63-
locations.add(spawnLocation);
63+
Location showLocation = getOrigin().clone().add(x, 0, z);
64+
if (hasMatrix()) {
65+
Vector vector = new Vector(x, 0 ,z);
66+
Vector changed = getMatrix().applyVector(vector);
67+
68+
showLocation = getOrigin().clone().add(changed);
69+
}
70+
71+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
72+
locations.add(showLocation);
73+
// Location spawnLocation = getOrigin().clone().add(x, 0, z);
74+
// locations.add(spawnLocation);
6475
}
6576
return locations;
6677
}

src/main/java/top/zoyn/particlelib/pobject/Grid.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.bukkit.util.Vector;
66

77
import java.util.List;
8+
import java.util.stream.Collectors;
89

910
public class Grid extends ParticleObject {
1011

@@ -115,7 +116,20 @@ public List<Location> calculateLocations() {
115116
points.add(start.clone().add(vector.clone().multiply(j)));
116117
}
117118
}
118-
return points;
119+
120+
// 做一个对 Matrix 和 Increment 的兼容
121+
return points.stream().map(location -> {
122+
Location showLocation = location;
123+
if (hasMatrix()) {
124+
Vector v = new Vector(location.getX() - getOrigin().getX(), location.getY() - getOrigin().getY(), location.getZ() - getOrigin().getZ());
125+
Vector changed = getMatrix().applyVector(v);
126+
127+
showLocation = getOrigin().clone().add(changed);
128+
}
129+
130+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
131+
return showLocation;
132+
}).collect(Collectors.toList());
119133
}
120134

121135
@Override

src/main/java/top/zoyn/particlelib/pobject/Heart.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.Lists;
44
import org.bukkit.Location;
55
import org.bukkit.scheduler.BukkitRunnable;
6+
import org.bukkit.util.Vector;
67
import top.zoyn.particlelib.ParticleLib;
78

89
import java.util.List;
@@ -76,7 +77,17 @@ public List<Location> calculateLocations() {
7677
double x = xScaleRate * Math.sin(t) * Math.cos(t) * Math.log(Math.abs(t));
7778
double y = yScaleRate * Math.sqrt(Math.abs(t)) * Math.cos(t);
7879

79-
points.add(getOrigin().clone().add(x, 0, y));
80+
Location showLocation = getOrigin().clone().add(x, 0, y);
81+
if (hasMatrix()) {
82+
Vector vector = new Vector(x, 0, y);
83+
Vector changed = getMatrix().applyVector(vector);
84+
85+
showLocation = getOrigin().clone().add(changed);
86+
}
87+
88+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
89+
points.add(showLocation);
90+
// points.add(getOrigin().clone().add(x, 0, y));
8091
}
8192
return points;
8293
}

src/main/java/top/zoyn/particlelib/pobject/Lotus.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import com.google.common.collect.Lists;
44
import org.bukkit.Location;
5+
import org.bukkit.util.Vector;
56
import top.zoyn.particlelib.utils.LocationUtils;
67

78
import java.util.List;
9+
import java.util.stream.Collectors;
810

911
public class Lotus extends ParticleObject {
1012

@@ -63,7 +65,19 @@ public List<Location> calculateLocations() {
6365

6466
points.add(spawn);
6567
}
66-
return points;
68+
// 做一个对 Matrix 和 Increment 的兼容
69+
return points.stream().map(location -> {
70+
Location showLocation = location;
71+
if (hasMatrix()) {
72+
Vector v = new Vector(location.getX() - getOrigin().getX(), location.getY() - getOrigin().getY(), location.getZ() - getOrigin().getZ());
73+
Vector changed = getMatrix().applyVector(v);
74+
75+
showLocation = getOrigin().clone().add(changed);
76+
}
77+
78+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
79+
return showLocation;
80+
}).collect(Collectors.toList());
6781
}
6882

6983
@Override

src/main/java/top/zoyn/particlelib/pobject/NStar.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import top.zoyn.particlelib.utils.VectorUtils;
77

88
import java.util.List;
9+
import java.util.stream.Collectors;
910

1011
/**
1112
* 表示一个N角星, N必须是一个奇数
@@ -57,7 +58,19 @@ public List<Location> calculateLocations() {
5758

5859
VectorUtils.rotateAroundAxisY(START, 180 - angle / 2);
5960
}
60-
return points;
61+
// 做一个对 Matrix 和 Increment 的兼容
62+
return points.stream().map(location -> {
63+
Location showLocation = location;
64+
if (hasMatrix()) {
65+
Vector v = new Vector(location.getX() - getOrigin().getX(), location.getY() - getOrigin().getY(), location.getZ() - getOrigin().getZ());
66+
Vector changed = getMatrix().applyVector(v);
67+
68+
showLocation = getOrigin().clone().add(changed);
69+
}
70+
71+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
72+
return showLocation;
73+
}).collect(Collectors.toList());
6174
}
6275

6376
@Override

src/main/java/top/zoyn/particlelib/pobject/OctagonalStar.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import top.zoyn.particlelib.utils.VectorUtils;
77

88
import java.util.List;
9+
import java.util.stream.Collectors;
910

1011
/**
1112
* 表示一个八角星
@@ -50,7 +51,19 @@ public List<Location> calculateLocations() {
5051

5152
VectorUtils.rotateAroundAxisY(START, 135);
5253
}
53-
return points;
54+
// 做一个对 Matrix 和 Increment 的兼容
55+
return points.stream().map(location -> {
56+
Location showLocation = location;
57+
if (hasMatrix()) {
58+
Vector v = new Vector(location.getX() - getOrigin().getX(), location.getY() - getOrigin().getY(), location.getZ() - getOrigin().getZ());
59+
Vector changed = getMatrix().applyVector(v);
60+
61+
showLocation = getOrigin().clone().add(changed);
62+
}
63+
64+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
65+
return showLocation;
66+
}).collect(Collectors.toList());
5467
}
5568

5669
@Override

src/main/java/top/zoyn/particlelib/pobject/Polygon.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.zoyn.particlelib.pobject;
22

3+
import com.google.common.collect.Lists;
34
import org.bukkit.Location;
45
import org.bukkit.scheduler.BukkitRunnable;
56
import org.bukkit.util.Vector;
@@ -8,6 +9,7 @@
89

910
import java.util.ArrayList;
1011
import java.util.List;
12+
import java.util.stream.Collectors;
1113

1214
/**
1315
* 表示一个多边形
@@ -67,8 +69,47 @@ public void setStep(double step) {
6769

6870
@Override
6971
public List<Location> calculateLocations() {
70-
resetLocations();
71-
return locations;
72+
List<Location> points = Lists.newArrayList();
73+
List<Location> temp = Lists.newArrayList();
74+
75+
for (double angle = 0; angle <= 360; angle += 360D / side) {
76+
double radians = Math.toRadians(angle);
77+
double x = Math.cos(radians);
78+
double z = Math.sin(radians);
79+
80+
temp.add(getOrigin().clone().add(x, 0, z));
81+
}
82+
for (int i = 0; i < temp.size(); i++) {
83+
if (i + 1 == temp.size()) {
84+
Vector vectorAB = temp.get(i).clone().subtract(temp.get(0)).toVector();
85+
double vectorLength = vectorAB.length();
86+
vectorAB.normalize();
87+
for (double j = 0; j < vectorLength; j += step) {
88+
points.add(temp.get(0).clone().add(vectorAB.clone().multiply(j)));
89+
}
90+
break;
91+
}
92+
93+
Vector vectorAB = temp.get(i + 1).clone().subtract(temp.get(i)).toVector();
94+
double vectorLength = vectorAB.length();
95+
vectorAB.normalize();
96+
for (double j = 0; j < vectorLength; j += step) {
97+
points.add(temp.get(i).clone().add(vectorAB.clone().multiply(j)));
98+
}
99+
}
100+
// 做一个对 Matrix 和 Increment 的兼容
101+
return points.stream().map(location -> {
102+
Location showLocation = location;
103+
if (hasMatrix()) {
104+
Vector v = new Vector(location.getX() - getOrigin().getX(), location.getY() - getOrigin().getY(), location.getZ() - getOrigin().getZ());
105+
Vector changed = getMatrix().applyVector(v);
106+
107+
showLocation = getOrigin().clone().add(changed);
108+
}
109+
110+
showLocation.add(getIncrementX(), getIncrementY(), getIncrementZ());
111+
return showLocation;
112+
}).collect(Collectors.toList());
72113
}
73114

74115
@Override

0 commit comments

Comments
 (0)