2019-01-01 04:15:55 +01:00
|
|
|
From 50cda9c60ae28cd18ad98fc7c6939974b7fec251 Mon Sep 17 00:00:00 2001
|
2016-05-05 02:10:22 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 17 Jun 2013 01:24:00 -0400
|
|
|
|
Subject: [PATCH] Entity Tracking Improvements
|
|
|
|
|
|
|
|
If any part of a Vehicle/Passenger relationship is visible to a player,
|
|
|
|
send all passenger/vehicles to the player in the chain.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-01-01 04:15:55 +01:00
|
|
|
index b6356966a..583cee415 100644
|
2016-05-05 02:10:22 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -70,6 +70,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2018-08-26 20:11:49 +02:00
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|
2016-05-05 02:10:22 +02:00
|
|
|
protected CraftEntity bukkitEntity;
|
|
|
|
|
|
|
|
+ EntityTrackerEntry tracker; // Paper
|
|
|
|
public CraftEntity getBukkitEntity() {
|
|
|
|
if (bukkitEntity == null) {
|
|
|
|
bukkitEntity = CraftEntity.getEntity(world.getServer(), this);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
2019-01-01 04:15:55 +01:00
|
|
|
index 638b54c1e..28a0ea034 100644
|
2016-05-05 02:10:22 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
2018-10-11 05:18:02 +02:00
|
|
|
@@ -56,6 +56,7 @@ public class EntityTrackerEntry {
|
2016-05-05 02:10:22 +02:00
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public EntityTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
|
|
|
+ entity.tracker = this; // Paper
|
|
|
|
this.tracker = entity;
|
|
|
|
this.e = i;
|
|
|
|
this.f = j;
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -454,17 +455,59 @@ public class EntityTrackerEntry {
|
2016-05-05 02:10:22 +02:00
|
|
|
|
|
|
|
this.tracker.b(entityplayer);
|
|
|
|
entityplayer.d(this.tracker);
|
|
|
|
+ updatePassengers(entityplayer); // Paper
|
|
|
|
}
|
|
|
|
} else if (this.trackedPlayers.contains(entityplayer)) {
|
|
|
|
this.trackedPlayers.remove(entityplayer);
|
|
|
|
this.tracker.c(entityplayer);
|
|
|
|
entityplayer.c(this.tracker);
|
|
|
|
+ updatePassengers(entityplayer); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean c(EntityPlayer entityplayer) {
|
|
|
|
+ // Paper start
|
|
|
|
+ if (tracker.isPassenger()) {
|
|
|
|
+ return isTrackedBy(tracker.getVehicle(), entityplayer);
|
|
|
|
+ } else if (hasPassengerInRange(tracker, entityplayer)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return isInRangeOfPlayer(entityplayer);
|
|
|
|
+ }
|
|
|
|
+ private static boolean hasPassengerInRange(Entity entity, EntityPlayer entityplayer) {
|
|
|
|
+ if (!entity.isVehicle()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ for (Entity passenger : entity.passengers) {
|
|
|
|
+ if (passenger.tracker != null && passenger.tracker.isInRangeOfPlayer(entityplayer)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (passenger.isVehicle()) {
|
|
|
|
+ if (hasPassengerInRange(passenger, entityplayer)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ private static boolean isTrackedBy(Entity entity, EntityPlayer entityplayer) {
|
2016-07-31 22:22:25 +02:00
|
|
|
+ return entity == entityplayer || entity.tracker != null && entity.tracker.trackedPlayers.contains(entityplayer);
|
2016-05-05 02:10:22 +02:00
|
|
|
+ }
|
|
|
|
+ private void updatePassengers(EntityPlayer player) {
|
|
|
|
+ if (tracker.isVehicle()) {
|
2016-05-06 16:09:52 +02:00
|
|
|
+ tracker.passengers.forEach((e) -> {
|
|
|
|
+ if (e.tracker != null) {
|
|
|
|
+ e.tracker.updatePlayer(player);
|
|
|
|
+ }
|
|
|
|
+ });
|
2016-05-05 02:10:22 +02:00
|
|
|
+ player.playerConnection.sendPacket(new PacketPlayOutMount(this.tracker));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private boolean isInRangeOfPlayer(EntityPlayer entityplayer) {
|
|
|
|
+ // Paper end
|
|
|
|
double d0 = entityplayer.locX - (double) this.xLoc / 4096.0D;
|
|
|
|
double d1 = entityplayer.locZ - (double) this.zLoc / 4096.0D;
|
2018-09-09 20:38:27 +02:00
|
|
|
int i = Math.min(this.e, (entityplayer.getViewDistance() - 1) * 16); // Paper - Use player view distance API
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -605,6 +648,7 @@ public class EntityTrackerEntry {
|
2016-05-05 02:10:22 +02:00
|
|
|
this.trackedPlayers.remove(entityplayer);
|
|
|
|
this.tracker.c(entityplayer);
|
|
|
|
entityplayer.c(this.tracker);
|
|
|
|
+ updatePassengers(entityplayer); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
--
|
2019-01-01 04:15:55 +01:00
|
|
|
2.20.1
|
2016-05-05 02:10:22 +02:00
|
|
|
|