diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt index 9105dc07..133cb0b9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt @@ -3,12 +3,16 @@ package ru.dbotthepony.kstarbound.defs.`object` import ru.dbotthepony.kstarbound.math.vector.Vector2i import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.defs.tile.TileDefinition +import ru.dbotthepony.kstarbound.defs.tile.isNullTile import ru.dbotthepony.kstarbound.world.World data class Anchor(val isBackground: Boolean, val position: Vector2i, val isTilled: Boolean, val isSoil: Boolean, val anchorMaterial: Registry.Ref?) { - fun isValidPlacement(world: World<*, *>, position: Vector2i): Boolean { + fun isValidPlacement(world: World<*, *>, position: Vector2i, considerNullAsValid: Boolean = false): Boolean { val cell = world.chunkMap.getCell(position + this.position) + if (considerNullAsValid && cell.tile(isBackground).material.isNullTile) + return true + if (!cell.isConnectible(false, isBackground)) return false diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt index 56ec4b34..18482b08 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt @@ -78,14 +78,14 @@ data class ObjectOrientation( } } - fun anchorsValid(world: World<*, *>, position: Vector2i): Boolean { + fun anchorsValid(world: World<*, *>, position: Vector2i, considerNullAsValid: Boolean = false): Boolean { if (anchors.isEmpty()) return true var anyValid = false for (anchor in anchors) { - val isValid = anchor.isValidPlacement(world, position) + val isValid = anchor.isValidPlacement(world, position, considerNullAsValid) if (isValid) anyValid = true diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt index 73c5d5f9..58471228 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/WorldObject.kt @@ -653,7 +653,7 @@ open class WorldObject(val config: Registry.Entry) : TileEntit if (!shouldBreak) { val orientation = orientation - if (orientation != null && !orientation.anchorsValid(world, tilePosition)) { + if (orientation != null && !orientation.anchorsValid(world, tilePosition, considerNullAsValid = true)) { shouldBreak = true } }