Test compile fixes

This commit is contained in:
Bjarne Koll 2024-10-25 19:15:40 +02:00
parent d333b32d4f
commit 4903e806c3
9 changed files with 33 additions and 20 deletions

View file

@ -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.
*/

View file

@ -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;

View file

@ -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());
+ }

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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()
+ )
+ );

View file

@ -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);

View file

@ -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());
+
+ }