9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-23 08:59:23 +00:00
Files
Leaf/patches/server/0051-SparklyPaper-Skip-MapItem-update-if-the-map-does-not.patch
2024-12-13 21:19:57 -05:00

50 lines
2.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrPowerGamerBR <git@mrpowergamerbr.com>
Date: Fri, 17 Nov 2023 14:22:41 -0300
Subject: [PATCH] SparklyPaper: Skip "MapItem#update()" if the map does not
have the CraftMapRenderer present
Original project: https://github.com/SparklyPower/SparklyPaper
Optimizes "image in map" maps, without requiring the map to be locked, which some old map plugins may not do
This has the disadvantage that the vanilla map data will never be updated while the CraftMapRenderer is not present, but that's not a huuuge problem for u
diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
index c2f3c8b3d8eeb609b6d6067c4fb404aefbf94ec5..dfec0daeefc040cdae578f44073824773db095f9 100644
--- a/src/main/java/net/minecraft/world/item/MapItem.java
+++ b/src/main/java/net/minecraft/world/item/MapItem.java
@@ -276,7 +276,7 @@ public class MapItem extends Item {
mapItemSavedData.tickCarriedBy(player, stack);
}
- if (!mapItemSavedData.locked && (selected || entity instanceof Player && ((Player)entity).getOffhandItem() == stack)) {
+ if (!mapItemSavedData.locked && (!org.dreeam.leaf.config.modules.opt.SkipMapItemDataUpdates.enabled || mapItemSavedData.mapView.getRenderers().stream().anyMatch(mapRenderer -> mapRenderer.getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class)) && (selected || entity instanceof Player && ((Player)entity).getOffhandItem() == stack)) { // SparklyPaper - don't update maps if they don't have the CraftMapRenderer in the render list
this.update(world, entity, mapItemSavedData);
}
}
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/SkipMapItemDataUpdates.java b/src/main/java/org/dreeam/leaf/config/modules/opt/SkipMapItemDataUpdates.java
new file mode 100644
index 0000000000000000000000000000000000000000..61687c05b5996115a40c364fbd013ee72f5de72e
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/SkipMapItemDataUpdates.java
@@ -0,0 +1,18 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.EnumConfigCategory;
+
+public class SkipMapItemDataUpdates extends ConfigModules {
+
+ public String getBasePath() {
+ return EnumConfigCategory.PERF.getBaseKeyName();
+ }
+
+ public static boolean enabled = true;
+
+ @Override
+ public void onLoaded() {
+ enabled = config.getBoolean(getBasePath() + ".skip-map-item-data-updates-if-map-does-not-have-craftmaprenderer", enabled);
+ }
+}