Skip to content

Commit c3bf9fe

Browse files
committed
# 修复
SequencedParticleStyle 使用addMultiple时 会导致index变为0
1 parent d80e032 commit c3bf9fe

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ open class ParticleShapeStyle(uuid: UUID) :
4949
}
5050
}
5151
}
52+
var spawnAge = 0
5253

5354
/**
5455
* 设置为true时 会利用scaleHelper 每tick增长一点
@@ -137,6 +138,7 @@ open class ParticleShapeStyle(uuid: UUID) :
137138
override fun onDisplay() {
138139
onDisplayInvoke()
139140
addPreTickAction {
141+
spawnAge++
140142
if (!scalePreTick || scaleHelper == null) {
141143
return@addPreTickAction
142144
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SequencedParticleShapeStyle(uuid: UUID) :
4040
* 符合条件后 animationIndex 会递增
4141
* 直到到达边界
4242
*/
43-
private val animationConditions = ArrayList<Pair<Predicate<SequencedParticleStyle>, Int>>()
43+
private val animationConditions = ArrayList<Pair<Predicate<SequencedParticleShapeStyle>, Int>>()
4444
var animationIndex = 0
4545
private set
4646

@@ -65,6 +65,7 @@ class SequencedParticleShapeStyle(uuid: UUID) :
6565
}
6666
}
6767
}
68+
var spawnAge = 0
6869

6970
/**
7071
* 设置为true时 会利用scaleHelper 每tick增长一点
@@ -100,7 +101,10 @@ class SequencedParticleShapeStyle(uuid: UUID) :
100101
* @param predicate 设置添加/删除动画的要求
101102
* @param add 向下的个数
102103
*/
103-
fun appendAnimateCondition(predicate: Predicate<SequencedParticleStyle>, add: Int): SequencedParticleShapeStyle {
104+
fun appendAnimateCondition(
105+
predicate: Predicate<SequencedParticleShapeStyle>,
106+
add: Int
107+
): SequencedParticleShapeStyle {
104108
animationConditions.add(predicate to add)
105109
return this
106110
}
@@ -148,7 +152,7 @@ class SequencedParticleShapeStyle(uuid: UUID) :
148152
/**
149153
* 在生成粒子之前执行
150154
*/
151-
fun toggleBeforeDisplay(toggleMethod: SequencedParticleShapeStyle.(Map<SortedStyleData, RelativeLocation>) -> Unit): SequencedParticleShapeStyle {
155+
fun toggleBeforeDisplay(toggleMethod: SequencedParticleShapeStyle.(SortedMap<SortedStyleData, RelativeLocation>) -> Unit): SequencedParticleShapeStyle {
152156
beforeDisplayInvoke = toggleMethod
153157
return this
154158
}
@@ -176,6 +180,7 @@ class SequencedParticleShapeStyle(uuid: UUID) :
176180
}
177181
}
178182
addPreTickAction {
183+
spawnAge++
179184
if (!scalePreTick || scaleHelper == null) {
180185
return@addPreTickAction
181186
}
@@ -188,9 +193,13 @@ class SequencedParticleShapeStyle(uuid: UUID) :
188193
}
189194
}
190195

191-
private val bufferFrame: SortedMap<SortedStyleData, RelativeLocation> = TreeMap()
196+
private var count = -1
192197
override fun getParticlesCount(): Int {
193-
return bufferFrame.size
198+
// 调用此方法比初始化count早
199+
if (count == -1 || count == 0) {
200+
count = getCurrentFramesSequenced().size
201+
}
202+
return count
194203
}
195204

196205
override fun getCurrentFramesSequenced(): SortedMap<SortedStyleData, RelativeLocation> {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
8181
*/
8282
var particleLinkageDisplayCurrentIndex = 0
8383
private set(value) {
84-
field = value.coerceAtLeast(0)
84+
field = value.coerceIn(0, getParticlesCount() - 1)
8585
}
8686

8787
/**
@@ -127,6 +127,10 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
127127
if (count <= 0) {
128128
return
129129
}
130+
if (count == 1) {
131+
addSingle()
132+
return
133+
}
130134
if (!client) {
131135
// 处理服务器
132136
// 发包
@@ -139,7 +143,7 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
139143
)
140144
change({
141145
particleLinkageDisplayCurrentIndex =
142-
(particleLinkageDisplayCurrentIndex + count).coerceAtMost(sequencedParticles.size - 1)
146+
(particleLinkageDisplayCurrentIndex + count).coerceAtMost(getParticlesCount() - 1)
143147
}, args)
144148
return
145149
}
@@ -171,6 +175,10 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
171175
if (count <= 0) {
172176
return
173177
}
178+
if (count == 1) {
179+
removeSingle()
180+
return
181+
}
174182

175183
if (!client) {
176184
// 处理服务器

src/main/kotlin/cn/coostack/cooparticlesapi/utils/Math3DUtil.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ object Math3DUtil {
336336
toPoint: RelativeLocation,
337337
axis: RelativeLocation
338338
): List<RelativeLocation> {
339-
if (axis.cross(toPoint).length() in -1e-5..1e-5) {
339+
// 同向共线
340+
if (axis.cross(toPoint).length() in -1e-5..1e-5 && axis.dot(toPoint) > 0) {
340341
return locList
341342
}
342343
// 计算旋转角度

0 commit comments

Comments
 (0)