9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

[ci skip] Fix SparklyPaper: Skip "MapItem#update()" if the map does not have the CraftMapRenderer present

This commit is contained in:
Dreeam
2025-06-14 23:17:24 +08:00
parent 13abe281c9
commit 0790debe92
2 changed files with 27 additions and 20 deletions

View File

@@ -11,26 +11,32 @@ Optimizes "image in map" maps, without requiring the map to be locked, which som
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/net/minecraft/world/item/MapItem.java b/net/minecraft/world/item/MapItem.java
index 780793750c99185e8139a1cd0ad52bc7b80899a9..dd20922e25710fe79fb4d37d04dd5cb59cb896fe 100644
index 780793750c99185e8139a1cd0ad52bc7b80899a9..0073f21245c98e7b5791f9db1ad221aef7cb594a 100644
--- a/net/minecraft/world/item/MapItem.java
+++ b/net/minecraft/world/item/MapItem.java
@@ -275,7 +275,18 @@ public class MapItem extends Item {
@@ -275,12 +275,24 @@ public class MapItem extends Item {
savedData.tickCarriedBy(player, stack);
}
- if (!savedData.locked && slot != null && slot.getType() == EquipmentSlot.Type.HAND) {
+ // SparklyPaper start - don't update maps if they don't have the CraftMapRenderer in the render list
+ boolean shouldUpdateMap = !savedData.locked && slot != null && slot.getType() == EquipmentSlot.Type.HAND;
+ if (org.dreeam.leaf.config.modules.opt.SkipMapItemDataUpdates.enabled) {
+ for (org.bukkit.map.MapRenderer mapRenderer : savedData.mapView.getRenderers()) {
+ if (mapRenderer.getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class) {
+ shouldUpdateMap = true;
+ break;
+ }
+ }
+ }
+ if (shouldUpdateMap) {
+ // SparklyPaper end - don't update maps if they don't have the CraftMapRenderer in the render list
+ if (!savedData.locked && (!org.dreeam.leaf.config.modules.opt.SkipMapItemDataUpdates.enabled || shouldUpdateMap(savedData)) && slot != null && slot.getType() == EquipmentSlot.Type.HAND) { // SparklyPaper - don't update maps if they don't have the CraftMapRenderer in the render list
this.update(level, entity, savedData);
}
}
}
+ // SparklyPaper start - don't update maps if they don't have the CraftMapRenderer in the render list
+ private static boolean shouldUpdateMap(MapItemSavedData savedData) {
+ for (org.bukkit.map.MapRenderer mapRenderer : savedData.mapView.getRenderers()) {
+ if (mapRenderer.getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ // SparklyPaper end - don't update maps if they don't have the CraftMapRenderer in the render list
+
@Override
public void onCraftedPostProcess(ItemStack stack, Level level) {
MapPostProcessing mapPostProcessing = stack.remove(DataComponents.MAP_POST_PROCESSING);

View File

@@ -23,7 +23,7 @@ and, in my opinion, worth the low risk of minor mob-spawning-related
inconsistencies.
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java b/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java
index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb32a394df 100644
index ece6db7b9a0dfd535141c0c756947c4898140503..82b84d72bf1b3c43d734fe381b67377de5f30187 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java
@@ -11,7 +11,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
@@ -88,7 +88,7 @@ index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb
this.defrag();
}
//this.check();
@@ -169,14 +172,16 @@ public final class IteratorSafeOrderedReferenceSet<E> {
@@ -169,14 +172,17 @@ public final class IteratorSafeOrderedReferenceSet<E> {
}
private void defrag() {
@@ -98,6 +98,7 @@ index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb
+ if (firstInvalidIndex < 0) {
return; // nothing to do
}
+ // Leaf end - Pufferfish - Async mob spawning
if (this.indexMap.isEmpty()) {
Arrays.fill(this.listElements, 0, this.listSize, null);
@@ -107,7 +108,7 @@ index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb
//this.check();
return;
}
@@ -186,11 +191,11 @@ public final class IteratorSafeOrderedReferenceSet<E> {
@@ -186,11 +192,11 @@ public final class IteratorSafeOrderedReferenceSet<E> {
int lastValidIndex;
java.util.Iterator<Reference2IntMap.Entry<E>> iterator;
@@ -121,7 +122,7 @@ index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb
final E key = backingArray[lastValidIndex - 1];
iterator = this.indexMap.reference2IntEntrySet().fastIterator(new Reference2IntMap.Entry<E>() {
@Override
@@ -221,7 +226,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
@@ -221,7 +227,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
// cleanup end
Arrays.fill(backingArray, lastValidIndex, this.listSize, null);
this.listSize = lastValidIndex;
@@ -130,7 +131,7 @@ index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb
//this.check();
}
@@ -235,7 +240,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
@@ -235,7 +241,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
}
public IteratorSafeOrderedReferenceSet.Iterator<E> iterator(final int flags) {
@@ -139,7 +140,7 @@ index ece6db7b9a0dfd535141c0c756947c4898140503..13df153d7b63a5c36a2fd14d3292e7eb
return new BaseIterator<>(this, true, (flags & ITERATOR_FLAG_SEE_ADDITIONS) != 0 ? Integer.MAX_VALUE : this.listSize);
}
@@ -322,7 +327,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
@@ -322,7 +328,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
}
this.lastReturned = null;
this.finished = true;