Stop objects from popping out of existence if they reside on chunk border and border chunk haven't loaded yet
This commit is contained in:
parent
ba0db89dcf
commit
b6ff323e5a
@ -3,12 +3,16 @@ package ru.dbotthepony.kstarbound.defs.`object`
|
|||||||
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
||||||
import ru.dbotthepony.kstarbound.Registry
|
import ru.dbotthepony.kstarbound.Registry
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
||||||
|
import ru.dbotthepony.kstarbound.defs.tile.isNullTile
|
||||||
import ru.dbotthepony.kstarbound.world.World
|
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<TileDefinition>?) {
|
data class Anchor(val isBackground: Boolean, val position: Vector2i, val isTilled: Boolean, val isSoil: Boolean, val anchorMaterial: Registry.Ref<TileDefinition>?) {
|
||||||
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)
|
val cell = world.chunkMap.getCell(position + this.position)
|
||||||
|
|
||||||
|
if (considerNullAsValid && cell.tile(isBackground).material.isNullTile)
|
||||||
|
return true
|
||||||
|
|
||||||
if (!cell.isConnectible(false, isBackground))
|
if (!cell.isConnectible(false, isBackground))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
@ -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())
|
if (anchors.isEmpty())
|
||||||
return true
|
return true
|
||||||
|
|
||||||
var anyValid = false
|
var anyValid = false
|
||||||
|
|
||||||
for (anchor in anchors) {
|
for (anchor in anchors) {
|
||||||
val isValid = anchor.isValidPlacement(world, position)
|
val isValid = anchor.isValidPlacement(world, position, considerNullAsValid)
|
||||||
|
|
||||||
if (isValid)
|
if (isValid)
|
||||||
anyValid = true
|
anyValid = true
|
||||||
|
@ -653,7 +653,7 @@ open class WorldObject(val config: Registry.Entry<ObjectDefinition>) : TileEntit
|
|||||||
if (!shouldBreak) {
|
if (!shouldBreak) {
|
||||||
val orientation = orientation
|
val orientation = orientation
|
||||||
|
|
||||||
if (orientation != null && !orientation.anchorsValid(world, tilePosition)) {
|
if (orientation != null && !orientation.anchorsValid(world, tilePosition, considerNullAsValid = true)) {
|
||||||
shouldBreak = true
|
shouldBreak = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user