mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
fix world clearing when changing dimensions
This commit is contained in:
parent
12c8218134
commit
a871c583fe
@ -22,6 +22,7 @@ import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
|||||||
import de.bixilon.kutil.observer.DataObserver.Companion.observed
|
import de.bixilon.kutil.observer.DataObserver.Companion.observed
|
||||||
import de.bixilon.kutil.random.RandomUtil.nextInt
|
import de.bixilon.kutil.random.RandomUtil.nextInt
|
||||||
import de.bixilon.minosoft.data.entities.block.BlockEntity
|
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.biomes.Biome
|
||||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||||
import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
|
import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
|
||||||
@ -77,6 +78,9 @@ class World(
|
|||||||
var weather by observed(WorldWeather.NONE)
|
var weather by observed(WorldWeather.NONE)
|
||||||
val view = WorldView(connection)
|
val view = WorldView(connection)
|
||||||
val border = WorldBorder()
|
val border = WorldBorder()
|
||||||
|
|
||||||
|
var name: ResourceLocation? by observed(null)
|
||||||
|
|
||||||
private val random = Random()
|
private val random = Random()
|
||||||
|
|
||||||
override var audioPlayer: AbstractAudioPlayer? = null
|
override var audioPlayer: AbstractAudioPlayer? = null
|
||||||
|
@ -42,6 +42,8 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
val entityId: Int
|
val entityId: Int
|
||||||
val isHardcore: Boolean
|
val isHardcore: Boolean
|
||||||
val gamemode: Gamemodes
|
val gamemode: Gamemodes
|
||||||
|
var world: ResourceLocation? = null
|
||||||
|
private set
|
||||||
var dimensionProperties: DimensionProperties? = null
|
var dimensionProperties: DimensionProperties? = null
|
||||||
private set
|
private set
|
||||||
var dimensionType: ResourceLocation? = null
|
var dimensionType: ResourceLocation? = null
|
||||||
@ -106,7 +108,7 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
} else {
|
} else {
|
||||||
dimensionProperties = DimensionProperties.deserialize(buffer.readNBT().asJsonObject())
|
dimensionProperties = DimensionProperties.deserialize(buffer.readNBT().asJsonObject())
|
||||||
}
|
}
|
||||||
buffer.readResourceLocation() // dimension id
|
this.world = buffer.readResourceLocation() // dimension id
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer.versionId >= ProtocolVersions.V_19W36A) {
|
if (buffer.versionId >= ProtocolVersions.V_19W36A) {
|
||||||
@ -159,6 +161,8 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
|
|
||||||
registries?.let { connection.registries.update(it) }
|
registries?.let { connection.registries.update(it) }
|
||||||
connection.world.dimension = dimensionProperties ?: connection.registries.dimensionRegistry[dimensionType]?.type ?: throw NullPointerException("Can not find dimension: $dimensionType")
|
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.getId(playerEntity)?.let { connection.world.entities.remove(it) } // e.g. bungeecord sends this packet twice
|
||||||
connection.world.entities.add(entityId, null, playerEntity)
|
connection.world.entities.add(entityId, null, playerEntity)
|
||||||
|
@ -47,7 +47,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
private set
|
private set
|
||||||
var keepAttributes = false
|
var keepAttributes = false
|
||||||
private set
|
private set
|
||||||
var keepFlags: Byte = 0
|
var keepFlags: Byte = 0xFF.toByte()
|
||||||
private set
|
private set
|
||||||
var world: ResourceLocation? = null
|
var world: ResourceLocation? = null
|
||||||
private set
|
private set
|
||||||
@ -107,13 +107,15 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
override fun handle(connection: PlayConnection) {
|
override fun handle(connection: PlayConnection) {
|
||||||
connection.util.prepareSpawn()
|
connection.util.prepareSpawn()
|
||||||
connection.player.additional.gamemode = gamemode
|
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) {
|
if (dimensionChange) {
|
||||||
connection.world.clear()
|
connection.world.clear()
|
||||||
}
|
}
|
||||||
connection.world.dimension = dimension
|
connection.world.dimension = dimension
|
||||||
|
connection.world.name = world
|
||||||
|
|
||||||
connection.state = PlayConnectionStates.SPAWNING
|
connection.state = PlayConnectionStates.SPAWNING
|
||||||
connection.fire(RespawnEvent(connection, dimensionChange))
|
connection.events.fire(RespawnEvent(connection, dimensionChange))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user