SpawnEntityPacket
This commit is contained in:
parent
8fe7a6f951
commit
164040b45b
@ -579,7 +579,7 @@ class TerrestrialWorldParameters : VisitableWorldParameters() {
|
||||
parameters.threatLevel = threadLevel
|
||||
parameters.typeName = typeName
|
||||
parameters.worldSize = params.size
|
||||
parameters.gravity = Vector2d(y = 10.0)
|
||||
parameters.gravity = Vector2d(y = random.nextRange(params.gravityRange))
|
||||
parameters.airless = primaryBiome.value.airless
|
||||
parameters.environmentStatusEffects = primaryBiome.value.statusEffects
|
||||
parameters.overrideTech = params.overrideTech
|
||||
|
@ -67,6 +67,7 @@ import ru.dbotthepony.kstarbound.network.packets.serverbound.FlyShipPacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.ModifyTileListPacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.PlayerWarpPacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.RequestDropPacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.SpawnEntityPacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.WorldClientStateUpdatePacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.WorldStartAcknowledgePacket
|
||||
import java.io.BufferedInputStream
|
||||
@ -460,7 +461,7 @@ class PacketRegistry(val isLegacy: Boolean) {
|
||||
LEGACY.add(::DamageTileGroupPacket)
|
||||
LEGACY.skip("CollectLiquid")
|
||||
LEGACY.add(::RequestDropPacket)
|
||||
LEGACY.skip("SpawnEntity")
|
||||
LEGACY.add(::SpawnEntityPacket)
|
||||
LEGACY.skip("ConnectWire")
|
||||
LEGACY.skip("DisconnectAllWires")
|
||||
LEGACY.add(::WorldClientStateUpdatePacket)
|
||||
|
@ -39,29 +39,18 @@ class EntityCreatePacket(val entityType: EntityType, val storeData: ByteArrayLis
|
||||
connection.disconnect("Creating entity with ID $entityID outside of allowed range ${connection.entityIDRange}")
|
||||
} else {
|
||||
val entity = when (entityType) {
|
||||
EntityType.PLAYER -> {
|
||||
try {
|
||||
val player = PlayerEntity(DataInputStream(FastByteArrayInputStream(storeData.elements(), 0, storeData.size)), connection.isLegacy)
|
||||
player.networkGroup.read(firstNetState, isLegacy = connection.isLegacy)
|
||||
|
||||
val (data) = player.networkGroup.write(isLegacy = true)
|
||||
player.networkGroup.read(data, isLegacy = true)
|
||||
player
|
||||
} catch (err: Throwable) {
|
||||
LOGGER.error("", err)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
EntityType.PLAYER -> PlayerEntity(DataInputStream(FastByteArrayInputStream(storeData.elements(), 0, storeData.size)), connection.isLegacy)
|
||||
else -> null
|
||||
}
|
||||
|
||||
entity?.entityID = entityID
|
||||
entity?.isRemote = true
|
||||
entity?.networkGroup?.upstream?.enableInterpolation(0.0)
|
||||
entity ?: return
|
||||
entity.networkGroup.read(firstNetState, isLegacy = true)
|
||||
entity.entityID = entityID
|
||||
entity.isRemote = true
|
||||
entity.networkGroup.upstream.enableInterpolation(0.0)
|
||||
|
||||
connection.enqueue {
|
||||
entity?.joinWorld(this)
|
||||
entity.joinWorld(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package ru.dbotthepony.kstarbound.network.packets.serverbound
|
||||
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrayList
|
||||
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream
|
||||
import ru.dbotthepony.kommons.io.readByteArray
|
||||
import ru.dbotthepony.kommons.io.writeByteArray
|
||||
import ru.dbotthepony.kstarbound.defs.EntityType
|
||||
import ru.dbotthepony.kstarbound.network.IServerPacket
|
||||
import ru.dbotthepony.kstarbound.server.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.world.entities.ItemDropEntity
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
|
||||
// similar to EntityCreatePacket, except client transfers ownership of entity to server
|
||||
class SpawnEntityPacket(val entityType: EntityType, val storeData: ByteArrayList, val firstNetState: ByteArrayList,) : IServerPacket {
|
||||
constructor(stream: DataInputStream, isLegacy: Boolean) : this(
|
||||
EntityType.entries[stream.readUnsignedByte()],
|
||||
ByteArrayList.wrap(stream.readByteArray()),
|
||||
ByteArrayList.wrap(stream.readByteArray()),
|
||||
)
|
||||
|
||||
override fun write(stream: DataOutputStream, isLegacy: Boolean) {
|
||||
stream.writeByte(entityType.ordinal)
|
||||
stream.writeByteArray(storeData.elements(), 0, storeData.size)
|
||||
stream.writeByteArray(firstNetState.elements(), 0, firstNetState.size)
|
||||
}
|
||||
|
||||
override fun play(connection: ServerConnection) {
|
||||
val entity = when (entityType) {
|
||||
EntityType.ITEM_DROP -> ItemDropEntity(DataInputStream(FastByteArrayInputStream(storeData.elements(), 0, storeData.size)), connection.isLegacy)
|
||||
else -> null
|
||||
}
|
||||
|
||||
entity ?: return
|
||||
entity.networkGroup.read(firstNetState, isLegacy = connection.isLegacy)
|
||||
|
||||
connection.enqueue {
|
||||
entity.joinWorld(this)
|
||||
}
|
||||
}
|
||||
}
|
@ -217,7 +217,7 @@ abstract class World<This : World<This, ChunkType>, ChunkType : Chunk<This, Chun
|
||||
* Random generator for in-world events
|
||||
*/
|
||||
val random: RandomGenerator = random()
|
||||
var gravity = Vector2d(0.0, -80.0)
|
||||
|
||||
abstract val isClient: Boolean
|
||||
val isServer: Boolean
|
||||
get() = !isClient
|
||||
@ -398,11 +398,11 @@ abstract class World<This : World<This, ChunkType>, ChunkType : Chunk<This, Chun
|
||||
}
|
||||
|
||||
fun gravityAt(pos: IStruct2i): Vector2d {
|
||||
return gravity
|
||||
return template.worldParameters?.gravity ?: Vector2d.ZERO
|
||||
}
|
||||
|
||||
fun gravityAt(pos: IStruct2d): Vector2d {
|
||||
return gravity
|
||||
return template.worldParameters?.gravity ?: Vector2d.ZERO
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -200,6 +200,13 @@ class ItemDropEntity() : DynamicEntity("/") {
|
||||
|
||||
movement.applyParameters(gravity)
|
||||
}
|
||||
|
||||
intangibleTimer.tick(delta)
|
||||
|
||||
if (state == State.INTANGIBLE && intangibleTimer.hasFinished)
|
||||
state = State.AVAILABLE
|
||||
|
||||
//if (!shouldNotExpire && state == State.AVAILABLE && age.time > )
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ open class MovementController() {
|
||||
if (!isZeroGravity && stickingDirection == null) {
|
||||
val buoyancy = (movementParameters.liquidBuoyancy ?: 0.0).coerceIn(0.0, 1.0) + liquidPercentage + (movementParameters.airBuoyancy ?: 0.0).coerceIn(0.0, 1.0) * (1.0 - liquidPercentage)
|
||||
val gravity = determineGravity() * (movementParameters.gravityMultiplier ?: 1.0) * (1.0 - buoyancy)
|
||||
var environmentVelocity = gravity * delta
|
||||
var environmentVelocity = -gravity * delta
|
||||
|
||||
if (isOnGround && (movementParameters.slopeSlidingFactor ?: 0.0) != 0.0 && surfaceSlope != Vector2d.ZERO)
|
||||
environmentVelocity += -surfaceSlope * (surfaceSlope.x * surfaceSlope.y) * (movementParameters.slopeSlidingFactor ?: 0.0)
|
||||
|
Loading…
Reference in New Issue
Block a user