From 4903e806c321e03e3f5751e9baf364119fb67dca Mon Sep 17 00:00:00 2001 From: Bjarne Koll <git@lynxplay.dev> Date: Fri, 25 Oct 2024 19:15:40 +0200 Subject: [PATCH] Test compile fixes --- .../api/Fix-SpawnerEntry-Equipment-API.patch | 2 +- .../server/Add-PlayerArmorChangeEvent.patch | 20 +++++++++---------- ...gistryAccess-for-managing-Registries.patch | 2 +- .../Add-methods-to-get-translation-keys.patch | 10 +++++++--- ...d-missing-structure-set-seed-configs.patch | 4 ++-- patches/server/Anti-Xray.patch | 9 +++++++++ .../server/Fix-issues-with-Recipe-API.patch | 2 +- .../server/Registry-Modification-API.patch | 2 +- patches/server/Test-changes.patch | 2 +- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/patches/api/Fix-SpawnerEntry-Equipment-API.patch b/patches/api/Fix-SpawnerEntry-Equipment-API.patch index 2e3227ee9e..ae337086e5 100644 --- a/patches/api/Fix-SpawnerEntry-Equipment-API.patch +++ b/patches/api/Fix-SpawnerEntry-Equipment-API.patch @@ -22,7 +22,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Set the loot table for the spawned entity's equipment slots. * <br> - * To remove a loot table use null. -+ * To remove a loot table use {@link org.bukkit.loot.LootTables#EMPTY}. ++ * To remove a loot table use the empty loot table. * * @param table this {@link org.bukkit.entity.Mob} will have. */ diff --git a/patches/server/Add-PlayerArmorChangeEvent.patch b/patches/server/Add-PlayerArmorChangeEvent.patch index dc28fd1499..da2e0c37ca 100644 --- a/patches/server/Add-PlayerArmorChangeEvent.patch +++ b/patches/server/Add-PlayerArmorChangeEvent.patch @@ -34,10 +34,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; ++import net.minecraft.core.component.DataComponents; +import net.minecraft.world.entity.EquipmentSlot; -+import net.minecraft.world.item.Equipable; +import net.minecraft.world.item.Item; -+import net.minecraft.world.item.ItemStack; ++import net.minecraft.world.item.equipment.Equippable; +import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.support.environment.AllFeatures; @@ -65,23 +65,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @MethodSource("slotTypeParams") + public void testSlotType(PlayerArmorChangeEvent.SlotType slotType, Material item) { + final Item nmsItem = CraftMagicNumbers.getItem(item); -+ final Equipable equipable = Equipable.get(new ItemStack(nmsItem)); -+ assertNotNull(equipable, item + " isn't equipable"); ++ final Equippable equippable = nmsItem.components().get(DataComponents.EQUIPPABLE); ++ assertNotNull(equippable, item + " isn't equipable"); + final EquipmentSlot slot = switch (slotType) { + case HEAD -> EquipmentSlot.HEAD; + case CHEST -> EquipmentSlot.CHEST; + case LEGS -> EquipmentSlot.LEGS; + case FEET -> EquipmentSlot.FEET; + }; -+ assertEquals(equipable.getEquipmentSlot(), slot, item + " isn't set to the right slot"); ++ assertEquals(equippable.slot(), slot, item + " isn't set to the right slot"); + } + + public static Stream<Object[]> equipableParams() { + final List<Object[]> parameters = new ArrayList<>(); + for (final Item item : net.minecraft.core.registries.BuiltInRegistries.ITEM) { -+ final Equipable equipable = Equipable.get(new ItemStack(item)); -+ if (equipable != null) { -+ parameters.add(new Object[]{equipable, item}); ++ final Equippable equippable = item.components().get(DataComponents.EQUIPPABLE); ++ if (equippable != null) { ++ parameters.add(new Object[]{equippable, item}); + } + } + return parameters.stream(); @@ -89,8 +89,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @ParameterizedTest(name = "{argumentsWithNames}") + @MethodSource("equipableParams") -+ public void testEquipable(Equipable equipable, Item item) { -+ final EquipmentSlot equipmentSlot = equipable.getEquipmentSlot(); ++ public void testEquipable(Equippable equipable, Item item) { ++ final EquipmentSlot equipmentSlot = equipable.slot(); + PlayerArmorChangeEvent.SlotType slotType = switch (equipmentSlot) { + case HEAD -> PlayerArmorChangeEvent.SlotType.HEAD; + case CHEST -> PlayerArmorChangeEvent.SlotType.CHEST; diff --git a/patches/server/Add-RegistryAccess-for-managing-Registries.patch b/patches/server/Add-RegistryAccess-for-managing-Registries.patch index cc534ef511..05313f833a 100644 --- a/patches/server/Add-RegistryAccess-for-managing-Registries.patch +++ b/patches/server/Add-RegistryAccess-for-managing-Registries.patch @@ -1030,7 +1030,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @AllFeatures @@ -0,0 +0,0 @@ class RegistryKeyTest { void testApiRegistryKeysExist(final RegistryKey<?> key) { - final Optional<Registry<Object>> registry = RegistryHelper.getRegistry().registry(ResourceKey.createRegistryKey(ResourceLocation.parse(key.key().asString()))); + final Optional<Registry<Object>> registry = RegistryHelper.getRegistry().lookup(ResourceKey.createRegistryKey(ResourceLocation.parse(key.key().asString()))); assertTrue(registry.isPresent(), "Missing vanilla registry for " + key.key().asString()); + } diff --git a/patches/server/Add-methods-to-get-translation-keys.patch b/patches/server/Add-methods-to-get-translation-keys.patch index 009748731b..4cc6306cb1 100644 --- a/patches/server/Add-methods-to-get-translation-keys.patch +++ b/patches/server/Add-methods-to-get-translation-keys.patch @@ -102,11 +102,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import com.destroystokyo.paper.ClientOption; +import java.util.Locale; +import java.util.Map; -+import net.minecraft.core.registries.BuiltInRegistries; ++import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.contents.TranslatableContents; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.ChatVisiblity; ++import net.minecraft.world.flag.FeatureFlags; ++import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.biome.Biome; import org.bukkit.Difficulty; @@ -115,6 +117,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.GameRule; +import org.bukkit.MusicInstrument; +import org.bukkit.attribute.Attribute; ++import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.support.RegistryHelper; +import org.bukkit.support.environment.AllFeatures; @@ -140,8 +143,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Test + public void testGameruleKeys() { ++ final Map<String, GameRules.Key<?>> gameRules = CraftWorld.getGameRulesNMS(new GameRules(FeatureFlags.REGISTRY.allFlags())); + for (GameRule<?> rule : GameRule.values()) { -+ Assertions.assertEquals(org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey(), rule.getName() + "'s translation doesn't match"); ++ Assertions.assertEquals(gameRules.get(rule.getName()).getDescriptionId(), rule.translationKey(), rule.getName() + "'s translation doesn't match"); + } + } + @@ -189,7 +193,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Test + public void testMusicInstrument() { -+ for (final ResourceLocation nms : BuiltInRegistries.INSTRUMENT.keySet()) { ++ for (final ResourceLocation nms : RegistryHelper.getRegistry().lookupOrThrow(Registries.INSTRUMENT).keySet()) { + final MusicInstrument bukkit = MusicInstrument.getByKey(CraftNamespacedKey.fromMinecraft(nms)); + Assertions.assertNotNull(bukkit, "Missing bukkit instrument for " + nms); + Assertions.assertEquals(nms.toLanguageKey("instrument"), bukkit.translationKey(), "translation key mismatch for " + bukkit); diff --git a/patches/server/Add-missing-structure-set-seed-configs.patch b/patches/server/Add-missing-structure-set-seed-configs.patch index 164562231d..f444dde2b2 100644 --- a/patches/server/Add-missing-structure-set-seed-configs.patch +++ b/patches/server/Add-missing-structure-set-seed-configs.patch @@ -356,10 +356,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + final SpigotWorldConfig config = PaperConfigurations.SPIGOT_WORLD_DEFAULTS.get(); + + -+ final Registry<StructureSet> structureSets = RegistryHelper.getRegistry().registryOrThrow(Registries.STRUCTURE_SET); ++ final Registry<StructureSet> structureSets = RegistryHelper.getRegistry().lookupOrThrow(Registries.STRUCTURE_SET); + for (final ResourceKey<StructureSet> setKey : structureSets.registryKeySet()) { + assertEquals(ResourceLocation.DEFAULT_NAMESPACE, setKey.location().getNamespace()); -+ final StructureSet set = structureSets.getOrThrow(setKey); ++ final StructureSet set = structureSets.getValueOrThrow(setKey); + if (setKey == BuiltinStructureSets.STRONGHOLDS) { // special case due to seed matching world seed + assertEquals(0, set.placement().salt); + continue; diff --git a/patches/server/Anti-Xray.patch b/patches/server/Anti-Xray.patch index db82939e34..ba57630adf 100644 --- a/patches/server/Anti-Xray.patch +++ b/patches/server/Anti-Xray.patch @@ -1522,6 +1522,15 @@ diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/SerializableC index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java +@@ -0,0 +0,0 @@ import org.slf4j.Logger; + // CraftBukkit - persistentDataContainer + public record SerializableChunkData(Registry<Biome> biomeRegistry, ChunkPos chunkPos, int minSectionY, long lastUpdateTime, long inhabitedTime, ChunkStatus chunkStatus, @Nullable BlendingData.Packed blendingData, @Nullable BelowZeroRetrogen belowZeroRetrogen, UpgradeData upgradeData, @Nullable long[] carvingMask, Map<Heightmap.Types, long[]> heightmaps, ChunkAccess.PackedTicks packedTicks, ShortList[] postProcessingSections, boolean lightCorrect, List<SerializableChunkData.SectionData> sectionData, List<CompoundTag> entities, List<CompoundTag> blockEntities, CompoundTag structureData, @Nullable Tag persistentDataContainer) { + +- public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState()); ++ public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), null); // Paper start - Anti-Xray + private static final Logger LOGGER = LogUtils.getLogger(); + private static final String TAG_UPGRADE_DATA = "UpgradeData"; + private static final String BLOCK_TICKS_TAG = "block_ticks"; @@ -0,0 +0,0 @@ public record SerializableChunkData(Registry<Biome> biomeRegistry, ChunkPos chun @Nullable diff --git a/patches/server/Fix-issues-with-Recipe-API.patch b/patches/server/Fix-issues-with-Recipe-API.patch index 2d4a110363..73daec3e89 100644 --- a/patches/server/Fix-issues-with-Recipe-API.patch +++ b/patches/server/Fix-issues-with-Recipe-API.patch @@ -84,7 +84,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - add test for recipe conversion + when(instance.recipeIterator()).thenAnswer(ignored -> + com.google.common.collect.Iterators.transform( -+ RegistryHelper.getDataPack().getRecipeManager().byType.entries().iterator(), ++ RegistryHelper.getDataPack().getRecipeManager().recipes.byType.entries().iterator(), + input -> input.getValue().toBukkitRecipe() + ) + ); diff --git a/patches/server/Registry-Modification-API.patch b/patches/server/Registry-Modification-API.patch index 7e00aa4ee9..4f332634e3 100644 --- a/patches/server/Registry-Modification-API.patch +++ b/patches/server/Registry-Modification-API.patch @@ -1426,7 +1426,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @ParameterizedTest + @MethodSource("registries") + <M, T> void testEquality(final ResourceKey<? extends Registry<M>> resourceKey, final PaperRegistryBuilder.Filler<M, T, ?> filler) { -+ final Registry<M> registry = RegistryHelper.getRegistry().registryOrThrow(resourceKey); ++ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(resourceKey); + for (final Map.Entry<ResourceKey<M>, M> entry : registry.entrySet()) { + final M built = filler.fill(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), PaperRegistries.fromNms(entry.getKey()), entry.getValue()).build(); + assertEquals(entry.getValue(), built); diff --git a/patches/server/Test-changes.patch b/patches/server/Test-changes.patch index 9912854f6e..26ee13b8f9 100644 --- a/patches/server/Test-changes.patch +++ b/patches/server/Test-changes.patch @@ -65,7 +65,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @ParameterizedTest + @MethodSource("data") + void testApiRegistryKeysExist(final RegistryKey<?> key) { -+ final Optional<Registry<Object>> registry = RegistryHelper.getRegistry().registry(ResourceKey.createRegistryKey(ResourceLocation.parse(key.key().asString()))); ++ final Optional<Registry<Object>> registry = RegistryHelper.getRegistry().lookup(ResourceKey.createRegistryKey(ResourceLocation.parse(key.key().asString()))); + assertTrue(registry.isPresent(), "Missing vanilla registry for " + key.key().asString()); + + }