Skip to content

Commit e166c09

Browse files
committed
update:
- 新增特效组功能 - 修复 ParticleObject#addMatrix NPE的问题 - 修复 Circle 使用 Matrix 失效的问题 - 对 Heart 增加可更改步长效果
1 parent 4398b5b commit e166c09

5 files changed

Lines changed: 304 additions & 24 deletions

File tree

src/top/zoyn/particlelib/ParticleLib.java

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@
44
import org.bukkit.Bukkit;
55
import org.bukkit.Location;
66
import org.bukkit.Particle;
7-
import org.bukkit.World;
87
import org.bukkit.block.Block;
98
import org.bukkit.command.Command;
109
import org.bukkit.command.CommandSender;
1110
import org.bukkit.entity.Player;
1211
import org.bukkit.plugin.java.JavaPlugin;
1312
import org.bukkit.util.Vector;
14-
import top.zoyn.particlelib.pobject.Arc;
15-
import top.zoyn.particlelib.pobject.Astroid;
16-
import top.zoyn.particlelib.pobject.Circle;
17-
import top.zoyn.particlelib.pobject.Grid;
18-
import top.zoyn.particlelib.utils.projector.ThreeDProjector;
19-
import top.zoyn.particlelib.utils.projector.TwoDProjector;
13+
import top.zoyn.particlelib.pobject.*;
14+
import top.zoyn.particlelib.utils.matrix.Matrixs;
2015

2116
import java.util.List;
2217
import java.util.concurrent.atomic.AtomicInteger;
23-
import java.util.function.BiFunction;
2418

