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.
|
|
|
|
|
2024-11-09 21:44:55 +01:00
|
|
|
Feature patch
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
|
|
|
index b6b80285a54efd6012c4eedbdc5b2af702f27981..be35f9ab6d8877aad755a6ac0344a901b61a49de 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
|
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
|
|
|
@@ -2338,6 +2338,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
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
|
|
|
}
|
2024-10-24 20:40:24 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2024-11-29 02:39:40 +01:00
|
|
|
index 1bf9dcc77676376184ea45465a6e5ea5ddeb99f4..e1102d8fb73c6b545c205cd5ad4b4a0ae1a32529 100644
|
2024-10-24 20:40:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2024-11-26 18:46:12 +01:00
|
|
|
@@ -2808,6 +2808,14 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
2024-10-24 20:40:24 +02:00
|
|
|
this.awardStat(Stats.DROP);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2024-10-24 20:40:24 +02:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start - remove player from map on drop
|
2024-10-25 12:30:19 +02:00
|
|
|
+ if (itemstack.getItem() == net.minecraft.world.item.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);
|
2024-10-24 20:40:24 +02:00
|
|
|
+ }
|
2021-07-31 22:47:01 +02:00
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
return entityitem;
|
|
|
|
}
|
2024-10-24 20:40:24 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
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-10-24 20:40:24 +02:00
|
|
|
index 2d5e7380e8a14cbc01ba48cd05deccc0c7f53430..ae321b3b8d98e42ef07fd1f0f738c1a2b428f6db 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-10-24 20:40:24 +02:00
|
|
|
@@ -80,6 +80,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-10-24 20:40:24 +02:00
|
|
|
RegistryOps<Tag> registryops = registries.createSerializationContext(NbtOps.INSTANCE);
|
2024-04-25 11:42:10 +02:00
|
|
|
List<MapBanner> list = (List) MapBanner.LIST_CODEC.parse(registryops, nbt.get("banners")).resultOrPartial((s) -> {
|
2024-10-24 20:40:24 +02:00
|
|
|
@@ -367,7 +370,7 @@ public class MapItemSavedData extends SavedData {
|
2024-09-19 16:27:33 +02:00
|
|
|
--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) {
|
2024-10-24 20:40:24 +02:00
|
|
|
@@ -621,6 +624,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-10-24 20:40:24 +02:00
|
|
|
@@ -654,7 +672,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) {
|
2024-10-24 20:40:24 +02:00
|
|
|
MapItemSavedData.MapPatch worldmap_c;
|
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-10-24 20:40:24 +02:00
|
|
|
@@ -670,6 +690,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() {
|