--- a/net/minecraft/world/item/MapItem.java
+++ b/net/minecraft/world/item/MapItem.java
@@ -32,8 +32,13 @@
 import net.minecraft.world.level.material.FluidState;
 import net.minecraft.world.level.material.MaterialColor;
 import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.event.server.MapInitializeEvent;
+// CraftBukkit end
 
 public class MapItem extends ComplexItem {
+
     public static final int IMAGE_WIDTH = 128;
     public static final int IMAGE_HEIGHT = 128;
     private static final int DEFAULT_MAP_COLOR = -12173266;
@@ -44,33 +49,41 @@
     }
 
     public static ItemStack create(Level world, int x, int z, byte scale, boolean showIcons, boolean unlimitedTracking) {
-        ItemStack itemStack = new ItemStack(Items.FILLED_MAP);
-        createAndStoreSavedData(itemStack, world, x, z, scale, showIcons, unlimitedTracking, world.dimension());
-        return itemStack;
+        ItemStack itemstack = new ItemStack(Items.FILLED_MAP);
+
+        MapItem.createAndStoreSavedData(itemstack, world, x, z, scale, showIcons, unlimitedTracking, world.dimension());
+        return itemstack;
     }
 
     @Nullable
     public static MapItemSavedData getSavedData(@Nullable Integer id, Level world) {
-        return id == null ? null : world.getMapData(makeKey(id));
+        return id == null ? null : world.getMapData(MapItem.makeKey(id));
     }
 
     @Nullable
     public static MapItemSavedData getSavedData(ItemStack map, Level world) {
-        Integer integer = getMapId(map);
-        return getSavedData(integer, world);
+        Integer integer = MapItem.getMapId(map);
+
+        return MapItem.getSavedData(integer, world);
     }
 
     @Nullable
     public static Integer getMapId(ItemStack stack) {
-        CompoundTag compoundTag = stack.getTag();
-        return compoundTag != null && compoundTag.contains("map", 99) ? compoundTag.getInt("map") : null;
+        CompoundTag nbttagcompound = stack.getTag();
+
+        return nbttagcompound != null && nbttagcompound.contains("map", 99) ? nbttagcompound.getInt("map") : null; // CraftBukkit - make new maps for no tag // Paper - don't return invalid ID
     }
 
     public static int createNewSavedData(Level world, int x, int z, int scale, boolean showIcons, boolean unlimitedTracking, ResourceKey<Level> dimension) {
-        MapItemSavedData mapItemSavedData = MapItemSavedData.createFresh((double)x, (double)z, (byte)scale, showIcons, unlimitedTracking, dimension);
-        int i = world.getFreeMapId();
-        world.setMapData(makeKey(i), mapItemSavedData);
-        return i;
+        MapItemSavedData worldmap = MapItemSavedData.createFresh((double) x, (double) z, (byte) scale, showIcons, unlimitedTracking, dimension);
+        int l = world.getFreeMapId();
+
+        world.setMapData(MapItem.makeKey(l), worldmap);
+        // CraftBukkit start
+        MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+        Bukkit.getServer().getPluginManager().callEvent(event);
+        // CraftBukkit end
+        return l;
     }
 
     private static void storeMapData(ItemStack stack, int id) {
@@ -78,8 +91,9 @@
     }
 
     private static void createAndStoreSavedData(ItemStack stack, Level world, int x, int z, int scale, boolean showIcons, boolean unlimitedTracking, ResourceKey<Level> dimension) {
-        int i = createNewSavedData(world, x, z, scale, showIcons, unlimitedTracking, dimension);
-        storeMapData(stack, i);
+        int l = MapItem.createNewSavedData(world, x, z, scale, showIcons, unlimitedTracking, dimension);
+
+        MapItem.storeMapData(stack, l);
     }
 
     public static String makeKey(int mapId) {
@@ -91,112 +105,122 @@
             int i = 1 << state.scale;
             int j = state.x;
             int k = state.z;
-            int l = Mth.floor(entity.getX() - (double)j) / i + 64;
-            int m = Mth.floor(entity.getZ() - (double)k) / i + 64;
-            int n = 128 / i;
+            int l = Mth.floor(entity.getX() - (double) j) / i + 64;
+            int i1 = Mth.floor(entity.getZ() - (double) k) / i + 64;
+            int j1 = 128 / i;
+
             if (world.dimensionType().hasCeiling()) {
-                n /= 2;
+                j1 /= 2;
             }
 
-            MapItemSavedData.HoldingPlayer holdingPlayer = state.getHoldingPlayer((Player)entity);
-            ++holdingPlayer.step;
-            boolean bl = false;
+            MapItemSavedData.HoldingPlayer worldmap_worldmaphumantracker = state.getHoldingPlayer((Player) entity);
 
-            for(int o = l - n + 1; o < l + n; ++o) {
-                if ((o & 15) == (holdingPlayer.step & 15) || bl) {
-                    bl = false;
-                    double d = 0.0D;
+            ++worldmap_worldmaphumantracker.step;
+            boolean flag = false;
 
-                    for(int p = m - n - 1; p < m + n; ++p) {
-                        if (o >= 0 && p >= -1 && o < 128 && p < 128) {
-                            int q = o - l;
-                            int r = p - m;
-                            boolean bl2 = q * q + r * r > (n - 2) * (n - 2);
-                            int s = (j / i + o - 64) * i;
-                            int t = (k / i + p - 64) * i;
+            for (int k1 = l - j1 + 1; k1 < l + j1; ++k1) {
+                if ((k1 & 15) == (worldmap_worldmaphumantracker.step & 15) || flag) {
+                    flag = false;
+                    double d0 = 0.0D;
+
+                    for (int l1 = i1 - j1 - 1; l1 < i1 + j1; ++l1) {
+                        if (k1 >= 0 && l1 >= -1 && k1 < 128 && l1 < 128) {
+                            int i2 = k1 - l;
+                            int j2 = l1 - i1;
+                            boolean flag1 = i2 * i2 + j2 * j2 > (j1 - 2) * (j1 - 2);
+                            int k2 = (j / i + k1 - 64) * i;
+                            int l2 = (k / i + l1 - 64) * i;
                             Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
-                            LevelChunk levelChunk = world.getChunkAt(new BlockPos(s, 0, t));
-                            if (!levelChunk.isEmpty()) {
-                                ChunkPos chunkPos = levelChunk.getPos();
-                                int u = s & 15;
-                                int v = t & 15;
-                                int w = 0;
-                                double e = 0.0D;
+                            LevelChunk chunk = world.getChunkIfLoaded(new BlockPos(k2, 0, l2)); // Paper - Maps shouldn't load chunks
+
+                            if (chunk != null && !chunk.isEmpty()) { // Paper - Maps shouldn't load chunks
+                                ChunkPos chunkcoordintpair = chunk.getPos();
+                                int i3 = k2 & 15;
+                                int j3 = l2 & 15;
+                                int k3 = 0;
+                                double d1 = 0.0D;
+
                                 if (world.dimensionType().hasCeiling()) {
-                                    int x = s + t * 231871;
-                                    x = x * x * 31287121 + x * 11;
-                                    if ((x >> 20 & 1) == 0) {
+                                    int l3 = k2 + l2 * 231871;
+
+                                    l3 = l3 * l3 * 31287121 + l3 * 11;
+                                    if ((l3 >> 20 & 1) == 0) {
                                         multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
                                     } else {
                                         multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
                                     }
 
-                                    e = 100.0D;
+                                    d1 = 100.0D;
                                 } else {
-                                    BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
-                                    BlockPos.MutableBlockPos mutableBlockPos2 = new BlockPos.MutableBlockPos();
+                                    BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
+                                    BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
 
-                                    for(int y = 0; y < i; ++y) {
-                                        for(int z = 0; z < i; ++z) {
-                                            int aa = levelChunk.getHeight(Heightmap.Types.WORLD_SURFACE, y + u, z + v) + 1;
-                                            BlockState blockState3;
-                                            if (aa <= world.getMinBuildHeight() + 1) {
-                                                blockState3 = Blocks.BEDROCK.defaultBlockState();
-                                            } else {
+                                    for (int i4 = 0; i4 < i; ++i4) {
+                                        for (int j4 = 0; j4 < i; ++j4) {
+                                            int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
+                                            BlockState iblockdata;
+
+                                            if (k4 > world.getMinBuildHeight() + 1) {
                                                 do {
-                                                    --aa;
-                                                    mutableBlockPos.set(chunkPos.getMinBlockX() + y + u, aa, chunkPos.getMinBlockZ() + z + v);
-                                                    blockState3 = levelChunk.getBlockState(mutableBlockPos);
-                                                } while(blockState3.getMapColor(world, mutableBlockPos) == MaterialColor.NONE && aa > world.getMinBuildHeight());
+                                                    --k4;
+                                                    blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
+                                                    iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
+                                                } while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
 
-                                                if (aa > world.getMinBuildHeight() && !blockState3.getFluidState().isEmpty()) {
-                                                    int ab = aa - 1;
-                                                    mutableBlockPos2.set(mutableBlockPos);
+                                                if (k4 > world.getMinBuildHeight() && !iblockdata.getFluidState().isEmpty()) {
+                                                    int l4 = k4 - 1;
+
+                                                    blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
+
+                                                    BlockState iblockdata1;
 
-                                                    BlockState blockState2;
                                                     do {
-                                                        mutableBlockPos2.setY(ab--);
-                                                        blockState2 = levelChunk.getBlockState(mutableBlockPos2);
-                                                        ++w;
-                                                    } while(ab > world.getMinBuildHeight() && !blockState2.getFluidState().isEmpty());
+                                                        blockposition_mutableblockposition1.setY(l4--);
+                                                        iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
+                                                        ++k3;
+                                                    } while (l4 > world.getMinBuildHeight() && !iblockdata1.getFluidState().isEmpty());
 
-                                                    blockState3 = this.getCorrectStateForFluidBlock(world, blockState3, mutableBlockPos);
+                                                    iblockdata = this.getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
                                                 }
+                                            } else {
+                                                iblockdata = Blocks.BEDROCK.defaultBlockState();
                                             }
 
-                                            state.checkBanners(world, chunkPos.getMinBlockX() + y + u, chunkPos.getMinBlockZ() + z + v);
-                                            e += (double)aa / (double)(i * i);
-                                            multiset.add(blockState3.getMapColor(world, mutableBlockPos));
+                                            state.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
+                                            d1 += (double) k4 / (double) (i * i);
+                                            multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
                                         }
                                     }
                                 }
 
-                                w /= i * i;
-                                MaterialColor materialColor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
-                                MaterialColor.Brightness brightness;
-                                if (materialColor == MaterialColor.WATER) {
-                                    double f = (double)w * 0.1D + (double)(o + p & 1) * 0.2D;
-                                    if (f < 0.5D) {
-                                        brightness = MaterialColor.Brightness.HIGH;
-                                    } else if (f > 0.9D) {
-                                        brightness = MaterialColor.Brightness.LOW;
+                                k3 /= i * i;
+                                MaterialColor materialmapcolor = (MaterialColor) Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
+                                double d2;
+                                MaterialColor.Brightness materialmapcolor_a;
+
+                                if (materialmapcolor == MaterialColor.WATER) {
+                                    d2 = (double) k3 * 0.1D + (double) (k1 + l1 & 1) * 0.2D;
+                                    if (d2 < 0.5D) {
+                                        materialmapcolor_a = MaterialColor.Brightness.HIGH;
+                                    } else if (d2 > 0.9D) {
+                                        materialmapcolor_a = MaterialColor.Brightness.LOW;
                                     } else {
-                                        brightness = MaterialColor.Brightness.NORMAL;
+                                        materialmapcolor_a = MaterialColor.Brightness.NORMAL;
                                     }
                                 } else {
-                                    double g = (e - d) * 4.0D / (double)(i + 4) + ((double)(o + p & 1) - 0.5D) * 0.4D;
-                                    if (g > 0.6D) {
-                                        brightness = MaterialColor.Brightness.HIGH;
-                                    } else if (g < -0.6D) {
-                                        brightness = MaterialColor.Brightness.LOW;
+                                    d2 = (d1 - d0) * 4.0D / (double) (i + 4) + ((double) (k1 + l1 & 1) - 0.5D) * 0.4D;
+                                    if (d2 > 0.6D) {
+                                        materialmapcolor_a = MaterialColor.Brightness.HIGH;
+                                    } else if (d2 < -0.6D) {
+                                        materialmapcolor_a = MaterialColor.Brightness.LOW;
                                     } else {
-                                        brightness = MaterialColor.Brightness.NORMAL;
+                                        materialmapcolor_a = MaterialColor.Brightness.NORMAL;
                                     }
                                 }
 
-                                d = e;
-                                if (p >= 0 && q * q + r * r < n * n && (!bl2 || (o + p & 1) != 0)) {
-                                    bl |= state.updateColor(o, p, materialColor.getPackedId(brightness));
+                                d0 = d1;
+                                if (l1 >= 0 && i2 * i2 + j2 * j2 < j1 * j1 && (!flag1 || (k1 + l1 & 1) != 0)) {
+                                    flag |= state.updateColor(k1, l1, materialmapcolor.getPackedId(materialmapcolor_a));
                                 }
                             }
                         }
@@ -208,8 +232,9 @@
     }
 
     private BlockState getCorrectStateForFluidBlock(Level world, BlockState state, BlockPos pos) {
-        FluidState fluidState = state.getFluidState();
-        return !fluidState.isEmpty() && !state.isFaceSturdy(world, pos, Direction.UP) ? fluidState.createLegacyBlock() : state;
+        FluidState fluid = state.getFluidState();
+
+        return !fluid.isEmpty() && !state.isFaceSturdy(world, pos, Direction.UP) ? fluid.createLegacyBlock() : state;
     }
 
     private static boolean isBiomeWatery(boolean[] biomes, int x, int z) {
@@ -217,73 +242,78 @@
     }
 
     public static void renderBiomePreviewMap(ServerLevel world, ItemStack map) {
-        MapItemSavedData mapItemSavedData = getSavedData(map, world);
-        if (mapItemSavedData != null) {
-            if (world.dimension() == mapItemSavedData.dimension) {
-                int i = 1 << mapItemSavedData.scale;
-                int j = mapItemSavedData.x;
-                int k = mapItemSavedData.z;
-                boolean[] bls = new boolean[16384];
+        MapItemSavedData worldmap = MapItem.getSavedData(map, world);
+
+        if (worldmap != null) {
+            if (world.dimension() == worldmap.dimension) {
+                int i = 1 << worldmap.scale;
+                int j = worldmap.x;
+                int k = worldmap.z;
+                boolean[] aboolean = new boolean[16384];
                 int l = j / i - 64;
-                int m = k / i - 64;
-                BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+                int i1 = k / i - 64;
 
-                for(int n = 0; n < 128; ++n) {
-                    for(int o = 0; o < 128; ++o) {
-                        Holder<Biome> holder = world.getBiome(mutableBlockPos.set((l + o) * i, 0, (m + n) * i));
-                        bls[n * 128 + o] = holder.is(BiomeTags.WATER_ON_MAP_OUTLINES);
+                int j1;
+                int k1;
+
+                for (j1 = 0; j1 < 128; ++j1) {
+                    for (k1 = 0; k1 < 128; ++k1) {
+                        Holder<Biome> holder = world.getUncachedNoiseBiome((l + k1) * i, 0, (i1 + j1) * i); // Paper
+
+                        aboolean[j1 * 128 + k1] = holder.is(BiomeTags.WATER_ON_MAP_OUTLINES);
                     }
                 }
 
-                for(int p = 1; p < 127; ++p) {
-                    for(int q = 1; q < 127; ++q) {
-                        int r = 0;
+                for (j1 = 1; j1 < 127; ++j1) {
+                    for (k1 = 1; k1 < 127; ++k1) {
+                        int l1 = 0;
 
-                        for(int s = -1; s < 2; ++s) {
-                            for(int t = -1; t < 2; ++t) {
-                                if ((s != 0 || t != 0) && isBiomeWatery(bls, p + s, q + t)) {
-                                    ++r;
+                        for (int i2 = -1; i2 < 2; ++i2) {
+                            for (int j2 = -1; j2 < 2; ++j2) {
+                                if ((i2 != 0 || j2 != 0) && MapItem.isBiomeWatery(aboolean, j1 + i2, k1 + j2)) {
+                                    ++l1;
                                 }
                             }
                         }
 
-                        MaterialColor.Brightness brightness = MaterialColor.Brightness.LOWEST;
-                        MaterialColor materialColor = MaterialColor.NONE;
-                        if (isBiomeWatery(bls, p, q)) {
-                            materialColor = MaterialColor.COLOR_ORANGE;
-                            if (r > 7 && q % 2 == 0) {
-                                switch ((p + (int)(Mth.sin((float)q + 0.0F) * 7.0F)) / 8 % 5) {
+                        MaterialColor.Brightness materialmapcolor_a = MaterialColor.Brightness.LOWEST;
+                        MaterialColor materialmapcolor = MaterialColor.NONE;
+
+                        if (MapItem.isBiomeWatery(aboolean, j1, k1)) {
+                            materialmapcolor = MaterialColor.COLOR_ORANGE;
+                            if (l1 > 7 && k1 % 2 == 0) {
+                                switch ((j1 + (int) (Mth.sin((float) k1 + 0.0F) * 7.0F)) / 8 % 5) {
                                     case 0:
                                     case 4:
-                                        brightness = MaterialColor.Brightness.LOW;
+                                        materialmapcolor_a = MaterialColor.Brightness.LOW;
                                         break;
                                     case 1:
                                     case 3:
-                                        brightness = MaterialColor.Brightness.NORMAL;
+                                        materialmapcolor_a = MaterialColor.Brightness.NORMAL;
                                         break;
                                     case 2:
-                                        brightness = MaterialColor.Brightness.HIGH;
+                                        materialmapcolor_a = MaterialColor.Brightness.HIGH;
                                 }
-                            } else if (r > 7) {
-                                materialColor = MaterialColor.NONE;
-                            } else if (r > 5) {
-                                brightness = MaterialColor.Brightness.NORMAL;
-                            } else if (r > 3) {
-                                brightness = MaterialColor.Brightness.LOW;
-                            } else if (r > 1) {
-                                brightness = MaterialColor.Brightness.LOW;
+                            } else if (l1 > 7) {
+                                materialmapcolor = MaterialColor.NONE;
+                            } else if (l1 > 5) {
+                                materialmapcolor_a = MaterialColor.Brightness.NORMAL;
+                            } else if (l1 > 3) {
+                                materialmapcolor_a = MaterialColor.Brightness.LOW;
+                            } else if (l1 > 1) {
+                                materialmapcolor_a = MaterialColor.Brightness.LOW;
                             }
-                        } else if (r > 0) {
-                            materialColor = MaterialColor.COLOR_BROWN;
-                            if (r > 3) {
-                                brightness = MaterialColor.Brightness.NORMAL;
+                        } else if (l1 > 0) {
+                            materialmapcolor = MaterialColor.COLOR_BROWN;
+                            if (l1 > 3) {
+                                materialmapcolor_a = MaterialColor.Brightness.NORMAL;
                             } else {
-                                brightness = MaterialColor.Brightness.LOWEST;
+                                materialmapcolor_a = MaterialColor.Brightness.LOWEST;
                             }
                         }
 
-                        if (materialColor != MaterialColor.NONE) {
-                            mapItemSavedData.setColor(p, q, materialColor.getPackedId(brightness));
+                        if (materialmapcolor != MaterialColor.NONE) {
+                            worldmap.setColor(j1, k1, materialmapcolor.getPackedId(materialmapcolor_a));
                         }
                     }
                 }
@@ -295,15 +325,17 @@
     @Override
     public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
         if (!world.isClientSide) {
-            MapItemSavedData mapItemSavedData = getSavedData(stack, world);
-            if (mapItemSavedData != null) {
+            MapItemSavedData worldmap = MapItem.getSavedData(stack, world);
+
+            if (worldmap != null) {
                 if (entity instanceof Player) {
-                    Player player = (Player)entity;
-                    mapItemSavedData.tickCarriedBy(player, stack);
+                    Player entityhuman = (Player) entity;
+
+                    worldmap.tickCarriedBy(entityhuman, stack);
                 }
 
-                if (!mapItemSavedData.locked && (selected || entity instanceof Player && ((Player)entity).getOffhandItem() == stack)) {
-                    this.update(world, entity, mapItemSavedData);
+                if (!worldmap.locked && (selected || entity instanceof Player && ((Player) entity).getOffhandItem() == stack)) {
+                    this.update(world, entity, worldmap);
                 }
 
             }
@@ -313,59 +345,66 @@
     @Nullable
     @Override
     public Packet<?> getUpdatePacket(ItemStack stack, Level world, Player player) {
-        Integer integer = getMapId(stack);
-        MapItemSavedData mapItemSavedData = getSavedData(integer, world);
-        return mapItemSavedData != null ? mapItemSavedData.getUpdatePacket(integer, player) : null;
+        Integer integer = MapItem.getMapId(stack);
+        MapItemSavedData worldmap = MapItem.getSavedData(integer, world);
+
+        return worldmap != null ? worldmap.getUpdatePacket(integer, player) : null;
     }
 
     @Override
     public void onCraftedBy(ItemStack stack, Level world, Player player) {
-        CompoundTag compoundTag = stack.getTag();
-        if (compoundTag != null && compoundTag.contains("map_scale_direction", 99)) {
-            scaleMap(stack, world, compoundTag.getInt("map_scale_direction"));
-            compoundTag.remove("map_scale_direction");
-        } else if (compoundTag != null && compoundTag.contains("map_to_lock", 1) && compoundTag.getBoolean("map_to_lock")) {
-            lockMap(world, stack);
-            compoundTag.remove("map_to_lock");
+        CompoundTag nbttagcompound = stack.getTag();
+
+        if (nbttagcompound != null && nbttagcompound.contains("map_scale_direction", 99)) {
+            MapItem.scaleMap(stack, world, nbttagcompound.getInt("map_scale_direction"));
+            nbttagcompound.remove("map_scale_direction");
+        } else if (nbttagcompound != null && nbttagcompound.contains("map_to_lock", 1) && nbttagcompound.getBoolean("map_to_lock")) {
+            MapItem.lockMap(world, stack);
+            nbttagcompound.remove("map_to_lock");
         }
 
     }
 
     private static void scaleMap(ItemStack map, Level world, int amount) {
-        MapItemSavedData mapItemSavedData = getSavedData(map, world);
-        if (mapItemSavedData != null) {
-            int i = world.getFreeMapId();
-            world.setMapData(makeKey(i), mapItemSavedData.scaled(amount));
-            storeMapData(map, i);
+        MapItemSavedData worldmap = MapItem.getSavedData(map, world);
+
+        if (worldmap != null) {
+            int j = world.getFreeMapId();
+
+            world.setMapData(MapItem.makeKey(j), worldmap.scaled(amount));
+            MapItem.storeMapData(map, j);
         }
 
     }
 
     public static void lockMap(Level world, ItemStack stack) {
-        MapItemSavedData mapItemSavedData = getSavedData(stack, world);
-        if (mapItemSavedData != null) {
+        MapItemSavedData worldmap = MapItem.getSavedData(stack, world);
+
+        if (worldmap != null) {
             int i = world.getFreeMapId();
-            String string = makeKey(i);
-            MapItemSavedData mapItemSavedData2 = mapItemSavedData.locked();
-            world.setMapData(string, mapItemSavedData2);
-            storeMapData(stack, i);
+            String s = MapItem.makeKey(i);
+            MapItemSavedData worldmap1 = worldmap.locked();
+
+            world.setMapData(s, worldmap1);
+            MapItem.storeMapData(stack, i);
         }
 
     }
 
     @Override
     public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag context) {
-        Integer integer = getMapId(stack);
-        MapItemSavedData mapItemSavedData = world == null ? null : getSavedData(integer, world);
-        if (mapItemSavedData != null && mapItemSavedData.locked) {
+        Integer integer = MapItem.getMapId(stack);
+        MapItemSavedData worldmap = world == null ? null : MapItem.getSavedData(integer, world);
+
+        if (worldmap != null && worldmap.locked) {
             tooltip.add(Component.translatable("filled_map.locked", integer).withStyle(ChatFormatting.GRAY));
         }
 
         if (context.isAdvanced()) {
-            if (mapItemSavedData != null) {
+            if (worldmap != null) {
                 tooltip.add(Component.translatable("filled_map.id", integer).withStyle(ChatFormatting.GRAY));
-                tooltip.add(Component.translatable("filled_map.scale", 1 << mapItemSavedData.scale).withStyle(ChatFormatting.GRAY));
-                tooltip.add(Component.translatable("filled_map.level", mapItemSavedData.scale, 4).withStyle(ChatFormatting.GRAY));
+                tooltip.add(Component.translatable("filled_map.scale", 1 << worldmap.scale).withStyle(ChatFormatting.GRAY));
+                tooltip.add(Component.translatable("filled_map.level", worldmap.scale, 4).withStyle(ChatFormatting.GRAY));
             } else {
                 tooltip.add(Component.translatable("filled_map.unknown").withStyle(ChatFormatting.GRAY));
             }
@@ -374,9 +413,11 @@
     }
 
     public static int getColor(ItemStack stack) {
-        CompoundTag compoundTag = stack.getTagElement("display");
-        if (compoundTag != null && compoundTag.contains("MapColor", 99)) {
-            int i = compoundTag.getInt("MapColor");
+        CompoundTag nbttagcompound = stack.getTagElement("display");
+
+        if (nbttagcompound != null && nbttagcompound.contains("MapColor", 99)) {
+            int i = nbttagcompound.getInt("MapColor");
+
             return -16777216 | i & 16777215;
         } else {
             return -12173266;
@@ -385,11 +426,13 @@
 
     @Override
     public InteractionResult useOn(UseOnContext context) {
-        BlockState blockState = context.getLevel().getBlockState(context.getClickedPos());
-        if (blockState.is(BlockTags.BANNERS)) {
+        BlockState iblockdata = context.getLevel().getBlockState(context.getClickedPos());
+
+        if (iblockdata.is(BlockTags.BANNERS)) {
             if (!context.getLevel().isClientSide) {
-                MapItemSavedData mapItemSavedData = getSavedData(context.getItemInHand(), context.getLevel());
-                if (mapItemSavedData != null && !mapItemSavedData.toggleBanner(context.getLevel(), context.getClickedPos())) {
+                MapItemSavedData worldmap = MapItem.getSavedData(context.getItemInHand(), context.getLevel());
+
+                if (worldmap != null && !worldmap.toggleBanner(context.getLevel(), context.getClickedPos())) {
                     return InteractionResult.FAIL;
                 }
             }
