PaperMC/Spigot-Server-Patches/0045-Send-absolute-position-the-first-time-an-entity-is-s.patch

98 lines
4.5 KiB
Diff
Raw Normal View History

2016-03-01 00:09:49 +01:00
From 1bb4693646197a671146dc8d34a8275ac43d8308 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
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
2016-03-01 00:09:49 +01:00
index f8570a8..1602dff 100644
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
2016-03-01 00:09:49 +01:00
@@ -41,7 +41,12 @@ public class EntityTrackerEntry {
private boolean x;
private boolean y;
2016-03-01 00:09:49 +01:00
public boolean b;
- public Set<EntityPlayer> trackedPlayers = Sets.newHashSet();
2016-03-01 00:09:49 +01:00
+ // 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<EntityPlayer, Boolean>();
+ public Set<EntityPlayer> trackedPlayers = trackedPlayerMap.keySet();
2016-03-01 00:09:49 +01:00
+ // Paper end
2016-03-01 00:09:49 +01:00
public EntityTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
this.tracker = entity;
2016-03-01 00:09:49 +01:00
@@ -126,20 +131,22 @@ public class EntityTrackerEntry {
boolean flag = k1 * k1 + l1 * l1 + i2 * i2 >= 128L || this.a % 60 == 0;
boolean flag1 = Math.abs(i1 - this.yRot) >= 1 || Math.abs(j1 - this.xRot) >= 1;
- // CraftBukkit start - Code moved from below
- if (flag) {
2016-03-01 00:09:49 +01:00
- this.xLoc = j;
- this.yLoc = k;
- this.zLoc = l;
- }
2016-03-01 00:09:49 +01:00
+ if (this.a > 0 || this.tracker instanceof EntityArrow) { // Paper - Moved up
+ // CraftBukkit start - Code moved from below
+ if (flag) {
2016-03-01 00:09:49 +01:00
+ this.xLoc = j;
+ this.yLoc = k;
+ this.zLoc = l;
+ }
- if (flag1) {
+ if (flag1) {
2016-03-01 00:09:49 +01:00
+ this.yRot = i1;
+ this.xRot = j1;
+ }
+ // CraftBukkit end
2016-03-01 00:09:49 +01:00
this.yRot = i1;
this.xRot = j1;
- }
// CraftBukkit end
-
- if (this.a > 0 || this.tracker instanceof EntityArrow) {
if (k1 >= -32768L && k1 < 32768L && l1 >= -32768L && l1 < 32768L && i2 >= -32768L && i2 < 32768L && this.v <= 400 && !this.x && this.y == this.tracker.onGround) {
if ((!flag || !flag1) && !(this.tracker instanceof EntityArrow)) {
if (flag) {
2016-03-01 00:09:49 +01:00
@@ -185,7 +192,26 @@ public class EntityTrackerEntry {
}
if (object != null) {
- this.broadcast((Packet) object);
2016-03-01 00:09:49 +01:00
+ // Paper start - ensure fresh viewers get an absolute position on their first update,
+ // since we can't be certain what position they received in the spawn packet.
+ if (object instanceof PacketPlayOutEntityTeleport) {
+ this.broadcast((Packet) object);
+ } else {
+ PacketPlayOutEntityTeleport teleportPacket = null;
+
+ 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);
+ }
+ viewer.getKey().playerConnection.sendPacket(teleportPacket);
+ } else {
+ viewer.getKey().playerConnection.sendPacket((Packet) object);
+ }
+ }
+ }
2016-03-01 00:09:49 +01:00
+ // Paper end
}
2016-03-01 00:09:49 +01:00
this.d();
@@ -338,7 +364,7 @@ public class EntityTrackerEntry {
entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId()));
// CraftBukkit end
- this.trackedPlayers.add(entityplayer);
2016-03-01 00:09:49 +01:00
+ this.trackedPlayerMap.put(entityplayer, true); // Paper
Packet packet = this.e();
entityplayer.playerConnection.sendPacket(packet);
--
2016-03-01 00:09:49 +01:00
2.7.2