2020-12-20 01:50:50 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lukas81298 <lukas81298@gmail.com>
Date: Sun, 13 Dec 2020 13:42:55 +0100
Subject: [PATCH] do not create unnecessary copies of passenger list
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java
index edc6fff87c4abad2c123b1a46d6e5b792602b3be..5e739b26b6b5490b2c7651d3e9ff8649e776137e 100644
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java
@@ -15,7 +15,7 @@ public class PacketPlayOutMount implements Packet<PacketListenerPlayOut> {
public PacketPlayOutMount(Entity entity) {
this.a = entity.getId();
- List<Entity> list = entity.getPassengers();
+ List<Entity> list = entity.passengers; // Paper - do not create a copy of the list
this.b = new int[list.size()];
diff --git a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
index aa5ba862f18ff706f11b0b26cea55a904a5a9473..f65eb0168ed365e5c1b490c56ec84e3b7ff87c1d 100644
--- a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
@@ -103,10 +103,10 @@ public class EntityTrackerEntry {
public final void tick() { this.a(); } // Paper - OBFHELPER
public void a() {
- List<Entity> list = this.tracker.getPassengers();
+ List<Entity> list = this.tracker.passengers; // Paper - do not copy list
if (!list.equals(this.p)) {
- this.p = list;
+ this.p = com.google.common.collect.ImmutableList.copyOf(list); // Paper - only copy list if something has changed
this.broadcastIncludingSelf(new PacketPlayOutMount(this.tracker)); // CraftBukkit
}
@@ -377,7 +377,7 @@ public class EntityTrackerEntry {
}
}
- if (!this.tracker.getPassengers().isEmpty()) {
+ if (!this.tracker.passengers.isEmpty()) { // Paper - do not create copy of list
consumer.accept(new PacketPlayOutMount(this.tracker));
}
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
index f3f906d8ffa195b100d5bd2d232ae8489d48d60d..5e5545f16daf20682e7984e1b4d3ffa0151ad1c1 100644
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
@@ -2297,7 +2297,7 @@ Sections go from 0..16. Now whenever a section is not empty, it can potentially
list.add(entity);
}
- if (!entity.getPassengers().isEmpty()) {
+ if (!entity.passengers.isEmpty()) { // Paper - do not copy list
list1.add(entity);
}
}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index bb3211d0177f569b018852fc2a9094431e952b02..f88af0aa6a86d7d2f7e12b710fce4d37c9ee421f 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2223,7 +2223,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-20 01:50:50 +01:00
}
protected boolean q(Entity entity) {
- return this.getPassengers().size() < 1;
+ return this.passengers.size() < 1; // Paper - do not copy list
}
public final float getCollisionBorderSize() { return bg(); } // Paper - OBFHELPER
2021-03-16 08:19:45 +01:00
@@ -2319,7 +2319,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-20 01:50:50 +01:00
}
public boolean isVehicle() {
- return !this.getPassengers().isEmpty();
+ return !this.passengers.isEmpty(); // Paper - do not copy list
}
public boolean bt() {
2021-03-16 08:19:45 +01:00
@@ -3131,7 +3131,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-20 01:50:50 +01:00
}
public boolean w(Entity entity) {
- Iterator iterator = this.getPassengers().iterator();
+ Iterator iterator = this.passengers.iterator(); // Paper - do not copy list
Entity entity1;
2021-03-16 08:19:45 +01:00
@@ -3147,7 +3147,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-20 01:50:50 +01:00
}
public boolean a(Class<? extends Entity> oclass) {
- Iterator iterator = this.getPassengers().iterator();
+ Iterator iterator = this.passengers.iterator(); // Paper - do not copy list
Entity entity;
2021-03-16 08:19:45 +01:00
@@ -3164,7 +3164,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-20 01:50:50 +01:00
public Collection<Entity> getAllPassengers() {
Set<Entity> set = Sets.newHashSet();
- Iterator iterator = this.getPassengers().iterator();
+ Iterator iterator = this.passengers.iterator(); // Paper - do not copy list
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2021-03-16 08:19:45 +01:00
@@ -3190,7 +3190,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-20 01:50:50 +01:00
private void a(boolean flag, Set<Entity> set) {
Entity entity;
- for (Iterator iterator = this.getPassengers().iterator(); iterator.hasNext(); entity.a(flag, set)) {
+ for (Iterator iterator = this.passengers.iterator(); iterator.hasNext(); entity.a(flag, set)) { // Paper - do not copy list
entity = (Entity) iterator.next();
if (!flag || EntityPlayer.class.isAssignableFrom(entity.getClass())) {
set.add(entity);
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
index ec51a5532576ce25465bacf61c716ddaffca514e..d285f5aa66fa81a2f56920c05afb4506cb82fa54 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
@@ -52,7 +52,7 @@ public class PathfinderGoalTame extends PathfinderGoal {
@Override
public void e() {
if (!this.entity.isTamed() && this.entity.getRandom().nextInt(50) == 0) {
- Entity entity = (Entity) this.entity.getPassengers().get(0);
+ Entity entity = this.entity.passengers.isEmpty() ? null : this.entity.passengers.get(0); // Paper - do not copy list, fixed array out of bounds exception as well
if (entity == null) {
return;
diff --git a/src/main/java/net/minecraft/world/entity/animal/EntityPig.java b/src/main/java/net/minecraft/world/entity/animal/EntityPig.java
index d6e1697f64e60f2a567288c604a1690159955f37..676ca381a5e111fc15f319e73504e4e60dbf0d2b 100644
--- a/src/main/java/net/minecraft/world/entity/animal/EntityPig.java
+++ b/src/main/java/net/minecraft/world/entity/animal/EntityPig.java
@@ -86,7 +86,7 @@ public class EntityPig extends EntityAnimal implements ISteerable, ISaddleable {
@Nullable
@Override
public Entity getRidingPassenger() {
- return this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
+ return this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java b/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java
index d678e3164ecdb7f0c600597bcb39d1054dfbc4b2..1e41c45af6dbcf097d7d6104e63db637f199301a 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java
@@ -972,7 +972,7 @@ public abstract class EntityHorseAbstract extends EntityAnimal implements IInven
@Nullable
@Override
public Entity getRidingPassenger() {
- return this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
+ return this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list
}
@Nullable
diff --git a/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java b/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java
index 7781386da593a1c4f3ad7e7e8761767dda7cb66c..16d5cae64887b82e67eeb61ccb714e6125ff0c09 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java
@@ -134,7 +134,7 @@ public class EntityRavager extends EntityRaider {
@Nullable
@Override
public Entity getRidingPassenger() {
- return this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
+ return this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
index 5ae7620be7b0b5fba6aab8173aed45dc28bf36e3..0e3fcf5facdac7f5d2d509f20cb45d5de38f72d4 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java
@@ -316,7 +316,7 @@ public class EntityBoat extends Entity {
2020-12-20 01:50:50 +01:00
super.tick();
this.r();
if (this.cs()) {
- if (this.getPassengers().isEmpty() || !(this.getPassengers().get(0) instanceof EntityHuman)) {
+ if (this.passengers.isEmpty() || !(this.passengers.get(0) instanceof EntityHuman)) { // Paper - do not copy list
this.a(false, false);
}
2021-03-16 08:19:45 +01:00
@@ -379,7 +379,7 @@ public class EntityBoat extends Entity {
2020-12-20 01:50:50 +01:00
Entity entity = (Entity) list.get(j);
if (!entity.w(this)) {
- if (flag && this.getPassengers().size() < 2 && !entity.isPassenger() && entity.getWidth() < this.getWidth() && entity instanceof EntityLiving && !(entity instanceof EntityWaterAnimal) && !(entity instanceof EntityHuman)) {
+ if (flag && this.passengers.size() < 2 && !entity.isPassenger() && entity.getWidth() < this.getWidth() && entity instanceof EntityLiving && !(entity instanceof EntityWaterAnimal) && !(entity instanceof EntityHuman)) { // Paper - do not copy passenger list
entity.startRiding(this);
} else {
this.collide(entity);
2021-03-16 08:19:45 +01:00
@@ -726,8 +726,8 @@ public class EntityBoat extends Entity {
2020-12-20 01:50:50 +01:00
float f = 0.0F;
float f1 = (float) ((this.dead ? 0.009999999776482582D : this.bc()) + entity.bb());
- if (this.getPassengers().size() > 1) {
- int i = this.getPassengers().indexOf(entity);
+ if (this.passengers.size() > 1) { // Paper - do not copy list
+ int i = this.passengers.indexOf(entity); // Paper - do not copy list
if (i == 0) {
f = 0.2F;
2021-03-16 08:19:45 +01:00
@@ -746,7 +746,7 @@ public class EntityBoat extends Entity {
2020-12-20 01:50:50 +01:00
entity.yaw += this.ak;
entity.setHeadRotation(entity.getHeadRotation() + this.ak);
this.a(entity);
- if (entity instanceof EntityAnimal && this.getPassengers().size() > 1) {
+ if (entity instanceof EntityAnimal && this.passengers.size() > 1) { // Paper - do not copy list
int j = entity.getId() % 2 == 0 ? 90 : 270;
entity.n(((EntityAnimal) entity).aA + (float) j);
2021-03-16 08:19:45 +01:00
@@ -906,13 +906,13 @@ public class EntityBoat extends Entity {
2020-12-20 01:50:50 +01:00
@Override
protected boolean q(Entity entity) {
- return this.getPassengers().size() < 2 && !this.a((Tag) TagsFluid.WATER);
+ return this.passengers.size() < 2 && !this.a((Tag) TagsFluid.WATER); // Paper - do not copy list
}
@Nullable
@Override
public Entity getRidingPassenger() {
- List<Entity> list = this.getPassengers();
+ List<Entity> list = this.passengers; // Paper - do not copy list
return list.isEmpty() ? null : (Entity) list.get(0);
}
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java b/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
index c79474ffb455bb87bfdd98bc68b3dc8dfcdca45e..f2b905e5689ee419e9d83bb4ca671ef44ccb031f 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java
@@ -560,7 +560,7 @@ public abstract class EntityMinecartAbstract extends Entity {
2020-12-20 01:50:50 +01:00
vec3d1 = new Vec3D(d8 * d4 / d6, vec3d1.y, d8 * d5 / d6);
this.setMot(vec3d1);
- Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
+ Entity entity = this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list
if (entity instanceof EntityHuman) {
Vec3D vec3d2 = entity.getMot();