Correct handling of invalid maps (#6302)

This commit is contained in:
PaulBGD 2021-07-31 15:47:01 -05:00
parent b8f6b49552
commit 1c0ded9f9b

View file

@ -51,12 +51,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - remove player from map on drop
+ if (stack.getItem() == Items.FILLED_MAP) {
+ MapItemSavedData worldmap = MapItem.getSavedData(stack, this.level);
+ worldmap.tickCarriedBy(this, stack);
+ if (worldmap != null) {
+ worldmap.tickCarriedBy(this, stack);
+ }
+ }
+ // Paper end
return entityitem;
}
diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/MapItem.java
+++ b/src/main/java/net/minecraft/world/item/MapItem.java
@@ -0,0 +0,0 @@ public class MapItem extends ComplexItem {
@Nullable
public static MapItemSavedData getSavedData(@Nullable Integer id, Level world) {
- return id == null ? null : world.getMapData(MapItem.makeKey(id));
+ return id == null || id < 0 ? null : world.getMapData(MapItem.makeKey(id)); // Paper - map ids under 0 are invalid
}
@Nullable
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java