mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
network: rewrite advancement reading
This commit is contained in:
parent
0449c17f7c
commit
7ddd0e6f68
@ -13,8 +13,10 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.advancements
|
package de.bixilon.minosoft.advancements
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||||
|
|
||||||
data class Advancement(
|
data class Advancement(
|
||||||
val parent: String?,
|
val parent: ResourceLocation?,
|
||||||
val display: AdvancementDisplay?,
|
val display: AdvancementDisplay?,
|
||||||
val criteria: Set<String>,
|
val criteria: Set<String>,
|
||||||
val requirements: Set<Set<String>>,
|
val requirements: Set<Set<String>>,
|
||||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.advancements
|
|||||||
|
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2
|
import de.bixilon.kotlinglm.vec2.Vec2
|
||||||
import de.bixilon.minosoft.data.container.stack.ItemStack
|
import de.bixilon.minosoft.data.container.stack.ItemStack
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||||
import de.bixilon.minosoft.data.text.ChatComponent
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
|
|
||||||
data class AdvancementDisplay(
|
data class AdvancementDisplay(
|
||||||
@ -22,6 +23,6 @@ data class AdvancementDisplay(
|
|||||||
val description: ChatComponent,
|
val description: ChatComponent,
|
||||||
val icon: ItemStack?,
|
val icon: ItemStack?,
|
||||||
val frame: AdvancementFrames,
|
val frame: AdvancementFrames,
|
||||||
val background: String?,
|
val background: ResourceLocation?,
|
||||||
val position: Vec2,
|
val position: Vec2,
|
||||||
)
|
)
|
||||||
|
@ -18,8 +18,10 @@ import de.bixilon.minosoft.advancements.Advancement
|
|||||||
import de.bixilon.minosoft.advancements.AdvancementDisplay
|
import de.bixilon.minosoft.advancements.AdvancementDisplay
|
||||||
import de.bixilon.minosoft.advancements.AdvancementFrames
|
import de.bixilon.minosoft.advancements.AdvancementFrames
|
||||||
import de.bixilon.minosoft.advancements.AdvancementProgress
|
import de.bixilon.minosoft.advancements.AdvancementProgress
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_23W18A
|
||||||
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
@ -28,45 +30,15 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
|||||||
@LoadPacket
|
@LoadPacket
|
||||||
class AdvancementsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
class AdvancementsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||||
val reset = buffer.readBoolean()
|
val reset = buffer.readBoolean()
|
||||||
val advancements: Map<String, Advancement?>
|
val advancements: Map<ResourceLocation, Advancement>
|
||||||
val progress: Map<String, Set<AdvancementProgress>>
|
val remove: Set<ResourceLocation>
|
||||||
|
val progress: Map<ResourceLocation, Set<AdvancementProgress>>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val advancements: MutableMap<String, Advancement?> = mutableMapOf()
|
this.advancements = buffer.readMap(key = { buffer.readResourceLocation() }, value = { buffer.readAdvancement() })
|
||||||
for (i in 0 until buffer.readVarInt()) {
|
this.remove = buffer.readSet { buffer.readResourceLocation() }
|
||||||
val key = buffer.readString()
|
|
||||||
val parent = buffer.readOptional { readString() }
|
|
||||||
val display = buffer.readOptional { buffer.readDisplay() }
|
|
||||||
val criteria = buffer.readArray { buffer.readString() }.toSet()
|
|
||||||
val requirements = buffer.readArray { buffer.readArray { buffer.readString() }.toSet() }.toSet()
|
|
||||||
|
|
||||||
advancements[key] = Advancement(
|
this.progress = buffer.readMap(key = { buffer.readResourceLocation() }, value = { buffer.readSet { buffer.readProgress() } })
|
||||||
parent = parent,
|
|
||||||
display = display,
|
|
||||||
criteria = criteria,
|
|
||||||
requirements = requirements,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
for (remove in buffer.readArray { buffer.readString() }) {
|
|
||||||
advancements[remove] = null
|
|
||||||
}
|
|
||||||
this.advancements = advancements
|
|
||||||
|
|
||||||
val progress: MutableMap<String, Set<AdvancementProgress>> = mutableMapOf()
|
|
||||||
for (i in 0 until buffer.readVarInt()) {
|
|
||||||
val name = buffer.readString()
|
|
||||||
val criteria: MutableSet<AdvancementProgress> = mutableSetOf()
|
|
||||||
for (ii in 0 until buffer.readVarInt()) {
|
|
||||||
val criterion = buffer.readString()
|
|
||||||
val archiveTime = buffer.readOptional { readLong() }
|
|
||||||
criteria += AdvancementProgress(
|
|
||||||
criterion = criterion,
|
|
||||||
archiveTime = archiveTime,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
progress[name] = criteria
|
|
||||||
}
|
|
||||||
this.progress = progress
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
@ -77,13 +49,40 @@ class AdvancementsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun PlayInByteBuffer.readProgress(): AdvancementProgress {
|
||||||
|
val criterion = readString()
|
||||||
|
val archiveTime = readOptional { readLong() }
|
||||||
|
|
||||||
|
return AdvancementProgress(
|
||||||
|
criterion = criterion,
|
||||||
|
archiveTime = archiveTime,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PlayInByteBuffer.readAdvancement(): Advancement {
|
||||||
|
val parent = readOptional { readResourceLocation() }
|
||||||
|
val display = readOptional { readDisplay() }
|
||||||
|
val criteria = readSet { readString() }
|
||||||
|
val requirements = readSet { readSet { readString() } }
|
||||||
|
if (versionId >= V_23W18A) { // TODO: not 100% sure
|
||||||
|
val sendTelemetry = readBoolean()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Advancement(
|
||||||
|
parent = parent,
|
||||||
|
display = display,
|
||||||
|
criteria = criteria,
|
||||||
|
requirements = requirements,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun PlayInByteBuffer.readDisplay(): AdvancementDisplay {
|
fun PlayInByteBuffer.readDisplay(): AdvancementDisplay {
|
||||||
val title = readChatComponent()
|
val title = readChatComponent()
|
||||||
val description = readChatComponent()
|
val description = readChatComponent()
|
||||||
val icon = readItemStack()
|
val icon = readItemStack()
|
||||||
val frame = AdvancementFrames[readVarInt()]
|
val frame = AdvancementFrames[readVarInt()]
|
||||||
val flags = readInt()
|
val flags = readInt()
|
||||||
val background = if (flags.isBit(0)) readString() else null
|
val background = if (flags.isBit(0)) readResourceLocation() else null
|
||||||
val position = readVec2f()
|
val position = readVec2f()
|
||||||
|
|
||||||
return AdvancementDisplay(
|
return AdvancementDisplay(
|
||||||
|
@ -191,4 +191,25 @@ open class InByteBuffer : de.bixilon.kutil.buffer.bytes.`in`.InByteBuffer {
|
|||||||
}
|
}
|
||||||
return readNBTTag(type)
|
return readNBTTag(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Kutil 1.23")
|
||||||
|
inline fun <reified T> readSet(length: Int = readVarInt(), reader: () -> T): Set<T> {
|
||||||
|
check(length <= size) { "Trying to allocate too much memory!" }
|
||||||
|
val set: MutableSet<T> = LinkedHashSet(length)
|
||||||
|
for (i in 0 until length) {
|
||||||
|
set += reader()
|
||||||
|
}
|
||||||
|
return set
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Kutil 1.23")
|
||||||
|
inline fun <reified K, reified V> readMap(length: Int = readVarInt(), key: () -> K, value: () -> V): Map<K, V> {
|
||||||
|
check(length <= size) { "Trying to allocate too much memory!" }
|
||||||
|
val map: MutableMap<K, V> = LinkedHashMap(length)
|
||||||
|
for (i in 0 until length) {
|
||||||
|
map[key()] = value()
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user