Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {

// Networking
api("io.ktor:ktor-server-netty:3.1.2")
api("io.github.dockyardmc:tide:3.7")
api("io.github.dockyardmc:tide:3.8")
api("io.github.dockyardmc:bytesocks-client-java:1.0-SNAPSHOT") {
exclude(module = "slf4j-api")
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/io/github/dockyardmc/codec/ExtraCodecs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.dockyardmc.codec

import io.github.dockyardmc.tide.codec.Codec
import io.github.dockyardmc.tide.stream.StreamCodec

object ExtraCodecs {

object BitSet {
val STREAM = StreamCodec.LONG_ARRAY.transform<java.util.BitSet>(java.util.BitSet::toLongArray, java.util.BitSet::valueOf)
val CODEC = Codec.LONG_ARRAY.transform<java.util.BitSet>(java.util.BitSet::valueOf, java.util.BitSet::toLongArray)
}

}
10 changes: 2 additions & 8 deletions src/main/kotlin/io/github/dockyardmc/entity/Entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
val potionEffectsHandler = EntityPotionEffectsHandler(this)
val itemPickupHandler = EntityItemPickupHandler(this)

val chunk: Chunk get() = world.chunks[ChunkPos.fromLocation(location).pack()]

var isDead: Boolean = false

override var autoViewable: Boolean = true
Expand Down Expand Up @@ -126,14 +128,6 @@
}
}

fun getCurrentChunk(): Chunk? {
return world.chunks[getCurrentChunkPos().pack()]
}

fun getCurrentChunkPos(): ChunkPos {
return ChunkPos.fromLocation(location)
}

fun updateEntity(player: Player, respawn: Boolean = false) {
sendMetadataPacketToViewers()
}
Expand Down Expand Up @@ -196,7 +190,7 @@
teleport(newLoc)
}

