Skip to content

Commit e6bc5d3

Browse files
committed
更新Math3DUti
修改一些示例类的代码
1 parent 50bd1cb commit e6bc5d3

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ loader_version=0.16.10
1010
fabric_kotlin_version=1.13.1+kotlin.2.1.10
1111

1212
# Mod Properties
13-
mod_version=1.3
13+
mod_version=1.31
1414
maven_group=cn.coostack
1515
archives_base_name=coo-particles-api
1616

src/main/kotlin/cn/coostack/items/TestParticleItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestParticleItem(settings: Settings) : Item(settings) {
2121
if (world.isClient) {
2222
return TypedActionResult.success(user.getStackInHand(hand))
2323
}
24-
val serverGroup = ScaleCircleGroupServer(user as ServerPlayerEntity)
24+
val serverGroup = ScaleCircleGroupServer(user.uuid)
2525
ServerParticleGroupManager.addParticleGroup(
2626
ScaleCircleGroupClient::class.java, serverGroup, user.pos, world as ServerWorld
2727
)

src/main/kotlin/cn/coostack/network/particle/ScaleCircleGroupServer.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import net.minecraft.server.network.ServerPlayerEntity
77
import net.minecraft.server.world.ServerWorld
88
import java.util.*
99

10-
class ScaleCircleGroupServer(private val bindPlayer: ServerPlayerEntity, visibleRange: Double = 32.0) :
10+
class ScaleCircleGroupServer(private val bindPlayerUUID: UUID, visibleRange: Double = 32.0) :
1111
ServerParticleGroup(visibleRange) {
1212
private var anTick = 0
1313
private var anMaxTick = 30
@@ -18,15 +18,24 @@ class ScaleCircleGroupServer(private val bindPlayer: ServerPlayerEntity, visible
1818
}
1919

2020
override fun tick() {
21+
val bindPlayer = world!!.getPlayerByUuid(bindPlayerUUID) ?: let {
22+
kill()
23+
return
24+
}
2125
doTickAlive()
2226
if (anTick++ >= anMaxTick) {
2327
anTick = anMaxTick
2428
}
25-
teleportGroupTo(bindPlayer.pos)
29+
setPosOnServer(bindPlayer.pos)
30+
withPlayerStats(bindPlayer as ServerPlayerEntity)
2631
}
2732

2833
override fun onTickAliveDeath() {
29-
val group = TestParticleGroup(bindPlayer)
34+
val bindPlayer = world!!.getPlayerByUuid(bindPlayerUUID) ?: let {
35+
kill()
36+
return
37+
}
38+
val group = TestParticleGroup(bindPlayerUUID)
3039
ServerParticleGroupManager.addParticleGroup(
3140
TestGroupClient::class.java,
3241
group,
@@ -37,7 +46,7 @@ class ScaleCircleGroupServer(private val bindPlayer: ServerPlayerEntity, visible
3746

3847
override fun otherPacketArgs(): Map<String, ParticleControlerDataBuffer<out Any>> {
3948
return mapOf(
40-
"bind_player" to ParticleControlerDataBuffers.uuid(bindPlayer.uuid),
49+
"bind_player" to ParticleControlerDataBuffers.uuid(bindPlayerUUID),
4150
"an_tick" to ParticleControlerDataBuffers.int(anTick),
4251
"tick" to ParticleControlerDataBuffers.int(tick),
4352
"max_tick" to ParticleControlerDataBuffers.int(maxTick)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ abstract class ServerParticleGroup(
220220
/**
221221
* 发送行为修改包
222222
* @param toggleMethod 修改Server层的参数的方法 如果不用此修改方法则会导致其他客户端渲染不同步
223+
* @param args 此参数出现过的键 必须在otherPacketArgs方法返回的args中存在 否则任然会存在同步问题
223224
*/
224225
fun change(toggleMethod: ServerParticleGroup.() -> Unit, args: Map<String, ParticleControlerDataBuffer<*>>) {
225226
world ?: return

src/main/kotlin/cn/coostack/network/particle/TestParticleGroup.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import cn.coostack.network.buffer.ParticleControlerDataBuffers
55
import net.minecraft.server.network.ServerPlayerEntity
66
import java.util.*
77

8-
class TestParticleGroup(private val bindPlayer: ServerPlayerEntity) : ServerParticleGroup(16.0) {
8+
class TestParticleGroup(private val bindPlayerUUID: UUID) : ServerParticleGroup(16.0) {
99
override fun tick() {
10-
withPlayerStats(bindPlayer)
10+
val bindPlayer = world!!.getPlayerByUuid(bindPlayerUUID)?: let {
11+
kill()
12+
return
13+
}
14+
withPlayerStats(bindPlayer as ServerPlayerEntity)
1115
setPosOnServer(bindPlayer.eyePos)
1216
}
1317

1418
override fun otherPacketArgs(): Map<String, ParticleControlerDataBuffer<out Any>> {
1519
return mapOf(
16-
"bindUUID" to ParticleControlerDataBuffers.uuid(bindPlayer.uuid)
20+
"bindUUID" to ParticleControlerDataBuffers.uuid(bindPlayerUUID)
1721
)
1822
}
1923
}

src/main/kotlin/cn/coostack/particles/control/group/ControlableParticleGroup.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ abstract class ControlableParticleGroup(val uuid: UUID) : Controlable<Controlabl
108108
displayParticles(origin, world!!)
109109
}
110110

111+
112+
111113
fun display(pos: Vec3d, world: ClientWorld) {
112114
if (displayed) {
113115
return

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ object Math3DUtil {
1111
return Vector3f(x.toFloat() / 255, y.toFloat() / 255, z.toFloat() / 255)
1212
}
1313

14-
1514
/**
1615
* DeepSeek解放大脑
1716
* @see getCycloidGraphic 获取此函数生成的图像的顶点
@@ -227,6 +226,37 @@ object Math3DUtil {
227226
return Math.toRadians(90.0) - acos(dot / l)
228227
}
229228

229+
/**
230+
* 获取在start-end线段内的count个点集合
231+
*/
232+
fun getLineLocations(start: Vec3d, end: Vec3d, count: Int): List<RelativeLocation> {
233+
val origin = RelativeLocation.of(start)
234+
val res = mutableListOf(origin)
235+
val step = start.distanceTo(end) / count
236+
val direction = start.relativize(end).normalize().multiply(step)
237+
val relativeDirection = RelativeLocation.of(direction)
238+
for (i in 2..count) {
239+
val next = origin + relativeDirection
240+
res.add(next)
241+
}
242+
return res
243+
}
244+
245+
/**
246+
* 获取 从origin 向 direction方向的射线上 每个间距为 step 且总数量为count的点集合
247+
*/
248+
fun getLineLocations(origin: Vec3d, direction: Vec3d, step: Double, count: Int): List<RelativeLocation> {
249+
val originRel = RelativeLocation.of(origin)
250+
val res = mutableListOf(originRel)
251+
val relativeDirection =
252+
RelativeLocation.of(Vec3d(direction.x, direction.y, direction.z).normalize().multiply(step))
253+
for (i in 2..count) {
254+
val next = originRel + relativeDirection
255+
res.add(next)
256+
}
257+
return res
258+
}
259+
230260
/**
231261
* 旋转是通过旋转x/z 轴来坐标值的
232262
* 由于sqrt pow 是恒大于0的值因此不能用于坐标求值

0 commit comments

Comments
 (0)