Archived
1
0
Fork 0

Some refactorings

This commit is contained in:
Moritz Ruth 2021-01-09 12:01:59 +01:00
parent ab09228565
commit 55806e3aba
No known key found for this signature in database
GPG key ID: AFD57E23E753841B
8 changed files with 40 additions and 11 deletions

View file

@ -5,9 +5,11 @@
package space.uranos.testplugin
import space.uranos.Position
import space.uranos.Uranos
import space.uranos.chat.ChatColor
import space.uranos.chat.TextComponent
import space.uranos.entity.CowEntity
import space.uranos.net.ServerListInfo
import space.uranos.net.event.ServerListInfoRequestEvent
import space.uranos.net.event.SessionAfterLoginEvent
@ -24,7 +26,7 @@ import space.uranos.world.block.GreenWoolBlock
import space.uranos.world.block.RedWoolBlock
class TestPlugin: Plugin("Test", "1.0.0") {
override fun onEnable() {
override suspend fun onEnable() {
val dimension = Dimension(
"test:test",
true,
@ -60,6 +62,9 @@ class TestPlugin: Plugin("Test", "1.0.0") {
event.response = ServerListInfo("1.16.4", 754, TextComponent of "Test", 10, 0, emptyList())
}
val entity = CowEntity(Position(0.0, 10.0, 0.0, 0f, 0f), 0f)
entity.setWorld(world)
Uranos.eventBus.on<SessionAfterLoginEvent> { event ->
event.gameMode = GameMode.CREATIVE
event.canFly = true

View file

@ -0,0 +1,26 @@
/*
* Copyright 2020-2021 Moritz Ruth and Uranos contributors
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file
*/
@file:Suppress("LeakingThis")
package space.uranos.entity
import space.uranos.Position
import space.uranos.Vector
import space.uranos.data.DataStorage
open class CowEntity(position: Position, override var headPitch: Float) : LivingEntity() {
final override val type: EntityType = Type
override var velocity: Vector = Vector.ZERO
@Suppress("LeakingThis")
override val dataStorage: DataStorage<CowEntity> = DataStorage(this)
init {
this.position = position
}
companion object Type : CowEntityType()
}

View file

@ -13,7 +13,7 @@ import space.uranos.data.DataStorage
import space.uranos.data.createDataStorageKey
abstract class LivingEntity : Entity(), Mobile {
abstract var headPitch: Float
abstract var headPitch: Float // TODO: This should probably be headYaw, but wiki.vg says headPitch
abstract override var velocity: Vector
abstract override val dataStorage: DataStorage<out LivingEntity>

View file

@ -8,8 +8,8 @@ package space.uranos.plugin
abstract class Plugin(name: String, version: String) {
val meta = Meta(name, version)
open fun onEnable() {}
open fun onDisable() {}
open suspend fun onEnable() {}
open suspend fun onDisable() {}
data class Meta(val name: String, val version: String)

View file

@ -107,7 +107,7 @@ class UranosServer internal constructor() : Server() {
exitProcess(1)
}
fun start() {
suspend fun start() {
logger info "Starting UranosServer ($VERSION_WITH_V)"
logger trace "Configuration: $config"
@ -145,7 +145,7 @@ class UranosServer internal constructor() : Server() {
val VERSION_WITH_V = if (VERSION == "development") VERSION else "v$VERSION"
@JvmStatic
fun main(args: Array<String>) {
fun main(args: Array<String>) = runBlocking {
UranosServer().also { setServerInstance(it) }.start()
}

View file

@ -208,10 +208,8 @@ class LoginAndJoinProcedure(val session: UranosSession) {
player.spawnInitially(state.world)
session.state = Session.State.Playing(player)
player.sendChunksAndLight()
// WorldBorder
session.send(CompassTargetPacket(player.compassTarget))
session.send(OutgoingPlayerPositionPacket(state.position))
session.sendNextTick(CompassTargetPacket(player.compassTarget))
}
}

View file

@ -79,6 +79,7 @@ class UranosPlayer(
suspend fun spawnInitially(world: World) {
entity.setWorld(world)
updateCurrentlyViewedChunks()
sendChunksAndLight()
}
/**
@ -101,7 +102,6 @@ class UranosPlayer(
suspend fun sendChunksAndLight() {
val chunks = currentlyViewedChunks.sortedBy { abs(it.key.x) + abs(it.key.z) }
chunks.forEach { session.send(ChunkLightDataPacket(it.key, it.getLightData(this))) }
chunks.forEach { session.send(ChunkDataPacket(it.key, it.getData(this))) }
}
}

View file

@ -88,7 +88,7 @@ class UranosPluginManager(private val server: UranosServer) : PluginManager {
object NoPluginClassFile : LoadError()
}
fun enableAll() {
suspend fun enableAll() {
plugins.forEach { it.onEnable() }
}