Allow configuring the displayed difficulty
This commit is contained in:
parent
2ffd7034a1
commit
114f6c9ccd
7 changed files with 25 additions and 26 deletions
10
blokk-api/src/main/kotlin/space/blokk/Difficulty.kt
Normal file
10
blokk-api/src/main/kotlin/space/blokk/Difficulty.kt
Normal file
|
@ -0,0 +1,10 @@
|
|||
package space.blokk
|
||||
|
||||
enum class Difficulty {
|
||||
PEACEFUL,
|
||||
EASY,
|
||||
NORMAL,
|
||||
HARD
|
||||
}
|
||||
|
||||
data class DifficultyOptions(val difficulty: Difficulty, val locked: Boolean)
|
|
@ -2,14 +2,15 @@ package space.blokk.server
|
|||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import space.blokk.events.EventBus
|
||||
import space.blokk.DifficultyOptions
|
||||
import space.blokk.events.EventTarget
|
||||
import space.blokk.server.events.ServerEvent
|
||||
|
||||
interface Server : EventTarget<ServerEvent> {
|
||||
override val eventBus: EventBus<ServerEvent>
|
||||
val scope: CoroutineScope
|
||||
|
||||
var displayedDifficultyOptions: DifficultyOptions
|
||||
|
||||
/**
|
||||
* Creates a [ReceiveChannel] which emits [Unit] every tick.
|
||||
*
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package space.blokk.worlds
|
||||
|
||||
enum class WorldDifficulty {
|
||||
PEACEFUL,
|
||||
EASY,
|
||||
NORMAL,
|
||||
HARD
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
package space.blokk.net.packets.play
|
||||
|
||||
import io.netty.buffer.ByteBuf
|
||||
import space.blokk.Difficulty
|
||||
import space.blokk.net.packets.OutgoingPacketCodec
|
||||
import space.blokk.worlds.WorldDifficulty
|
||||
|
||||
object ServerDifficultyPacketCodec : OutgoingPacketCodec<ServerDifficultyPacket>(0x0E, ServerDifficultyPacket::class) {
|
||||
override fun ServerDifficultyPacket.encode(dst: ByteBuf) {
|
||||
dst.writeByte(
|
||||
when (difficulty) {
|
||||
WorldDifficulty.PEACEFUL -> 0
|
||||
WorldDifficulty.EASY -> 1
|
||||
WorldDifficulty.NORMAL -> 2
|
||||
WorldDifficulty.HARD -> 3
|
||||
when (difficultyOptions.difficulty) {
|
||||
Difficulty.PEACEFUL -> 0
|
||||
Difficulty.EASY -> 1
|
||||
Difficulty.NORMAL -> 2
|
||||
Difficulty.HARD -> 3
|
||||
}
|
||||
)
|
||||
|
||||
dst.writeBoolean(locked)
|
||||
dst.writeBoolean(difficultyOptions.locked)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package space.blokk.net.packets.play
|
||||
|
||||
import space.blokk.DifficultyOptions
|
||||
import space.blokk.net.packets.OutgoingPacket
|
||||
import space.blokk.worlds.WorldDifficulty
|
||||
|
||||
/**
|
||||
* Sets the difficulty shown in the pause menu.
|
||||
*/
|
||||
data class ServerDifficultyPacket(val difficulty: WorldDifficulty, val locked: Boolean) : OutgoingPacket()
|
||||
data class ServerDifficultyPacket(val difficultyOptions: DifficultyOptions) : OutgoingPacket()
|
||||
|
|
|
@ -24,6 +24,7 @@ class BlokkServer internal constructor() : Server {
|
|||
|
||||
override val scope = CoroutineScope(CoroutineName("BlokkServer"))
|
||||
override val eventBus = EventBus(ServerEvent::class, scope)
|
||||
override var displayedDifficultyOptions = DifficultyOptions(Difficulty.NORMAL, true)
|
||||
|
||||
val logger = Logger("Server")
|
||||
var socketServer = BlokkSocketServer(); private set
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package space.blokk.net
|
||||
|
||||
import io.netty.buffer.Unpooled
|
||||
import space.blokk.Blokk
|
||||
import space.blokk.BlokkServer
|
||||
import space.blokk.chat.TextComponent
|
||||
import space.blokk.net.MinecraftDataTypes.writeString
|
||||
|
@ -15,7 +16,6 @@ import space.blokk.net.packets.play.ServerDifficultyPacket
|
|||
import space.blokk.players.GameMode
|
||||
import space.blokk.utils.AuthenticationHelper
|
||||
import space.blokk.utils.EncryptionUtils
|
||||
import space.blokk.worlds.WorldDifficulty
|
||||
import space.blokk.worlds.WorldDimension
|
||||
import space.blokk.worlds.WorldType
|
||||
import java.security.MessageDigest
|
||||
|
@ -121,11 +121,6 @@ class JoinProcedure(val session: BlokkSession) {
|
|||
}
|
||||
|
||||
private suspend fun joinWorld() {
|
||||
session.send(
|
||||
ServerDifficultyPacket(
|
||||
WorldDifficulty.NORMAL,
|
||||
true
|
||||
)
|
||||
)
|
||||
session.send(ServerDifficultyPacket(Blokk.server.displayedDifficultyOptions))
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue