Skip to content

Commit e2d1537

Browse files
committed
#
1 parent 19a654b commit e2d1537

19 files changed

Lines changed: 69 additions & 97 deletions

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ open class ControlableParticleData {
3232
buf.writeString(data.textureSheet.toString())
3333
buf.writeString(data.effect::class.java.name)
3434
buf.writeUuid(data.uuid)
35+
buf.writeDouble(data.speed)
3536
// val effectPacketCodec =
3637
// data.effect.getPacketCodec() as PacketCodec<RegistryByteBuf, ControlableParticleEffect>
3738
// effectPacketCodec.encode(buf, data.effect)
@@ -55,6 +56,7 @@ open class ControlableParticleData {
5556
effectUUID,
5657
Class.forName(effectType) as Class<ControlableParticleEffect>
5758
)
59+
val speed = buf.readDouble()
5860
// val effect = ParticleTypes.PACKET_CODEC.decode(buf) as ControlableParticleEffect
5961
return ControlableParticleData().apply {
6062
this.uuid = uuid
@@ -67,6 +69,7 @@ open class ControlableParticleData {
6769
this.maxAge = maxAge
6870
this.textureSheet = this.textureSheetFromString(textureSheet)
6971
this.effect = effect
72+
this.speed = speed
7073
}
7174
}
7275
}
@@ -82,6 +85,10 @@ open class ControlableParticleData {
8285
var effect: ControlableParticleEffect = TestEndRodEffect(uuid)
8386
var textureSheet = ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT
8487

88+
/**
89+
* 粒子移动速度
90+
*/
91+
var speed: Double = 1.0
8592
fun textureSheetFromString(sheet: String): ParticleTextureSheet? {
8693
return when (sheet) {
8794
ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT.toString() -> ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT
@@ -99,7 +106,7 @@ open class ControlableParticleData {
99106
}
100107

101108

102-
fun clone(): ControlableParticleData {
109+
open fun clone(): ControlableParticleData {
103110
return ControlableParticleData().also {
104111
it.uuid = UUID.randomUUID()
105112
it.velocity = this.velocity
@@ -112,6 +119,7 @@ open class ControlableParticleData {
112119
it.maxAge = this.maxAge
113120
it.effect = this.effect.clone()
114121
it.textureSheet = this.textureSheet
122+
it.speed = this.speed
115123
}
116124
}
117125
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ interface ParticleEmitters {
2424
var uuid: UUID
2525
var cancelled: Boolean
2626
var playing: Boolean
27-
2827
fun getEmittersID(): String
28+
2929
/**
3030
* 发射粒子
3131
* 服务器发包
@@ -38,6 +38,7 @@ interface ParticleEmitters {
3838
fun tick()
3939

4040
fun spawnParticle()
41+
4142
/**
4243
* 更新发射器属性状态
4344
* 服务器发包到客户端

src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/impl/PhysicsParticleEmitters.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,12 @@ class PhysicsParticleEmitters(
215215
val actualPositions = shootType.getPositions(currentPos, tick, actualCount)
216216
actualPositions.forEach {
217217
val newData = templateData.clone()
218-
val v = shootType.getDefaultDirection(newData.velocity, tick, it, currentPos)
218+
val v = shootType.getDefaultDirection(
219+
newData.velocity,
220+
tick,
221+
it,
222+
currentPos
223+
).normalize().multiply(newData.speed)
219224
newData.velocity = v
220225
spawnParticle(world, it, newData)
221226
}

src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/impl/SimpleParticleEmitters.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class SimpleParticleEmitters(
180180
actualPositions.forEach {
181181
val newData = templateData.clone()
182182
val v = shootType.getDefaultDirection(newData.velocity, tick, it, currentPos)
183+
.normalize().multiply(newData.speed)
183184
newData.velocity = v
184185
spawnParticle(world, it, newData)
185186
}

src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/type/BoxEmittersShootType.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ class BoxEmittersShootType(val box: HitBox) : EmittersShootType {
6565
}
6666

6767
override fun getDefaultDirection(enter: Vec3d, tick: Int, pos: Vec3d, origin: Vec3d): Vec3d {
68+
if (enter.length() < 1e-7) {
69+
// 随机速度
70+
val p = Vec3d(
71+
random.nextDouble(-1.0, 1.0),
72+
random.nextDouble(-1.0, 1.0),
73+
random.nextDouble(-1.0, 1.0)
74+
)
75+
return p
76+
}
6877
return enter
6978
}
7079
}

src/main/kotlin/cn/coostack/cooparticlesapi/network/particle/emitters/type/PointEmittersShootType.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cn.coostack.cooparticlesapi.network.particle.emitters.type
33
import net.minecraft.network.RegistryByteBuf
44
import net.minecraft.network.codec.PacketCodec
55
import net.minecraft.util.math.Vec3d
6+
import kotlin.random.Random
67

78
class PointEmittersShootType : EmittersShootType {
89
companion object {
@@ -31,6 +32,16 @@ class PointEmittersShootType : EmittersShootType {
3132
}
3233

3334
override fun getDefaultDirection(enter: Vec3d, tick: Int, pos: Vec3d, origin: Vec3d): Vec3d {
35+
val random = Random(System.currentTimeMillis())
36+
if (enter.length() < 1e-7) {
37+
// 随机速度
38+
val p = Vec3d(
39+
random.nextDouble(-1.0, 1.0),
40+
random.nextDouble(-1.0, 1.0),
41+
random.nextDouble(-1.0, 1.0)
42+
)
43+
return p
44+
}
3445
return enter
3546
}
3647
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
8080
* 此参数所指向的状态为false
8181
*/
8282
var particleLinkageDisplayCurrentIndex = 0
83-
private set(value) {
84-
field = value.coerceIn(0, getParticlesCount() - 1)
85-
}
83+
private set
8684

8785
/**
8886
* @return 当前粒子样式的样式个数 (客户端执行getCurrentFramesSequenced返回的集合长度)
@@ -461,7 +459,7 @@ abstract class SequencedParticleStyle(visibleRange: Double = 32.0, uuid: UUID =
461459
}
462460

463461
private fun toggleFromStatus(index: Int, status: Boolean) {
464-
if (index >= sequencedParticles.size && client) return
462+
if (index >= sequencedParticles.size && client || index > getParticlesCount()) return
465463
if (status && client) {
466464
createWithIndex(index)
467465
} else {

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main/kotlin/cn/coostack/cooparticlesapi/utils/helper/HelperUtil.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ import cn.coostack.cooparticlesapi.utils.helper.impl.StyleProgressSequencedHelpe
1111
import cn.coostack.cooparticlesapi.utils.helper.impl.StyleScaleHelper
1212
import cn.coostack.cooparticlesapi.utils.helper.impl.StyleStatusHelper
1313

14+
/**
15+
* 所有Helper使用规范
16+
* 必须在构造函数内调用Helper.loadControler()方法
17+
* 否则无法使用此类!
18+
*/
1419
object HelperUtil {
1520

16-
fun sequencedStyle(maxCount: Int, progressMaxTick: Int): ProgressSequencedHelper {
21+
fun sequencedStyle(maxCount: Int, progressMaxTick: Int): StyleProgressSequencedHelper {
1722
return StyleProgressSequencedHelper(
1823
maxCount, progressMaxTick,
1924
)
2025
}
2126

22-
fun sequencedGroup(maxCount: Int, progressMaxTick: Int): ProgressSequencedHelper {
27+
fun sequencedGroup(maxCount: Int, progressMaxTick: Int): GroupProgressSequencedHelper {
2328
return GroupProgressSequencedHelper(
2429
maxCount, progressMaxTick,
2530
)
2631
}
2732

28-
fun scaleStyle(minScale: Double, maxScale: Double, scaleTick: Int): ScaleHelper =
33+
fun scaleStyle(minScale: Double, maxScale: Double, scaleTick: Int): StyleScaleHelper =
2934
StyleScaleHelper(minScale, maxScale, scaleTick)
3035

3136
fun bezierValueScaleStyle(
@@ -43,21 +48,21 @@ object HelperUtil {
4348
scaleTick: Int,
4449
c1: RelativeLocation,
4550
c2: RelativeLocation
46-
): BezierValueScaleHelper {
51+
): GroupBezierValueScaleHelper {
4752
return GroupBezierValueScaleHelper(scaleTick, minScale, maxScale, c1, c2)
4853
}
4954

50-
fun scaleGroup(minScale: Double, maxScale: Double, scaleTick: Int): ScaleHelper =
55+
fun scaleGroup(minScale: Double, maxScale: Double, scaleTick: Int): GroupScaleHelper =
5156
GroupScaleHelper(minScale, maxScale, scaleTick)
5257

53-
fun styleStatus(closedInterval: Int): StatusHelper =
58+
fun styleStatus(closedInterval: Int): StyleStatusHelper =
5459
StyleStatusHelper().apply { this.closedInternal = closedInterval }
5560

56-
fun alphaStyle(minAlpha: Double, maxAlpha: Double, alphaTick: Int): AlphaHelper {
61+
fun alphaStyle(minAlpha: Double, maxAlpha: Double, alphaTick: Int): StyleAlphaHelper {
5762
return StyleAlphaHelper(minAlpha, maxAlpha, alphaTick)
5863
}
5964

60-
fun particleAlpha(minAlpha: Double, maxAlpha: Double, alphaTick: Int): AlphaHelper {
65+
fun particleAlpha(minAlpha: Double, maxAlpha: Double, alphaTick: Int): ParticleAlphaHelper {
6166
return ParticleAlphaHelper(minAlpha, maxAlpha, alphaTick)
6267
}
6368

src/main/kotlin/cn/coostack/cooparticlesapi/utils/helper/StatusHelper.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,11 @@ abstract class StatusHelper : ParticleHelper {
4444
val enter = status.coerceIn(1, 2)
4545
this.displayStatus = enter
4646

47-
if (enter == 2) {
48-
setClosedAge()
49-
}
5047
changeStatus(status)
5148
}
5249

5350
fun setStatus(status: Status) {
5451
this.displayStatus = status.id
55-
56-
if (status == Status.DISABLE) {
57-
setClosedAge()
58-
}
5952
changeStatus(status.id)
6053
}
6154

@@ -80,7 +73,6 @@ abstract class StatusHelper : ParticleHelper {
8073
*/
8174
abstract fun changeStatus(status: Int)
8275

83-
abstract fun setClosedAge()
8476
abstract fun initHelper()
8577

8678
}

0 commit comments

Comments
 (0)