#1250: Standardize and centralize Bukkit / Minecraft registry conversion
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -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<Holder<PaintingVariant>, Art> cache = new HashMap<>();
|
||||
for (Art art : Art.values()) {
|
||||
Holder<PaintingVariant> enumArt = CraftArt.BukkitToNotch(art);
|
||||
Holder<PaintingVariant> 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<Art, Holder<PaintingVariant>> cache = new EnumMap(Art.class);
|
||||
for (Holder<PaintingVariant> 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()));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -14,43 +14,43 @@ public class CraftMemoryKeyTest extends AbstractTestingBase {
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitHomeKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.HOME);
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME);
|
||||
Assert.assertEquals("MemoryModuleType should be HOME", MemoryModuleType.HOME, nmsHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.JOB_SITE);
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE);
|
||||
Assert.assertEquals("MemoryModuleType should be JOB_SITE", MemoryModuleType.JOB_SITE, nmsHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.fromMemoryKey(MemoryKey.MEETING_POINT);
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT);
|
||||
Assert.assertEquals("MemoryModuleType should be MEETING_POINT", MemoryModuleType.MEETING_POINT, nmsHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSHomeKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.HOME);
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME);
|
||||
Assert.assertEquals("MemoryModuleType should be HOME", MemoryKey.HOME, bukkitHomeKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.JOB_SITE);
|
||||
MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE);
|
||||
Assert.assertEquals("MemoryKey should be JOB_SITE", MemoryKey.JOB_SITE, bukkitJobSiteKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.toMemoryKey(MemoryModuleType.MEETING_POINT);
|
||||
MemoryKey<Location> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user