2519
/**
2620
* 粒子库主类
@@ -48,6 +42,51 @@ public static void sendLog(String message) {
4842
Bukkit.getConsoleSender().sendMessage("§e[§6ParticleLib§e] " + message);
4943
}
5044

45+
/**
46+
* 围绕一个方块画出其边框
47+
*
48+
* @param block 给定的方块
49+
* @param particle 要显示的粒子
50+
*/
51+
public static void showBorderAboutBlock(Block block, Particle particle) {
52+
Location low = block.getLocation();
53+
Location high = low.clone().add(0, 1, 0);
54+
List<Location> lowers = Lists.newArrayList(
55+
low,
56+
low.clone().add(1, 0, 0),
57+
low.clone().add(1, 0, 1),
58+
low.clone().add(0, 0, 1));
59+
List<Location> highers = Lists.newArrayList(
60+
high,
61+
high.clone().add(1, 0, 0),
62+
high.clone().add(1, 0, 1),
63+
high.clone().add(0, 0, 1));
64+
for (int i = 0; i < lowers.size(); i++) {
65+
Location origin = lowers.get(i);
66+
Location top = highers.get(i);
67+
Location next;
68+
Location topNext;
69+
// 最后一个的时候
70+
if (i == 3) {
71+
next = lowers.get(0);
72+
topNext = highers.get(0);
73+
} else {
74+
next = lowers.get(i + 1);
75+
topNext = highers.get(i + 1);
76+
}
77+
78+
// 以下为画线操作
79+
Vector vectorON = next.clone().subtract(origin).toVector().normalize();
80+
Vector vectorOT = top.clone().subtract(origin).toVector().normalize();
81+
Vector vectorTT = topNext.clone().subtract(top).toVector().normalize();
82+
for (double j = 0; j < 1; j += 0.1) {
83+
low.getWorld().spawnParticle(particle, origin.clone().add(vectorON.clone().multiply(j)), 1, 0, 0, 0, 0);
84+
low.getWorld().spawnParticle(particle, origin.clone().add(vectorOT.clone().multiply(j)), 1, 0, 0, 0, 0);
85+
low.getWorld().spawnParticle(particle, top.clone().add(vectorTT.clone().multiply(j)), 1, 0, 0, 0, 0);
86+
}
87+
}
88+
}
89+
5190
/**
5291
* 围绕一个方块画出其边框
5392
*
@@ -123,19 +162,52 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
123162
// Bukkit.getScheduler().runTaskTimer(this, () -> showBorderAndGridAboutBlock(location.getBlock(), Particle.FIREWORKS_SPARK), 0L, 10L);
124163

125164

126-
// Circle circle = new Circle(player.getLocation());
127-
// circle.setStep(10D);
128-
// circle.setRadius(3D);
129-
// circle.setPeriod(2);
130-
// circle.play();
131-
// circle.alwaysPlayAsync();
132-
133-
// Astroid astroid = new Astroid(player.getLocation());
134-
// astroid.setParticle(Particle.FIREWORKS_SPARK);
135-
// astroid.setRadius(1.3D);
136-
// astroid.setStep(10D);
137-
// astroid.setPeriod(1L);
138-
// astroid.alwaysPlayAsync();
165+
Circle circle = new Circle(player.getLocation());
166+
circle.setStep(10D);
167+
168+
Astroid astroid = new Astroid(player.getLocation());
169+
astroid.setParticle(Particle.FIREWORKS_SPARK);
170+
astroid.setStep(10D);
171+
astroid.alwaysPlayAsync();
172+
173+
Heart heart = new Heart(player.getLocation());
174+
heart.setXScaleRate(1.5D);
175+
heart.setYScaleRate(1.5D);
176+
heart.setParticle(Particle.FLAME);
177+
heart.setStep(0.05D);
178+
179+
Heart heart2 = new Heart(player.getLocation());
180+
heart2.setXScaleRate(1.5D);
181+
heart2.setYScaleRate(1.5D);
182+
heart2.addMatrix(Matrixs.rotate2D(90));
183+
heart2.setParticle(Particle.FLAME);
184+
heart2.setStep(0.05D);
185+
186+
Heart heart3 = new Heart(player.getLocation());
187+
heart3.setXScaleRate(1.5D);
188+
heart3.setYScaleRate(1.5D);
189+
heart3.addMatrix(Matrixs.rotate2D(180));
190+
heart3.setParticle(Particle.FLAME);
191+
heart3.setStep(0.05D);
192+
193+
Heart heart4 = new Heart(player.getLocation());
194+
heart4.setXScaleRate(1.5D);
195+
heart4.setYScaleRate(1.5D);
196+
heart4.addMatrix(Matrixs.rotate2D(270));
197+
heart4.setParticle(Particle.FLAME);
198+
heart4.setStep(0.05D);
199+
200+
EffectGroup group = new EffectGroup()
201+
.addEffect(circle)
202+
.addEffect(astroid)
203+
.addEffect(heart)
204+
.addEffect(heart2)
205+
.addEffect(heart3)
206+
.addEffect(heart4)
207+
.scale(2)
208+
.rotate(45)
209+
.setPeriod(1)
210+
.alwaysPlayAsync();
139211

140212
// Arc arc = new Arc(player.getLocation());
141213
// arc.setAngle(360D);

src/top/zoyn/particlelib/pobject/Circle.java

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

33
import org.bukkit.Location;
4+
import top.zoyn.particlelib.utils.matrix.Matrix;
45

56
/**
67
* 表示一个圆
@@ -47,6 +48,26 @@ public Circle(Location origin, double radius, double step, long period) {
4748
fullArc.setPeriod(period);
4849
}
4950

51+
@Override
52+
public void addMatrix(Matrix matrix) {
53+
fullArc.addMatrix(matrix);
54+
}
55+
56+
@Override
57+
public void setMatrix(Matrix matrix) {
58+
fullArc.setMatrix(matrix);
59+
}
60+
61+
@Override
62+
public void removeMatrix() {
63+
fullArc.removeMatrix();
64+
}
65+
66+
@Override
67+
public boolean hasMatrix() {
68+
return fullArc.hasMatrix();
69+
}
70+
5071
@Override
5172
public void show() {
5273
fullArc.show();
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package top.zoyn.particlelib.pobject;
2+
3+
import com.google.common.collect.Lists;
4+
import top.zoyn.particlelib.utils.matrix.Matrixs;
5+
6+
import java.util.List;
7+
8+
/**
9+
* 代表一个特效组
10+
* <p>
11+
* 如果你要使用 EffectGroup#scale 这样的方法, 我不建议你将 2D 的特效和 3D 的特效放在一起
12+
* </p>
13+
*
14+
* @author Zoyn
15+
*/
16+
public class EffectGroup {
17+
18+
/**
19+
* 特效表
20+
*/
21+
private final List<ParticleObject> effectList;
22+
23+
public EffectGroup() {
24+
effectList = Lists.newArrayList();
25+
}
26+
27+
/**
28+
* 利用给定的特效列表构造出一个特效组
29+
*
30+
* @param effectList 特效列表
31+
*/
32+
public EffectGroup(List<ParticleObject> effectList) {
33+
this.effectList = effectList;
34+
}
35+
36+
/**
37+
* 往特效组添加一项特效
38+
*
39+
* @param particleObj 特效对象
40+
* @return {@link EffectGroup}
41+
*/
42+
public EffectGroup addEffect(ParticleObject particleObj) {
43+
effectList.add(particleObj);
44+
return this;
45+
}
46+
47+
/**
48+
* 利用给定的下标, 将特效组里的第 index-1 个特效进行删除
49+
*
50+
* @param index 下标
51+
* @return {@link EffectGroup}
52+
*/
53+
public EffectGroup removeEffect(int index) {
54+
effectList.remove(index);
55+
return this;
56+
}
57+
58+
/**
59+
* 利用给定的数字, 设置每一个特效的循环 tick
60+
*
61+
* @param period 循环tick
62+
* @return {@link EffectGroup}
63+
*/
64+
public EffectGroup setPeriod(long period) {
65+
effectList.forEach(effect -> effect.setPeriod(period));
66+
return this;
67+
}
68+
69+
/**
70+
* 将特效组内的特效进行缩小或扩大
71+
*
72+
* @param value 缩小或扩大的倍率
73+
* @return {@link EffectGroup}
74+
*/
75+
public EffectGroup scale(double value) {
76+
effectList.forEach(effect -> effect.addMatrix(Matrixs.scale(2, 2, value)));
77+
return this;
78+
}
79+
80+
/**
81+
* 将特效组内的特效进行旋转
82+
*
83+
* @param angle 旋转角度
84+
* @return {@link EffectGroup}
85+
*/
86+
public EffectGroup rotate(double angle) {
87+
effectList.forEach(effect -> effect.addMatrix(Matrixs.rotate2D(angle)));
88+
return this;
89+
}
90+
91+
/**
92+
* 将特效组内的特效一次性展现出来
93+
*
94+
* @return {@link EffectGroup}
95+
*/
96+
public EffectGroup show() {
97+
effectList.forEach(ParticleObject::show);
98+
return this;
99+
}
100+
101+
/**
102+
* 将特效组内的特效一直地展现出来
103+
*
104+
* @return {@link EffectGroup}
105+
*/
106+
public EffectGroup alwaysShow() {
107+
effectList.forEach(ParticleObject::alwaysShow);
108+
return this;
109+
}
110+
111+
/**
112+
* 将特效组内的特效一直且异步地展现出来
113+
*
114+
* @return {@link EffectGroup}
115+
*/
116+
public EffectGroup alwaysShowAsync() {
117+
effectList.forEach(ParticleObject::alwaysShowAsync);
118+
return this;
119+
}
120+
121+
/**
122+
* 将特效组内的特效同时播放出来
123+
*
124+
* @return {@link EffectGroup}
125+
*/
126+
public EffectGroup play() {
127+
for (ParticleObject pObj : effectList) {
128+
if (pObj instanceof Playable) {
129+
Playable playable = (Playable) pObj;
130+
playable.play();
131+
}
132+
}
133+
return this;
134+
}
135+
136+
/**
137+
* 将特效组内的特效一直地同时播放出来
138+
*
139+
* @return {@link EffectGroup}
140+
*/
141+
public EffectGroup alwaysPlay() {
142+
for (ParticleObject pObj : effectList) {
143+
if (pObj instanceof Playable) {
144+
pObj.alwaysPlay();
145+
}
146+
}
147+
return this;
148+
}
149+
150+
/**
151+
* 将特效组内的特效一直且异步地同时播放出来
152+
*
153+
* @return {@link EffectGroup}
154+
*/
155+
public EffectGroup alwaysPlayAsync() {
156+
for (ParticleObject pObj : effectList) {
157+
if (pObj instanceof Playable) {
158+
pObj.alwaysPlayAsync();
159+
}
160+
}
161+
return this;
162+
}
163+
164+
/**
165+
* 获取特效列表
166+
*
167+
* @return {@link List}
168+
*/
169+
public List<ParticleObject> getEffectList() {
170+
return effectList;
171+
}
172+
173+
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class Heart extends ParticleObject implements Playable {
1414
private double xScaleRate;
1515
private double yScaleRate;
1616

17+
private double step = 0.001D;
18+
1719
private double currentT = -1.0D;
1820

1921
/**
@@ -54,9 +56,17 @@ public void setYScaleRate(double yScaleRate) {
5456
this.yScaleRate = yScaleRate;
5557
}
5658

59+
public double getStep() {
60+
return step;
61+
}
62+
63+
public void setStep(double step) {
64+
this.step = step;
65+
}
66+
5767
@Override
5868
public void show() {
59-
for (double t = -1.0D; t <= 1.0D; t += 0.001D) {
69+
for (double t = -1.0D; t <= 1.0D; t += step) {
6070
double x = xScaleRate * Math.sin(t) * Math.cos(t) * Math.log(Math.abs(t));
6171
double y = yScaleRate * Math.sqrt(Math.abs(t)) * Math.cos(t);
6272

@@ -73,7 +83,7 @@ public void run() {
7383
cancel();
7484
return;
7585
}
76-
currentT += 0.001D;
86+
currentT += step;
7787
double x = xScaleRate * Math.sin(currentT) * Math.cos(currentT) * Math.log(Math.abs(currentT));
7888
double y = yScaleRate * Math.sqrt(Math.abs(currentT)) * Math.cos(currentT);
7989

@@ -84,7 +94,7 @@ public void run() {
8494

8595
@Override
8696
public void playNextPoint() {
87-
currentT += 0.001D;
97+
currentT += step;
8898
double x = xScaleRate * Math.sin(currentT) * Math.cos(currentT) * Math.log(Math.abs(currentT));
8999
double y = yScaleRate * Math.sqrt(Math.abs(currentT)) * Math.cos(currentT);
90100

0 commit comments

Comments
 (0)