2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2019-04-25 06:53:51 +00:00
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Wed, 2 Mar 2016 23:13:07 -0600
Subject: [PATCH] Send absolute position the first time an entity is seen
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
2021-04-04 07:22:27 +00:00
index 9ad74b380a92e3a563e1a891e81401d8b4707bcf..beb0beb716869978be6bc5a78ce3b6cf785c5aee 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
2020-06-25 09:27:25 +00:00
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Pair;
2019-04-25 06:53:51 +00: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;
2021-03-16 07:19:45 +00:00
@@ -52,7 +53,7 @@ public class EntityTrackerEntry {
2019-04-25 06:53:51 +00:00
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;
2021-03-16 07:19:45 +00:00
@@ -67,8 +68,23 @@ public class EntityTrackerEntry {
2019-04-25 06:53:51 +00:00
private boolean r;
// CraftBukkit start
private final Set<EntityPlayer> trackedPlayers;
+ // Paper start
+ private java.util.Map<EntityPlayer, Boolean> trackedPlayerMap = null;
+
+ /**
+ * Requested in https://github.com/PaperMC/Paper/issues/1537 to allow intercepting packets
+ */
+ public void sendPlayerPacket(EntityPlayer player, Packet packet) {
+ player.playerConnection.sendPacket(packet);
+ }
+
+ 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;
+ }
public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<EntityPlayer> trackedPlayers) {
+ // Paper end
this.trackedPlayers = trackedPlayers;
// CraftBukkit end
2020-09-10 23:47:58 +00:00
this.m = Vec3D.ORIGIN;
2021-04-04 07:22:27 +00:00
@@ -189,7 +205,25 @@ public class EntityTrackerEntry {
2019-04-25 06:53:51 +00:00
}
if (packet1 != null) {
- this.f.accept(packet1);
+ // paper start
+ if (trackedPlayerMap == null || packet1 instanceof PacketPlayOutEntityTeleport) {
+ this.f.accept((packet1));
+ } else {
+ PacketPlayOutEntityTeleport teleportPacket = null;
+
+ for (java.util.Map.Entry<EntityPlayer, Boolean> viewer : trackedPlayerMap.entrySet()) {
+ if (viewer.getValue()) {
+ viewer.setValue(false);
+ if (teleportPacket == null) {
+ teleportPacket = new PacketPlayOutEntityTeleport(this.tracker);
+ }
+ sendPlayerPacket(viewer.getKey(), teleportPacket);
+ } else {
+ sendPlayerPacket(viewer.getKey(), packet1);
+ }
+ }
+ }
+ // Paper end
}
this.c();
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
2021-03-16 13:04:28 +00:00
index 9eae9d7e9d18d73b1050e1d9b8859802cbd286ed..e9657faf0a24aee8444372e6f1ca0d971339ce5a 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
2021-03-16 13:04:28 +00:00
@@ -1295,10 +1295,14 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2019-04-25 06:53:51 +00:00
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();
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);
2021-03-16 13:04:28 +00:00
@@ -1380,7 +1384,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2019-04-25 06:53:51 +00:00
entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId()));
// CraftBukkit end
- if (flag1 && this.trackedPlayers.add(entityplayer)) {
2019-05-29 04:54:11 +00:00
+ if (flag1 && this.trackedPlayerMap.putIfAbsent(entityplayer, true) == null) { // Paper
2019-04-25 06:53:51 +00:00
this.trackerEntry.b(entityplayer);
}
} else if (this.trackedPlayers.remove(entityplayer)) {