2015-07-23 13:13:26 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
2016-03-01 00:09:49 +01:00
Date: Wed, 2 Mar 2016 23:13:07 -0600
2015-07-23 13:13:26 +02:00
Subject: [PATCH] Send absolute position the first time an entity is seen
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
2020-05-06 11:48:49 +02:00
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
2015-07-23 13:13:26 +02:00
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
2020-06-25 11:27:25 +02:00
@@ -0,0 +0,0 @@ import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Pair;
2019-04-25 08:53:51 +02:00
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -0,0 +0,0 @@ public class EntityTrackerEntry {
private final Entity tracker;
private final int d;
private final boolean e;
- private final Consumer<Packet<?>> f;
+ private final Consumer<Packet<?>> f; private Consumer<Packet<?>> getPacketConsumer() { return f; } // Paper - OBFHELPER
private long xLoc;
private long yLoc;
private long zLoc;
2015-07-23 13:13:26 +02:00
@@ -0,0 +0,0 @@ public class EntityTrackerEntry {
2019-04-25 08:53:51 +02:00
private boolean r;
// CraftBukkit start
private final Set<EntityPlayer> trackedPlayers;
2016-03-01 00:09:49 +01:00
+ // Paper start
2019-04-25 08:53:51 +02:00
+ private java.util.Map<EntityPlayer, Boolean> trackedPlayerMap = null;
2018-10-11 05:18:02 +02:00
+
+ /**
+ * Requested in https://github.com/PaperMC/Paper/issues/1537 to allow intercepting packets
+ */
+ public void sendPlayerPacket(EntityPlayer player, Packet packet) {
+ player.playerConnection.sendPacket(packet);
+ }
2019-04-25 08:53:51 +02:00
+
+ public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, java.util.Map<EntityPlayer, Boolean> trackedPlayers) {
+ this(worldserver, entity, i, flag, consumer, trackedPlayers.keySet());
+ trackedPlayerMap = trackedPlayers;
+ }
2016-06-09 05:57:14 +02:00
2019-04-25 08:53:51 +02:00
public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<EntityPlayer> trackedPlayers) {
+ // Paper end
this.trackedPlayers = trackedPlayers;
// CraftBukkit end
this.m = Vec3D.a;
2015-07-23 13:13:26 +02:00
@@ -0,0 +0,0 @@ public class EntityTrackerEntry {
2019-01-02 17:39:33 +01:00
}
2015-07-23 13:13:26 +02:00
2019-01-01 04:15:55 +01:00
if (packet1 != null) {
2019-04-25 08:53:51 +02:00
- this.f.accept(packet1);
+ // paper start
+ if (trackedPlayerMap == null || packet1 instanceof PacketPlayOutEntityTeleport) {
+ this.f.accept((packet1));
2015-07-23 13:13:26 +02:00
+ } else {
2015-12-23 04:55:00 +01:00
+ PacketPlayOutEntityTeleport teleportPacket = null;
2015-07-23 13:13:26 +02:00
+
2015-12-23 04:55:00 +01:00
+ for (java.util.Map.Entry<EntityPlayer, Boolean> viewer : trackedPlayerMap.entrySet()) {
+ if (viewer.getValue()) {
+ viewer.setValue(false);
+ if (teleportPacket == null) {
2016-03-01 00:09:49 +01:00
+ teleportPacket = new PacketPlayOutEntityTeleport(this.tracker);
2015-12-23 04:55:00 +01:00
+ }
2018-10-11 05:18:02 +02:00
+ sendPlayerPacket(viewer.getKey(), teleportPacket);
2015-07-23 13:13:26 +02:00
+ } else {
2019-04-25 08:53:51 +02:00
+ sendPlayerPacket(viewer.getKey(), packet1);
2015-07-23 13:13:26 +02:00
+ }
+ }
+ }
2016-03-01 00:09:49 +01:00
+ // Paper end
2015-07-23 13:13:26 +02:00
}
2019-04-25 08:53:51 +02:00
this.c();
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
2020-05-06 11:48:49 +02:00
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
2019-04-25 08:53:51 +02:00
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -0,0 +0,0 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
private final Entity tracker;
private final int trackingDistance;
private SectionPosition e;
- public final Set<EntityPlayer> trackedPlayers = Sets.newHashSet();
+ // Paper start
+ // Replace trackedPlayers Set with a Map. The value is true until the player receives
+ // their first update (which is forced to have absolute coordinates), false afterward.
+ public java.util.Map<EntityPlayer, Boolean> trackedPlayerMap = new java.util.HashMap<>();
+ public Set<EntityPlayer> trackedPlayers = trackedPlayerMap.keySet();
2015-07-23 13:13:26 +02:00
2019-04-25 08:53:51 +02:00
public EntityTracker(Entity entity, int i, int j, boolean flag) {
- this.trackerEntry = new EntityTrackerEntry(PlayerChunkMap.this.world, entity, j, flag, this::broadcast, trackedPlayers); // CraftBukkit
+ this.trackerEntry = new EntityTrackerEntry(PlayerChunkMap.this.world, entity, j, flag, this::broadcast, trackedPlayerMap); // CraftBukkit // Paper
this.tracker = entity;
this.trackingDistance = i;
this.e = SectionPosition.a(entity);
@@ -0,0 +0,0 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2015-07-23 13:13:26 +02:00
entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId()));
// CraftBukkit end
2019-04-25 08:53:51 +02:00
- if (flag1 && this.trackedPlayers.add(entityplayer)) {
2019-05-29 06:54:11 +02:00
+ if (flag1 && this.trackedPlayerMap.putIfAbsent(entityplayer, true) == null) { // Paper
2019-04-25 08:53:51 +02:00
this.trackerEntry.b(entityplayer);
}
} else if (this.trackedPlayers.remove(entityplayer)) {