From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lukas81298 Date: Sun, 13 Dec 2020 13:42:55 +0100 Subject: [PATCH] do not create unnecessary copies of passenger list diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPassengersPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPassengersPacket.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPassengersPacket.java +++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPassengersPacket.java @@ -0,0 +0,0 @@ public class ClientboundSetPassengersPacket implements Packet list = entity.getPassengers(); + List list = entity.passengers; // Paper - do not create a copy of the list this.passengers = new int[list.size()]; diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -0,0 +0,0 @@ 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/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ServerEntity.java +++ b/src/main/java/net/minecraft/server/level/ServerEntity.java @@ -0,0 +0,0 @@ public class ServerEntity { public final void tick() { this.sendChanges(); } // Paper - OBFHELPER public void sendChanges() { - List list = this.entity.getPassengers(); + List list = this.entity.passengers; // Paper - do not copy list if (!list.equals(this.lastPassengers)) { - this.lastPassengers = list; + this.lastPassengers = com.google.common.collect.ImmutableList.copyOf(list); // Paper - only copy list if something has changed this.broadcastAndSend(new ClientboundSetPassengersPacket(this.entity)); // CraftBukkit } @@ -0,0 +0,0 @@ public class ServerEntity { } } - if (!this.entity.getPassengers().isEmpty()) { + if (!this.entity.passengers.isEmpty()) { // Paper - do not create copy of list consumer.accept(new ClientboundSetPassengersPacket(this.entity)); } diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s } protected boolean canAddPassenger(Entity passenger) { - return this.getPassengers().size() < 1; + return this.passengers.size() < 1; // Paper - do not copy list } public final float getCollisionBorderSize() { return getPickRadius(); } // Paper - OBFHELPER @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s } public boolean isVehicle() { - return !this.getPassengers().isEmpty(); + return !this.passengers.isEmpty(); // Paper - do not copy list } public boolean rideableUnderWater() { @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s } public boolean hasPassenger(Entity passenger) { - Iterator iterator = this.getPassengers().iterator(); + Iterator iterator = this.passengers.iterator(); // Paper - do not copy list Entity entity1; @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s } public boolean hasPassenger(Class clazz) { - Iterator iterator = this.getPassengers().iterator(); + Iterator iterator = this.passengers.iterator(); // Paper - do not copy list Entity entity; @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s public Collection getIndirectPassengers() { Set 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(); @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s private void fillIndirectPassengers(boolean playersOnly, Set output) { Entity entity; - for (Iterator iterator = this.getPassengers().iterator(); iterator.hasNext(); entity.fillIndirectPassengers(playersOnly, output)) { + for (Iterator iterator = this.passengers.iterator(); iterator.hasNext(); entity.fillIndirectPassengers(playersOnly, output)) { // Paper - do not copy list entity = (Entity) iterator.next(); if (!playersOnly || ServerPlayer.class.isAssignableFrom(entity.getClass())) { output.add(entity); diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/RunAroundLikeCrazyGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/RunAroundLikeCrazyGoal.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/ai/goal/RunAroundLikeCrazyGoal.java +++ b/src/main/java/net/minecraft/world/entity/ai/goal/RunAroundLikeCrazyGoal.java @@ -0,0 +0,0 @@ public class RunAroundLikeCrazyGoal extends Goal { @Override public void tick() { if (!this.horse.isTamed() && this.horse.getRandom().nextInt(50) == 0) { - Entity entity = (Entity) this.horse.getPassengers().get(0); + Entity entity = this.horse.passengers.isEmpty() ? null : this.horse.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/Pig.java b/src/main/java/net/minecraft/world/entity/animal/Pig.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Pig.java +++ b/src/main/java/net/minecraft/world/entity/animal/Pig.java @@ -0,0 +0,0 @@ public class Pig extends Animal implements ItemSteerable, Saddleable { @Nullable @Override public Entity getControllingPassenger() { - 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/AbstractHorse.java b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java +++ b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java @@ -0,0 +0,0 @@ public abstract class AbstractHorse extends Animal implements ContainerListener, @Nullable @Override public Entity getControllingPassenger() { - 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/Ravager.java b/src/main/java/net/minecraft/world/entity/monster/Ravager.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Ravager.java +++ b/src/main/java/net/minecraft/world/entity/monster/Ravager.java @@ -0,0 +0,0 @@ public class Ravager extends Raider { @Nullable @Override public Entity getControllingPassenger() { - 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/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java @@ -0,0 +0,0 @@ public abstract class AbstractMinecart extends Entity { vec3d1 = new Vec3(d8 * d4 / d6, vec3d1.y, d8 * d5 / d6); this.setDeltaMovement(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 Player) { Vec3 vec3d2 = entity.getDeltaMovement(); diff --git a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java @@ -0,0 +0,0 @@ public class Boat extends Entity { super.tick(); this.tickLerp(); if (this.isControlledByLocalInstance()) { - if (this.getPassengers().isEmpty() || !(this.getPassengers().get(0) instanceof Player)) { + if (this.passengers.isEmpty() || !(this.passengers.get(0) instanceof Player)) { // Paper - do not copy list this.setPaddleState(false, false); } @@ -0,0 +0,0 @@ public class Boat extends Entity { Entity entity = (Entity) list.get(j); if (!entity.hasPassenger(this)) { - if (flag && this.getPassengers().size() < 2 && !entity.isPassenger() && entity.getBbWidth() < this.getBbWidth() && entity instanceof LivingEntity && !(entity instanceof WaterAnimal) && !(entity instanceof Player)) { + if (flag && this.passengers.size() < 2 && !entity.isPassenger() && entity.getBbWidth() < this.getBbWidth() && entity instanceof LivingEntity && !(entity instanceof WaterAnimal) && !(entity instanceof Player)) { // Paper - do not copy passenger list entity.startRiding(this); } else { this.push(entity); @@ -0,0 +0,0 @@ public class Boat extends Entity { float f = 0.0F; float f1 = (float) ((this.removed ? 0.009999999776482582D : this.getPassengersRidingOffset()) + passenger.getMyRidingOffset()); - if (this.getPassengers().size() > 1) { - int i = this.getPassengers().indexOf(passenger); + if (this.passengers.size() > 1) { // Paper - do not copy list + int i = this.passengers.indexOf(passenger); // Paper - do not copy list if (i == 0) { f = 0.2F; @@ -0,0 +0,0 @@ public class Boat extends Entity { passenger.yRot += this.deltaRotation; passenger.setYHeadRot(passenger.getYHeadRot() + this.deltaRotation); this.clampRotation(passenger); - if (passenger instanceof Animal && this.getPassengers().size() > 1) { + if (passenger instanceof Animal && this.passengers.size() > 1) { // Paper - do not copy list int j = passenger.getId() % 2 == 0 ? 90 : 270; passenger.setYBodyRot(((Animal) passenger).yBodyRot + (float) j); @@ -0,0 +0,0 @@ public class Boat extends Entity { @Override protected boolean canAddPassenger(Entity passenger) { - return this.getPassengers().size() < 2 && !this.isEyeInFluid((Tag) FluidTags.WATER); + return this.passengers.size() < 2 && !this.isEyeInFluid((Tag) FluidTags.WATER); // Paper - do not copy list } @Nullable @Override public Entity getControllingPassenger() { - List list = this.getPassengers(); + List list = this.passengers; // Paper - do not copy list return list.isEmpty() ? null : (Entity) list.get(0); }