2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
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
|
2024-07-17 01:39:57 +02:00
|
|
|
index 2e30f8a12391222e612a9c1bf56e93625f52a8dc..162671f8e370c84832b18697a1ef787981e1632d 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2024-07-15 20:11:04 +02:00
|
|
|
@@ -2518,6 +2518,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
|
2021-06-11 14:02:28 +02:00
|
|
|
{
|
2021-06-12 06:38:04 +02:00
|
|
|
if ( iter.next().player == entity )
|
|
|
|
{
|
|
|
|
+ map.decorations.remove(entity.getName().getString()); // Paper
|
|
|
|
iter.remove();
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
2024-07-06 21:19:14 +02:00
|
|
|
index d0b51d96d6795b5fa03bc195b90324680545b752..09bcbc0ae36e4e69fee87a7e0c49acf496117a39 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
2024-07-06 21:19:14 +02:00
|
|
|
@@ -808,6 +808,14 @@ public abstract class Player extends LivingEntity {
|
2021-06-11 14:02:28 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - remove player from map on drop
|
2022-03-13 08:47:54 +01:00
|
|
|
+ if (itemstack.getItem() == Items.FILLED_MAP) {
|
2023-06-07 22:19:14 +02:00
|
|
|
+ net.minecraft.world.level.saveddata.maps.MapItemSavedData worldmap = net.minecraft.world.item.MapItem.getSavedData(itemstack, this.level());
|
2021-07-31 22:47:01 +02:00
|
|
|
+ if (worldmap != null) {
|
2022-03-13 08:47:54 +01:00
|
|
|
+ worldmap.tickCarriedBy(this, itemstack);
|
2021-07-31 22:47:01 +02:00
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // 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
|
2024-06-15 14:12:22 +02:00
|
|
|
index a43544704109f21bab230dd9bf0401e28f878582..17f33c83c6033564d6bf4fbd388b0b847c68adb3 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
2024-06-15 14:12:22 +02:00
|
|
|
@@ -79,6 +79,7 @@ public class MapItemSavedData extends SavedData {
|
2021-06-11 14:02:28 +02:00
|
|
|
public final Map<String, MapDecoration> decorations = Maps.newLinkedHashMap();
|
|
|
|
private final Map<String, MapFrame> frameMarkers = Maps.newHashMap();
|
2021-06-12 06:38:04 +02:00
|
|
|
private int trackedDecorationCount;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ private org.bukkit.craftbukkit.map.RenderData vanillaRender = new org.bukkit.craftbukkit.map.RenderData(); // Paper
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
public final CraftMapView mapView;
|
2024-06-15 14:12:22 +02:00
|
|
|
@@ -105,6 +106,7 @@ public class MapItemSavedData extends SavedData {
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit start
|
2021-06-12 06:38:04 +02:00
|
|
|
this.mapView = new CraftMapView(this);
|
|
|
|
this.server = (CraftServer) org.bukkit.Bukkit.getServer();
|
|
|
|
+ this.vanillaRender.buffer = colors; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2024-06-15 14:12:22 +02:00
|
|
|
@@ -179,6 +181,7 @@ public class MapItemSavedData extends SavedData {
|
2021-06-12 06:38:04 +02:00
|
|
|
if (abyte.length == 16384) {
|
|
|
|
worldmap.colors = abyte;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2021-06-12 06:38:04 +02:00
|
|
|
+ worldmap.vanillaRender.buffer = abyte; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2024-04-25 11:42:10 +02:00
|
|
|
RegistryOps<Tag> registryops = registryLookup.createSerializationContext(NbtOps.INSTANCE);
|
|
|
|
List<MapBanner> list = (List) MapBanner.LIST_CODEC.parse(registryops, nbt.get("banners")).resultOrPartial((s) -> {
|
2024-06-15 14:12:22 +02:00
|
|
|
@@ -588,6 +591,21 @@ public class MapItemSavedData extends SavedData {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
public class HoldingPlayer {
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ private void addSeenPlayers(java.util.Collection<MapDecoration> icons) {
|
2021-06-12 06:38:04 +02:00
|
|
|
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) this.player.getBukkitEntity();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ 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;
|
2024-06-15 14:12:22 +02:00
|
|
|
@@ -621,7 +639,9 @@ public class MapItemSavedData extends SavedData {
|
2021-06-11 14:02:28 +02:00
|
|
|
@Nullable
|
2024-04-25 11:42:10 +02:00
|
|
|
Packet<?> nextUpdatePacket(MapId mapId) {
|
2021-06-12 06:38:04 +02:00
|
|
|
MapItemSavedData.MapPatch worldmap_b;
|
2021-06-11 14:02:28 +02:00
|
|
|
- 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
|
|
|
|
|
2021-06-12 06:38:04 +02:00
|
|
|
if (this.dirtyData) {
|
|
|
|
this.dirtyData = false;
|
2024-06-15 14:12:22 +02:00
|
|
|
@@ -637,6 +657,8 @@ public class MapItemSavedData extends SavedData {
|
2021-06-12 06:38:04 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
java.util.Collection<MapDecoration> icons = new java.util.ArrayList<MapDecoration>();
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-12 06:38:04 +02:00
|
|
|
+ if (vanillaMaps) addSeenPlayers(icons); // Paper
|
|
|
|
+
|
|
|
|
for (org.bukkit.map.MapCursor cursor : render.cursors) {
|
|
|
|
if (cursor.isVisible()) {
|
2024-04-25 11:42:10 +02:00
|
|
|
icons.add(new MapDecoration(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), Optional.ofNullable(PaperAdventure.asVanilla(cursor.caption()))));
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/map/RenderData.java b/src/main/java/org/bukkit/craftbukkit/map/RenderData.java
|
|
|
|
index 256a131781721c86dd6cdbc329335964570cbe8c..5768cd512ec166f1e8d1f4a28792015347297c3f 100644
|
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/map/RenderData.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/map/RenderData.java
|
|
|
|
@@ -5,7 +5,7 @@ import org.bukkit.map.MapCursor;
|
|
|
|
|
|
|
|
public class RenderData {
|
|
|
|
|
|
|
|
- public final byte[] buffer;
|
|
|
|
+ public byte[] buffer; // Paper
|
|
|
|
public final ArrayList<MapCursor> cursors;
|
|
|
|
|
|
|
|
public RenderData() {
|