Wire connecting?
This commit is contained in:
parent
a46269aa15
commit
7f0f647494
@ -193,6 +193,8 @@ data class ObjectOrientation(
|
|||||||
var occupySpaces = obj["spaces"]?.let { spaces.fromJsonTree(it) } ?: ImmutableSet.of(Vector2i.ZERO)
|
var occupySpaces = obj["spaces"]?.let { spaces.fromJsonTree(it) } ?: ImmutableSet.of(Vector2i.ZERO)
|
||||||
|
|
||||||
if ("spaceScan" in obj) {
|
if ("spaceScan" in obj) {
|
||||||
|
occupySpaces = ImmutableSet.of()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (drawable in drawables) {
|
for (drawable in drawables) {
|
||||||
if (drawable is Drawable.Image) {
|
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 sprite = bound.sprite ?: throw IllegalStateException("Not a valid sprite reference: ${bound.raw} (${bound.imagePath} / ${bound.spritePath})")
|
||||||
|
|
||||||
val new = ImmutableSet.Builder<Vector2i>()
|
val new = ImmutableSet.Builder<Vector2i>()
|
||||||
// new.addAll(occupySpaces)
|
new.addAll(occupySpaces)
|
||||||
new.addAll(sprite.worldSpaces(imagePositionI, obj["spaceScan"].asDouble, flipImages))
|
new.addAll(sprite.worldSpaces(imagePositionI, obj["spaceScan"].asDouble, flipImages))
|
||||||
occupySpaces = new.build()
|
occupySpaces = new.build()
|
||||||
}
|
}
|
||||||
|
@ -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.CelestialRequestPacket
|
||||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.ChatSendPacket
|
import ru.dbotthepony.kstarbound.network.packets.serverbound.ChatSendPacket
|
||||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.ClientDisconnectRequestPacket
|
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.DamageTileGroupPacket
|
||||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.EntityInteractPacket
|
import ru.dbotthepony.kstarbound.network.packets.serverbound.EntityInteractPacket
|
||||||
import ru.dbotthepony.kstarbound.network.packets.serverbound.FindUniqueEntityPacket
|
import ru.dbotthepony.kstarbound.network.packets.serverbound.FindUniqueEntityPacket
|
||||||
@ -462,7 +463,7 @@ class PacketRegistry(val isLegacy: Boolean) {
|
|||||||
LEGACY.skip("CollectLiquid")
|
LEGACY.skip("CollectLiquid")
|
||||||
LEGACY.add(::RequestDropPacket)
|
LEGACY.add(::RequestDropPacket)
|
||||||
LEGACY.add(::SpawnEntityPacket)
|
LEGACY.add(::SpawnEntityPacket)
|
||||||
LEGACY.skip("ConnectWire")
|
LEGACY.add(::ConnectWirePacket)
|
||||||
LEGACY.skip("DisconnectAllWires")
|
LEGACY.skip("DisconnectAllWires")
|
||||||
LEGACY.add(::WorldClientStateUpdatePacket)
|
LEGACY.add(::WorldClientStateUpdatePacket)
|
||||||
LEGACY.add(::FindUniqueEntityPacket)
|
LEGACY.add(::FindUniqueEntityPacket)
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -196,8 +196,8 @@ open class WorldObject(val config: Registry.Entry<ObjectDefinition>) : TileEntit
|
|||||||
val chatConfig by networkedJsonElement().also { networkGroup.upstream.add(it) }
|
val chatConfig by networkedJsonElement().also { networkGroup.upstream.add(it) }
|
||||||
|
|
||||||
inner class WireNode(val position: Vector2i, val isInput: Boolean) {
|
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) }
|
val connections = NetworkedList(WireConnection.CODEC).also { networkGroup.upstream.add(it) }
|
||||||
|
var state by networkedBoolean().also { networkGroup.upstream.add(it) }
|
||||||
|
|
||||||
fun addConnection(connection: WireConnection) {
|
fun addConnection(connection: WireConnection) {
|
||||||
if (connection !in connections) {
|
if (connection !in connections) {
|
||||||
|
Loading…
Reference in New Issue
Block a user