|
57 | 57 |
|
58 | 58 | ```kotlin |
59 | 59 | // 作为构造参数 |
60 | | -class TestEndRodEffect(val controlUUID: UUID) : ParticleEffect { |
| 60 | +class TestEndRodEffect(controlUUID: UUID) : ControlableParticleEffect(controlUUID) { |
61 | 61 | companion object { |
62 | 62 | @JvmStatic |
63 | 63 | val codec: MapCodec<TestEndRodEffect> = RecordCodecBuilder.mapCodec { |
@@ -131,11 +131,14 @@ class TestGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGro |
131 | 131 | withEffect({ |
132 | 132 | // 提供ParticleEffect (在display方法中 world.addParticle)使用 |
133 | 133 | // it类型为UUID |
134 | | - TestEndRodEffect(it) |
| 134 | + // 如果需要在这个位置设置一个ParticleGroup则使用 |
| 135 | + // ParticleDisplayer.withGroup(你的particleGroup) |
| 136 | + ParticleDisplayer.withSingle(TestEndRodEffect(it)) |
135 | 137 | }) { |
136 | 138 | // kt: this is ControlableParticle |
137 | 139 | // java: this instanceof ControlableParticle |
138 | 140 | // 用于初始化粒子信息 |
| 141 | + // 如果参数是withGroup 则不需要实现该方法 |
139 | 142 | color = Vector3f(230 / 255f, 130 / 255f, 60 / 255f) |
140 | 143 | this.maxAliveTick = this.maxAliveTick |
141 | 144 | } |
@@ -169,6 +172,8 @@ class TestGroupClient(uuid: UUID, val bindPlayer: UUID) : ControlableParticleGro |
169 | 172 |
|
170 | 173 | ```kotlin |
171 | 174 | ClientParticleGroupManager.register( |
| 175 | + // 如果这个particleGroup的 loadParticleLocations方法中输入了一个子ParticleGroup 这个子Group就无需在这注册 |
| 176 | + // 除非你需要ClientParticleGroupManager.addVisibleGroup(子Group) |
172 | 177 | TestGroupClient::class.java, TestGroupClient.Provider() |
173 | 178 | ) |
174 | 179 | ``` |
@@ -217,4 +222,91 @@ ServerParticleGroupManager.addParticleGroup( |
217 | 222 | 其余特殊用法可以查看 |
218 | 223 | cn.coostack.particles.control.group.ControlableParticleGroup 与 |
219 | 224 |
|
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 | +``` |
0 commit comments