Wire connecting?

This commit is contained in:
DBotThePony 2024-04-12 10:36:43 +07:00
parent a46269aa15
commit 7f0f647494
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 36 additions and 3 deletions

View File

@ -193,6 +193,8 @@ data class ObjectOrientation(
var occupySpaces = obj["spaces"]?.let { spaces.fromJsonTree(it) } ?: ImmutableSet.of(Vector2i.ZERO)
if ("spaceScan" in obj) {
occupySpaces = ImmutableSet.of()
try {
for (drawable in drawables) {
if (drawable is Drawable.Image) {
@ -200,7 +202,7 @@ data class ObjectOrientation(
val sprite = bound.sprite ?: throw IllegalStateException("Not a valid sprite reference: ${bound.raw} (${bound.imagePath} / ${bound.spritePath})")
val new = ImmutableSet.Builder<Vector2i>()
// new.addAll(occupySpaces)
new.addAll(occupySpaces)
new.addAll(sprite.worldSpaces(imagePositionI, obj["spaceScan"].asDouble, flipImages))
occupySpaces = new.build()
}

View File

@ -60,6 +60,7 @@ import ru.dbotthepony.kstarbound.network.packets.clientbound.WorldStopPacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.CelestialRequestPacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.ChatSendPacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.ClientDisconnectRequestPacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.ConnectWirePacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.DamageTileGroupPacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.EntityInteractPacket
import ru.dbotthepony.kstarbound.network.packets.serverbound.FindUniqueEntityPacket
@ -462,7 +463,7 @@ class PacketRegistry(val isLegacy: Boolean) {
LEGACY.skip("CollectLiquid")
LEGACY.add(::RequestDropPacket)
LEGACY.add(::SpawnEntityPacket)
LEGACY.skip("ConnectWire")
LEGACY.add(::ConnectWirePacket)
LEGACY.skip("DisconnectAllWires")
LEGACY.add(::WorldClientStateUpdatePacket)
LEGACY.add(::FindUniqueEntityPacket)

View File

@ -0,0 +1,30 @@
package ru.dbotthepony.kstarbound.network.packets.serverbound
import ru.dbotthepony.kstarbound.network.IServerPacket
import ru.dbotthepony.kstarbound.server.ServerConnection
import ru.dbotthepony.kstarbound.world.entities.tile.WorldObject
import ru.dbotthepony.kstarbound.world.entities.wire.WireConnection
import java.io.DataInputStream
import java.io.DataOutputStream
class ConnectWirePacket(val target: WireConnection, val source: WireConnection) : IServerPacket {
constructor(stream: DataInputStream, isLegacy: Boolean) : this(WireConnection(stream), WireConnection(stream))
override fun write(stream: DataOutputStream, isLegacy: Boolean) {
target.write(stream)
source.write(stream)
}
override fun play(connection: ServerConnection) {
connection.enqueue {
val target = entityIndex.tileEntityAt(target.entityLocation) as? WorldObject ?: return@enqueue
val source = entityIndex.tileEntityAt(source.entityLocation) as? WorldObject ?: return@enqueue
val targetNode = target.outputNodes.getOrNull(this@ConnectWirePacket.target.index) ?: return@enqueue
val sourceNode = source.inputNodes.getOrNull(this@ConnectWirePacket.source.index) ?: return@enqueue
targetNode.addConnection(this@ConnectWirePacket.source)
sourceNode.addConnection(this@ConnectWirePacket.target)
}
}
}

View File

@ -196,8 +196,8 @@ open class WorldObject(val config: Registry.Entry<ObjectDefinition>) : TileEntit
val chatConfig by networkedJsonElement().also { networkGroup.upstream.add(it) }
inner class WireNode(val position: Vector2i, val isInput: Boolean) {
var state by networkedBoolean().also { networkGroup.upstream.add(it) }
val connections = NetworkedList(WireConnection.CODEC).also { networkGroup.upstream.add(it) }
var state by networkedBoolean().also { networkGroup.upstream.add(it) }
fun addConnection(connection: WireConnection) {
if (connection !in connections) {