Skip to content

Commit 50bd1cb

Browse files
committed
支持刷新(重新生成) ParticleGroup (只限于客户端)
1 parent 6276787 commit 50bd1cb

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

src/main/kotlin/cn/coostack/particles/control/group/ControlableParticleGroup.kt

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ abstract class ControlableParticleGroup(val uuid: UUID) : Controlable<Controlabl
9696
(it.value.getControlObject() as ControlableParticleGroup).tick()
9797
}
9898
}
99+
/**
100+
* 清除所有粒子并且重新按照相对位置渲染
101+
*/
102+
fun flush() {
103+
// 即使flush也不会被处理
104+
// 如果没有display则不会出现origin world数据 因此也就无法进行操作
105+
if (canceled || !valid || !displayed) return
106+
clearParticles()
107+
valid = true
108+
displayParticles(origin, world!!)
109+
}
99110

100111
fun display(pos: Vec3d, world: ClientWorld) {
101112
if (displayed) {
@@ -104,27 +115,11 @@ abstract class ControlableParticleGroup(val uuid: UUID) : Controlable<Controlabl
104115
this.origin = pos
105116
this.world = world
106117
displayed = true
107-
for ((v, rl) in loadParticleLocations()) {
108-
val uuid = UUID.randomUUID()
109-
val particleDisplayer = v.effect(uuid)
110-
if (particleDisplayer is ParticleDisplayer.SingleParticleDisplayer) {
111-
val controler = ControlParticleManager.createControl(uuid)
112-
controler.initInvoker = v.invoker
113-
}
114-
val toPos = Vec3d(pos.x + rl.x, pos.y + rl.y, pos.z + rl.z)
115-
val controler = particleDisplayer.display(toPos, world) ?: continue
116-
if (controler is ParticleControler) {
117-
v.controlerAction(controler)
118-
}
119-
// world.addParticle(
120-
// v.effect(uuid), pos.x + rl.x, pos.y + rl.y, pos.z + rl.z, 0.0, 0.0, 0.0
121-
// )
122-
particles[uuid] = controler
123-
particlesLocations[controler] = rl
124-
}
118+
displayParticles(pos, world)
125119
onGroupDisplay()
126120
}
127121

122+
128123
override fun rotateParticlesToPoint(to: RelativeLocation) {
129124
if (!displayed) {
130125
return
@@ -202,6 +197,24 @@ abstract class ControlableParticleGroup(val uuid: UUID) : Controlable<Controlabl
202197
return this
203198
}
204199

200+
private fun displayParticles(pos: Vec3d, world: ClientWorld) {
201+
for ((v, rl) in loadParticleLocations()) {
202+
val uuid = UUID.randomUUID()
203+
val particleDisplayer = v.effect(uuid)
204+
if (particleDisplayer is ParticleDisplayer.SingleParticleDisplayer) {
205+
val controler = ControlParticleManager.createControl(uuid)
206+
controler.initInvoker = v.invoker
207+
}
208+
val toPos = Vec3d(pos.x + rl.x, pos.y + rl.y, pos.z + rl.z)
209+
val controler = particleDisplayer.display(toPos, world) ?: continue
210+
if (controler is ParticleControler) {
211+
v.controlerAction(controler)
212+
}
213+
particles[uuid] = controler
214+
particlesLocations[controler] = rl
215+
}
216+
}
217+
205218
class ParticleRelativeData(
206219
val effect: (UUID) -> ParticleDisplayer,
207220
val invoker: ControlableParticle.() -> Unit

src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"schemaVersion": 1,
3-
"id": "cooparticleapi",
3+
"id": "cooparticlesapi",
44
"version": "${version}",
55
"name": "CooParticleAPI",
66
"description": "此插件会修改粒子个数上限(使用mixin) 如果存在其他插件也使用了类似的方法可能会冲突",

0 commit comments

Comments
 (0)