Skip to content

Commit 034fbfe

Browse files
committed
现在ControlableParticleGroup支持在生成粒子时输入一个子ParticleGroup
子ParticleGroup无需注册Provider 优化了粒子传送时的移动, 现在进行复杂运动(例如旋转+位移) 更加流畅
1 parent dda2cbc commit 034fbfe

File tree

2 files changed

+96
-4
lines changed

2 files changed

+96
-4
lines changed

README.md

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
```kotlin
5959
// 作为构造参数
60-
class TestEndRodEffect(val controlUUID: UUID) : ParticleEffect {
60+
class TestEndRodEffect(controlUUID: UUID) : ControlableParticleEffect(controlUUID) {
6161
companion object {
6262
@JvmStatic
6363
val codec: MapCodec<TestEndRodEffect> = RecordCodecBuilder.mapCodec {
@@ -131,11 +131,14 @@ class TestGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGro
131131
withEffect({
132132
// 提供ParticleEffect (在display方法中 world.addParticle)使用
133133
// it类型为UUID
134-
TestEndRodEffect(it)
134+
// 如果需要在这个位置设置一个ParticleGroup则使用
135+
// ParticleDisplayer.withGroup(你的particleGroup)
136+
ParticleDisplayer.withSingle(TestEndRodEffect(it))
135137
}) {
136138
// kt: this is ControlableParticle
137139
// java: this instanceof ControlableParticle
138140
// 用于初始化粒子信息
141+
// 如果参数是withGroup 则不需要实现该方法
139142
color = Vector3f(230 / 255f, 130 / 255f, 60 / 255f)
140143
this.maxAliveTick = this.maxAliveTick
141144
}
@@ -169,6 +172,8 @@ class TestGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGro
169172

170173
```kotlin
171174
ClientParticleGroupManager.register(
175+
// 如果这个particleGroup的 loadParticleLocations方法中输入了一个子ParticleGroup 这个子Group就无需在这注册
176+
// 除非你需要ClientParticleGroupManager.addVisibleGroup(子Group)
172177
TestGroupClient::class.java, TestGroupClient.Provider()
173178
)
174179
```
@@ -217,4 +222,91 @@ ServerParticleGroupManager.addParticleGroup(
217222
其余特殊用法可以查看
218223
cn.coostack.particles.control.group.ControlableParticleGroup 与
219224

220-
cn.coostack.network.particle.ServerParticleGroup
225+
cn.coostack.network.particle.ServerParticleGroup
226+
227+
228+
#### ParticleGroup嵌套示例
229+
- 主ParticleGroup:
230+
```kotlin
231+
class TestGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGroup(uuid) {
232+
233+
class Provider : ControlableParticleGroupProvider {
234+
override fun createGroup(
235+
uuid: UUID,
236+
args: Map<String, ParticleControlerDataBuffer<*>>
237+
): ControlableParticleGroup {
238+
val bindUUID = args["bindUUID"]!!.loadedValue as UUID
239+
return TestGroupClient(uuid, bindUUID)
240+
}
241+
}
242+
243+
override fun loadParticleLocations(): Map<ParticleRelativeData, RelativeLocation> {
244+
val r1 = 3.0
245+
val r2 = 5.0
246+
val w1 = -2
247+
val w2 = 3
248+
val scale = 1.0
249+
val count = 360
250+
val list = Math3DUtil.getCycloidGraphic(r1, r2, w1, w2, count, scale).onEach { it.y += 6 }
251+
val map = list.associateBy {
252+
withEffect({ ParticleDisplayer.withSingle(TestEndRodEffect(it)) }) {
253+
color = Vector3f(230 / 255f, 130 / 255f, 60 / 255f)
254+
this.maxAliveTick = this.maxAliveTick
255+
}
256+
}
257+
val mutable = map.toMutableMap()
258+
// 获取此参数下生成图像的顶点
259+
for (rel in Math3DUtil.computeCycloidVertices(r1, r2, w1, w2, count, scale)) {
260+
// 在这些顶点上设置一个SubParticleGroup
261+
mutable[withEffect({ u -> ParticleDisplayer.withGroup(TestSubGroupClient(u, bindPlayer)) }) {}] =
262+
rel.clone()
263+
}
264+
return mutable
265+
}
266+
267+
268+
override fun onGroupDisplay() {
269+
MinecraftClient.getInstance().player?.sendMessage(Text.of("发送粒子: ${this::class.java.name} 成功"))
270+
addPreTickAction {
271+
// 这种方法就是其他人看到的话粒子会显示在他们的头上而不是某个玩家的头上....
272+
val bindPlayerEntity = world!!.getPlayerByUuid(bindPlayer) ?: let {
273+
return@addPreTickAction
274+
}
275+
teleportTo(bindPlayerEntity.eyePos)
276+
rotateToWithAngle(
277+
RelativeLocation.of(bindPlayerEntity.rotationVector),
278+
Math.toRadians(10.0)
279+
)
280+
}
281+
}
282+
}
283+
```
284+
子ParticleGroup实例
285+
```kotlin
286+
class TestSubGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGroup(uuid) {
287+
288+
override fun loadParticleLocations(): Map<ParticleRelativeData, RelativeLocation> {
289+
val list = Math3DUtil.getCycloidGraphic(2.0, 2.0, -1, 2, 360, 1.0).onEach { it.y += 6 }
290+
return list.associateBy {
291+
withEffect({ ParticleDisplayer.withSingle(TestEndRodEffect(it)) }) {
292+
color = Vector3f(100 / 255f, 100 / 255f, 255 / 255f)
293+
this.maxAliveTick = this.maxAliveTick
294+
}
295+
}
296+
297+
}
298+
299+
300+
override fun onGroupDisplay() {
301+
addPreTickAction {
302+
val bindPlayerEntity = world!!.getPlayerByUuid(bindPlayer) ?: let {
303+
return@addPreTickAction
304+
}
305+
rotateToWithAngle(
306+
RelativeLocation.of(bindPlayerEntity.rotationVector),
307+
Math.toRadians(-10.0)
308+
)
309+
}
310+
}
311+
}
312+
```

src/main/kotlin/cn/coostack/particles/control/group/impl/TestGroupClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TestGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGro
5454
val bindPlayerEntity = world!!.getPlayerByUuid(bindPlayer) ?: let {
5555
return@addPreTickAction
5656
}
57-
teleportGroupTo(bindPlayerEntity.eyePos)
57+
teleportTo(bindPlayerEntity.eyePos)
5858
rotateToWithAngle(
5959
RelativeLocation.of(bindPlayerEntity.rotationVector),
6060
Math.toRadians(10.0)

0 commit comments

Comments
 (0)