Skip to content

Commit be2529a

Browse files
committed
ServerControler 可以查看是否消散
修复CodecHelper不能实例化 Empty Stack的问题
1 parent 3e3f03f commit be2529a

14 files changed

Lines changed: 39 additions & 11 deletions

File tree

common/src/main/kotlin/cn/coostack/cooparticlesapi/annotations/codec/CodecHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ object CodecHelper {
7575
}, {
7676
HitBox(it.readDouble(), it.readDouble(), it.readDouble(), it.readDouble(), it.readDouble(), it.readDouble())
7777
}))
78-
register(ItemStack::class.java, ItemStack.STREAM_CODEC)
78+
register(ItemStack::class.java, ItemStack.OPTIONAL_STREAM_CODEC)
7979
register(SimpleRandomParticleData::class.java, SimpleRandomParticleData.PACKET_CODEC)
8080
register(RelativeLocation::class.java, StreamCodec.of({ buf, r ->
8181
buf.apply {

common/src/main/kotlin/cn/coostack/cooparticlesapi/api/controler/server/ServerControler.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ interface ServerControler<T> {
2323
fun spawn(world: Level, pos: Vec3)
2424

2525
fun getValue(): T
26+
27+
fun isValid(): Boolean
28+
2629
}

common/src/main/kotlin/cn/coostack/cooparticlesapi/display/DisplayEntity.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ abstract class DisplayEntity(
8383
var prevScale = 1f
8484
var scale = 1f
8585

86-
var valid = true
87-
private set
86+
private var valid = true
8887

8988
/**
9089
* 由 DisplayEntityManager计算模型旋转
@@ -298,6 +297,10 @@ abstract class DisplayEntity(
298297
)
299298
}
300299

300+
override fun isValid(): Boolean {
301+
return valid
302+
}
303+
301304
override fun getValue(): DisplayEntity {
302305
return this
303306
}

common/src/main/kotlin/cn/coostack/cooparticlesapi/display/DisplayEntityManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ object DisplayEntityManager {
130130
while (iterator.hasNext()) {
131131
val entry = iterator.next()
132132
entry.value.tick()
133-
if (!entry.value.valid) {
133+
if (!entry.value.isValid()) {
134134
iterator.remove()
135135
}
136136
}
@@ -141,7 +141,7 @@ object DisplayEntityManager {
141141
while (iterator.hasNext()) {
142142
val entry = iterator.next()
143143
entry.value.tick()
144-
if (!entry.value.valid) {
144+
if (!entry.value.isValid()) {
145145
iterator.remove()
146146
}
147147
sendCreateOrUpdate(entry.value)

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/ServerParticleGroup.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ abstract class ServerParticleGroup(
3131
internal set
3232
var world: Level? = null
3333
internal set
34-
var valid = true
35-
internal set
34+
internal var valid = true
3635
var canceled = false
3736
internal set
3837

@@ -322,5 +321,8 @@ abstract class ServerParticleGroup(
322321
this.clientMaxTick = maxTick
323322
}
324323

324+
override fun isValid(): Boolean {
325+
return valid
326+
}
325327

326328
}

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/composition/ParticleComposition.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ abstract class ParticleComposition(var position: Vec3, var world: Level? = null)
388388
return this
389389
}
390390

391+
override fun isValid(): Boolean {
392+
return !canceled
393+
}
394+
391395
protected open fun displayEntry(data: CompositionData, pos: RelativeLocation) {
392396
val uuid = data.uuid
393397
val displayer = data.displayerBuilder(uuid)

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/ClassEmitters.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ abstract class ClassEmitters(
372372
}
373373
}
374374

375+
375376
/**
376377
* 数据同步需要实现此方法。
377378
*

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/ClassParticleEmitters.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ abstract class ClassParticleEmitters(
485485
data.velocity = v.add(a)
486486
}
487487

488+
489+
488490
/**
489491
* # 处理单个粒子的位移位置
490492
* - 方便更真实的物理模拟

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/ParticleEmitters.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ interface ParticleEmitters : ServerControler<ParticleEmitters> {
8585
ParticleEmittersManager.spawnEmitters(this)
8686
}
8787

88+
override fun isValid(): Boolean {
89+
return !cancelled
90+
}
91+
8892
override fun rotateAsAxis(radian: Double) {
8993
}
9094

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/style/ParticleGroupStyle.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ abstract class ParticleGroupStyle(var visibleRange: Double = 32.0, val uuid: UUI
5959

6060
var displayed = false
6161
internal set
62-
var valid = true
63-
internal set
62+
internal var valid = true
6463
internal val invokeQueue = ArrayList<ParticleGroupStyle.() -> Unit>()
6564
val particles = ConcurrentHashMap<UUID, Controlable<*>>()
6665
val particleLocations = ConcurrentHashMap<Controlable<*>, RelativeLocation>()
6766

67+
override fun isValid(): Boolean {
68+
return valid
69+
}
6870

6971
/** 当粒子组合初始化时, 存储1倍缩放粒子组与原点的距离 */
7072
val particleDefaultLength = ConcurrentHashMap<UUID, Double>()

0 commit comments

Comments
 (0)