mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
refactor InitializeS2CP, RespawnS2CP, remove RespawnEvent
This commit is contained in:
parent
4fee62885f
commit
e6bc1babc2
@ -19,7 +19,7 @@ import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLoc
|
||||
|
||||
data class Dimension(
|
||||
override val identifier: ResourceLocation,
|
||||
val type: DimensionProperties,
|
||||
val properties: DimensionProperties,
|
||||
) : RegistryItem() {
|
||||
|
||||
override fun toString(): String {
|
||||
@ -30,7 +30,7 @@ data class Dimension(
|
||||
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Dimension {
|
||||
return Dimension(
|
||||
identifier = resourceLocation,
|
||||
type = DimensionProperties.deserialize(data)
|
||||
properties = DimensionProperties.deserialize(data)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -25,8 +25,7 @@ import de.bixilon.minosoft.gui.rendering.gui.gui.ElementStates
|
||||
import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder
|
||||
import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement
|
||||
import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.Menu
|
||||
import de.bixilon.minosoft.modding.event.events.RespawnEvent
|
||||
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.play.ClientActionC2SP
|
||||
|
||||
class RespawnMenu(guiRenderer: GUIRenderer) : Menu(guiRenderer) {
|
||||
@ -72,10 +71,12 @@ class RespawnMenu(guiRenderer: GUIRenderer) : Menu(guiRenderer) {
|
||||
guiRenderer.gui.pop(element)
|
||||
}
|
||||
}
|
||||
guiRenderer.connection.events.listen<RespawnEvent> {
|
||||
guiRenderer.connection::state.observe(this) {
|
||||
if (it != PlayConnectionStates.SPAWNING) return@observe
|
||||
|
||||
val element = guiRenderer.gui[this]
|
||||
if (element.state == ElementStates.CLOSED) {
|
||||
return@listen
|
||||
return@observe
|
||||
}
|
||||
element.layout.canPop = true
|
||||
guiRenderer.gui.pop(element)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -20,7 +20,7 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.inSectionHeight
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.inChunkSectionPosition
|
||||
import de.bixilon.minosoft.gui.rendering.world.WorldRenderer
|
||||
import de.bixilon.minosoft.modding.event.events.RespawnEvent
|
||||
import de.bixilon.minosoft.modding.event.events.DimensionChangeEvent
|
||||
import de.bixilon.minosoft.modding.event.events.blocks.BlockDataChangeEvent
|
||||
import de.bixilon.minosoft.modding.event.events.blocks.BlockSetEvent
|
||||
import de.bixilon.minosoft.modding.event.events.blocks.BlocksSetEvent
|
||||
@ -122,7 +122,7 @@ object WorldRendererChangeListener {
|
||||
listenBlockSet(renderer)
|
||||
listenBlocksSet(renderer)
|
||||
|
||||
events.listen<RespawnEvent> { if (it.dimensionChange) renderer.unloadWorld() }
|
||||
events.listen<DimensionChangeEvent> { renderer.unloadWorld() }
|
||||
events.listen<ChunkDataChangeEvent> { renderer.master.tryQueue(it.chunk) }
|
||||
|
||||
events.listen<LightChangeEvent> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -15,8 +15,6 @@ package de.bixilon.minosoft.modding.event.events
|
||||
import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
|
||||
@Deprecated("Observables")
|
||||
class RespawnEvent(
|
||||
class DimensionChangeEvent(
|
||||
connection: PlayConnection,
|
||||
val dimensionChange: Boolean,
|
||||
) : PlayConnectionEvent(connection)
|
@ -44,21 +44,17 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
val gamemode: Gamemodes
|
||||
var world: ResourceLocation? = null
|
||||
private set
|
||||
var dimensionProperties: DimensionProperties? = null
|
||||
var dimension: DimensionProperties? = null
|
||||
private set
|
||||
var dimensionType: ResourceLocation? = null
|
||||
var dimensionName: ResourceLocation? = null
|
||||
private set
|
||||
var difficulty: Difficulties = Difficulties.NORMAL
|
||||
private set
|
||||
var viewDistance = 0
|
||||
private set
|
||||
var maxPlayers = 0
|
||||
var reducedDebugScreen = false
|
||||
private set
|
||||
var levelType: String? = null
|
||||
private set
|
||||
var isReducedDebugScreen = false
|
||||
private set
|
||||
var isEnableRespawnScreen = true
|
||||
var respawnScreen = true
|
||||
private set
|
||||
var hashedSeed: Long = 0L
|
||||
private set
|
||||
@ -83,32 +79,32 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}
|
||||
|
||||
if (buffer.versionId < ProtocolVersions.V_1_9_1) {
|
||||
dimensionProperties = buffer.connection.registries.dimension[buffer.readByte().toInt()].type
|
||||
dimension = buffer.connection.registries.dimension[buffer.readByte().toInt()].properties
|
||||
difficulty = Difficulties[buffer.readUnsignedByte()]
|
||||
maxPlayers = buffer.readUnsignedByte()
|
||||
buffer.readUnsignedByte() // max players
|
||||
if (buffer.versionId >= ProtocolVersions.V_13W42B) {
|
||||
levelType = buffer.readString()
|
||||
buffer.readString() // level type
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_14W29A) {
|
||||
isReducedDebugScreen = buffer.readBoolean()
|
||||
reducedDebugScreen = buffer.readBoolean()
|
||||
}
|
||||
} else {
|
||||
if (buffer.versionId >= ProtocolVersions.V_1_16_PRE6) {
|
||||
buffer.readByte() // previous game mode
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_20W22A) {
|
||||
buffer.readArray { buffer.readResourceLocation() } // list of dimensions
|
||||
buffer.readArray { buffer.readResourceLocation() } // list of worlds
|
||||
}
|
||||
if (buffer.versionId < ProtocolVersions.V_20W21A) {
|
||||
dimensionProperties = buffer.connection.registries.dimension[buffer.readInt()].type
|
||||
dimension = buffer.connection.registries.dimension[buffer.readInt()].properties
|
||||
} else {
|
||||
registries = buffer.readNBT().asJsonObject()
|
||||
if (buffer.versionId < ProtocolVersions.V_1_16_2_PRE3 || buffer.versionId >= ProtocolVersions.V_22W19A) {
|
||||
dimensionType = buffer.readResourceLocation() // dimension type
|
||||
dimensionName = buffer.readResourceLocation() // dimension type
|
||||
} else {
|
||||
dimensionProperties = DimensionProperties.deserialize(buffer.readNBT().asJsonObject())
|
||||
dimension = DimensionProperties.deserialize(buffer.readNBT().asJsonObject())
|
||||
}
|
||||
this.world = buffer.readResourceLocation() // dimension id
|
||||
this.world = buffer.readResourceLocation()
|
||||
}
|
||||
|
||||
if (buffer.versionId >= ProtocolVersions.V_19W36A) {
|
||||
@ -117,13 +113,13 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
if (buffer.versionId < ProtocolVersions.V_19W11A) {
|
||||
difficulty = Difficulties[buffer.readUnsignedByte()]
|
||||
}
|
||||
maxPlayers = if (buffer.versionId < ProtocolVersions.V_1_16_2_RC1) {
|
||||
buffer.readByte().toInt()
|
||||
if (buffer.versionId < ProtocolVersions.V_1_16_2_RC1) {
|
||||
buffer.readUnsignedByte() // max players
|
||||
} else {
|
||||
buffer.readVarInt()
|
||||
buffer.readVarInt() // max players
|
||||
}
|
||||
if (buffer.versionId < ProtocolVersions.V_20W20A) {
|
||||
levelType = buffer.readString()
|
||||
buffer.readString() // level type
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_19W13A) {
|
||||
viewDistance = buffer.readVarInt()
|
||||
@ -133,13 +129,11 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_20W20A) {
|
||||
buffer.readBoolean() // isDebug
|
||||
if (buffer.readBoolean()) {
|
||||
levelType = "flat"
|
||||
}
|
||||
buffer.readBoolean() // flat
|
||||
}
|
||||
isReducedDebugScreen = buffer.readBoolean()
|
||||
reducedDebugScreen = buffer.readBoolean()
|
||||
if (buffer.versionId >= ProtocolVersions.V_19W36A) {
|
||||
isEnableRespawnScreen = buffer.readBoolean()
|
||||
respawnScreen = buffer.readBoolean()
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_1_19_PRE2) {
|
||||
lastDeathPosition = buffer.readPlayOptional { GlobalPositionEntityDataType.read(this) }
|
||||
@ -160,7 +154,7 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
connection.world.hardcore = isHardcore
|
||||
|
||||
registries?.let { connection.registries.update(it) }
|
||||
connection.world.dimension = dimensionProperties ?: connection.registries.dimension[dimensionType]?.type ?: throw NullPointerException("Can not find dimension: $dimensionType")
|
||||
connection.world.dimension = dimension ?: connection.registries.dimension[dimensionName]?.properties ?: throw NullPointerException("Can not find dimension: $dimensionName")
|
||||
connection.world.name = world
|
||||
|
||||
|
||||
@ -184,7 +178,7 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}
|
||||
|
||||
override fun log(reducedLog: Boolean) {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Initialize (entityId=$entityId, gamemode=$gamemode, dimensionType=$dimensionProperties, difficulty=$difficulty, hardcore=$isHardcore, viewDistance=$viewDistance)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Initialize (entityId=$entityId, gamemode=$gamemode, dimension=$dimension, difficulty=$difficulty, hardcore=$isHardcore, viewDistance=$viewDistance)" }
|
||||
}
|
||||
|
||||
companion object : PacketErrorHandler {
|
||||
|
@ -19,7 +19,7 @@ import de.bixilon.minosoft.data.entities.data.types.GlobalPositionEntityDataType
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
|
||||
import de.bixilon.minosoft.data.world.difficulty.Difficulties
|
||||
import de.bixilon.minosoft.modding.event.events.RespawnEvent
|
||||
import de.bixilon.minosoft.modding.event.events.DimensionChangeEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
|
||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||
@ -37,14 +37,8 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
var difficulty: Difficulties = Difficulties.NORMAL
|
||||
private set
|
||||
val gamemode: Gamemodes
|
||||
var levelType: String? = null
|
||||
private set
|
||||
var hashedSeed = 0L
|
||||
private set
|
||||
var isDebug = false
|
||||
private set
|
||||
var isFlat = false
|
||||
private set
|
||||
var keepAttributes = false
|
||||
private set
|
||||
var keepFlags: Byte = 0xFF.toByte()
|
||||
@ -57,20 +51,19 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
init {
|
||||
dimension = when {
|
||||
buffer.versionId < ProtocolVersions.V_20W21A -> {
|
||||
buffer.connection.registries.dimension[if (buffer.versionId < ProtocolVersions.V_1_8_9) { // ToDo: this should be 108 but wiki.vg is wrong. In 1.8 it is an int.
|
||||
val id = if (buffer.versionId < ProtocolVersions.V_1_8_9) { // ToDo: this should be 108 but wiki.vg is wrong. In 1.8 it is an int.
|
||||
buffer.readByte().toInt()
|
||||
} else {
|
||||
buffer.readInt()
|
||||
}].type
|
||||
}
|
||||
buffer.connection.registries.dimension[id].properties
|
||||
}
|
||||
|
||||
buffer.versionId < ProtocolVersions.V_1_16_2_PRE3 || buffer.versionId >= ProtocolVersions.V_22W19A -> {
|
||||
buffer.readLegacyRegistryItem(buffer.connection.registries.dimension)!!.type
|
||||
buffer.readLegacyRegistryItem(buffer.connection.registries.dimension)!!.properties
|
||||
}
|
||||
|
||||
else -> {
|
||||
DimensionProperties.deserialize(buffer.readNBT().asJsonObject()) // current dimension data
|
||||
}
|
||||
else -> DimensionProperties.deserialize(buffer.readNBT().asJsonObject()) // current dimension data
|
||||
}
|
||||
if (buffer.versionId < ProtocolVersions.V_19W11A) {
|
||||
difficulty = Difficulties[buffer.readUnsignedByte()]
|
||||
@ -86,11 +79,11 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
buffer.readByte() // previous game mode
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_13W42B && buffer.versionId < ProtocolVersions.V_20W20A) {
|
||||
levelType = buffer.readString()
|
||||
buffer.readString() // level type
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_20W20A) {
|
||||
isDebug = buffer.readBoolean()
|
||||
isFlat = buffer.readBoolean()
|
||||
buffer.readBoolean() // debug
|
||||
buffer.readBoolean() // flat
|
||||
}
|
||||
if (buffer.versionId >= ProtocolVersions.V_20W18A) {
|
||||
if (buffer.versionId >= ProtocolVersions.V_1_19_3_RC3) {
|
||||
@ -115,10 +108,12 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
connection.world.name = world
|
||||
|
||||
connection.state = PlayConnectionStates.SPAWNING
|
||||
connection.events.fire(RespawnEvent(connection, dimensionChange))
|
||||
if (dimensionChange) {
|
||||
connection.events.fire(DimensionChangeEvent(connection))
|
||||
}
|
||||
}
|
||||
|
||||
override fun log(reducedLog: Boolean) {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Respawn (dimension=$dimension, difficulty=$difficulty, gamemode=$gamemode, levelType=$levelType)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Respawn (dimension=$dimension, difficulty=$difficulty, gamemode=$gamemode)" }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user