Fix getVoxelsInCube
This commit is contained in:
parent
c090b1461a
commit
20e054c0f8
6 changed files with 25 additions and 12 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
package space.blokk.util
|
||||||
|
|
||||||
|
infix fun Int.untilPossiblyNegative(other: Int) =
|
||||||
|
IntProgression.fromClosedRange(this, other, if (this > other) -1 else 1)
|
|
@ -5,6 +5,7 @@ import space.blokk.Blokk
|
||||||
import space.blokk.entity.Entity
|
import space.blokk.entity.Entity
|
||||||
import space.blokk.util.newSingleThreadDispatcher
|
import space.blokk.util.newSingleThreadDispatcher
|
||||||
import space.blokk.util.supervisorChild
|
import space.blokk.util.supervisorChild
|
||||||
|
import space.blokk.util.untilPossiblyNegative
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
@ -59,17 +60,14 @@ abstract class World(val uuid: UUID) {
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
fun getVoxelsInCube(cornerA: VoxelLocation, cornerB: VoxelLocation, hollow: Boolean = false): List<Voxel> {
|
fun getVoxelsInCube(cornerA: VoxelLocation, cornerB: VoxelLocation, hollow: Boolean = false): List<Voxel> {
|
||||||
val xList = if (hollow) listOf(cornerA.x, cornerB.x).distinct() else (cornerA.x..cornerB.x).toList()
|
fun getList(a: Int, b: Int) =
|
||||||
val zList = if (hollow) listOf(cornerA.z, cornerB.z).distinct() else (cornerA.z..cornerB.z).toList()
|
if (hollow) listOf(a, b).distinct()
|
||||||
|
else (a untilPossiblyNegative b).toList()
|
||||||
val yList =
|
|
||||||
if (hollow) listOf(cornerA.y.toInt(), cornerB.y.toInt()).distinct()
|
|
||||||
else (cornerA.y.toInt()..cornerB.y.toInt()).toList()
|
|
||||||
|
|
||||||
return buildList {
|
return buildList {
|
||||||
for(x in xList) {
|
for(x in getList(cornerA.x, cornerB.x)) {
|
||||||
for(y in yList) {
|
for(y in getList(cornerA.y.toInt(), cornerB.y.toInt())) {
|
||||||
for(z in zList) {
|
for(z in getList(cornerA.z, cornerB.z)) {
|
||||||
add(getVoxel(VoxelLocation(x, y.toUByte(), z)))
|
add(getVoxel(VoxelLocation(x, y.toUByte(), z)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,12 @@ import space.blokk.world.ChunkData
|
||||||
/**
|
/**
|
||||||
* Sent to inform the player about blocks and biomes in a chunk.
|
* Sent to inform the player about blocks and biomes in a chunk.
|
||||||
*/
|
*/
|
||||||
data class ChunkDataPacket(val key: Chunk.Key, val data: ChunkData) : OutgoingPacket()
|
data class ChunkDataPacket(val key: Chunk.Key, val data: ChunkData) : OutgoingPacket() {
|
||||||
|
init {
|
||||||
|
if (key.x == 0 && key.z == 0) {
|
||||||
|
data.sections[0]?.forEach {
|
||||||
|
print(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import kotlin.properties.Delegates
|
||||||
class BlokkSession(private val channel: io.netty.channel.Channel, val server: BlokkServer) : Session() {
|
class BlokkSession(private val channel: io.netty.channel.Channel, val server: BlokkServer) : Session() {
|
||||||
override val address: InetAddress = (channel.remoteAddress() as InetSocketAddress).address
|
override val address: InetAddress = (channel.remoteAddress() as InetSocketAddress).address
|
||||||
|
|
||||||
private val identifier = "BlokkSession(${address.hostAddress})" + System.identityHashCode(this)
|
private val identifier = "BlokkSession(${address.hostAddress})"
|
||||||
val logger = Logger(identifier)
|
val logger = Logger(identifier)
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext = server.coroutineContext.supervisorChild(identifier)
|
override val coroutineContext: CoroutineContext = server.coroutineContext.supervisorChild(identifier)
|
||||||
|
|
|
@ -201,7 +201,7 @@ class LoginAndJoinProcedure(val session: BlokkSession) {
|
||||||
|
|
||||||
session.send(UpdateViewPositionPacket(Chunk.Key.from(player.location.toVoxelLocation())))
|
session.send(UpdateViewPositionPacket(Chunk.Key.from(player.location.toVoxelLocation())))
|
||||||
|
|
||||||
session.scheduleKeepAlivePacket()
|
session.scheduleKeepAlivePacket(true)
|
||||||
player.sendChunksAndLight()
|
player.sendChunksAndLight()
|
||||||
|
|
||||||
// WorldBorder
|
// WorldBorder
|
||||||
|
|
|
@ -38,6 +38,9 @@ class TestPlugin: Plugin("Test", "1.0.0") {
|
||||||
}
|
}
|
||||||
|
|
||||||
Blokk.eventBus.on<SessionAfterLoginEvent> { event ->
|
Blokk.eventBus.on<SessionAfterLoginEvent> { event ->
|
||||||
|
event.gameMode = GameMode.CREATIVE
|
||||||
|
event.canFly = true
|
||||||
|
event.flying = true
|
||||||
event.initialWorldAndLocation = WorldAndLocationWithRotation(
|
event.initialWorldAndLocation = WorldAndLocationWithRotation(
|
||||||
world,
|
world,
|
||||||
VoxelLocation.of(0, 2, 0).atTopCenter().withRotation(0f, 0f)
|
VoxelLocation.of(0, 2, 0).atTopCenter().withRotation(0f, 0f)
|
||||||
|
|
Reference in a new issue