Skip to content

Commit e85188b

Browse files
committed
修复RenderEntity无法在Flashback正常显示的问题
1 parent fc6d93a commit e85188b

File tree

6 files changed

+18
-24
lines changed

6 files changed

+18
-24
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
tasks.register("publish-all") {
1010
group("build")
1111
description = "上传Fabric和Neoforge的内容到仓库中"
12-
dependsOn(":neoforge:publish", ":fabric:publish", ":kapt:publish")
12+
dependsOn(":neoforge:publish", ":fabric:publish")
1313
}
1414

1515
subprojects {

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/packet/PacketRenderEntityS2C.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload
88
import net.minecraft.resources.ResourceLocation
99
import java.util.UUID
1010

11-
class PacketRenderEntityS2C(var uuid: UUID, var entityData: ByteBuf, var id: ResourceLocation, var method: Method) :
11+
class PacketRenderEntityS2C(var uuid: UUID, var entityData: ByteArray, var id: ResourceLocation, var method: Method) :
1212
CustomPacketPayload {
1313
enum class Method(val id: Int) {
1414
CREATE(0),
@@ -35,26 +35,26 @@ class PacketRenderEntityS2C(var uuid: UUID, var entityData: ByteBuf, var id: Res
3535
@JvmStatic
3636
val CODEC: StreamCodec<FriendlyByteBuf, PacketRenderEntityS2C> =
3737
CustomPacketPayload.codec({ packet, buf ->
38-
val entity = packet.entityData.copy().array()
38+
val entity = packet.entityData
3939
buf.writeInt(packet.method.id)
4040
buf.writeUUID(packet.uuid)
4141
buf.writeResourceLocation(packet.id)
42+
buf.writeInt(entity.size)
4243
buf.writeBytes(entity)
4344
}, { buf ->
4445
val method = buf.readInt()
4546
val uuid = buf.readUUID()
4647
val id = buf.readResourceLocation()
47-
val entity = buf.readBytes(buf.readableBytes())
48-
val packet = PacketRenderEntityS2C(uuid, entity, id, Method.idOf(method))
48+
val size = buf.readInt()
49+
val entity = buf.readBytes(size)
50+
val bytes = ByteArray(size)
51+
entity.readBytes(bytes)
52+
val packet = PacketRenderEntityS2C(uuid, bytes, id, Method.idOf(method))
4953
return@codec packet
5054
}
5155
)
5256
}
5357

54-
fun copyWithBuffer(): PacketRenderEntityS2C {
55-
return PacketRenderEntityS2C(uuid, entityData.copy(), id, method)
56-
}
57-
5858
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload?> {
5959
return payloadID
6060
}

common/src/main/kotlin/cn/coostack/cooparticlesapi/network/packet/client/listener/ClientRenderEntityPacketHandler.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package cn.coostack.cooparticlesapi.network.packet.client.listener
33
import cn.coostack.cooparticlesapi.network.packet.PacketRenderEntityS2C
44
import cn.coostack.cooparticlesapi.platform.network.ClientContext
55
import cn.coostack.cooparticlesapi.renderer.client.ClientRenderEntityManager
6+
import io.netty.buffer.Unpooled
67
import net.minecraft.network.FriendlyByteBuf
78

89
object ClientRenderEntityPacketHandler {
910
fun receive(
10-
payload: PacketRenderEntityS2C,
11+
packet: PacketRenderEntityS2C,
1112
context: ClientContext
1213
) {
13-
val packet = payload.copyWithBuffer()
1414
val method = packet.method
1515
val data = packet.entityData
1616
val id = packet.id
17-
val buf = FriendlyByteBuf(data)
17+
val buf = FriendlyByteBuf(Unpooled.wrappedBuffer(data))
1818
val codec = ClientRenderEntityManager.getCodecFromID(id) ?: return
1919
val entity = codec.decode(buf)
2020
entity.world = context.client().level
@@ -24,11 +24,11 @@ object ClientRenderEntityPacketHandler {
2424
}
2525

2626
PacketRenderEntityS2C.Method.TOGGLE -> {
27-
ClientRenderEntityManager.getFrom(payload.uuid)?.loadProfileFromEntity(entity)
27+
ClientRenderEntityManager.getFrom(packet.uuid)?.loadProfileFromEntity(entity)
2828
}
2929

3030
PacketRenderEntityS2C.Method.REMOVE -> {
31-
ClientRenderEntityManager.getFrom(payload.uuid)?.canceled = true
31+
ClientRenderEntityManager.getFrom(packet.uuid)?.canceled = true
3232
}
3333
}
3434
}

common/src/main/kotlin/cn/coostack/cooparticlesapi/renderer/RenderEntity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ abstract class RenderEntity(var world: Level?, var pos: Vec3 = Vec3.ZERO) : Serv
7272
}
7373
val buf = FriendlyByteBuf(Unpooled.buffer())
7474
getCodec().encode(buf, this)
75+
val bytes = ByteArray(buf.readableBytes())
76+
buf.readBytes(bytes)
7577
// 发包
76-
val packet = PacketRenderEntityS2C(uuid, buf, getRenderID(), method)
78+
val packet = PacketRenderEntityS2C(uuid, bytes, getRenderID(), method)
7779
return packet
7880
}
7981

common/src/main/kotlin/cn/coostack/cooparticlesapi/test/TestA.kt

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

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Important Notes:
22
# Every field you add must be added to the root build.gradle expandProps map.
33
# Project
4-
version=2.2.4
4+
version=2.2.4.2
55
group=cn.coostack
66
artifact=cooparticlesapi
77
java_version=21

0 commit comments

Comments
 (0)