open fun lookAt(targetLocation: Location) {

Check warning on line 193 in src/main/kotlin/io/github/dockyardmc/entity/Entity.kt

View check run for this annotation

codefactor.io / CodeFactor

src/main/kotlin/io/github/dockyardmc/entity/Entity.kt#L193

Parentheses in (this.location) are unnecessary and can be replaced with: this.location. (detekt.UnnecessaryParentheses)
val newLoc = this.location.setDirection(targetLocation.toVector3d() - (this.location).toVector3d())
teleport(newLoc)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,27 @@
package io.github.dockyardmc.protocol.packets.play.clientbound

import io.github.dockyardmc.extentions.*
import io.github.dockyardmc.protocol.packets.ClientboundPacket
import io.github.dockyardmc.protocol.types.writeList
import io.github.dockyardmc.protocol.types.writeMap
import io.github.dockyardmc.world.Light
import io.github.dockyardmc.tide.stream.StreamCodec
import io.github.dockyardmc.world.LightData
import io.github.dockyardmc.world.block.BlockEntity
import io.github.dockyardmc.world.chunk.ChunkHeightmap
import io.github.dockyardmc.world.chunk.ChunkSection
import io.github.dockyardmc.world.chunk.ChunkUtils
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import it.unimi.dsi.fastutil.objects.ObjectCollection

class ClientboundChunkDataPacket(x: Int, z: Int, heightmaps: Map<ChunkHeightmap.Type, LongArray>, sections: MutableList<ChunkSection>, blockEntities: ObjectCollection<BlockEntity>, light: Light) : ClientboundPacket() {
data class ClientboundChunkDataPacket(val x: Int, val z: Int, val heightmaps: Map<ChunkHeightmap.Type, LongArray>, val sections: List<ChunkSection>, val blockEntities: List<BlockEntity>, val light: LightData) : ClientboundPacket() {

companion object {
val STREAM_CODEC = StreamCodec.of(
StreamCodec.INT, ClientboundChunkDataPacket::x,
StreamCodec.INT, ClientboundChunkDataPacket::z,
StreamCodec.enum<ChunkHeightmap.Type>().mapTo(StreamCodec.LONG_ARRAY), ClientboundChunkDataPacket::heightmaps,
ChunkSection.BYTE_ARRAY_STREAM_CODEC, ClientboundChunkDataPacket::sections,
BlockEntity.STREAM_CODEC.list(), ClientboundChunkDataPacket::blockEntities,
LightData.STREAM_CODEC, ClientboundChunkDataPacket::light,
::ClientboundChunkDataPacket
)
}

init {
//X Z
buffer.writeInt(x)
buffer.writeInt(z)

//Heightmaps
buffer.writeMap<ChunkHeightmap.Type, List<Long>>(heightmaps.mapValues { map -> map.value.toList() }, ByteBuf::writeEnum, ByteBuf::writeLongArray)

//Chunk Sections
val chunkSectionData = Unpooled.buffer()
sections.forEach { section ->
section.write(chunkSectionData)
}
buffer.writeByteArray(chunkSectionData.toByteArraySafe())

//Block Entities
buffer.writeVarInt(blockEntities.size)
blockEntities.forEach { blockEntity ->
val id = blockEntity.blockEntityTypeId
val point = ChunkUtils.chunkBlockIndexGetGlobal(blockEntity.positionIndex, 0, 0)

buffer.writeByte(((point.x and 15) shl 4 or (point.z and 15)))
buffer.writeShort(point.y)
buffer.writeVarInt(id)
buffer.writeNBT(blockEntity.data)
}

// Light stuff
buffer.writeLongArray(light.skyMask.toLongArray().toList())
buffer.writeLongArray(light.blockMask.toLongArray().toList())

buffer.writeLongArray(light.emptySkyMask.toLongArray().toList())
buffer.writeLongArray(light.emptyBlockMask.toLongArray().toList())

buffer.writeList(light.skyLight, ByteBuf::writeByteArray)
buffer.writeList(light.blockLight, ByteBuf::writeByteArray)
STREAM_CODEC.write(buffer, this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.dockyardmc.protocol.packets.play.clientbound

import io.github.dockyardmc.protocol.packets.ClientboundPacket
import io.github.dockyardmc.tide.stream.StreamCodec
import io.github.dockyardmc.world.LightData

data class ClientboundUpdateLightPacket(
val chunkX: Int,
val chunkZ: Int,
val light: LightData
) : ClientboundPacket() {

companion object {
val STREAM_CODEC = StreamCodec.of(
StreamCodec.VAR_INT, ClientboundUpdateLightPacket::chunkX,
StreamCodec.VAR_INT, ClientboundUpdateLightPacket::chunkZ,
LightData.STREAM_CODEC, ClientboundUpdateLightPacket::light,
::ClientboundUpdateLightPacket
)
}

init {
STREAM_CODEC.write(buffer, this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object ClientPacketRegistry : PacketRegistry() {
addPlay(ClientboundChunkDataPacket::class)
addPlay(ClientboundWorldEventPacket::class)
addPlay(ClientboundSendParticlePacket::class)
skipPlay("update light")
addPlay(ClientboundUpdateLightPacket::class)
addPlay(ClientboundLoginPacket::class)
skipPlay("map data")
skipPlay("trade list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.concurrent.CompletableFuture
import java.util.concurrent.atomic.AtomicInteger

class LoginPluginMessageHandler(val networkManager: PlayerNetworkManager) {

companion object {
val REQUEST_ID = AtomicInteger(0)
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/kotlin/io/github/dockyardmc/world/LightData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.dockyardmc.world

import io.github.dockyardmc.codec.ExtraCodecs
import io.github.dockyardmc.tide.codec.Codec
import io.github.dockyardmc.tide.codec.StructCodec
import io.github.dockyardmc.tide.stream.StreamCodec
import io.netty.buffer.ByteBuf
import java.util.*

data class LightData(
val skyMask: BitSet = BitSet(),
val blockMask: BitSet = BitSet(),
val emptySkyMask: BitSet = BitSet(),
val emptyBlockMask: BitSet = BitSet(),
val skyLight: List<ByteBuf> = mutableListOf(),
val blockLight: List<ByteBuf> = mutableListOf()
) {
companion object {

val STREAM_CODEC = StreamCodec.of(
ExtraCodecs.BitSet.STREAM, LightData::skyMask,
ExtraCodecs.BitSet.STREAM, LightData::blockMask,
ExtraCodecs.BitSet.STREAM, LightData::emptySkyMask,
ExtraCodecs.BitSet.STREAM, LightData::emptyBlockMask,
StreamCodec.BYTE_ARRAY.list(), LightData::skyLight,
StreamCodec.BYTE_ARRAY.list(), LightData::blockLight,
::LightData
)

val CODEC = StructCodec.of(
"sky_mask", ExtraCodecs.BitSet.CODEC, LightData::skyMask,
"block_mask", ExtraCodecs.BitSet.CODEC, LightData::blockMask,
"empty_sky_mask", ExtraCodecs.BitSet.CODEC, LightData::emptySkyMask,
"empty_block_mask", ExtraCodecs.BitSet.CODEC, LightData::emptyBlockMask,
"sky_light", Codec.BYTE_BUFFER.list(), LightData::skyLight,
"block_light", Codec.BYTE_BUFFER.list(), LightData::blockLight,
::LightData
)
}
}
Loading
Loading