mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
generalize network registry item and enum reading
This commit is contained in:
parent
919340fbac
commit
a08e81b1c7
@ -27,7 +27,7 @@ object GlobalPositionEntityDataType : EntityDataType<GlobalPosition> {
|
||||
if (buffer.versionId < ProtocolVersions.V_1_19_PRE2) { // ToDo: find out version
|
||||
return buffer.readNBT()?.toJsonObject()?.toGlobalPosition(buffer.connection)
|
||||
}
|
||||
val dimension = buffer.connection.registries.dimensionRegistry[buffer.readResourceLocation()]
|
||||
val dimension = buffer.readLegacyRegistryItem(buffer.connection.registries.dimensionRegistry)
|
||||
val position = buffer.readBlockPosition()
|
||||
return GlobalPosition(dimension, position)
|
||||
}
|
||||
|
@ -144,17 +144,17 @@ class RenderWindow(
|
||||
tintManager.init(connection.assetsManager)
|
||||
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Creating context (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Creating context (after ${stopwatch.labTime()})..." }
|
||||
|
||||
renderSystem.init()
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Enabling all open gl features (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Enabling all open gl features (after ${stopwatch.labTime()})..." }
|
||||
|
||||
renderSystem.reset()
|
||||
|
||||
// Init stage
|
||||
val initLatch = CountUpAndDownLatch(1, latch)
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Generating font and gathering textures (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Generating font and gathering textures (after ${stopwatch.labTime()})..." }
|
||||
textureManager.dynamicTextures.load(initLatch)
|
||||
textureManager.loadDefaultSkins(connection)
|
||||
textureManager.loadDefaultTextures()
|
||||
@ -164,7 +164,7 @@ class RenderWindow(
|
||||
framebufferManager.init()
|
||||
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Initializing renderer (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Initializing renderer (after ${stopwatch.labTime()})..." }
|
||||
lightMap.init()
|
||||
skeletalManager.init()
|
||||
renderer.init(initLatch)
|
||||
@ -174,27 +174,27 @@ class RenderWindow(
|
||||
initLatch.await()
|
||||
|
||||
// Post init stage
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Preloading textures (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Preloading textures (after ${stopwatch.labTime()})..." }
|
||||
textureManager.staticTextures.preLoad(latch)
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Loading textures (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Loading textures (after ${stopwatch.labTime()})..." }
|
||||
textureManager.staticTextures.load(latch)
|
||||
font.postInit(latch)
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Post loading renderer (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Post loading renderer (after ${stopwatch.labTime()})..." }
|
||||
shaderManager.postInit()
|
||||
skeletalManager.postInit()
|
||||
renderer.postInit(latch)
|
||||
framebufferManager.postInit()
|
||||
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Loading skeletal meshes ${stopwatch.totalTime()}" }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Loading skeletal meshes (after ${stopwatch.labTime()})" }
|
||||
|
||||
for (model in modelLoader.entities.skeletal.values) {
|
||||
model.loadMesh(this)
|
||||
}
|
||||
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Registering callbacks (${stopwatch.labTime()})..." }
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Registering callbacks (after ${stopwatch.labTime()})..." }
|
||||
|
||||
connection.registerEvent(CallbackEventInvoker.of<WindowFocusChangeEvent> {
|
||||
renderingState = it.focused.decide(RenderingStates.RUNNING, RenderingStates.SLOW)
|
||||
|
@ -24,7 +24,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
@LoadPacket
|
||||
class ItemCooldownS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val item = buffer.connection.registries.itemRegistry[buffer.readVarInt()]
|
||||
val item = buffer.readRegistryItem(buffer.connection.registries.itemRegistry)
|
||||
val time = buffer.readVarInt()
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
|
@ -29,9 +29,9 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@LoadPacket
|
||||
class ParticleS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val type: ParticleType = if (buffer.versionId < ProtocolVersions.V_14W19A) {
|
||||
buffer.connection.registries.particleTypeRegistry[buffer.readResourceLocation()]!!
|
||||
buffer.readLegacyRegistryItem(buffer.connection.registries.particleTypeRegistry)!!
|
||||
} else if (buffer.versionId >= ProtocolVersions.V_22W17A) { // ToDo: maybe this was even earlier, should only differ some snapshots
|
||||
buffer.connection.registries.particleTypeRegistry[buffer.readVarInt()]
|
||||
buffer.readRegistryItem(buffer.connection.registries.particleTypeRegistry)
|
||||
} else {
|
||||
buffer.connection.registries.particleTypeRegistry[buffer.readInt()]
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}].type
|
||||
}
|
||||
buffer.versionId < ProtocolVersions.V_1_16_2_PRE3 || buffer.versionId >= ProtocolVersions.V_22W19A -> {
|
||||
buffer.connection.registries.dimensionRegistry[buffer.readResourceLocation()]!!.type
|
||||
buffer.readLegacyRegistryItem(buffer.connection.registries.dimensionRegistry)!!.type
|
||||
}
|
||||
else -> {
|
||||
DimensionProperties.deserialize(buffer.readNBT().asJsonObject()) // current dimension data
|
||||
|
@ -35,7 +35,7 @@ class StatisticsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val name = buffer.readResourceLocation()
|
||||
val value = buffer.readVarInt()
|
||||
} else {
|
||||
val type = buffer.connection.registries.statisticRegistry[buffer.readVarInt()]
|
||||
val type = buffer.readRegistryItem(buffer.connection.registries.statisticRegistry)
|
||||
val keyId = buffer.readVarInt()
|
||||
val key: Any = when (type.unit) {
|
||||
StatisticUnits.BLOCK -> buffer.connection.registries.blockRegistry[keyId]
|
||||
|
@ -33,7 +33,7 @@ class BlockActionS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}
|
||||
val data1: Byte = buffer.readByte()
|
||||
val data2: Byte = buffer.readByte()
|
||||
val block: Block = buffer.connection.registries.blockRegistry[buffer.readVarInt()]
|
||||
val block: Block = buffer.readRegistryItem(buffer.connection.registries.blockRegistry)
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val blockEntity = connection.world.getOrPutBlockEntity(position) ?: return
|
||||
|
@ -33,7 +33,7 @@ class BlockDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
buffer.readBlockPosition()
|
||||
}
|
||||
val type = if (buffer.versionId >= V_21W37A) {
|
||||
buffer.connection.registries.blockEntityTypeRegistry[buffer.readVarInt()].resourceLocation
|
||||
buffer.readRegistryItem(buffer.connection.registries.blockEntityTypeRegistry).resourceLocation
|
||||
} else {
|
||||
buffer.connection.registries.blockDataTypeRegistry.getOrNull(buffer.readUnsignedByte())?.resourceLocation
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@LoadPacket
|
||||
class LegacyBlockBreakS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val blockPosition: Vec3i = buffer.readBlockPosition()
|
||||
val blockState: BlockState? = buffer.connection.registries.blockStateRegistry[buffer.readVarInt()]
|
||||
val blockState: BlockState? = buffer.connection.registries.blockStateRegistry.getOrNull(buffer.readVarInt())
|
||||
val actions: Actions = Actions[buffer.readVarInt()]
|
||||
val successful: Boolean = buffer.readBoolean()
|
||||
|
||||
|
@ -41,10 +41,10 @@ class OpenContainerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
buffer.connection.registries.containerTypeRegistry[buffer.readUnsignedByte()]
|
||||
}
|
||||
buffer.versionId >= V_1_14 -> { // ToDo: This is completely guessed
|
||||
buffer.connection.registries.containerTypeRegistry[buffer.readVarInt()]
|
||||
buffer.readRegistryItem(buffer.connection.registries.containerTypeRegistry)
|
||||
}
|
||||
else -> {
|
||||
buffer.connection.registries.containerTypeRegistry[buffer.readResourceLocation()]!!
|
||||
buffer.readLegacyRegistryItem(buffer.connection.registries.containerTypeRegistry)!!
|
||||
}
|
||||
}
|
||||
val title: ChatComponent = buffer.readChatComponent()
|
||||
|
@ -24,7 +24,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@LoadPacket
|
||||
class EntityAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val entityId: Int = buffer.readVarInt()
|
||||
val animation: EntityAnimations = buffer.connection.registries.entityAnimationRegistry[buffer.readVarInt()]!!
|
||||
val animation: EntityAnimations = buffer.readEnum(buffer.connection.registries.entityAnimationRegistry)!!
|
||||
|
||||
|
||||
override fun log(reducedLog: Boolean) {
|
||||
|
@ -42,9 +42,9 @@ class EntityPaintingS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
|
||||
init {
|
||||
val motif: Motif? = if (buffer.versionId < ProtocolVersions.V_18W02A) {
|
||||
buffer.connection.registries.motifRegistry[buffer.readResourceLocation()]
|
||||
buffer.readLegacyRegistryItem(buffer.connection.registries.motifRegistry)
|
||||
} else {
|
||||
buffer.connection.registries.motifRegistry[buffer.readVarInt()]
|
||||
buffer.readRegistryItem(buffer.connection.registries.motifRegistry)
|
||||
}
|
||||
val position: Vec3i
|
||||
val direction: Directions
|
||||
|
@ -24,7 +24,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
@LoadPacket
|
||||
class EntitySoundS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val soundEvent: ResourceLocation = buffer.connection.registries.soundEventRegistry[buffer.readVarInt()]!!
|
||||
val soundEvent: ResourceLocation = buffer.readRegistryItem(buffer.connection.registries.soundEventRegistry)
|
||||
val category: SoundCategories = SoundCategories[buffer.readVarInt()]
|
||||
val entityId: Int = buffer.readVarInt()
|
||||
val volume: Float = buffer.readFloat()
|
||||
|
@ -42,7 +42,7 @@ class SoundEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
// category was moved to the top
|
||||
this.category = SoundCategories[buffer.readVarInt()]
|
||||
}
|
||||
soundEvent = buffer.connection.registries.soundEventRegistry[buffer.readVarInt()]!!
|
||||
soundEvent = buffer.readRegistryItem(buffer.connection.registries.soundEventRegistry)
|
||||
if (buffer.versionId >= ProtocolVersions.V_17W15A && buffer.versionId < ProtocolVersions.V_17W18A) {
|
||||
buffer.readString() // parrot entity type
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ object TitleS2CF : PlayPacketFactory {
|
||||
override val direction: PacketDirection = PacketDirection.SERVER_TO_CLIENT
|
||||
|
||||
override fun createPacket(buffer: PlayInByteBuffer): TitleS2CP {
|
||||
return when (buffer.connection.registries.titleActionsRegistry[buffer.readVarInt()]!!) {
|
||||
return when (buffer.readEnum(buffer.connection.registries.titleActionsRegistry)!!) {
|
||||
TitleActions.TITLE_TEXT -> TitleTextS2CP(buffer)
|
||||
TitleActions.SUBTITLE -> SubtitleS2CP(buffer)
|
||||
TitleActions.HOTBAR_TEXT -> HotbarTextS2CP(buffer)
|
||||
|
@ -32,6 +32,10 @@ import de.bixilon.minosoft.data.registries.particle.data.BlockParticleData
|
||||
import de.bixilon.minosoft.data.registries.particle.data.DustParticleData
|
||||
import de.bixilon.minosoft.data.registries.particle.data.ItemParticleData
|
||||
import de.bixilon.minosoft.data.registries.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.EnumRegistry
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.Registry
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.protocol.PlayerPublicKey
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
@ -257,6 +261,7 @@ class PlayInByteBuffer : InByteBuffer {
|
||||
}
|
||||
textures = PlayerTextures.of(value, signature)
|
||||
}
|
||||
|
||||
else -> Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN) { "Unknown player property $name: $value" }
|
||||
}
|
||||
}
|
||||
@ -338,4 +343,16 @@ class PlayInByteBuffer : InByteBuffer {
|
||||
BitSet.valueOf(readLongArray())
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> readRegistryItem(registry: AbstractRegistry<T>): T {
|
||||
return registry[readVarInt()]
|
||||
}
|
||||
|
||||
fun <T : RegistryItem> readLegacyRegistryItem(registry: Registry<T>): T? {
|
||||
return registry[readResourceLocation()]
|
||||
}
|
||||
|
||||
fun <T : Enum<*>> readEnum(registry: EnumRegistry<T>): T? {
|
||||
return registry[readVarInt()]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user