From 635ece80cfe466a34b081021c60e99c9cfec5979 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/Allow-Saving-of-Oversized-Chunks.patch | 4 ++-- ...-not-let-the-server-load-chunks-from-newer-version.patch | 2 +- patches/server/Entity-Origin-API.patch | 2 +- ...perienceOrbs-API-for-Reason-Source-Triggering-play.patch | 2 +- patches/server/Handle-Item-Meta-Inconsistencies.patch | 4 ++-- .../LootTable-API-Replenishable-Lootables-Feature.patch | 4 ++-- patches/server/Mob-Spawner-API-Enhancements.patch | 2 +- patches/server/Rewrite-chunk-system.patch | 2 +- patches/server/Support-old-UUID-format-for-NBT.patch | 6 +++--- patches/server/Update-itemstack-legacy-name-and-lore.patch | 6 +++--- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/patches/server/Allow-Saving-of-Oversized-Chunks.patch b/patches/server/Allow-Saving-of-Oversized-Chunks.patch index 90f2dcb1e9..e56b109ec3 100644 --- a/patches/server/Allow-Saving-of-Oversized-Chunks.patch +++ b/patches/server/Allow-Saving-of-Oversized-Chunks.patch @@ -191,8 +191,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + 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/Do-not-let-the-server-load-chunks-from-newer-version.patch b/patches/server/Do-not-let-the-server-load-chunks-from-newer-version.patch index 347e9fbe66..b612800b21 100644 --- a/patches/server/Do-not-let-the-server-load-chunks-from-newer-version.patch +++ b/patches/server/Do-not-let-the-server-load-chunks-from-newer-version.patch @@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 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(); diff --git a/patches/server/Entity-Origin-API.patch b/patches/server/Entity-Origin-API.patch index c059b349e7..24fe449646 100644 --- a/patches/server/Entity-Origin-API.patch +++ b/patches/server/Entity-Origin-API.patch @@ -77,7 +77,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // 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/ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch b/patches/server/ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch index 2437688a6e..592b669825 100644 --- a/patches/server/ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch +++ b/patches/server/ExperienceOrbs-API-for-Reason-Source-Triggering-play.patch @@ -36,7 +36,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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"); diff --git a/patches/server/Handle-Item-Meta-Inconsistencies.patch b/patches/server/Handle-Item-Meta-Inconsistencies.patch index 61456225bd..fcd82dbbf5 100644 --- a/patches/server/Handle-Item-Meta-Inconsistencies.patch +++ b/patches/server/Handle-Item-Meta-Inconsistencies.patch @@ -28,10 +28,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // 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; + } diff --git a/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch b/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch index 3d5fbe709c..49efc6769b 100644 --- a/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch +++ b/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch @@ -364,8 +364,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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()); diff --git a/patches/server/Mob-Spawner-API-Enhancements.patch b/patches/server/Mob-Spawner-API-Enhancements.patch index 1908fe29a4..0cb8e4be12 100644 --- a/patches/server/Mob-Spawner-API-Enhancements.patch +++ b/patches/server/Mob-Spawner-API-Enhancements.patch @@ -31,7 +31,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + // 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/Rewrite-chunk-system.patch b/patches/server/Rewrite-chunk-system.patch index 1928fa8f04..80c07a3dba 100644 --- a/patches/server/Rewrite-chunk-system.patch +++ b/patches/server/Rewrite-chunk-system.patch @@ -8574,7 +8574,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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/Support-old-UUID-format-for-NBT.patch b/patches/server/Support-old-UUID-format-for-NBT.patch index 9d4b1e52c2..91e36bad51 100644 --- a/patches/server/Support-old-UUID-format-for-NBT.patch +++ b/patches/server/Support-old-UUID-format-for-NBT.patch @@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 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 0000000000000000000000000000000000000000..00000000000000000000000000000000 */ 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 0000000000000000000000000000000000000000..00000000000000000000000000000000 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/Update-itemstack-legacy-name-and-lore.patch b/patches/server/Update-itemstack-legacy-name-and-lore.patch index 54f02abdbb..28d59c7284 100644 --- a/patches/server/Update-itemstack-legacy-name-and-lore.patch +++ b/patches/server/Update-itemstack-legacy-name-and-lore.patch @@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + } + } -+ 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