diff --git a/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunk.kt b/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunk.kt index d463e5a..e7cb4ff 100644 --- a/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunk.kt +++ b/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunk.kt @@ -9,14 +9,15 @@ import com.google.common.cache.LoadingCache import space.uranos.player.Player import space.uranos.util.createWeakValuesLoadingCache import space.uranos.world.* -import space.uranos.world.block.Air +import space.uranos.world.block.AirBlock class AnvilChunk(world: AnvilWorld, key: Key) : Chunk(world, key) { // TODO: Implement light override fun getData(player: Player?): ChunkData { return ChunkData( - sections.map { section -> if (section.blocks.all { it == Air }) null else section.blocks }.toTypedArray(), + sections.map { section -> if (section.blocks.all { it == AirBlock }) null else section.blocks } + .toTypedArray(), Array(ChunkData.BIOME_AREAS_IN_CHUNK) { Biome.PLAINS } ) } diff --git a/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunkSection.kt b/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunkSection.kt index 7a13546..6e955e6 100644 --- a/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunkSection.kt +++ b/test-plugin/src/main/kotlin/space/uranos/testplugin/anvil/AnvilChunkSection.kt @@ -6,11 +6,11 @@ package space.uranos.testplugin.anvil import space.uranos.world.Chunk -import space.uranos.world.block.Air +import space.uranos.world.block.AirBlock import space.uranos.world.block.Block class AnvilChunkSection { - val blocks: Array = Array(Chunk.BLOCKS_IN_A_SECTION) { Air } + val blocks: Array = Array(Chunk.BLOCKS_IN_A_SECTION) { AirBlock } val blockLightValues: UByteArray = UByteArray(Chunk.BLOCKS_IN_A_SECTION / 2) { 0xFF.toUByte() } val skyLightValues: UByteArray = UByteArray(Chunk.BLOCKS_IN_A_SECTION / 2) { 0xFF.toUByte() } } diff --git a/uranos-api/src/main/kotlin/space/uranos/world/ChunkData.kt b/uranos-api/src/main/kotlin/space/uranos/world/ChunkData.kt index 047a0c8..aa4befb 100644 --- a/uranos-api/src/main/kotlin/space/uranos/world/ChunkData.kt +++ b/uranos-api/src/main/kotlin/space/uranos/world/ChunkData.kt @@ -12,7 +12,7 @@ data class ChunkData( * The outer array must have 16 items representing the chunk sections. * * The inner arrays contain the blocks (x, z, y) of a chunk section and must have a size of 4096. - * If a chunk section only contains air, it should be null (instead of an array of Air). + * If a chunk section only contains air, it should be null (instead of an array of AirBlock). */ val sections: Array?>, @@ -29,7 +29,7 @@ data class ChunkData( /** * An array (first x, then z) containing the y coordinates of the highest block in every column which is - * neither [Air][space.uranos.world.block.Air] nor [CaveAir][space.uranos.world.block.CaveAir]. + * neither [AirBlock][space.uranos.world.block.AirBlock] nor [CaveAirBlock][space.uranos.world.block.CaveAirBlock]. * Will be computed using [sections] if null. */ val nonAirBlocksHeightmap: ByteArray? = null diff --git a/uranos-api/src/main/kotlin/space/uranos/world/block/Air.kt b/uranos-api/src/main/kotlin/space/uranos/world/block/AirBlock.kt similarity index 85% rename from uranos-api/src/main/kotlin/space/uranos/world/block/Air.kt rename to uranos-api/src/main/kotlin/space/uranos/world/block/AirBlock.kt index 47cea38..2f1967a 100644 --- a/uranos-api/src/main/kotlin/space/uranos/world/block/Air.kt +++ b/uranos-api/src/main/kotlin/space/uranos/world/block/AirBlock.kt @@ -9,7 +9,7 @@ package space.uranos.world.block /** * Material: [AIR][Material.AIR] */ -object Air : Block(), Material by material( +object AirBlock : Block(), Material by material( 0, "minecraft:air", 0, diff --git a/uranos-api/src/main/kotlin/space/uranos/world/block/Block.kt b/uranos-api/src/main/kotlin/space/uranos/world/block/Block.kt index f48fc29..a1f9b3c 100644 --- a/uranos-api/src/main/kotlin/space/uranos/world/block/Block.kt +++ b/uranos-api/src/main/kotlin/space/uranos/world/block/Block.kt @@ -16,7 +16,7 @@ import kotlin.reflect.KClass abstract class Block internal constructor() { companion object { /** - * See [DaylightDetector] for an example on how this function should be used. + * See [DaylightDetectorBlock] for an example on how this function should be used. */ internal inline fun material( numericID: Int, diff --git a/uranos-api/src/main/kotlin/space/uranos/world/block/CaveAir.kt b/uranos-api/src/main/kotlin/space/uranos/world/block/CaveAirBlock.kt similarity index 84% rename from uranos-api/src/main/kotlin/space/uranos/world/block/CaveAir.kt rename to uranos-api/src/main/kotlin/space/uranos/world/block/CaveAirBlock.kt index 0986f28..e54f43b 100644 --- a/uranos-api/src/main/kotlin/space/uranos/world/block/CaveAir.kt +++ b/uranos-api/src/main/kotlin/space/uranos/world/block/CaveAirBlock.kt @@ -8,7 +8,7 @@ package space.uranos.world.block /** * Material: [CAVE_AIR][Material.CAVE_AIR] */ -object CaveAir : Block(), Material by material( +object CaveAirBlock : Block(), Material by material( 617, "minecraft:cave_air", 9130, diff --git a/uranos-api/src/main/kotlin/space/uranos/world/block/DaylightDetector.kt b/uranos-api/src/main/kotlin/space/uranos/world/block/DaylightDetectorBlock.kt similarity index 82% rename from uranos-api/src/main/kotlin/space/uranos/world/block/DaylightDetector.kt rename to uranos-api/src/main/kotlin/space/uranos/world/block/DaylightDetectorBlock.kt index 46c6d83..c0ace32 100644 --- a/uranos-api/src/main/kotlin/space/uranos/world/block/DaylightDetector.kt +++ b/uranos-api/src/main/kotlin/space/uranos/world/block/DaylightDetectorBlock.kt @@ -5,13 +5,13 @@ package space.uranos.world.block -data class DaylightDetector( +data class DaylightDetectorBlock( @Attribute val inverted: Boolean = false, @Attribute(15) val power: Int ) : Block() { - companion object : Material by material( + companion object : Material by material( 333, "minecraft:daylight_detector", 6698, diff --git a/uranos-api/src/test/kotlin/space/blokk/world/block/BlockCodecTest.kt b/uranos-api/src/test/kotlin/space/blokk/world/block/BlockCodecTest.kt index 11cc8a3..65186d2 100644 --- a/uranos-api/src/test/kotlin/space/blokk/world/block/BlockCodecTest.kt +++ b/uranos-api/src/test/kotlin/space/blokk/world/block/BlockCodecTest.kt @@ -7,11 +7,11 @@ import strikt.assertions.isEqualTo class BlockCodecTest { @Test fun `getStateID returns 6698 for DaylightDetector(inverted=true, power=0)`() { - expectThat(DaylightDetector.codec.getStateID(DaylightDetector(true, 0))).isEqualTo(6698) + expectThat(DaylightDetectorBlock.codec.getStateID(DaylightDetectorBlock(true, 0))).isEqualTo(6698) } @Test fun `getStateID returns 6729 for DaylightDetector(inverted=false, power=15)`() { - expectThat(DaylightDetector.codec.getStateID(DaylightDetector(false, 15))).isEqualTo(6729) + expectThat(DaylightDetectorBlock.codec.getStateID(DaylightDetectorBlock(false, 15))).isEqualTo(6729) } } diff --git a/uranos-packet-codecs/src/main/kotlin/space/uranos/net/packet/play/ChunkDataPacketCodec.kt b/uranos-packet-codecs/src/main/kotlin/space/uranos/net/packet/play/ChunkDataPacketCodec.kt index 0de5560..442f0c0 100644 --- a/uranos-packet-codecs/src/main/kotlin/space/uranos/net/packet/play/ChunkDataPacketCodec.kt +++ b/uranos-packet-codecs/src/main/kotlin/space/uranos/net/packet/play/ChunkDataPacketCodec.kt @@ -14,15 +14,15 @@ import space.uranos.net.packet.OutgoingPacketCodec import space.uranos.util.generateHeightmap import space.uranos.util.setBit import space.uranos.util.toCompactLongArray -import space.uranos.world.block.Air -import space.uranos.world.block.CaveAir +import space.uranos.world.block.AirBlock +import space.uranos.world.block.CaveAirBlock import space.uranos.world.block.Material import space.uranos.world.block.material import kotlin.math.ceil import kotlin.math.log object ChunkDataPacketCodec : OutgoingPacketCodec(0x20, ChunkDataPacket::class) { - private val airBlocks: Set> = setOf(Air, CaveAir) + private val airBlocks: Set> = setOf(AirBlock, CaveAirBlock) private val nonSolidBlocks = Material.all.filter { it.collisionShape.isEmpty() } private val numberOfBitsPerBlock = ceil(log(Material.all.last().codec.lastStateID.toDouble(), 2.0)).toInt() @@ -67,8 +67,11 @@ object ChunkDataPacketCodec : OutgoingPacketCodec(0x20, ChunkDa // Blocks val dataBuf = Unpooled.buffer() // TODO: Set an initial capacity for (section in data.sections.filterNotNull()) { - val ids = section.map { it.material().codec.getStateID(it) }.toIntArray() - dataBuf.writeShort(ids.count { !(it == Air.codec.id || it == CaveAir.codec.id) }) + val ids = section.map { + println(it) + it.material().codec.getStateID(it) + }.toIntArray() + dataBuf.writeShort(ids.count { !(it == AirBlock.codec.id || it == CaveAirBlock.codec.id) }) dataBuf.writeByte(numberOfBitsPerBlock) val array = ids.toCompactLongArray(numberOfBitsPerBlock)