mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 17:37:58 -04:00
fix 1.9..1.12.2 chunk reading + tests
This commit is contained in:
parent
200ca36bce
commit
7b2593778f
@ -96,5 +96,22 @@ class ChunkS2CPTest {
|
||||
assertEquals(blocks[3]!![0, 8, 0]!!.block.identifier, MinecraftBlocks.STONE)
|
||||
assertEquals(blocks[3]!![0, 11, 0]!!.block.identifier, MinecraftBlocks.DIRT)
|
||||
}
|
||||
|
||||
@Test(groups = ["packet"], invocationCount = 10)
|
||||
fun cuberite_1_12_2() {
|
||||
val packet = read("cuberite_1_12_2", "1.12.2", dimension = DimensionProperties(light = true, skyLight = true, minY = 0, height = 256))
|
||||
assertEquals(packet.position, Vec2i(0, 0))
|
||||
val blocks = packet.prototype.blocks
|
||||
assertNotNull(blocks); blocks!!
|
||||
assertNull(blocks[0]!![0, 0, 0])
|
||||
|
||||
assertEquals(blocks[0]!![2, 0, 0]!!.block.identifier, MinecraftBlocks.BEDROCK)
|
||||
assertEquals(blocks[0]!![5, 5, 1]!!.block.identifier, MinecraftBlocks.STONE)
|
||||
assertEquals(blocks[1]!![0, 0, 0]!!.block.identifier, MinecraftBlocks.STONE)
|
||||
assertEquals(blocks[2]!![0, 0, 0]!!.block.identifier, MinecraftBlocks.STONE)
|
||||
assertEquals(blocks[3]!![0, 0, 0]!!.block.identifier, MinecraftBlocks.STONE)
|
||||
assertEquals(blocks[3]!![1, 11, 0]!!.block.identifier, MinecraftBlocks.DIRT)
|
||||
assertEquals(blocks[4]!![4, 3, 4]!!.block.identifier, MinecraftBlocks.STONE)
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
src/integration-test/resources/packets/chunk/cuberite_1_12_2.bin
Normal file
BIN
src/integration-test/resources/packets/chunk/cuberite_1_12_2.bin
Normal file
Binary file not shown.
@ -23,7 +23,7 @@ object PalettedContainerReader {
|
||||
fun <T> read(buffer: PlayInByteBuffer, registry: AbstractRegistry<T?>, paletteFactory: PaletteFactory): PalettedContainer<T> {
|
||||
val bits = buffer.readUnsignedByte()
|
||||
|
||||
val palette = paletteFactory.createPalette(registry, bits)
|
||||
val palette = paletteFactory.createPalette(registry, bits, buffer.versionId)
|
||||
palette.read(buffer)
|
||||
|
||||
val paletteData = PaletteData.create(buffer.versionId, palette.bits, paletteFactory.containerSize)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 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.
|
||||
*
|
||||
@ -18,7 +18,7 @@ import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
|
||||
object BiomePaletteFactory : PaletteFactory {
|
||||
override val edgeBits get() = 2
|
||||
|
||||
override fun <T : Any?> createPalette(registry: AbstractRegistry<T?>, bits: Int): Palette<T> {
|
||||
override fun <T : Any?> createPalette(registry: AbstractRegistry<T?>, bits: Int, version: Int): Palette<T> {
|
||||
return when (bits) {
|
||||
0 -> SingularPalette(registry)
|
||||
1, 2, 3 -> ArrayPalette(registry, bits)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 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.
|
||||
*
|
||||
@ -14,16 +14,19 @@
|
||||
package de.bixilon.minosoft.data.world.container.palette.palettes
|
||||
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_17W46A
|
||||
|
||||
object BlockStatePaletteFactory : PaletteFactory {
|
||||
override val edgeBits get() = 4
|
||||
|
||||
override fun <T : Any?> createPalette(registry: AbstractRegistry<T?>, bits: Int): Palette<T> {
|
||||
return when (bits) {
|
||||
0 -> SingularPalette(registry)
|
||||
1, 2, 3, 4 -> ArrayPalette(registry, 4)
|
||||
5, 6, 7, 8 -> ArrayPalette(registry, bits)
|
||||
else -> RegistryPalette(registry)
|
||||
override fun <T : Any?> createPalette(registry: AbstractRegistry<T?>, bits: Int, version: Int): Palette<T> {
|
||||
when (bits) {
|
||||
0 -> return SingularPalette(registry)
|
||||
1, 2, 3, 4 -> return ArrayPalette(registry, 4)
|
||||
5, 6, 7, 8 -> return ArrayPalette(registry, bits)
|
||||
}
|
||||
if (version > V_17W46A) return RegistryPalette(registry) // flattened
|
||||
|
||||
return RegistryPalette(registry, 13) // minecraft uses 13 bits to encode the blocks (8 bits id + 4 bits meta + 1 magic bit, thanks)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 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.
|
||||
*
|
||||
@ -19,5 +19,5 @@ interface PaletteFactory {
|
||||
val containerSize: Int
|
||||
get() = 1 shl (edgeBits * 3)
|
||||
|
||||
fun <T> createPalette(registry: AbstractRegistry<T?>, bits: Int): Palette<T>
|
||||
fun <T> createPalette(registry: AbstractRegistry<T?>, bits: Int, version: Int): Palette<T>
|
||||
}
|
||||
|
@ -15,15 +15,22 @@ package de.bixilon.minosoft.data.world.container.palette.palettes
|
||||
|
||||
import de.bixilon.kutil.math.simple.IntMath.binaryBase
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_12_2
|
||||
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||
|
||||
class RegistryPalette<T>(private val registry: AbstractRegistry<T?>) : Palette<T> {
|
||||
override val bits = registry.size.binaryBase
|
||||
class RegistryPalette<T>(
|
||||
private val registry: AbstractRegistry<T?>,
|
||||
override val bits: Int = registry.size.binaryBase,
|
||||
) : Palette<T> {
|
||||
|
||||
override val isEmpty: Boolean
|
||||
get() = false
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer) {}
|
||||
override fun read(buffer: PlayInByteBuffer) {
|
||||
if (buffer.versionId <= V_1_12_2) { // TODO: find out exact version
|
||||
buffer.readVarInt() // no data
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun getOrNull(id: Int): T? {
|
||||
|
@ -142,6 +142,7 @@ class StatusConnection(
|
||||
state = StatusConnectionStates.RESOLVING
|
||||
val addresses: List<ServerAddress>
|
||||
try {
|
||||
// TODO: Don't resolve if address is ip
|
||||
addresses = resolve()
|
||||
} catch (exception: Exception) {
|
||||
Log.log(LogMessageType.NETWORK) { "Can not resolve ${this.address}" }
|
||||
|
@ -16,6 +16,7 @@ import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.array.ArrayUtil.cast
|
||||
import de.bixilon.kutil.compression.zlib.ZlibUtil.decompress
|
||||
import de.bixilon.kutil.exception.Broken
|
||||
import de.bixilon.kutil.json.JsonUtil.asJsonObject
|
||||
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
@ -37,6 +38,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W28A
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_15W34C
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_15W36D
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_18W44A
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_19W36A
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_16_2_PRE2
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_16_PRE7
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_9_4
|
||||
@ -94,7 +96,7 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
if (buffer.versionId >= V_18W44A) {
|
||||
buffer.readNBT()?.toJsonObject() // heightmap
|
||||
}
|
||||
if (action == ChunkAction.CREATE && buffer.versionId < V_21W37A) {
|
||||
if (action == ChunkAction.CREATE && buffer.versionId >= V_19W36A && buffer.versionId < V_21W37A) {
|
||||
this.prototype.biomeSource = SpatialBiomeArray(buffer.readBiomeArray())
|
||||
}
|
||||
readingData = ChunkReadingData(PlayInByteBuffer(buffer.readByteArray(), buffer.connection), dimension, sectionBitMask)
|
||||
@ -153,8 +155,8 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
fun PlayInByteBuffer.readBiomeArray(): Array<Biome> {
|
||||
val length = when {
|
||||
versionId >= ProtocolVersions.V_20W28A -> readVarInt()
|
||||
versionId >= ProtocolVersions.V_19W36A -> ProtocolDefinition.BLOCKS_PER_SECTION / 4 // 1024, 4x4 blocks
|
||||
else -> 0
|
||||
versionId >= V_19W36A -> ProtocolDefinition.BLOCKS_PER_SECTION / 4 // 1024, 4x4 blocks
|
||||
else -> Broken("")
|
||||
}
|
||||
|
||||
check(length <= this.size) { "Trying to allocate too much memory" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user