From 4bb84c46ac4d9f7875658fb3d4b1f50da8e444c9 Mon Sep 17 00:00:00 2001
From: Redned <redned235@gmail.com>
Date: Mon, 19 Jun 2023 15:45:53 -0500
Subject: [PATCH] Only tick item frames if players can see it

In the event that an item frame cannot be seen by any players, ticking the item frame every tick is unnecessary. This can be a very hot section of the entity tracker when lots of item frames are present on a server, so this reduces the logic which speeds it up.
---
 .../net/minecraft/server/level/ServerEntity.java.patch      | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerEntity.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerEntity.java.patch
index 4c4ebee4eb..d4a7729154 100644
--- a/paper-server/patches/sources/net/minecraft/server/level/ServerEntity.java.patch
+++ b/paper-server/patches/sources/net/minecraft/server/level/ServerEntity.java.patch
@@ -60,11 +60,13 @@
              ServerEntity.removedPassengers(list, this.lastPassengers).forEach((entity) -> {
                  if (entity instanceof ServerPlayer entityplayer) {
                      entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
-@@ -107,18 +117,18 @@
+@@ -106,19 +116,19 @@
+ 
          Entity entity = this.entity;
  
-         if (entity instanceof ItemFrame entityitemframe) {
+-        if (entity instanceof ItemFrame entityitemframe) {
 -            if (this.tickCount % 10 == 0) {
++        if (!this.trackedPlayers.isEmpty() && entity instanceof ItemFrame entityitemframe) { // Paper - Perf: Only tick item frames if players can see it
 +            if (true || this.tickCount % 10 == 0) { // CraftBukkit - Moved below, should always enter this block
                  ItemStack itemstack = entityitemframe.getItem();