diff options
author | Nassim Jahnke <[email protected]> | 2024-12-11 12:13:51 +0100 |
---|---|---|
committer | Nassim Jahnke <[email protected]> | 2024-12-11 12:13:51 +0100 |
commit | 8dc76e715261f97bbf4a3f254e123aae08588ad5 (patch) | |
tree | 8022cecd70c4fcb899dbc49eca0d59390cc9b809 /patches/server/1038-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch | |
parent | c17ef64339ab27e5e50f331e53b00f6de45f7444 (diff) | |
download | Paper-8dc76e715261f97bbf4a3f254e123aae08588ad5.tar.gz Paper-8dc76e715261f97bbf4a3f254e123aae08588ad5.zip |
[ci skip] Move back more
Diffstat (limited to 'patches/server/1038-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch')
-rw-r--r-- | patches/server/1038-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/patches/server/1038-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch b/patches/server/1038-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch new file mode 100644 index 0000000000..73fea5a3cb --- /dev/null +++ b/patches/server/1038-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar <[email protected]> +Date: Fri, 29 Apr 2016 20:02:00 -0400 +Subject: [PATCH] Improve Maps (in item frames) performance and bug fixes + +Maps used a modified version of rendering to support plugin controlled +imaging on maps. The Craft Map Renderer is much slower than Vanilla, +causing maps in item frames to cause a noticeable hit on server performance. + +This updates the map system to not use the Craft system if we detect that no +custom renderers are in use, defaulting to the much simpler Vanilla system. + +Additionally, numerous issues to player position tracking on maps has been fixed. + +diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java +index f02fbe3d1ba00c9b1fb8533da22d2670870316bf..b98b8d42fb95185551a4559ce22abad33e000d33 100644 +--- a/src/main/java/net/minecraft/server/level/ServerLevel.java ++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +@@ -2362,6 +2362,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + { + if ( iter.next().player == entity ) + { ++ map.decorations.remove(entity.getName().getString()); // Paper + iter.remove(); + } + } +diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java +index 382194ef4b5723d2b3476084c566b6d07cc9c91d..f6e3073e1f1ff99f6917d84974a18e3e756fa9ea 100644 +--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java ++++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java +@@ -2793,6 +2793,14 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player { + this.awardStat(Stats.DROP); + } + ++ // Paper start - remove player from map on drop ++ if (itemstack.getItem() == net.minecraft.world.item.Items.FILLED_MAP) { ++ net.minecraft.world.level.saveddata.maps.MapItemSavedData worldmap = net.minecraft.world.item.MapItem.getSavedData(itemstack, this.level()); ++ if (worldmap != null) { ++ worldmap.tickCarriedBy(this, itemstack); ++ } ++ } ++ // Paper end + return entityitem; + } + } +diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java +index 2d5e7380e8a14cbc01ba48cd05deccc0c7f53430..ae321b3b8d98e42ef07fd1f0f738c1a2b428f6db 100644 +--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java ++++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java +@@ -80,6 +80,7 @@ public class MapItemSavedData extends SavedData { + public final Map<String, MapDecoration> decorations = Maps.newLinkedHashMap(); + private final Map<String, MapFrame> frameMarkers = Maps.newHashMap(); + private int trackedDecorationCount; ++ private org.bukkit.craftbukkit.map.RenderData vanillaRender = new org.bukkit.craftbukkit.map.RenderData(); // Paper + + // CraftBukkit start + public final CraftMapView mapView; +@@ -105,6 +106,7 @@ public class MapItemSavedData extends SavedData { + // CraftBukkit start + this.mapView = new CraftMapView(this); + this.server = (CraftServer) org.bukkit.Bukkit.getServer(); ++ this.vanillaRender.buffer = colors; // Paper + // CraftBukkit end + } + +@@ -179,6 +181,7 @@ public class MapItemSavedData extends SavedData { + if (abyte.length == 16384) { + worldmap.colors = abyte; + } ++ worldmap.vanillaRender.buffer = abyte; // Paper + + RegistryOps<Tag> registryops = registries.createSerializationContext(NbtOps.INSTANCE); + List<MapBanner> list = (List) MapBanner.LIST_CODEC.parse(registryops, nbt.get("banners")).resultOrPartial((s) -> { +@@ -367,7 +370,7 @@ public class MapItemSavedData extends SavedData { + --this.trackedDecorationCount; + } + +- this.setDecorationsDirty(); ++ if (mapicon != null) this.setDecorationsDirty(); // Paper - only mark dirty if a change occurs + } + + public static void addTargetDecoration(ItemStack stack, BlockPos pos, String id, Holder<MapDecorationType> decorationType) { +@@ -621,6 +624,21 @@ public class MapItemSavedData extends SavedData { + + public class HoldingPlayer { + ++ // Paper start ++ private void addSeenPlayers(java.util.Collection<MapDecoration> icons) { ++ org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.player.getBukkitEntity(); ++ MapItemSavedData.this.decorations.forEach((name, mapIcon) -> { ++ // If this cursor is for a player check visibility with vanish system ++ org.bukkit.entity.Player other = org.bukkit.Bukkit.getPlayerExact(name); // Spigot ++ if (other == null || player.canSee(other)) { ++ icons.add(mapIcon); ++ } ++ }); ++ } ++ private boolean shouldUseVanillaMap() { ++ return mapView.getRenderers().size() == 1 && mapView.getRenderers().get(0).getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class; ++ } ++ // Paper end + public final Player player; + private boolean dirtyData = true; + private int minDirtyX; +@@ -654,7 +672,9 @@ public class MapItemSavedData extends SavedData { + @Nullable + Packet<?> nextUpdatePacket(MapId mapId) { + MapItemSavedData.MapPatch worldmap_c; +- org.bukkit.craftbukkit.map.RenderData render = MapItemSavedData.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.player.getBukkitEntity()); // CraftBukkit ++ if (!this.dirtyData && this.tick % 5 != 0) { this.tick++; return null; } // Paper - this won't end up sending, so don't render it! ++ boolean vanillaMaps = shouldUseVanillaMap(); // Paper ++ org.bukkit.craftbukkit.map.RenderData render = !vanillaMaps ? MapItemSavedData.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.player.getBukkitEntity()) : MapItemSavedData.this.vanillaRender; // CraftBukkit // Paper + + if (this.dirtyData) { + this.dirtyData = false; +@@ -670,6 +690,8 @@ public class MapItemSavedData extends SavedData { + // CraftBukkit start + java.util.Collection<MapDecoration> icons = new java.util.ArrayList<MapDecoration>(); + ++ if (vanillaMaps) addSeenPlayers(icons); // Paper ++ + for (org.bukkit.map.MapCursor cursor : render.cursors) { + if (cursor.isVisible()) { + icons.add(new MapDecoration(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), Optional.ofNullable(PaperAdventure.asVanilla(cursor.caption())))); |