Final fixes to synchronization of mattery player to other players

This commit is contained in:
DBotThePony 2022-10-21 23:56:38 +07:00
parent 949e529b19
commit 2816250774
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 44 additions and 15 deletions

View File

@ -128,6 +128,8 @@ public final class OverdriveThatMatters {
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryPlayerCapability.Companion::onPlayerDeath); EVENT_BUS.addListener(EventPriority.LOWEST, MatteryPlayerCapability.Companion::onPlayerDeath);
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerCloneEvent); EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerCloneEvent);
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::canEntitySpawn); EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::canEntitySpawn);
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onStartTracking);
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onStopTracking);
EVENT_BUS.addListener(EventPriority.LOW, MatterDataKt::serverStartData); EVENT_BUS.addListener(EventPriority.LOW, MatterDataKt::serverStartData);
EVENT_BUS.addListener(EventPriority.NORMAL, MatterRegistryKt::onPlayerJoin); EVENT_BUS.addListener(EventPriority.NORMAL, MatterRegistryKt::onPlayerJoin);

View File

@ -1,5 +1,7 @@
package ru.dbotthepony.mc.otm.capability package ru.dbotthepony.mc.otm.capability
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import net.minecraft.ChatFormatting import net.minecraft.ChatFormatting
import net.minecraft.core.Direction import net.minecraft.core.Direction
import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.CompoundTag
@ -179,6 +181,17 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
private var shouldPlaySound = false private var shouldPlaySound = false
private val research = IdentityHashMap<AndroidResearchType, AndroidResearch>() private val research = IdentityHashMap<AndroidResearchType, AndroidResearch>()
// players tracking us
// stored separately because EntityTracker and ChunkMup, etc are buried deep and
// getting them unburied will be a very work intense task
private val trackingPlayers = Reference2ObjectOpenHashMap<ServerPlayer, FieldSynchronizer.Endpoint>()
init {
if (ply is ServerPlayer) {
trackingPlayers[ply] = publicSynchronizer.Endpoint()
}
}
val isEverAndroid: Boolean get() = isAndroid || willBecomeAndroid val isEverAndroid: Boolean get() = isAndroid || willBecomeAndroid
var lastJumpTicks = 14 var lastJumpTicks = 14
@ -665,8 +678,14 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload, false)) MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload, false))
} }
for (ply in MINECRAFT_SERVER.playerList.players) { val trackingIterator = trackingPlayers.entries.iterator()
val endpoint = publicSynchronizer.computeEndpointFor(ply)
for ((ply, endpoint) in trackingIterator) {
if (ply.hasDisconnected()) {
trackingIterator.remove()
continue
}
val payload2 = endpoint.collectNetworkPayload() val payload2 = endpoint.collectNetworkPayload()
if (payload2 != null) { if (payload2 != null) {
@ -973,5 +992,19 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
MatteryPlayerNetworkChannel.sendToServer(PickItemFromInventoryPacket(targetSlot, itemSlot)) MatteryPlayerNetworkChannel.sendToServer(PickItemFromInventoryPacket(targetSlot, itemSlot))
} }
fun onStartTracking(event: PlayerEvent.StartTracking) {
if (event.target is ServerPlayer) {
event.target.matteryPlayer?.let {
it.trackingPlayers[event.entity as ServerPlayer] = it.publicSynchronizer.Endpoint()
}
}
}
fun onStopTracking(event: PlayerEvent.StopTracking) {
if (event.target is ServerPlayer) {
event.target.matteryPlayer?.trackingPlayers?.remove(event.entity as ServerPlayer)
}
}
} }
} }

View File

@ -611,11 +611,9 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
} }
override fun markDirty() { override fun markDirty() {
if (!isDirty) {
notifyEndpoints(this@Field) notifyEndpoints(this@Field)
isDirty = true isDirty = true
} }
}
override fun markDirty(endpoint: Endpoint) { override fun markDirty(endpoint: Endpoint) {
endpoint.addDirtyField(this) endpoint.addDirtyField(this)
@ -664,11 +662,9 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
} }
override fun markDirty() { override fun markDirty() {
if (!isDirty && clientValue == null) {
notifyEndpoints(this) notifyEndpoints(this)
isDirty = true isDirty = true
} }
}
override fun markDirty(endpoint: Endpoint) { override fun markDirty(endpoint: Endpoint) {
endpoint.addDirtyField(this) endpoint.addDirtyField(this)
@ -729,11 +725,9 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
} }
override fun markDirty() { override fun markDirty() {
if (!isDirty) {
notifyEndpoints(this) notifyEndpoints(this)
isDirty = true isDirty = true
} }
}
override fun markDirty(endpoint: Endpoint) { override fun markDirty(endpoint: Endpoint) {
endpoint.addDirtyField(this) endpoint.addDirtyField(this)
@ -1105,7 +1099,7 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
val payloadSize = stream.readVarIntLE() val payloadSize = stream.readVarIntLE()
if (field == null) { if (field == null) {
LOGGER.error("Unable to read field $fieldId (${missingFieldsMap[fieldId]}) because we don't know anything about it!") LOGGER.error("Unable to read field $fieldId (${missingFieldsMap[fieldId]}) because we don't know anything about it! Skipping $payloadSize bytes", IllegalStateException("Unknown field $fieldId"))
stream.skipNBytes(payloadSize.toLong()) stream.skipNBytes(payloadSize.toLong())
continue continue
} }