Final fixes to synchronization of mattery player to other players
This commit is contained in:
parent
949e529b19
commit
2816250774
@ -128,6 +128,8 @@ public final class OverdriveThatMatters {
|
||||
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryPlayerCapability.Companion::onPlayerDeath);
|
||||
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerCloneEvent);
|
||||
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.NORMAL, MatterRegistryKt::onPlayerJoin);
|
||||
|
@ -1,5 +1,7 @@
|
||||
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.core.Direction
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
@ -179,6 +181,17 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
||||
private var shouldPlaySound = false
|
||||
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
|
||||
var lastJumpTicks = 14
|
||||
|
||||
@ -665,8 +678,14 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
||||
MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload, false))
|
||||
}
|
||||
|
||||
for (ply in MINECRAFT_SERVER.playerList.players) {
|
||||
val endpoint = publicSynchronizer.computeEndpointFor(ply)
|
||||
val trackingIterator = trackingPlayers.entries.iterator()
|
||||
|
||||
for ((ply, endpoint) in trackingIterator) {
|
||||
if (ply.hasDisconnected()) {
|
||||
trackingIterator.remove()
|
||||
continue
|
||||
}
|
||||
|
||||
val payload2 = endpoint.collectNetworkPayload()
|
||||
|
||||
if (payload2 != null) {
|
||||
@ -973,5 +992,19 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -611,10 +611,8 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
}
|
||||
|
||||
override fun markDirty() {
|
||||
if (!isDirty) {
|
||||
notifyEndpoints(this@Field)
|
||||
isDirty = true
|
||||
}
|
||||
notifyEndpoints(this@Field)
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
override fun markDirty(endpoint: Endpoint) {
|
||||
@ -664,10 +662,8 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
}
|
||||
|
||||
override fun markDirty() {
|
||||
if (!isDirty && clientValue == null) {
|
||||
notifyEndpoints(this)
|
||||
isDirty = true
|
||||
}
|
||||
notifyEndpoints(this)
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
override fun markDirty(endpoint: Endpoint) {
|
||||
@ -729,10 +725,8 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
}
|
||||
|
||||
override fun markDirty() {
|
||||
if (!isDirty) {
|
||||
notifyEndpoints(this)
|
||||
isDirty = true
|
||||
}
|
||||
notifyEndpoints(this)
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
override fun markDirty(endpoint: Endpoint) {
|
||||
@ -1105,7 +1099,7 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
val payloadSize = stream.readVarIntLE()
|
||||
|
||||
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())
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user