From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:35:28 +0200 Subject: [PATCH] Fix missing map initialize event call diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index d5543fe1c1f25798e7dea774d6e20132901dc05e..eba414c592332b67143268ef56b912b35f2a2c14 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -2129,7 +2129,23 @@ public class ServerLevel extends Level implements WorldGenLevel { @Nullable @Override public MapItemSavedData getMapData(String id) { - return (MapItemSavedData) this.getServer().overworld().getDataStorage().get(MapItemSavedData.factory(), id); + // Paper start - Call missing map initialize event & set id + final DimensionDataStorage storage = this.getServer().overworld().getDataStorage(); + + final net.minecraft.world.level.saveddata.SavedData existing = storage.cache.get(id); + if (existing == null && !storage.cache.containsKey(id)) { + final net.minecraft.world.level.saveddata.SavedData.Factory factory = MapItemSavedData.factory(); + final MapItemSavedData map = storage.readSavedData(factory.deserializer(), factory.type(), id); + storage.cache.put(id, map); + if (map != null) { + map.id = id; + new MapInitializeEvent(map.mapView).callEvent(); + return map; + } + } + + return existing instanceof MapItemSavedData data ? data : null; + // Paper end } @Override diff --git a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java index 1aea6a257ffceb511368a6e8dee5051e120894ad..269c81cd60d98a94721c77d700af223bda15a61a 100644 --- a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java +++ b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java @@ -58,7 +58,7 @@ public class DimensionDataStorage { } @Nullable - private T readSavedData(Function readFunction, DataFixTypes dataFixTypes, String id) { + public T readSavedData(Function readFunction, DataFixTypes dataFixTypes, String id) { // Paper try { File file = this.getDataFile(id); if (file.exists()) {