From 4248b8a4d899d22129f5575171a18dcc751e24aa Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 22 Sep 2023 03:02:16 +1000 Subject: [PATCH] #1250: Standardize and centralize Bukkit / Minecraft registry conversion By: DerFrZocker --- .../entity/ai/behavior/BehaviorCareer.patch | 4 +- .../ai/behavior/BehaviorProfession.patch | 4 +- .../java/org/bukkit/craftbukkit/CraftArt.java | 49 ++++++++++------ .../org/bukkit/craftbukkit/CraftChunk.java | 3 +- .../craftbukkit/CraftChunkSnapshot.java | 6 +- .../org/bukkit/craftbukkit/CraftFluid.java | 30 ++++++++++ .../org/bukkit/craftbukkit/CraftParticle.java | 8 +-- .../craftbukkit/CraftRegionAccessor.java | 5 +- .../org/bukkit/craftbukkit/CraftSound.java | 38 +++++++++---- .../bukkit/craftbukkit/CraftSoundGroup.java | 10 ++-- .../bukkit/craftbukkit/CraftStatistic.java | 6 +- .../org/bukkit/craftbukkit/CraftWorld.java | 4 +- .../craftbukkit/attribute/CraftAttribute.java | 38 +++++++++++++ .../attribute/CraftAttributeMap.java | 14 +---- .../bukkit/craftbukkit/block/CraftBiome.java | 55 ++++++++++++++++++ .../bukkit/craftbukkit/block/CraftBlock.java | 28 --------- .../block/CraftCreatureSpawner.java | 5 +- .../entity/CraftAreaEffectCloud.java | 2 +- .../bukkit/craftbukkit/entity/CraftCat.java | 28 +++++++-- .../craftbukkit/entity/CraftEntity.java | 9 ++- .../craftbukkit/entity/CraftEntityType.java | 31 ++++++++++ .../bukkit/craftbukkit/entity/CraftFrog.java | 30 +++++++++- .../craftbukkit/entity/CraftLivingEntity.java | 18 +++--- .../bukkit/craftbukkit/entity/CraftMob.java | 2 +- .../craftbukkit/entity/CraftPainting.java | 5 +- .../craftbukkit/entity/CraftPlayer.java | 42 +++++++------- .../craftbukkit/entity/CraftRaider.java | 2 +- .../craftbukkit/entity/CraftVillager.java | 57 +++++++++++++++---- .../entity/CraftVillagerZombie.java | 12 ++-- .../entity/memory/CraftMemoryKey.java | 26 +++++++-- .../craftbukkit/generator/CraftChunkData.java | 4 +- .../generator/CustomChunkGenerator.java | 6 +- .../generator/CustomWorldChunkManager.java | 6 +- .../generator/structure/CraftStructure.java | 18 +++--- .../structure/CraftStructureType.java | 20 ++++--- .../inventory/CraftItemFactory.java | 4 +- .../craftbukkit/inventory/CraftMetaItem.java | 3 +- .../packs/CraftDataPackManager.java | 5 +- .../craftbukkit/tag/CraftEntityTag.java | 11 ++-- .../bukkit/craftbukkit/tag/CraftFluidTag.java | 7 ++- .../craftbukkit/util/CraftMagicNumbers.java | 24 +------- .../src/test/java/org/bukkit/ArtTest.java | 6 +- .../src/test/java/org/bukkit/BiomeTest.java | 6 +- .../test/java/org/bukkit/ParticleTest.java | 2 +- .../src/test/java/org/bukkit/SoundTest.java | 2 +- .../craftbukkit/attribute/AttributeTest.java | 7 +-- .../entity/memory/CraftMemoryKeyTest.java | 18 +++--- 47 files changed, 468 insertions(+), 252 deletions(-) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftFluid.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorCareer.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorCareer.patch index da83bdcf6c..ec8f9aad80 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorCareer.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorCareer.patch @@ -19,12 +19,12 @@ }).ifPresent((villagerprofession) -> { - entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(villagerprofession)); + // CraftBukkit start - Fire VillagerCareerChangeEvent where Villager gets employed -+ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.nmsToBukkitProfession(villagerprofession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED); ++ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.CraftProfession.minecraftToBukkit(villagerprofession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED); + if (event.isCancelled()) { + return; + } + -+ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(event.getProfession()))); ++ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.CraftProfession.bukkitToMinecraft(event.getProfession()))); + // CraftBukkit end entityvillager.refreshBrain(worldserver); }); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorProfession.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorProfession.patch index ba56da049a..71a1571ee4 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorProfession.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorProfession.patch @@ -19,12 +19,12 @@ if (villagerdata.getProfession() != VillagerProfession.NONE && villagerdata.getProfession() != VillagerProfession.NITWIT && entityvillager.getVillagerXp() == 0 && villagerdata.getLevel() <= 1) { - entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(VillagerProfession.NONE)); + // CraftBukkit start -+ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.nmsToBukkitProfession(VillagerProfession.NONE), VillagerCareerChangeEvent.ChangeReason.LOSING_JOB); ++ VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityvillager, CraftVillager.CraftProfession.minecraftToBukkit(VillagerProfession.NONE), VillagerCareerChangeEvent.ChangeReason.LOSING_JOB); + if (event.isCancelled()) { + return false; + } + -+ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(event.getProfession()))); ++ entityvillager.setVillagerData(entityvillager.getVillagerData().setProfession(CraftVillager.CraftProfession.bukkitToMinecraft(event.getProfession()))); + // CraftBukkit end entityvillager.refreshBrain(worldserver); return true; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArt.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArt.java index a4f35fed6a..e67ec2ea8c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArt.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArt.java @@ -1,35 +1,48 @@ package org.bukkit.craftbukkit; import com.google.common.base.Preconditions; -import com.google.common.collect.BiMap; -import com.google.common.collect.ImmutableBiMap; import net.minecraft.core.Holder; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceKey; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.decoration.PaintingVariant; import org.bukkit.Art; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; public class CraftArt { - private static final BiMap, Art> artwork; - static { - ImmutableBiMap.Builder, Art> artworkBuilder = ImmutableBiMap.builder(); - for (ResourceKey key : BuiltInRegistries.PAINTING_VARIANT.registryKeySet()) { - artworkBuilder.put(BuiltInRegistries.PAINTING_VARIANT.getHolderOrThrow(key), Art.getByName(key.location().getPath())); - } + public static Art minecraftToBukkit(PaintingVariant minecraft) { + Preconditions.checkArgument(minecraft != null); - artwork = artworkBuilder.build(); - } + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT); + Art bukkit = Registry.ART.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); - public static Art NotchToBukkit(Holder art) { - Art bukkit = artwork.get(art); Preconditions.checkArgument(bukkit != null); + return bukkit; } - public static Holder BukkitToNotch(Art art) { - Holder nms = artwork.inverse().get(art); - Preconditions.checkArgument(nms != null); - return nms; + public static Art minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + + public static PaintingVariant bukkitToMinecraft(Art bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } + + public static Holder bukkitToMinecraftHolder(Art bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT); + + if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { + return holder; + } + + throw new IllegalArgumentException("No Reference holder found for " + bukkit + + ", this can happen if a plugin creates its own painting variant with out properly registering it."); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index a66c5162dd..08aac87346 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -44,6 +44,7 @@ import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.entity.Entity; @@ -279,7 +280,7 @@ public class CraftChunk implements Chunk { Preconditions.checkArgument(biome != null, "Biome cannot be null"); IChunkAccess chunk = getHandle(ChunkStatus.BIOMES); - Predicate> nms = Predicates.equalTo(CraftBlock.biomeToBiomeBase(chunk.biomeRegistry, biome)); + Predicate> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome)); for (ChunkSection section : chunk.getSections()) { if (section != null && section.getBiomes().maybeHas(nms)) { return true; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java index 69bb8b432c..05dc2415eb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java @@ -15,7 +15,7 @@ import org.bukkit.ChunkSnapshot; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; @@ -85,7 +85,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot { public boolean contains(Biome biome) { Preconditions.checkArgument(biome != null, "Biome cannot be null"); - Predicate> nms = Predicates.equalTo(CraftBlock.biomeToBiomeBase(this.biomeRegistry, biome)); + Predicate> nms = Predicates.equalTo(CraftBiome.bukkitToMinecraftHolder(biome)); for (PalettedContainerRO> palette : this.biome) { if (palette.maybeHas(nms)) { return true; @@ -151,7 +151,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot { validateChunkCoordinates(x, y, z); PalettedContainerRO> biome = this.biome[getSectionIndex(y)]; // SPIGOT-7188: Don't need to convert y to biome coordinate scale since it is bound to the block chunk section - return CraftBlock.biomeBaseToBiome(biomeRegistry, biome.get(x >> 2, (y & 0xF) >> 2, z >> 2)); + return CraftBiome.minecraftHolderToBukkit(biome.get(x >> 2, (y & 0xF) >> 2, z >> 2)); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftFluid.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftFluid.java new file mode 100644 index 0000000000..8157c81eed --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftFluid.java @@ -0,0 +1,30 @@ +package org.bukkit.craftbukkit; + +import com.google.common.base.Preconditions; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.material.FluidType; +import org.bukkit.Fluid; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; + +public class CraftFluid { + + public static Fluid minecraftToBukkit(FluidType minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.FLUID); + Fluid bukkit = Registry.FLUID.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static FluidType bukkitToMinecraft(Fluid bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.FLUID) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java index 90cdcf1eb5..87692150d9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java @@ -229,11 +229,7 @@ public enum CraftParticle { throw new IllegalArgumentException(particle.getDataType().toString()); } - public static Particle toBukkit(net.minecraft.core.particles.ParticleParam nms) { - return toBukkit(nms.getType()); - } - - public static Particle toBukkit(net.minecraft.core.particles.Particle nms) { - return particles.inverse().get(BuiltInRegistries.PARTICLE_TYPE.getKey(nms)); + public static Particle minecraftToBukkit(net.minecraft.core.particles.Particle minecraft) { + return particles.inverse().get(BuiltInRegistries.PARTICLE_TYPE.getKey(minecraft)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 5a363abc5b..f6a476a127 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -61,6 +61,7 @@ import org.bukkit.block.Biome; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -231,7 +232,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor { @Override public Biome getBiome(int x, int y, int z) { - return CraftBlock.biomeBaseToBiome(getHandle().registryAccess().registryOrThrow(Registries.BIOME), getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2)); + return CraftBiome.minecraftHolderToBukkit(getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2)); } @Override @@ -242,7 +243,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor { @Override public void setBiome(int x, int y, int z, Biome biome) { Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot set the biome to %s", biome); - Holder biomeBase = CraftBlock.biomeToBiomeBase(getHandle().registryAccess().registryOrThrow(Registries.BIOME), biome); + Holder biomeBase = CraftBiome.bukkitToMinecraftHolder(biome); setBiome(x, y, z, biomeBase); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSound.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSound.java index 04b6975312..db0d2acc68 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSound.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSound.java @@ -1,8 +1,9 @@ package org.bukkit.craftbukkit; import com.google.common.base.Preconditions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.MinecraftKey; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.sounds.SoundEffect; import org.bukkit.Registry; import org.bukkit.Sound; @@ -10,21 +11,34 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey; public class CraftSound { - public static SoundEffect getSoundEffect(String s) { - SoundEffect effect = BuiltInRegistries.SOUND_EVENT.get(new MinecraftKey(s)); - Preconditions.checkArgument(effect != null, "Sound effect %s does not exist", s); + public static Sound minecraftToBukkit(SoundEffect minecraft) { + Preconditions.checkArgument(minecraft != null); - return effect; + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT); + Sound bukkit = Registry.SOUNDS.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; } - public static SoundEffect getSoundEffect(Sound s) { - SoundEffect effect = BuiltInRegistries.SOUND_EVENT.get(CraftNamespacedKey.toMinecraft(s.getKey())); - Preconditions.checkArgument(effect != null, "Sound effect %s does not exist", s); + public static SoundEffect bukkitToMinecraft(Sound bukkit) { + Preconditions.checkArgument(bukkit != null); - return effect; + return CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); } - public static Sound getBukkit(SoundEffect soundEffect) { - return Registry.SOUNDS.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.SOUND_EVENT.getKey(soundEffect))); + public static Holder bukkitToMinecraftHolder(Sound bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.SOUND_EVENT); + + if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { + return holder; + } + + throw new IllegalArgumentException("No Reference holder found for " + bukkit + + ", this can happen if a plugin creates its own sound effect with out properly registering it."); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSoundGroup.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSoundGroup.java index 8fe42fb337..3859fc6bea 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSoundGroup.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSoundGroup.java @@ -34,26 +34,26 @@ public class CraftSoundGroup implements SoundGroup { @Override public Sound getBreakSound() { - return CraftSound.getBukkit(getHandle().breakSound); + return CraftSound.minecraftToBukkit(getHandle().breakSound); } @Override public Sound getStepSound() { - return CraftSound.getBukkit(getHandle().getStepSound()); + return CraftSound.minecraftToBukkit(getHandle().getStepSound()); } @Override public Sound getPlaceSound() { - return CraftSound.getBukkit(getHandle().getPlaceSound()); + return CraftSound.minecraftToBukkit(getHandle().getPlaceSound()); } @Override public Sound getHitSound() { - return CraftSound.getBukkit(getHandle().hitSound); + return CraftSound.minecraftToBukkit(getHandle().hitSound); } @Override public Sound getFallSound() { - return CraftSound.getBukkit(getHandle().getFallSound()); + return CraftSound.minecraftToBukkit(getHandle().getFallSound()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java index f3ed30a722..19bd47553d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java @@ -14,6 +14,7 @@ import net.minecraft.world.level.block.Block; import org.bukkit.Material; import org.bukkit.Statistic; import org.bukkit.Statistic.Type; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.EntityType; @@ -171,7 +172,7 @@ public enum CraftStatistic { public static net.minecraft.stats.Statistic getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) { Preconditions.checkArgument(entity != null, "EntityType cannot be null"); if (entity.getName() != null) { - EntityTypes nmsEntity = BuiltInRegistries.ENTITY_TYPE.get(new MinecraftKey(entity.getName())); + EntityTypes nmsEntity = CraftEntityType.bukkitToMinecraft(entity); if (stat == org.bukkit.Statistic.KILL_ENTITY) { return net.minecraft.stats.StatisticList.ENTITY_KILLED.get(nmsEntity); @@ -185,8 +186,7 @@ public enum CraftStatistic { public static EntityType getEntityTypeFromStatistic(net.minecraft.stats.Statistic> statistic) { Preconditions.checkArgument(statistic != null, "NMS Statistic cannot be null"); - MinecraftKey name = EntityTypes.getKey(statistic.getValue()); - return EntityType.fromName(name.getPath()); + return CraftEntityType.minecraftToBukkit(statistic.getValue()); } public static Material getMaterialFromStatistic(net.minecraft.stats.Statistic statistic) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 32ef944745..901f7bc5b3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1556,7 +1556,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { double y = loc.getY(); double z = loc.getZ(); - getHandle().playSound(null, x, y, z, CraftSound.getSoundEffect(sound), SoundCategory.valueOf(category.name()), volume, pitch); + getHandle().playSound(null, x, y, z, CraftSound.bukkitToMinecraft(sound), SoundCategory.valueOf(category.name()), volume, pitch); } @Override @@ -1585,7 +1585,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; - PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong()); + PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong()); PlayerChunkMap.EntityTracker entityTracker = getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId()); if (entityTracker != null) { entityTracker.broadcastAndSend(packet); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java new file mode 100644 index 0000000000..a6ca9fa0c3 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java @@ -0,0 +1,38 @@ +package org.bukkit.craftbukkit.attribute; + +import com.google.common.base.Preconditions; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.entity.ai.attributes.AttributeBase; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; +import org.bukkit.attribute.Attribute; +import org.bukkit.craftbukkit.CraftRegistry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; + +public class CraftAttribute { + + public static Attribute minecraftToBukkit(AttributeBase minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE); + Attribute bukkit = Registry.ATTRIBUTE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static Attribute stringToBukkit(String bukkit) { + Preconditions.checkArgument(bukkit != null); + + return Registry.ATTRIBUTE.get(NamespacedKey.fromString(bukkit)); + } + + public static AttributeBase bukkitToMinecraft(Attribute bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java index 136b69b901..f5bbaaa66c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java @@ -1,14 +1,10 @@ package org.bukkit.craftbukkit.attribute; import com.google.common.base.Preconditions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.entity.ai.attributes.AttributeBase; import net.minecraft.world.entity.ai.attributes.AttributeMapBase; -import org.bukkit.Registry; import org.bukkit.attribute.Attributable; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; public class CraftAttributeMap implements Attributable { @@ -21,16 +17,8 @@ public class CraftAttributeMap implements Attributable { @Override public AttributeInstance getAttribute(Attribute attribute) { Preconditions.checkArgument(attribute != null, "attribute"); - net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(toMinecraft(attribute)); + net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(CraftAttribute.bukkitToMinecraft(attribute)); return (nms == null) ? null : new CraftAttributeInstance(nms, attribute); } - - public static AttributeBase toMinecraft(Attribute attribute) { - return BuiltInRegistries.ATTRIBUTE.get(CraftNamespacedKey.toMinecraft(attribute.getKey())); - } - - public static Attribute fromMinecraft(String nms) { - return Registry.ATTRIBUTE.get(CraftNamespacedKey.fromString(nms)); - } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java new file mode 100644 index 0000000000..7a668c6b54 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java @@ -0,0 +1,55 @@ +package org.bukkit.craftbukkit.block; + +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.biome.BiomeBase; +import org.bukkit.Registry; +import org.bukkit.block.Biome; +import org.bukkit.craftbukkit.CraftRegistry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; + +public class CraftBiome { + + public static Biome minecraftToBukkit(BiomeBase minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME); + Biome bukkit = Registry.BIOME.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + if (bukkit == null) { + return Biome.CUSTOM; + } + + return bukkit; + } + + public static Biome minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + + public static BiomeBase bukkitToMinecraft(Biome bukkit) { + if (bukkit == null || bukkit == Biome.CUSTOM) { + return null; + } + + return CraftRegistry.getMinecraftRegistry(Registries.BIOME) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } + + public static Holder bukkitToMinecraftHolder(Biome bukkit) { + if (bukkit == null || bukkit == Biome.CUSTOM) { + return null; + } + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.BIOME); + + if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { + return holder; + } + + throw new IllegalArgumentException("No Reference holder found for " + bukkit + + ", this can happen if a plugin creates its own biome base with out properly registering it."); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index c683616d4a..f87b95fa73 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -8,10 +8,6 @@ import java.util.List; import java.util.stream.Collectors; import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.WorldServer; import net.minecraft.world.EnumHand; import net.minecraft.world.EnumInteractionResult; @@ -21,7 +17,6 @@ import net.minecraft.world.item.context.ItemActionContext; import net.minecraft.world.level.EnumSkyBlock; import net.minecraft.world.level.GeneratorAccess; import net.minecraft.world.level.RayTrace; -import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.block.BlockRedstoneWire; import net.minecraft.world.level.block.BlockSapling; import net.minecraft.world.level.block.Blocks; @@ -36,7 +31,6 @@ import org.bukkit.Chunk; import org.bukkit.FluidCollisionMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Registry; import org.bukkit.TreeType; import org.bukkit.World; import org.bukkit.block.Biome; @@ -53,7 +47,6 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftRayTraceResult; import org.bukkit.craftbukkit.util.CraftVoxelShape; import org.bukkit.entity.Entity; @@ -345,27 +338,6 @@ public class CraftBlock implements Block { getWorld().setBiome(getX(), getY(), getZ(), bio); } - public static Biome biomeBaseToBiome(IRegistry registry, Holder base) { - return biomeBaseToBiome(registry, base.value()); - } - - public static Biome biomeBaseToBiome(IRegistry registry, BiomeBase base) { - if (base == null) { - return null; - } - - Biome biome = Registry.BIOME.get(CraftNamespacedKey.fromMinecraft(registry.getKey(base))); - return (biome == null) ? Biome.CUSTOM : biome; - } - - public static Holder biomeToBiomeBase(IRegistry registry, Biome bio) { - if (bio == null || bio == Biome.CUSTOM) { - return null; - } - - return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(bio.getKey()))); - } - @Override public double getTemperature() { return world.getBiome(position).value().getTemperature(position); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java index 885195fbdd..c7382a9f7e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java @@ -9,6 +9,7 @@ import net.minecraft.world.level.MobSpawnerData; import net.minecraft.world.level.block.entity.TileEntityMobSpawner; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.entity.EntityType; public class CraftCreatureSpawner extends CraftBlockEntityState implements CreatureSpawner { @@ -25,7 +26,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState> type = EntityTypes.by(spawnData.getEntityToSpawn()); - return type.map(entityTypes -> EntityType.fromName(EntityTypes.getKey(entityTypes).getPath())).orElse(null); + return type.map(CraftEntityType::minecraftToBukkit).orElse(null); } @Override @@ -38,7 +39,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState registry = CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT); + + return Type.values()[registry.getId(minecraft)]; + } + + public static CatVariant bukkitToMinecraft(Type bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT) + .byId(bukkit.ordinal()); + } + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 4bc06b5ad3..83f5e00e69 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -210,8 +210,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { public CraftEntity(final CraftServer server, final Entity entity) { this.server = server; this.entity = entity; - EntityType type = Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(EntityTypes.getKey(entity.getType()))); - this.entityType = (type != null) ? type : EntityType.UNKNOWN; + this.entityType = CraftEntityType.minecraftToBukkit(entity.getType()); } public static CraftEntity getEntity(CraftServer server, Entity entity) { @@ -778,17 +777,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public Sound getSwimSound() { - return CraftSound.getBukkit(getHandle().getSwimSound0()); + return CraftSound.minecraftToBukkit(getHandle().getSwimSound0()); } @Override public Sound getSwimSplashSound() { - return CraftSound.getBukkit(getHandle().getSwimSplashSound0()); + return CraftSound.minecraftToBukkit(getHandle().getSwimSplashSound0()); } @Override public Sound getSwimHighSpeedSplashSound() { - return CraftSound.getBukkit(getHandle().getSwimHighSpeedSplashSound0()); + return CraftSound.minecraftToBukkit(getHandle().getSwimHighSpeedSplashSound0()); } public void setHandle(final Entity entity) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java new file mode 100644 index 0000000000..86a90a5916 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java @@ -0,0 +1,31 @@ +package org.bukkit.craftbukkit.entity; + +import com.google.common.base.Preconditions; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.entity.EntityTypes; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.entity.EntityType; + +public class CraftEntityType { + + public static EntityType minecraftToBukkit(EntityTypes minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE); + EntityType bukkit = Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static EntityTypes bukkitToMinecraft(EntityType bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java index 426327c336..b7eff43498 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java @@ -1,9 +1,12 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.entity.animal.FrogVariant; import net.minecraft.world.entity.animal.frog.Frog; import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Entity; @@ -40,13 +43,34 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog { @Override public Variant getVariant() { - return Registry.FROG_VARIANT.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.FROG_VARIANT.getKey(getHandle().getVariant()))); + return CraftVariant.minecraftToBukkit(getHandle().getVariant()); } @Override public void setVariant(Variant variant) { Preconditions.checkArgument(variant != null, "variant"); - getHandle().setVariant(BuiltInRegistries.FROG_VARIANT.get(CraftNamespacedKey.toMinecraft(variant.getKey()))); + getHandle().setVariant(CraftVariant.bukkitToMinecraft(variant)); + } + + public static class CraftVariant { + + public static Variant minecraftToBukkit(FrogVariant minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT); + Variant bukkit = Registry.FROG_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static FrogVariant bukkitToMinecraft(Variant bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 4a2c855c14..7abf87ca2d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -710,51 +710,51 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public T getMemory(MemoryKey memoryKey) { - return (T) getHandle().getBrain().getMemory(CraftMemoryKey.fromMemoryKey(memoryKey)).map(CraftMemoryMapper::fromNms).orElse(null); + return (T) getHandle().getBrain().getMemory(CraftMemoryKey.bukkitToMinecraft(memoryKey)).map(CraftMemoryMapper::fromNms).orElse(null); } @Override public void setMemory(MemoryKey memoryKey, T t) { - getHandle().getBrain().setMemory(CraftMemoryKey.fromMemoryKey(memoryKey), CraftMemoryMapper.toNms(t)); + getHandle().getBrain().setMemory(CraftMemoryKey.bukkitToMinecraft(memoryKey), CraftMemoryMapper.toNms(t)); } @Override public Sound getHurtSound() { SoundEffect sound = getHandle().getHurtSound0(getHandle().damageSources().generic()); - return (sound != null) ? CraftSound.getBukkit(sound) : null; + return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null; } @Override public Sound getDeathSound() { SoundEffect sound = getHandle().getDeathSound0(); - return (sound != null) ? CraftSound.getBukkit(sound) : null; + return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null; } @Override public Sound getFallDamageSound(int fallHeight) { - return CraftSound.getBukkit(getHandle().getFallDamageSound0(fallHeight)); + return CraftSound.minecraftToBukkit(getHandle().getFallDamageSound0(fallHeight)); } @Override public Sound getFallDamageSoundSmall() { - return CraftSound.getBukkit(getHandle().getFallSounds().small()); + return CraftSound.minecraftToBukkit(getHandle().getFallSounds().small()); } @Override public Sound getFallDamageSoundBig() { - return CraftSound.getBukkit(getHandle().getFallSounds().big()); + return CraftSound.minecraftToBukkit(getHandle().getFallSounds().big()); } @Override public Sound getDrinkingSound(ItemStack itemStack) { Preconditions.checkArgument(itemStack != null, "itemStack must not be null"); - return CraftSound.getBukkit(getHandle().getDrinkingSound0(CraftItemStack.asNMSCopy(itemStack))); + return CraftSound.minecraftToBukkit(getHandle().getDrinkingSound0(CraftItemStack.asNMSCopy(itemStack))); } @Override public Sound getEatingSound(ItemStack itemStack) { Preconditions.checkArgument(itemStack != null, "itemStack must not be null"); - return CraftSound.getBukkit(getHandle().getEatingSound0(CraftItemStack.asNMSCopy(itemStack))); + return CraftSound.minecraftToBukkit(getHandle().getEatingSound0(CraftItemStack.asNMSCopy(itemStack))); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java index 10eccc5fd5..3b8689b5e1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java @@ -50,7 +50,7 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob { @Override public Sound getAmbientSound() { SoundEffect sound = getHandle().getAmbientSound0(); - return (sound != null) ? CraftSound.getBukkit(sound) : null; + return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null; } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java index 7a7a6b4c36..c8f74b33c7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java @@ -17,8 +17,7 @@ public class CraftPainting extends CraftHanging implements Painting { @Override public Art getArt() { - Holder art = getHandle().getVariant(); - return CraftArt.NotchToBukkit(art); + return CraftArt.minecraftHolderToBukkit(getHandle().getVariant()); } @Override @@ -30,7 +29,7 @@ public class CraftPainting extends CraftHanging implements Painting { public boolean setArt(Art art, boolean force) { EntityPainting painting = this.getHandle(); Holder oldArt = painting.getVariant(); - painting.setVariant(CraftArt.BukkitToNotch(art)); + painting.setVariant(CraftArt.bukkitToMinecraftHolder(art)); painting.setDirection(painting.getDirection()); if (!force && !getHandle().generation && !painting.survives()) { // Revert painting since it doesn't fit diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index a3245bf71c..97df91de67 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -436,29 +436,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (getHandle().connection == null) return; - String instrumentName = switch (instrument.ordinal()) { - case 0 -> "harp"; - case 1 -> "basedrum"; - case 2 -> "snare"; - case 3 -> "hat"; - case 4 -> "bass"; - case 5 -> "flute"; - case 6 -> "bell"; - case 7 -> "guitar"; - case 8 -> "chime"; - case 9 -> "xylophone"; - case 10 -> "iron_xylophone"; - case 11 -> "cow_bell"; - case 12 -> "didgeridoo"; - case 13 -> "bit"; - case 14 -> "banjo"; - case 15 -> "pling"; - case 16 -> "xylophone"; + Sound instrumentSound = switch (instrument.ordinal()) { + case 0 -> Sound.BLOCK_NOTE_BLOCK_HARP; + case 1 -> Sound.BLOCK_NOTE_BLOCK_BASEDRUM; + case 2 -> Sound.BLOCK_NOTE_BLOCK_SNARE; + case 3 -> Sound.BLOCK_NOTE_BLOCK_HAT; + case 4 -> Sound.BLOCK_NOTE_BLOCK_BASS; + case 5 -> Sound.BLOCK_NOTE_BLOCK_FLUTE; + case 6 -> Sound.BLOCK_NOTE_BLOCK_BELL; + case 7 -> Sound.BLOCK_NOTE_BLOCK_GUITAR; + case 8 -> Sound.BLOCK_NOTE_BLOCK_CHIME; + case 9 -> Sound.BLOCK_NOTE_BLOCK_XYLOPHONE; + case 10 -> Sound.BLOCK_NOTE_BLOCK_IRON_XYLOPHONE; + case 11 -> Sound.BLOCK_NOTE_BLOCK_COW_BELL; + case 12 -> Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO; + case 13 -> Sound.BLOCK_NOTE_BLOCK_BIT; + case 14 -> Sound.BLOCK_NOTE_BLOCK_BANJO; + case 15 -> Sound.BLOCK_NOTE_BLOCK_PLING; + case 16 -> Sound.BLOCK_NOTE_BLOCK_XYLOPHONE; default -> null; }; float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D); - getHandle().connection.send(new PacketPlayOutNamedSoundEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect("block.note_block." + instrumentName)), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong())); + getHandle().connection.send(new PacketPlayOutNamedSoundEffect(CraftSound.bukkitToMinecraftHolder(instrumentSound), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong())); } @Override @@ -475,7 +475,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { if (loc == null || sound == null || category == null || getHandle().connection == null) return; - playSound0(loc, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); + playSound0(loc, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); } @Override @@ -508,7 +508,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return; - playSound0(entity, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect(sound)), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); + playSound0(entity, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaider.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaider.java index a3c9968e1e..2deb3c1ee6 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaider.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaider.java @@ -106,6 +106,6 @@ public abstract class CraftRaider extends CraftMonster implements Raider { @Override public Sound getCelebrationSound() { - return CraftSound.getBukkit(getHandle().getCelebrateSound()); + return CraftSound.minecraftToBukkit(getHandle().getCelebrateSound()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index d31bd0156c..a3cc78d328 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -1,16 +1,19 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; -import java.util.Locale; import net.minecraft.core.BlockPosition; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.monster.EntityZombie; import net.minecraft.world.entity.monster.EntityZombieVillager; import net.minecraft.world.entity.npc.EntityVillager; import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.entity.npc.VillagerType; import net.minecraft.world.level.block.BlockBed; import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.Location; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftNamespacedKey; @@ -43,24 +46,24 @@ public class CraftVillager extends CraftAbstractVillager implements Villager { @Override public Profession getProfession() { - return CraftVillager.nmsToBukkitProfession(getHandle().getVillagerData().getProfession()); + return CraftProfession.minecraftToBukkit(getHandle().getVillagerData().getProfession()); } @Override public void setProfession(Profession profession) { Preconditions.checkArgument(profession != null, "Profession cannot be null"); - getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(profession))); + getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftProfession.bukkitToMinecraft(profession))); } @Override public Type getVillagerType() { - return Type.valueOf(BuiltInRegistries.VILLAGER_TYPE.getKey(getHandle().getVillagerData().getType()).getPath().toUpperCase(Locale.ROOT)); + return CraftType.minecraftToBukkit(getHandle().getVillagerData().getType()); } @Override public void setVillagerType(Type type) { Preconditions.checkArgument(type != null, "Type cannot be null"); - getHandle().setVillagerData(getHandle().getVillagerData().setType(BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())))); + getHandle().setVillagerData(getHandle().getVillagerData().setType(CraftType.bukkitToMinecraft(type))); } @Override @@ -123,11 +126,45 @@ public class CraftVillager extends CraftAbstractVillager implements Villager { return (entityzombievillager != null) ? (ZombieVillager) entityzombievillager.getBukkitEntity() : null; } - public static Profession nmsToBukkitProfession(VillagerProfession nms) { - return Profession.valueOf(BuiltInRegistries.VILLAGER_PROFESSION.getKey(nms).getPath().toUpperCase(Locale.ROOT)); + public static class CraftType { + + public static Type minecraftToBukkit(VillagerType minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_TYPE); + Type bukkit = Registry.VILLAGER_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static VillagerType bukkitToMinecraft(Type bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_TYPE) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } } - public static VillagerProfession bukkitToNmsProfession(Profession bukkit) { - return BuiltInRegistries.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(bukkit.getKey())); + public static class CraftProfession { + + public static Profession minecraftToBukkit(VillagerProfession minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_PROFESSION); + Profession bukkit = Registry.VILLAGER_PROFESSION.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static VillagerProfession bukkitToMinecraft(Profession bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.VILLAGER_PROFESSION) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java index be847f1b22..ccdd0fd828 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java @@ -1,15 +1,11 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; -import java.util.Locale; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.monster.EntityZombieVillager; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Villager; import org.bukkit.entity.ZombieVillager; @@ -31,24 +27,24 @@ public class CraftVillagerZombie extends CraftZombie implements ZombieVillager { @Override public Villager.Profession getVillagerProfession() { - return Villager.Profession.valueOf(BuiltInRegistries.VILLAGER_PROFESSION.getKey(getHandle().getVillagerData().getProfession()).getPath().toUpperCase(Locale.ROOT)); + return CraftVillager.CraftProfession.minecraftToBukkit(getHandle().getVillagerData().getProfession()); } @Override public void setVillagerProfession(Villager.Profession profession) { Preconditions.checkArgument(profession != null, "Villager.Profession cannot be null"); - getHandle().setVillagerData(getHandle().getVillagerData().setProfession(BuiltInRegistries.VILLAGER_PROFESSION.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT))))); + getHandle().setVillagerData(getHandle().getVillagerData().setProfession(CraftVillager.CraftProfession.bukkitToMinecraft(profession))); } @Override public Villager.Type getVillagerType() { - return Villager.Type.valueOf(BuiltInRegistries.VILLAGER_TYPE.getKey(getHandle().getVillagerData().getType()).getPath().toUpperCase(Locale.ROOT)); + return CraftVillager.CraftType.minecraftToBukkit(getHandle().getVillagerData().getType()); } @Override public void setVillagerType(Villager.Type type) { Preconditions.checkArgument(type != null, "Villager.Type cannot be null"); - getHandle().setVillagerData(getHandle().getVillagerData().setType(BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())))); + getHandle().setVillagerData(getHandle().getVillagerData().setType(CraftVillager.CraftType.bukkitToMinecraft(type))); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/memory/CraftMemoryKey.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/memory/CraftMemoryKey.java index 0307516d18..27d93dbaa0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/memory/CraftMemoryKey.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/memory/CraftMemoryKey.java @@ -1,7 +1,11 @@ package org.bukkit.craftbukkit.entity.memory; -import net.minecraft.core.registries.BuiltInRegistries; +import com.google.common.base.Preconditions; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.memory.MemoryKey; @@ -9,11 +13,23 @@ public final class CraftMemoryKey { private CraftMemoryKey() {} - public static MemoryModuleType fromMemoryKey(MemoryKey memoryKey) { - return (MemoryModuleType) BuiltInRegistries.MEMORY_MODULE_TYPE.get(CraftNamespacedKey.toMinecraft(memoryKey.getKey())); + public static MemoryKey minecraftToBukkit(MemoryModuleType minecraft) { + if (minecraft == null) { + return null; + } + + IRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.MEMORY_MODULE_TYPE); + MemoryKey bukkit = Registry.MEMORY_MODULE_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + return bukkit; } - public static MemoryKey toMemoryKey(MemoryModuleType memoryModuleType) { - return MemoryKey.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType))); + public static MemoryModuleType bukkitToMinecraft(MemoryKey bukkit) { + if (bukkit == null) { + return null; + } + + return (MemoryModuleType) CraftRegistry.getMinecraftRegistry(Registries.MEMORY_MODULE_TYPE) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java index 1c9f2f1204..eccd6be0c0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -12,7 +12,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.generator.ChunkGenerator; @@ -60,7 +60,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { @Override public Biome getBiome(int x, int y, int z) { - return CraftBlock.biomeBaseToBiome(getHandle().biomeRegistry, getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2)); + return CraftBiome.minecraftHolderToBukkit(getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2)); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java index 48f2e0f69e..3f32122977 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java @@ -38,7 +38,7 @@ import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.CraftHeightMap; -import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.util.RandomSourceWrapper; import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator.BiomeGrid; @@ -76,13 +76,13 @@ public class CustomChunkGenerator extends InternalChunkGenerator { @Override public Biome getBiome(int x, int y, int z) { - return CraftBlock.biomeBaseToBiome(biome.biomeRegistry, biome.getNoiseBiome(x >> 2, y >> 2, z >> 2)); + return CraftBiome.minecraftHolderToBukkit(biome.getNoiseBiome(x >> 2, y >> 2, z >> 2)); } @Override public void setBiome(int x, int y, int z, Biome bio) { Preconditions.checkArgument(bio != Biome.CUSTOM, "Cannot set the biome to %s", bio); - biome.setBiome(x >> 2, y >> 2, z >> 2, CraftBlock.biomeToBiomeBase(biome.biomeRegistry, bio)); + biome.setBiome(x >> 2, y >> 2, z >> 2, CraftBiome.bukkitToMinecraftHolder(bio)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java index 0b2417d411..c3b8d55310 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java @@ -11,7 +11,7 @@ import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.WorldChunkManager; import org.bukkit.block.Biome; -import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.generator.BiomeProvider; import org.bukkit.generator.WorldInfo; @@ -26,7 +26,7 @@ public class CustomWorldChunkManager extends WorldChunkManager { for (Biome biome : biomes) { Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); - biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome)); + biomeBases.add(CraftBiome.bukkitToMinecraftHolder(biome)); } return biomeBases; @@ -48,7 +48,7 @@ public class CustomWorldChunkManager extends WorldChunkManager { Biome biome = biomeProvider.getBiome(worldInfo, x << 2, y << 2, z << 2, CraftBiomeParameterPoint.createBiomeParameterPoint(sampler, sampler.sample(x, y, z))); Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot set the biome to %s", biome); - return CraftBlock.biomeToBiomeBase(registry, biome); + return CraftBiome.bukkitToMinecraftHolder(biome); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructure.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructure.java index 9ee00be527..f8cbec8372 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructure.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructure.java @@ -1,9 +1,12 @@ package org.bukkit.craftbukkit.generator.structure; +import com.google.common.base.Preconditions; +import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistryCustom; import net.minecraft.core.registries.Registries; import org.bukkit.NamespacedKey; import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.generator.structure.Structure; import org.bukkit.generator.structure.StructureType; @@ -11,17 +14,18 @@ import org.bukkit.generator.structure.StructureType; public class CraftStructure extends Structure { public static Structure minecraftToBukkit(net.minecraft.world.level.levelgen.structure.Structure minecraft, IRegistryCustom registryHolder) { - if (minecraft == null) { - return null; - } + Preconditions.checkArgument(minecraft != null); - return Registry.STRUCTURE.get(CraftNamespacedKey.fromMinecraft(registryHolder.registryOrThrow(Registries.STRUCTURE).getKey(minecraft))); + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE); + Structure bukkit = Registry.STRUCTURE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; } public static net.minecraft.world.level.levelgen.structure.Structure bukkitToMinecraft(Structure bukkit) { - if (bukkit == null) { - return null; - } + Preconditions.checkArgument(bukkit != null); return ((CraftStructure) bukkit).getHandle(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructureType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructureType.java index 540fce5e34..9d46e35363 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructureType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/structure/CraftStructureType.java @@ -1,25 +1,29 @@ package org.bukkit.craftbukkit.generator.structure; -import net.minecraft.core.registries.BuiltInRegistries; +import com.google.common.base.Preconditions; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import org.bukkit.NamespacedKey; import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.generator.structure.StructureType; public class CraftStructureType extends StructureType { public static StructureType minecraftToBukkit(net.minecraft.world.level.levelgen.structure.StructureType minecraft) { - if (minecraft == null) { - return null; - } + Preconditions.checkArgument(minecraft != null); - return Registry.STRUCTURE_TYPE.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.STRUCTURE_TYPE.getKey(minecraft))); + IRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE_TYPE); + StructureType bukkit = Registry.STRUCTURE_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; } public static net.minecraft.world.level.levelgen.structure.StructureType bukkitToMinecraft(StructureType bukkit) { - if (bukkit == null) { - return null; - } + Preconditions.checkArgument(bukkit != null); return ((CraftStructureType) bukkit).getHandle(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java index d163cfbfc3..5e53a822fd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java @@ -12,9 +12,9 @@ import net.minecraft.world.item.ItemMonsterEgg; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.util.CraftLegacy; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; @@ -448,7 +448,7 @@ public final class CraftItemFactory implements ItemFactory { if (type == EntityType.UNKNOWN) { return null; } - EntityTypes nmsType = BuiltInRegistries.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())); + EntityTypes nmsType = CraftEntityType.bukkitToMinecraft(type); Item nmsItem = ItemMonsterEgg.byId(nmsType); if (nmsItem == null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index bf5fb75161..48c89c4292 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -56,6 +56,7 @@ import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.craftbukkit.CraftEquipmentSlot; import org.bukkit.craftbukkit.Overridden; +import org.bukkit.craftbukkit.attribute.CraftAttribute; import org.bukkit.craftbukkit.attribute.CraftAttributeInstance; import org.bukkit.craftbukkit.attribute.CraftAttributeMap; import org.bukkit.craftbukkit.block.data.CraftBlockData; @@ -434,7 +435,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { continue; } - Attribute attribute = CraftAttributeMap.fromMinecraft(attributeName); + Attribute attribute = CraftAttribute.stringToBukkit(attributeName); if (attribute == null) { continue; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java index b4f8408419..bdcdaa0a84 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java @@ -4,8 +4,6 @@ import com.google.common.base.Preconditions; import java.util.Collection; import java.util.Objects; import java.util.stream.Collectors; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.MinecraftKey; import net.minecraft.server.packs.repository.ResourcePackLoader; import net.minecraft.server.packs.repository.ResourcePackRepository; import net.minecraft.world.entity.EntityTypes; @@ -13,6 +11,7 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.EntityType; import org.bukkit.packs.DataPack; @@ -96,7 +95,7 @@ public class CraftDataPackManager implements DataPackManager { Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "EntityType.UNKNOWN its not allowed here"); CraftWorld craftWorld = ((CraftWorld) world); - EntityTypes nmsEntity = BuiltInRegistries.ENTITY_TYPE.get(new MinecraftKey(entityType.getKey().getKey())); + EntityTypes nmsEntity = CraftEntityType.bukkitToMinecraft(entityType); return nmsEntity.isEnabled(craftWorld.getHandle().enabledFeatures()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java index 8a43688cd2..85ec0c5c60 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java @@ -1,15 +1,12 @@ package org.bukkit.craftbukkit.tag; -import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import net.minecraft.world.entity.EntityTypes; -import org.bukkit.Registry; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.entity.EntityType; public class CraftEntityTag extends CraftTag, EntityType> { @@ -20,11 +17,11 @@ public class CraftEntityTag extends CraftTag, EntityType> { @Override public boolean isTagged(EntityType entity) { - return registry.getHolderOrThrow(ResourceKey.create(Registries.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(entity.getKey()))).is(tag); + return CraftEntityType.bukkitToMinecraft(entity).is(tag); } @Override public Set getValues() { - return getHandle().stream().map((nms) -> Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(EntityTypes.getKey(nms.value())))).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet()); + return getHandle().stream().map(Holder::value).map(CraftEntityType::minecraftToBukkit).collect(Collectors.toUnmodifiableSet()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java index 2ce610d323..efb03e841d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java @@ -2,11 +2,12 @@ package org.bukkit.craftbukkit.tag; import java.util.Set; import java.util.stream.Collectors; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.tags.TagKey; import net.minecraft.world.level.material.FluidType; import org.bukkit.Fluid; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.CraftFluid; public class CraftFluidTag extends CraftTag { @@ -16,11 +17,11 @@ public class CraftFluidTag extends CraftTag { @Override public boolean isTagged(Fluid fluid) { - return CraftMagicNumbers.getFluid(fluid).is(tag); + return CraftFluid.bukkitToMinecraft(fluid).is(tag); } @Override public Set getValues() { - return getHandle().stream().map((fluid) -> CraftMagicNumbers.getFluid(fluid.value())).collect(Collectors.toUnmodifiableSet()); + return getHandle().stream().map(Holder::value).map(CraftFluid::minecraftToBukkit).collect(Collectors.toUnmodifiableSet()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 2ea1c8f72d..3877d5631f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -2,8 +2,6 @@ package org.bukkit.craftbukkit.util; import com.google.common.base.Charsets; import com.google.common.base.Preconditions; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; @@ -43,14 +41,11 @@ import net.minecraft.world.entity.ai.attributes.AttributeBase; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.material.FluidType; import net.minecraft.world.level.storage.SavedFile; import org.bukkit.Bukkit; import org.bukkit.FeatureFlag; -import org.bukkit.Fluid; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.Registry; import org.bukkit.UnsafeValues; import org.bukkit.advancement.Advancement; import org.bukkit.attribute.Attribute; @@ -58,9 +53,8 @@ import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.CraftEquipmentSlot; import org.bukkit.craftbukkit.CraftFeatureFlag; +import org.bukkit.craftbukkit.attribute.CraftAttribute; import org.bukkit.craftbukkit.attribute.CraftAttributeInstance; -import org.bukkit.craftbukkit.attribute.CraftAttributeMap; -import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.legacy.CraftLegacy; @@ -105,7 +99,6 @@ public final class CraftMagicNumbers implements UnsafeValues { // ======================================================================== private static final Map BLOCK_MATERIAL = new HashMap<>(); private static final Map ITEM_MATERIAL = new HashMap<>(); - private static final BiMap FLUIDTYPE_FLUID = HashBiMap.create(); private static final Map MATERIAL_ITEM = new HashMap<>(); private static final Map MATERIAL_BLOCK = new HashMap<>(); @@ -118,11 +111,6 @@ public final class CraftMagicNumbers implements UnsafeValues { ITEM_MATERIAL.put(item, Material.getMaterial(BuiltInRegistries.ITEM.getKey(item).getPath().toUpperCase(Locale.ROOT))); } - for (FluidType fluidType : BuiltInRegistries.FLUID) { - Fluid fluid = Registry.FLUID.get(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.FLUID.getKey(fluidType))); - FLUIDTYPE_FLUID.put(fluidType, fluid); - } - for (Material material : Material.values()) { if (material.isLegacy()) { continue; @@ -146,10 +134,6 @@ public final class CraftMagicNumbers implements UnsafeValues { return ITEM_MATERIAL.getOrDefault(item, Material.AIR); } - public static Fluid getFluid(FluidType fluid) { - return FLUIDTYPE_FLUID.get(fluid); - } - public static Item getItem(Material material) { if (material != null && material.isLegacy()) { material = CraftLegacy.fromLegacy(material); @@ -166,10 +150,6 @@ public final class CraftMagicNumbers implements UnsafeValues { return MATERIAL_BLOCK.get(material); } - public static FluidType getFluid(Fluid fluid) { - return FLUIDTYPE_FLUID.inverse().get(fluid); - } - public static MinecraftKey key(Material mat) { return CraftNamespacedKey.toMinecraft(mat.getKey()); } @@ -352,7 +332,7 @@ public final class CraftMagicNumbers implements UnsafeValues { Multimap nmsDefaultAttributes = getItem(material).getDefaultAttributeModifiers(CraftEquipmentSlot.getNMS(slot)); for (Entry mapEntry : nmsDefaultAttributes.entries()) { - Attribute attribute = CraftAttributeMap.fromMinecraft(BuiltInRegistries.ATTRIBUTE.getKey(mapEntry.getKey()).toString()); + Attribute attribute = CraftAttribute.minecraftToBukkit(mapEntry.getKey()); defaultAttributes.put(attribute, CraftAttributeInstance.convert(mapEntry.getValue(), slot)); } diff --git a/paper-server/src/test/java/org/bukkit/ArtTest.java b/paper-server/src/test/java/org/bukkit/ArtTest.java index 68c938eae3..f89e2d95a4 100644 --- a/paper-server/src/test/java/org/bukkit/ArtTest.java +++ b/paper-server/src/test/java/org/bukkit/ArtTest.java @@ -29,7 +29,7 @@ public class ArtTest extends AbstractTestingBase { int width = enumArt.value().getWidth() / UNIT_MULTIPLIER; int height = enumArt.value().getHeight() / UNIT_MULTIPLIER; - Art subject = CraftArt.NotchToBukkit(enumArt); + Art subject = CraftArt.minecraftHolderToBukkit(enumArt); String message = String.format("org.bukkit.Art is missing '%s'", name); assertNotNull(message, subject); @@ -48,7 +48,7 @@ public class ArtTest extends AbstractTestingBase { public void testCraftArtToNotch() { Map, Art> cache = new HashMap<>(); for (Art art : Art.values()) { - Holder enumArt = CraftArt.BukkitToNotch(art); + Holder enumArt = CraftArt.bukkitToMinecraftHolder(art); assertNotNull(art.name(), enumArt); assertThat(art.name(), cache.put(enumArt, art), is(nullValue())); } @@ -58,7 +58,7 @@ public class ArtTest extends AbstractTestingBase { public void testCraftArtToBukkit() { Map> cache = new EnumMap(Art.class); for (Holder enumArt : BuiltInRegistries.PAINTING_VARIANT.asHolderIdMap()) { - Art art = CraftArt.NotchToBukkit(enumArt); + Art art = CraftArt.minecraftHolderToBukkit(enumArt); assertNotNull("Could not CraftArt.NotchToBukkit " + enumArt, art); assertThat("Duplicate artwork " + enumArt, cache.put(art, enumArt), is(nullValue())); } diff --git a/paper-server/src/test/java/org/bukkit/BiomeTest.java b/paper-server/src/test/java/org/bukkit/BiomeTest.java index 07a61ad335..e737bc5e48 100644 --- a/paper-server/src/test/java/org/bukkit/BiomeTest.java +++ b/paper-server/src/test/java/org/bukkit/BiomeTest.java @@ -2,7 +2,7 @@ package org.bukkit; import net.minecraft.world.level.biome.BiomeBase; import org.bukkit.block.Biome; -import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.support.AbstractTestingBase; import org.junit.Assert; import org.junit.Test; @@ -16,14 +16,14 @@ public class BiomeTest extends AbstractTestingBase { continue; } - Assert.assertNotNull("No NMS mapping for " + biome, CraftBlock.biomeToBiomeBase(BIOMES, biome)); + Assert.assertNotNull("No NMS mapping for " + biome, CraftBiome.bukkitToMinecraftHolder(biome)); } } @Test public void testMinecraftToBukkit() { for (BiomeBase biomeBase : BIOMES) { - Biome biome = CraftBlock.biomeBaseToBiome(BIOMES, biomeBase); + Biome biome = CraftBiome.minecraftToBukkit(biomeBase); Assert.assertTrue("No Bukkit mapping for " + biomeBase, biome != null && biome != Biome.CUSTOM); } } diff --git a/paper-server/src/test/java/org/bukkit/ParticleTest.java b/paper-server/src/test/java/org/bukkit/ParticleTest.java index a1f9358540..e1cca688f7 100644 --- a/paper-server/src/test/java/org/bukkit/ParticleTest.java +++ b/paper-server/src/test/java/org/bukkit/ParticleTest.java @@ -37,7 +37,7 @@ public class ParticleTest extends AbstractTestingBase { Assert.assertNotNull("Missing Bukkit->NMS particle mapping for " + bukkit, CraftParticle.toNMS(bukkit, data)); } for (net.minecraft.core.particles.Particle nms : BuiltInRegistries.PARTICLE_TYPE) { - Assert.assertNotNull("Missing NMS->Bukkit particle mapping for " + BuiltInRegistries.PARTICLE_TYPE.getKey(nms), CraftParticle.toBukkit(nms)); + Assert.assertNotNull("Missing NMS->Bukkit particle mapping for " + BuiltInRegistries.PARTICLE_TYPE.getKey(nms), CraftParticle.minecraftToBukkit(nms)); } } } diff --git a/paper-server/src/test/java/org/bukkit/SoundTest.java b/paper-server/src/test/java/org/bukkit/SoundTest.java index e6274f9f7a..d96a2820c0 100644 --- a/paper-server/src/test/java/org/bukkit/SoundTest.java +++ b/paper-server/src/test/java/org/bukkit/SoundTest.java @@ -13,7 +13,7 @@ public class SoundTest extends AbstractTestingBase { @Test public void testGetSound() { for (Sound sound : Sound.values()) { - assertThat(sound.name(), CraftSound.getSoundEffect(sound), is(not(nullValue()))); + assertThat(sound.name(), CraftSound.bukkitToMinecraft(sound), is(not(nullValue()))); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java index 458e4e7001..a5ddd1e1fe 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java @@ -1,7 +1,6 @@ package org.bukkit.craftbukkit.attribute; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.entity.ai.attributes.AttributeBase; import org.bukkit.attribute.Attribute; import org.bukkit.support.AbstractTestingBase; @@ -12,8 +11,8 @@ public class AttributeTest extends AbstractTestingBase { @Test public void testToBukkit() { - for (MinecraftKey nms : BuiltInRegistries.ATTRIBUTE.keySet()) { - Attribute bukkit = CraftAttributeMap.fromMinecraft(nms.toString()); + for (AttributeBase nms : BuiltInRegistries.ATTRIBUTE) { + Attribute bukkit = CraftAttribute.minecraftToBukkit(nms); Assert.assertNotNull(nms.toString(), bukkit); } @@ -22,7 +21,7 @@ public class AttributeTest extends AbstractTestingBase { @Test public void testToNMS() { for (Attribute attribute : Attribute.values()) { - AttributeBase nms = CraftAttributeMap.toMinecraft(attribute); + AttributeBase nms = CraftAttribute.bukkitToMinecraft(attribute); Assert.assertNotNull(attribute.name(), nms); } diff --git a/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java b/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java index 4131128e6c..6abd61ed50 100644 --- a/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java @@ -14,43 +14,43 @@ public class CraftMemoryKeyTest extends AbstractTestingBase { @Test public void shouldConvertBukkitHomeKeyToNMSRepresentation() { - MemoryModuleType nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.HOME); + MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME); Assert.assertEquals("MemoryModuleType should be HOME", MemoryModuleType.HOME, nmsHomeKey); } @Test public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() { - MemoryModuleType nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.JOB_SITE); + MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE); Assert.assertEquals("MemoryModuleType should be JOB_SITE", MemoryModuleType.JOB_SITE, nmsHomeKey); } @Test public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() { - MemoryModuleType nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.MEETING_POINT); + MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT); Assert.assertEquals("MemoryModuleType should be MEETING_POINT", MemoryModuleType.MEETING_POINT, nmsHomeKey); } @Test public void shouldConvertNMSHomeKeyToBukkitRepresentation() { - MemoryKey bukkitHomeKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.HOME); + MemoryKey bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME); Assert.assertEquals("MemoryModuleType should be HOME", MemoryKey.HOME, bukkitHomeKey); } @Test public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() { - MemoryKey bukkitJobSiteKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.JOB_SITE); + MemoryKey bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE); Assert.assertEquals("MemoryKey should be JOB_SITE", MemoryKey.JOB_SITE, bukkitJobSiteKey); } @Test public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() { - MemoryKey bukkitHomeKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.MEETING_POINT); + MemoryKey bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.MEETING_POINT); Assert.assertEquals("MemoryKey should be MEETING_POINT", MemoryKey.MEETING_POINT, bukkitHomeKey); } @Test public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailable() { - MemoryKey bukkitNoKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.NEAREST_LIVING_ENTITIES); + MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.NEAREST_LIVING_ENTITIES); Assert.assertNull("MemoryModuleType should be null", bukkitNoKey); } @@ -58,7 +58,7 @@ public class CraftMemoryKeyTest extends AbstractTestingBase { public void shouldReturnNullWhenBukkitRepresentationOfKeyisNotAvailableAndSerializerIsNotPresent() { for (MemoryModuleType memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) { if (!memoryModuleType.getCodec().isPresent()) { - MemoryKey bukkitNoKey = CraftMemoryKey.toMemoryKey(memoryModuleType); + MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType); Assert.assertNull("MemoryModuleType should be null", bukkitNoKey); } } @@ -69,7 +69,7 @@ public class CraftMemoryKeyTest extends AbstractTestingBase { public void shouldReturnAnInstanceOfMemoryKeyWhenBukkitRepresentationOfKeyisAvailableAndSerializerIsPresent() { for (MemoryModuleType memoryModuleType : BuiltInRegistries.MEMORY_MODULE_TYPE) { if (memoryModuleType.getCodec().isPresent()) { - MemoryKey bukkitNoKey = CraftMemoryKey.toMemoryKey(memoryModuleType); + MemoryKey bukkitNoKey = CraftMemoryKey.minecraftToBukkit(memoryModuleType); Assert.assertNotNull("MemoryModuleType should not be null " + BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType), bukkitNoKey); } }