mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
wip world border #65
This commit is contained in:
parent
2adad42f7e
commit
4f329768ca
@ -29,6 +29,7 @@ import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
|
|||||||
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
|
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
|
||||||
import de.bixilon.minosoft.data.world.biome.accessor.BiomeAccessor
|
import de.bixilon.minosoft.data.world.biome.accessor.BiomeAccessor
|
||||||
import de.bixilon.minosoft.data.world.biome.accessor.NoiseBiomeAccessor
|
import de.bixilon.minosoft.data.world.biome.accessor.NoiseBiomeAccessor
|
||||||
|
import de.bixilon.minosoft.data.world.border.WorldBorder
|
||||||
import de.bixilon.minosoft.data.world.time.WorldTime
|
import de.bixilon.minosoft.data.world.time.WorldTime
|
||||||
import de.bixilon.minosoft.data.world.view.WorldView
|
import de.bixilon.minosoft.data.world.view.WorldView
|
||||||
import de.bixilon.minosoft.data.world.weather.WorldWeather
|
import de.bixilon.minosoft.data.world.weather.WorldWeather
|
||||||
@ -68,6 +69,7 @@ class World(
|
|||||||
val time = WorldTime(this)
|
val time = WorldTime(this)
|
||||||
val weather = WorldWeather()
|
val weather = WorldWeather()
|
||||||
val view = WorldView(connection)
|
val view = WorldView(connection)
|
||||||
|
val border = WorldBorder()
|
||||||
private val random = Random
|
private val random = Random
|
||||||
|
|
||||||
var audioPlayer: AbstractAudioPlayer? = null
|
var audioPlayer: AbstractAudioPlayer? = null
|
||||||
@ -117,7 +119,9 @@ class World(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isPositionChangeable(blockPosition: Vec3i): Boolean {
|
fun isPositionChangeable(blockPosition: Vec3i): Boolean {
|
||||||
// ToDo: World border
|
if (border.isOutside(blockPosition)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
val dimension = connection.world.dimension!!
|
val dimension = connection.world.dimension!!
|
||||||
return (blockPosition.y >= dimension.minY || blockPosition.y < dimension.height)
|
return (blockPosition.y >= dimension.minY || blockPosition.y < dimension.height)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.world.border
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec2.Vec2d
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||||
|
import de.bixilon.minosoft.data.world.World
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2dUtil.EMPTY
|
||||||
|
|
||||||
|
class WorldBorder {
|
||||||
|
var center = Vec2d.EMPTY
|
||||||
|
var radius = World.MAX_SIZE.toDouble()
|
||||||
|
var warningTime = 0
|
||||||
|
var warningBlocks = 0
|
||||||
|
var portalBound = 0
|
||||||
|
|
||||||
|
fun isOutside(blockPosition: Vec3i): Boolean {
|
||||||
|
return isOutside(blockPosition.x.toDouble(), blockPosition.z.toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isOutside(position: Vec3): Boolean {
|
||||||
|
return isOutside(position.x.toDouble(), position.z.toDouble())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isOutside(position: Vec3d): Boolean {
|
||||||
|
return isOutside(position.x, position.z)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isOutside(x: Double, z: Double): Boolean {
|
||||||
|
if (x !in radius - center.x..radius + center.x) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (z !in radius - center.y..radius + center.y) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lerp(oldRadius: Double, newRadius: Double, speed: Long) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -111,6 +111,11 @@ class BreakInteractionHandler(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!connection.world.isPositionChangeable(target.blockPosition)) {
|
||||||
|
cancelDigging()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// check if we look at another block or our inventory changed
|
// check if we look at another block or our inventory changed
|
||||||
if (breakPosition != target.blockPosition || breakBlockState != target.blockState || breakSelectedSlot != connection.player.selectedHotbarSlot) {
|
if (breakPosition != target.blockPosition || breakBlockState != target.blockState || breakSelectedSlot != connection.player.selectedHotbarSlot) {
|
||||||
cancelDigging()
|
cancelDigging()
|
||||||
|
@ -75,6 +75,9 @@ class InteractInteractionHandler(
|
|||||||
if (target.distance >= connection.player.reachDistance) {
|
if (target.distance >= connection.player.reachDistance) {
|
||||||
return InteractionResults.PASS
|
return InteractionResults.PASS
|
||||||
}
|
}
|
||||||
|
if (connection.world.border.isOutside(target.blockPosition)) {
|
||||||
|
return InteractionResults.CONSUME
|
||||||
|
}
|
||||||
// if out of world (border): return CONSUME
|
// if out of world (border): return CONSUME
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -21,10 +22,13 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
|||||||
|
|
||||||
@LoadPacket(parent = true)
|
@LoadPacket(parent = true)
|
||||||
class CenterWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
class CenterWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
||||||
val x = buffer.readDouble()
|
val center = buffer.readVec2d()
|
||||||
val z = buffer.readDouble()
|
|
||||||
|
override fun handle(connection: PlayConnection) {
|
||||||
|
connection.world.border.center = center
|
||||||
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Center set world border (x=$x, z=$z)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Center set world border (center=$center)" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -21,8 +22,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
|||||||
|
|
||||||
@LoadPacket(parent = true)
|
@LoadPacket(parent = true)
|
||||||
class InitializeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
class InitializeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
||||||
val x = buffer.readDouble()
|
val center = buffer.readVec2d()
|
||||||
val z = buffer.readDouble()
|
|
||||||
val oldRadius = buffer.readDouble()
|
val oldRadius = buffer.readDouble()
|
||||||
val newRadius = buffer.readDouble()
|
val newRadius = buffer.readDouble()
|
||||||
val speed = buffer.readVarLong()
|
val speed = buffer.readVarLong()
|
||||||
@ -30,7 +30,15 @@ class InitializeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
|||||||
val warningTime = buffer.readVarInt()
|
val warningTime = buffer.readVarInt()
|
||||||
val warningBlocks = buffer.readVarInt()
|
val warningBlocks = buffer.readVarInt()
|
||||||
|
|
||||||
|
override fun handle(connection: PlayConnection) {
|
||||||
|
connection.world.border.center = center
|
||||||
|
connection.world.border.lerp(oldRadius, newRadius, speed)
|
||||||
|
connection.world.border.portalBound = portalBound
|
||||||
|
connection.world.border.warningTime = warningTime
|
||||||
|
connection.world.border.warningBlocks = warningBlocks
|
||||||
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Initialize world border (x=$x, z=$z, oldRadius=$oldRadius, newRadius=$newRadius, speed=$speed, portalBound=$portalBound, warningTime=$warningTime, warningBlocks=$warningBlocks)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Initialize world border (center=$center, oldRadius=$oldRadius, newRadius=$newRadius, speed=$speed, portalBound=$portalBound, warningTime=$warningTime, warningBlocks=$warningBlocks)" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -25,6 +26,10 @@ class LerpWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
|||||||
val newRadius = buffer.readDouble()
|
val newRadius = buffer.readDouble()
|
||||||
val speed = buffer.readVarLong()
|
val speed = buffer.readVarLong()
|
||||||
|
|
||||||
|
override fun handle(connection: PlayConnection) {
|
||||||
|
connection.world.border.lerp(oldRadius, newRadius, speed)
|
||||||
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Lerp size world border (oldRadius=$oldRadius, newRadius=$newRadius, speed=$speed)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Lerp size world border (oldRadius=$oldRadius, newRadius=$newRadius, speed=$speed)" }
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -23,6 +24,10 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
|||||||
class SizeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
class SizeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
||||||
val radius = buffer.readDouble()
|
val radius = buffer.readDouble()
|
||||||
|
|
||||||
|
override fun handle(connection: PlayConnection) {
|
||||||
|
connection.world.border.radius = radius
|
||||||
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Size set world border (radius=$radius)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Size set world border (radius=$radius)" }
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -23,6 +24,10 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
|||||||
class WarnBlocksWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
class WarnBlocksWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
||||||
val warningBlocks = buffer.readVarInt()
|
val warningBlocks = buffer.readVarInt()
|
||||||
|
|
||||||
|
override fun handle(connection: PlayConnection) {
|
||||||
|
connection.world.border.warningBlocks = warningBlocks
|
||||||
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Warning blocks set world border (warningBlocks=$warningBlocks)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Warning blocks set world border (warningBlocks=$warningBlocks)" }
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
package de.bixilon.minosoft.protocol.packets.s2c.play.border
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -24,6 +25,10 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
|||||||
class WarnTimeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
class WarnTimeWorldBorderS2CP(buffer: PlayInByteBuffer) : WorldBorderS2CP {
|
||||||
val warningTime = buffer.readVarInt()
|
val warningTime = buffer.readVarInt()
|
||||||
|
|
||||||
|
override fun handle(connection: PlayConnection) {
|
||||||
|
connection.world.border.warningTime = warningTime
|
||||||
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
override fun log(reducedLog: Boolean) {
|
||||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Warning time set world border (warningTime=$warningTime)" }
|
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Warning time set world border (warningTime=$warningTime)" }
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
package de.bixilon.minosoft.protocol.protocol
|
package de.bixilon.minosoft.protocol.protocol
|
||||||
|
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2
|
import de.bixilon.kotlinglm.vec2.Vec2
|
||||||
|
import de.bixilon.kotlinglm.vec2.Vec2d
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
import de.bixilon.kotlinglm.vec3.Vec3
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||||
@ -308,6 +309,10 @@ open class InByteBuffer {
|
|||||||
return Vec2(readFloat(), readFloat())
|
return Vec2(readFloat(), readFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun readVec2d(): Vec2d {
|
||||||
|
return Vec2d(readDouble(), readDouble())
|
||||||
|
}
|
||||||
|
|
||||||
fun readVec3f(): Vec3 {
|
fun readVec3f(): Vec3 {
|
||||||
return Vec3(readFloat(), readFloat(), readFloat())
|
return Vec3(readFloat(), readFloat(), readFloat())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user