From 7eaff48d7c9ae5825a475e74f92e3d81d9a682e2 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 4 Jan 2024 14:38:26 +0100 Subject: [PATCH] [ci skip] Replace some magic values with constant references --- patches/server/0018-Rewrite-chunk-system.patch | 4 ++-- patches/server/0033-Entity-Origin-API.patch | 4 ++-- .../server/0068-Handle-Item-Meta-Inconsistencies.patch | 8 ++++---- ...96-LootTable-API-Replenishable-Lootables-Feature.patch | 8 ++++---- ...rienceOrbs-API-for-Reason-Source-Triggering-play.patch | 6 +++--- patches/server/0304-Mob-Spawner-API-Enhancements.patch | 4 ++-- .../server/0309-Allow-Saving-of-Oversized-Chunks.patch | 6 +++--- patches/server/0419-Support-old-UUID-format-for-NBT.patch | 8 ++++---- .../0426-Update-itemstack-legacy-name-and-lore.patch | 8 ++++---- ...ot-let-the-server-load-chunks-from-newer-version.patch | 4 ++-- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/patches/server/0018-Rewrite-chunk-system.patch b/patches/server/0018-Rewrite-chunk-system.patch index ac597c6bb2..b898001760 100644 --- a/patches/server/0018-Rewrite-chunk-system.patch +++ b/patches/server/0018-Rewrite-chunk-system.patch @@ -8168,7 +8168,7 @@ index 0000000000000000000000000000000000000000..53ddd7e9ac05e6a9eb809f329796e6d4 +} diff --git a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkLoadTask.java b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkLoadTask.java new file mode 100644 -index 0000000000000000000000000000000000000000..e7fb084ddb88ab62f1d493a999cc82b9258d275e +index 0000000000000000000000000000000000000000..310e61db5d845f904119dcb84d981e7c608bf1a8 --- /dev/null +++ b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkLoadTask.java @@ -0,0 +1,484 @@ @@ -8574,7 +8574,7 @@ index 0000000000000000000000000000000000000000..e7fb084ddb88ab62f1d493a999cc82b9 + try { + data = data.copy(); // coming from the I/O thread, so we need to copy + // run converters -+ final int dataVersion = !data.contains(SharedConstants.DATA_VERSION_TAG, 99) ? 1945 : data.getInt(SharedConstants.DATA_VERSION_TAG); ++ final int dataVersion = !data.contains(SharedConstants.DATA_VERSION_TAG, net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) ? 1945 : data.getInt(SharedConstants.DATA_VERSION_TAG); + final CompoundTag converted = MCDataConverter.convertTag( + MCTypeRegistry.POI_CHUNK, data, dataVersion, SharedConstants.getCurrentVersion().getDataVersion().getVersion() + ); diff --git a/patches/server/0033-Entity-Origin-API.patch b/patches/server/0033-Entity-Origin-API.patch index 134242c957..f8ea2c0a67 100644 --- a/patches/server/0033-Entity-Origin-API.patch +++ b/patches/server/0033-Entity-Origin-API.patch @@ -25,7 +25,7 @@ index 0ff6e1f3f24b4086ce62faecf400c493f31fc964..7431b66079406a311a8e46ccabc8f3ef public void onTrackingEnd(Entity entity) { diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index fa3d294b36eb0c23b293466fc72bd2970a452b55..9f3598371c854ec74f3b5752c9779d6c0d99ec39 100644 +index fa3d294b36eb0c23b293466fc72bd2970a452b55..30f7702f4fa3452cdc15df5ca8873bed08c9b30f 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -317,7 +317,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -77,7 +77,7 @@ index fa3d294b36eb0c23b293466fc72bd2970a452b55..9f3598371c854ec74f3b5752c9779d6c // CraftBukkit end + // Paper start - Restore the entity's origin location -+ ListTag originTag = nbt.getList("Paper.Origin", 6); ++ ListTag originTag = nbt.getList("Paper.Origin", net.minecraft.nbt.Tag.TAG_DOUBLE); + if (!originTag.isEmpty()) { + UUID originWorld = null; + if (nbt.contains("Paper.OriginWorld")) { diff --git a/patches/server/0068-Handle-Item-Meta-Inconsistencies.patch b/patches/server/0068-Handle-Item-Meta-Inconsistencies.patch index 38e06d033b..30bd005856 100644 --- a/patches/server/0068-Handle-Item-Meta-Inconsistencies.patch +++ b/patches/server/0068-Handle-Item-Meta-Inconsistencies.patch @@ -18,7 +18,7 @@ For consistency, the old API methods now forward to use the ItemMeta API equivalents, and should deprecate the old API's. diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java -index 9861cd23b07f8fbacb1d125af835dee58c2debbb..e6a47317eb24fc65ed02a4d4f9c4b19b5abc920d 100644 +index 9861cd23b07f8fbacb1d125af835dee58c2debbb..b0ea04fc0bac640f7076100e44c16c03b86b2a0e 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java +++ b/src/main/java/net/minecraft/world/item/ItemStack.java @@ -180,6 +180,23 @@ public final class ItemStack { @@ -28,10 +28,10 @@ index 9861cd23b07f8fbacb1d125af835dee58c2debbb..e6a47317eb24fc65ed02a4d4f9c4b19b + // Paper start + private static final java.util.Comparator enchantSorter = java.util.Comparator.comparing(o -> o.getString("id")); + private void processEnchantOrder(@Nullable CompoundTag tag) { -+ if (tag == null || !tag.contains("Enchantments", 9)) { ++ if (tag == null || !tag.contains("Enchantments", net.minecraft.nbt.Tag.TAG_LIST)) { + return; + } -+ ListTag list = tag.getList("Enchantments", 10); ++ ListTag list = tag.getList("Enchantments", net.minecraft.nbt.Tag.TAG_COMPOUND); + if (list.size() < 2) { + return; + } @@ -168,7 +168,7 @@ index 7278ac809eff364e8b838d63a2ec1291493869f8..7dd0c000fa7f363997178ffa6de7d39e static Map getEnchantments(net.minecraft.world.item.ItemStack item) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java -index 9e74a28d77c4c91ad46750d924a3e0789683a875..89dac1d16a90717e6a99d41e8ea04810f78fdee4 100644 +index fbde42a814f846ce8c9df6ea621f10610d9322b3..2a63d2af178f8e8f12d6a57226257da41c3dac7c 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableList; diff --git a/patches/server/0096-LootTable-API-Replenishable-Lootables-Feature.patch b/patches/server/0096-LootTable-API-Replenishable-Lootables-Feature.patch index 55a5d386cb..edfd811f40 100644 --- a/patches/server/0096-LootTable-API-Replenishable-Lootables-Feature.patch +++ b/patches/server/0096-LootTable-API-Replenishable-Lootables-Feature.patch @@ -240,7 +240,7 @@ index 0000000000000000000000000000000000000000..8e6dac2cef7af26ad74928eff631c182 +} diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java new file mode 100644 -index 0000000000000000000000000000000000000000..5408cbc21fc7577a6100b5a1ca0463e899d2df8b +index 0000000000000000000000000000000000000000..6e72c43b9d3834eb91c02ce68e7d114ad907812d --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java @@ -0,0 +1,188 @@ @@ -364,8 +364,8 @@ index 0000000000000000000000000000000000000000..5408cbc21fc7577a6100b5a1ca0463e8 + if (comp.contains("numRefills")) { + this.numRefills = comp.getInt("numRefills"); + } -+ if (comp.contains("lootedPlayers", 9)) { // 9 = list -+ ListTag list = comp.getList("lootedPlayers", 10); // 10 = compound ++ if (comp.contains("lootedPlayers", net.minecraft.nbt.Tag.TAG_LIST)) { ++ ListTag list = comp.getList("lootedPlayers", net.minecraft.nbt.Tag.TAG_COMPOUND); + final int size = list.size(); + if (size > 0) { + this.lootedPlayers = new HashMap<>(list.size()); @@ -504,7 +504,7 @@ index 0000000000000000000000000000000000000000..9cfa5d36a6991067a3866e0d437749fa + } +} diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index cc762d3eb68d2f8bf9529ecf07adfc343953c7a2..1b7b3114cd6ced0587a0e7e4a4c94584c72ed17f 100644 +index e0534859f631e0bdec2db4ae92de0036c4bc62d2..d63cbd3e0e49a5c00d411574a3ca1d081c23dfdd 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -236,6 +236,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S diff --git a/patches/server/0126-ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch b/patches/server/0126-ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch index a7fbd387b9..e0ceff545c 100644 --- a/patches/server/0126-ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch +++ b/patches/server/0126-ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch @@ -21,7 +21,7 @@ index 4f3c82f1b5ae24d5f70318fa96fae2a58ce7fd9f..45236a077d798d6a257a2e982b589011 return true; diff --git a/src/main/java/net/minecraft/world/entity/ExperienceOrb.java b/src/main/java/net/minecraft/world/entity/ExperienceOrb.java -index 59bad6c92cc421dd05c7315e2ab694a669433ab4..627fcf000f40e1bda025da874c447a99c727b98b 100644 +index 59bad6c92cc421dd05c7315e2ab694a669433ab4..b49e48fa6dd37b5eddb45877be90018ec9d23b0e 100644 --- a/src/main/java/net/minecraft/world/entity/ExperienceOrb.java +++ b/src/main/java/net/minecraft/world/entity/ExperienceOrb.java @@ -39,13 +39,67 @@ public class ExperienceOrb extends Entity { @@ -36,7 +36,7 @@ index 59bad6c92cc421dd05c7315e2ab694a669433ab4..627fcf000f40e1bda025da874c447a99 + public org.bukkit.entity.ExperienceOrb.SpawnReason spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN; + + private void loadPaperNBT(CompoundTag nbttagcompound) { -+ if (!nbttagcompound.contains("Paper.ExpData", 10)) { // 10 = compound ++ if (!nbttagcompound.contains("Paper.ExpData", net.minecraft.nbt.Tag.TAG_COMPOUND)) { + return; + } + CompoundTag comp = nbttagcompound.getCompound("Paper.ExpData"); @@ -205,7 +205,7 @@ index 83dbf663cd725adcbcfee4ac633f369240375381..0dab0da65788720e56a568918de458ab } diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java -index c12c387cc2bc87346414dccaa7b2d9347087388d..2eeffb6c31ccdec14001b0a3a82d0f01117b96f3 100644 +index 2471800014d1661c2f422e5a24f0f3b00fa838f2..f5ce6423b8146cc741023e15004fe9814a035da8 100644 --- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java +++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java @@ -673,7 +673,7 @@ public class EnderDragon extends Mob implements Enemy { diff --git a/patches/server/0304-Mob-Spawner-API-Enhancements.patch b/patches/server/0304-Mob-Spawner-API-Enhancements.patch index b16a1d736b..512623b3ed 100644 --- a/patches/server/0304-Mob-Spawner-API-Enhancements.patch +++ b/patches/server/0304-Mob-Spawner-API-Enhancements.patch @@ -9,7 +9,7 @@ public net.minecraft.world.level.BaseSpawner delay(Lnet/minecraft/world/level/Le public net.minecraft.world.level.BaseSpawner setNextSpawnData(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/SpawnData;)V diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java -index 231674f1483ad71630ac71ba92efc50f94a5659b..41f549f16f69f9bc50a004096e6c3c0f6e4d4eaf 100644 +index 231674f1483ad71630ac71ba92efc50f94a5659b..0578ac12d92f9af0b0113587db9351b4a41bedd5 100644 --- a/src/main/java/net/minecraft/world/level/BaseSpawner.java +++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java @@ -235,7 +235,13 @@ public abstract class BaseSpawner { @@ -31,7 +31,7 @@ index 231674f1483ad71630ac71ba92efc50f94a5659b..41f549f16f69f9bc50a004096e6c3c0f } + // Paper start - use ints if set -+ if (nbt.contains("Paper.MinSpawnDelay", 99)) { ++ if (nbt.contains("Paper.MinSpawnDelay", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) { + this.minSpawnDelay = nbt.getInt("Paper.MinSpawnDelay"); + this.maxSpawnDelay = nbt.getInt("Paper.MaxSpawnDelay"); + this.spawnCount = nbt.getShort("SpawnCount"); diff --git a/patches/server/0309-Allow-Saving-of-Oversized-Chunks.patch b/patches/server/0309-Allow-Saving-of-Oversized-Chunks.patch index 1233e2c468..56f3a3abe8 100644 --- a/patches/server/0309-Allow-Saving-of-Oversized-Chunks.patch +++ b/patches/server/0309-Allow-Saving-of-Oversized-Chunks.patch @@ -141,7 +141,7 @@ index 2a7f17726a161ddbcd0397fb4332de6980199c38..72dacdc271325c814fb43cd6daaf3a20 private final ChunkPos pos; diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java -index 465ad0bae446a20e941e8f2dbf2d85f2627482b9..42dc999d820e62c6a222afbd9239cc671fc7de53 100644 +index 465ad0bae446a20e941e8f2dbf2d85f2627482b9..c46320794e9673d7ff24aae5e9086cc90988791c 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java @@ -121,6 +121,71 @@ public class RegionFileStorage implements AutoCloseable { @@ -191,8 +191,8 @@ index 465ad0bae446a20e941e8f2dbf2d85f2627482b9..42dc999d820e62c6a222afbd9239cc67 + } + + private static void mergeChunkList(CompoundTag level, CompoundTag oversizedLevel, String key, String oversizedKey) { -+ net.minecraft.nbt.ListTag levelList = level.getList(key, 10); -+ net.minecraft.nbt.ListTag oversizedList = oversizedLevel.getList(oversizedKey, 10); ++ net.minecraft.nbt.ListTag levelList = level.getList(key, net.minecraft.nbt.Tag.TAG_COMPOUND); ++ net.minecraft.nbt.ListTag oversizedList = oversizedLevel.getList(oversizedKey, net.minecraft.nbt.Tag.TAG_COMPOUND); + + if (!oversizedList.isEmpty()) { + levelList.addAll(oversizedList); diff --git a/patches/server/0419-Support-old-UUID-format-for-NBT.patch b/patches/server/0419-Support-old-UUID-format-for-NBT.patch index 84e478795b..15609535ef 100644 --- a/patches/server/0419-Support-old-UUID-format-for-NBT.patch +++ b/patches/server/0419-Support-old-UUID-format-for-NBT.patch @@ -8,7 +8,7 @@ We have stored UUID in plenty of places that did not get DFU'd So just look for old format and load it if it exists. diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/net/minecraft/nbt/CompoundTag.java -index 135530bc9d7ecd0348ace6474f4ca6d2e1bad283..e464ada187fd1f15efef29a0e5033aeb0c688059 100644 +index 135530bc9d7ecd0348ace6474f4ca6d2e1bad283..4c8f2dbdd6e384be026ae1c890096f89fd744eb0 100644 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java @@ -237,6 +237,12 @@ public class CompoundTag implements Tag { @@ -16,7 +16,7 @@ index 135530bc9d7ecd0348ace6474f4ca6d2e1bad283..e464ada187fd1f15efef29a0e5033aeb public void putUUID(String key, UUID value) { + // Paper start - support old format -+ if (this.contains(key + "Most", 99) && this.contains(key + "Least", 99)) { ++ if (this.contains(key + "Most", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) && this.contains(key + "Least", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) { + this.tags.remove(key + "Most"); + this.tags.remove(key + "Least"); + } @@ -29,7 +29,7 @@ index 135530bc9d7ecd0348ace6474f4ca6d2e1bad283..e464ada187fd1f15efef29a0e5033aeb */ public UUID getUUID(String key) { + // Paper start - support old format -+ if (!contains(key, 11) && this.contains(key + "Most", 99) && this.contains(key + "Least", 99)) { ++ if (!contains(key, 11) && this.contains(key + "Most", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) && this.contains(key + "Least", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) { + return new UUID(this.getLong(key + "Most"), this.getLong(key + "Least")); + } + // Paper end @@ -38,7 +38,7 @@ index 135530bc9d7ecd0348ace6474f4ca6d2e1bad283..e464ada187fd1f15efef29a0e5033aeb public boolean hasUUID(String key) { + // Paper start - support old format -+ if (this.contains(key + "Most", 99) && this.contains(key + "Least", 99)) { ++ if (this.contains(key + "Most", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) && this.contains(key + "Least", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) { + return true; + } + // Paper end diff --git a/patches/server/0426-Update-itemstack-legacy-name-and-lore.patch b/patches/server/0426-Update-itemstack-legacy-name-and-lore.patch index d6f85477a6..5f75a5e37d 100644 --- a/patches/server/0426-Update-itemstack-legacy-name-and-lore.patch +++ b/patches/server/0426-Update-itemstack-legacy-name-and-lore.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Update itemstack legacy name and lore diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java -index 19e8d10727fc4838cd8261dfec92f3828ea5b09f..e9df7ea1228603ee3ebf515b6419f668cbe3aef7 100644 +index 0c4727f383313762893b0a7af7bdeb746c80861a..c5e36e7e96902fc0e8e9bb409907c6424cf223bd 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java +++ b/src/main/java/net/minecraft/world/item/ItemStack.java @@ -195,6 +195,44 @@ public final class ItemStack { @@ -16,7 +16,7 @@ index 19e8d10727fc4838cd8261dfec92f3828ea5b09f..e9df7ea1228603ee3ebf515b6419f668 + private void processText() { + CompoundTag display = getTagElement("display"); + if (display != null) { -+ if (display.contains("Name", 8)) { ++ if (display.contains("Name", net.minecraft.nbt.Tag.TAG_STRING)) { + String json = display.getString("Name"); + if (json != null && json.contains("\u00A7")) { + try { @@ -26,8 +26,8 @@ index 19e8d10727fc4838cd8261dfec92f3828ea5b09f..e9df7ea1228603ee3ebf515b6419f668 + } + } + } -+ if (display.contains("Lore", 9)) { -+ ListTag list = display.getList("Lore", 8); ++ if (display.contains("Lore", net.minecraft.nbt.Tag.TAG_LIST)) { ++ ListTag list = display.getList("Lore", net.minecraft.nbt.Tag.TAG_STRING); + for (int index = 0; index < list.size(); index++) { + String json = list.getString(index); + if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json diff --git a/patches/server/0443-Do-not-let-the-server-load-chunks-from-newer-version.patch b/patches/server/0443-Do-not-let-the-server-load-chunks-from-newer-version.patch index 977fecbd78..7e56aa8fb7 100644 --- a/patches/server/0443-Do-not-let-the-server-load-chunks-from-newer-version.patch +++ b/patches/server/0443-Do-not-let-the-server-load-chunks-from-newer-version.patch @@ -9,7 +9,7 @@ the game, immediately stop the server to prevent data corruption. You can override this functionality at your own peril. diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java -index 02beedb84a8bec001270116c6ce496db012e6b8a..19b35d1c07c75b27cef9a53258a68ec5d9f721d5 100644 +index 02beedb84a8bec001270116c6ce496db012e6b8a..a95909bc818f395ce5772c5129f9cc9b789ce133 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java @@ -124,8 +124,20 @@ public class ChunkSerializer { @@ -23,7 +23,7 @@ index 02beedb84a8bec001270116c6ce496db012e6b8a..19b35d1c07c75b27cef9a53258a68ec5 public static InProgressChunkHolder loadChunk(ServerLevel world, PoiManager poiStorage, ChunkPos chunkPos, CompoundTag nbt, boolean distinguish) { + // Paper start - Do NOT attempt to load chunks saved with newer versions -+ if (nbt.contains("DataVersion", 99)) { ++ if (nbt.contains("DataVersion", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) { + int dataVersion = nbt.getInt("DataVersion"); + if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) { + new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace();