Better item spewing
This commit is contained in:
parent
58ec1b7933
commit
9d049ec3aa
@ -11,7 +11,6 @@ import ru.dbotthepony.kstarbound.math.vector.Vector2d
|
|||||||
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.Starbound
|
import ru.dbotthepony.kstarbound.Starbound
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.BuiltinMetaMaterials
|
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileDamage
|
import ru.dbotthepony.kstarbound.defs.tile.TileDamage
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.orEmptyTile
|
import ru.dbotthepony.kstarbound.defs.tile.orEmptyTile
|
||||||
@ -19,12 +18,13 @@ import ru.dbotthepony.kstarbound.item.ItemStack
|
|||||||
import ru.dbotthepony.kstarbound.network.syncher.networkedSignedInt
|
import ru.dbotthepony.kstarbound.network.syncher.networkedSignedInt
|
||||||
import ru.dbotthepony.kstarbound.server.world.ServerChunk
|
import ru.dbotthepony.kstarbound.server.world.ServerChunk
|
||||||
import ru.dbotthepony.kstarbound.server.world.ServerWorld
|
import ru.dbotthepony.kstarbound.server.world.ServerWorld
|
||||||
|
import ru.dbotthepony.kstarbound.util.random.nextNormalDouble
|
||||||
import ru.dbotthepony.kstarbound.util.random.random
|
import ru.dbotthepony.kstarbound.util.random.random
|
||||||
import ru.dbotthepony.kstarbound.world.ChunkPos
|
|
||||||
import ru.dbotthepony.kstarbound.world.ChunkState
|
import ru.dbotthepony.kstarbound.world.ChunkState
|
||||||
import ru.dbotthepony.kstarbound.world.World
|
import ru.dbotthepony.kstarbound.world.World
|
||||||
import ru.dbotthepony.kstarbound.world.entities.AbstractEntity
|
import ru.dbotthepony.kstarbound.world.entities.AbstractEntity
|
||||||
import ru.dbotthepony.kstarbound.world.entities.ItemDropEntity
|
import ru.dbotthepony.kstarbound.world.entities.ItemDropEntity
|
||||||
|
import kotlin.math.PI
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Hopefully) Static world entities (Plants, Objects, etc), which reside on cell grid
|
* (Hopefully) Static world entities (Plants, Objects, etc), which reside on cell grid
|
||||||
@ -334,11 +334,24 @@ abstract class TileEntity : AbstractEntity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun spewItem(item: ItemStack) {
|
fun spewItem(item: ItemStack, maxVelocity: Double = 8.0) {
|
||||||
val entity = ItemDropEntity(item)
|
val entity = ItemDropEntity(item)
|
||||||
|
|
||||||
entity.position = occupySpaces.random(world.random) { tilePosition }.toDoubleVector()
|
if (occupySpaces.isEmpty()) {
|
||||||
entity.movement.velocity += Vector2d(world.random.nextDouble(-1.0, 1.0), world.random.nextDouble(-1.0, 1.0))
|
entity.position = position
|
||||||
|
} else {
|
||||||
|
val rand = occupySpaces.random(world.random)
|
||||||
|
|
||||||
|
entity.position = Vector2d(
|
||||||
|
rand.x + world.random.nextDouble(),
|
||||||
|
rand.y + world.random.nextDouble(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// push items out of hypothetical center
|
||||||
|
val center = if (occupySpaces.isNotEmpty()) AABB.ofPoints(occupySpaces).centre else position
|
||||||
|
val angle = world.random.nextNormalDouble(0.5, (entity.position - center).toAngle())
|
||||||
|
entity.movement.velocity += Vector2d.angle(angle, world.random.nextDouble(0.0, maxVelocity))
|
||||||
|
|
||||||
entity.joinWorld(world)
|
entity.joinWorld(world)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user