Fix not networking collision type

This commit is contained in:
DBotThePony 2024-03-27 15:02:11 +07:00
parent 9c1772a766
commit 9bbef92ea9
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 10 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.network
import ru.dbotthepony.kommons.io.readVarInt
import ru.dbotthepony.kommons.io.writeVarInt
import ru.dbotthepony.kstarbound.defs.tile.BuiltinMetaMaterials
import ru.dbotthepony.kstarbound.world.physics.CollisionType
import java.io.DataInputStream
import java.io.DataOutputStream
@ -66,7 +67,7 @@ data class LegacyNetworkCellState(
val background: LegacyNetworkTileState,
val foreground: LegacyNetworkTileState,
val collisionType: Int, // ubyte
val collisionType: CollisionType, // ubyte
val blockBiomeIndex: Int, // ubyte
val environmentBiomeIndex: Int, // ubyte
val liquid: LegacyNetworkLiquidState,
@ -76,22 +77,22 @@ data class LegacyNetworkCellState(
background.write(stream)
foreground.write(stream)
stream.write(collisionType)
stream.write(blockBiomeIndex)
stream.write(environmentBiomeIndex)
stream.writeByte(collisionType.ordinal)
stream.writeByte(blockBiomeIndex)
stream.writeByte(environmentBiomeIndex)
liquid.write(stream)
stream.writeVarInt(dungeonId)
}
companion object {
val EMPTY = LegacyNetworkCellState(LegacyNetworkTileState.EMPTY, LegacyNetworkTileState.EMPTY, 0, 0, 0, LegacyNetworkLiquidState.EMPTY, 0)
val NULL = LegacyNetworkCellState(LegacyNetworkTileState.NULL, LegacyNetworkTileState.NULL, 0, 0, 0, LegacyNetworkLiquidState.EMPTY, 0)
val EMPTY = LegacyNetworkCellState(LegacyNetworkTileState.EMPTY, LegacyNetworkTileState.EMPTY, CollisionType.NONE, 0, 0, LegacyNetworkLiquidState.EMPTY, 0)
val NULL = LegacyNetworkCellState(LegacyNetworkTileState.NULL, LegacyNetworkTileState.NULL, CollisionType.NULL, 0, 0, LegacyNetworkLiquidState.EMPTY, 0)
fun read(stream: DataInputStream): LegacyNetworkCellState {
return LegacyNetworkCellState(
LegacyNetworkTileState.read(stream),
LegacyNetworkTileState.read(stream),
stream.readUnsignedByte(),
CollisionType.entries[stream.readUnsignedByte()],
stream.readUnsignedByte(),
stream.readUnsignedByte(),
LegacyNetworkLiquidState.read(stream),

View File

@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Interner
import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.network.LegacyNetworkCellState
import ru.dbotthepony.kstarbound.util.HashTableInterner
import ru.dbotthepony.kstarbound.world.physics.CollisionType
import java.io.DataInputStream
import java.io.DataOutputStream
@ -21,7 +22,7 @@ sealed class AbstractCell {
abstract fun mutable(): MutableCell
fun toLegacyNet(): LegacyNetworkCellState {
return LegacyNetworkCellState(background.toLegacyNet(), foreground.toLegacyNet(), 0, biome, envBiome, liquid.toLegacyNet(), dungeonId)
return LegacyNetworkCellState(background.toLegacyNet(), foreground.toLegacyNet(), foreground.material.value.collisionKind, biome, envBiome, liquid.toLegacyNet(), dungeonId)
}
fun write(stream: DataOutputStream) {