fix world clearing when changing dimensions

This commit is contained in:
Bixilon 2022-12-23 17:04:02 +01:00
parent 12c8218134
commit a871c583fe
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 14 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
import de.bixilon.kutil.observer.DataObserver.Companion.observed
import de.bixilon.kutil.random.RandomUtil.nextInt
import de.bixilon.minosoft.data.entities.block.BlockEntity
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
@ -77,6 +78,9 @@ class World(
var weather by observed(WorldWeather.NONE)
val view = WorldView(connection)
val border = WorldBorder()
var name: ResourceLocation? by observed(null)
private val random = Random()
override var audioPlayer: AbstractAudioPlayer? = null

View File

@ -42,6 +42,8 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val entityId: Int
val isHardcore: Boolean
val gamemode: Gamemodes
var world: ResourceLocation? = null
private set
var dimensionProperties: DimensionProperties? = null
private set
var dimensionType: ResourceLocation? = null
@ -106,7 +108,7 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
} else {
dimensionProperties = DimensionProperties.deserialize(buffer.readNBT().asJsonObject())
}
buffer.readResourceLocation() // dimension id
this.world = buffer.readResourceLocation() // dimension id
}
if (buffer.versionId >= ProtocolVersions.V_19W36A) {
@ -159,6 +161,8 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
registries?.let { connection.registries.update(it) }
connection.world.dimension = dimensionProperties ?: connection.registries.dimensionRegistry[dimensionType]?.type ?: throw NullPointerException("Can not find dimension: $dimensionType")
connection.world.name = world
connection.world.entities.getId(playerEntity)?.let { connection.world.entities.remove(it) } // e.g. bungeecord sends this packet twice
connection.world.entities.add(entityId, null, playerEntity)

View File

@ -47,7 +47,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
private set
var keepAttributes = false
private set
var keepFlags: Byte = 0
var keepFlags: Byte = 0xFF.toByte()
private set
var world: ResourceLocation? = null
private set
@ -107,13 +107,15 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
override fun handle(connection: PlayConnection) {
connection.util.prepareSpawn()
connection.player.additional.gamemode = gamemode
val dimensionChange = this.dimension != connection.world.dimension
val dimensionChange = this.dimension != connection.world.dimension || this.world != connection.world.name
if (dimensionChange) {
connection.world.clear()
}
connection.world.dimension = dimension
connection.world.name = world
connection.state = PlayConnectionStates.SPAWNING
connection.fire(RespawnEvent(connection, dimensionChange))
connection.events.fire(RespawnEvent(connection, dimensionChange))
}
override fun log(reducedLog: Boolean) {