mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-12 19:30:42 +01:00
drop old tests
This commit is contained in:
parent
b91d217d4a
commit
7d4e855366
@ -6,7 +6,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents the applicable target for a {@link Enchantment}
|
||||
*
|
||||
* @deprecated enchantment groupings are now managed by tags, not categories
|
||||
*/
|
||||
@Deprecated(since = "1.20.5", forRemoval = true)
|
||||
public enum EnchantmentTarget {
|
||||
/**
|
||||
* Allows the Enchantment to be placed on all items
|
||||
|
@ -3041,7 +3041,7 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans
|
||||
* Get the {@link CreativeCategory} to which this item type belongs.
|
||||
*
|
||||
* @return the creative category. null if does not belong to a category
|
||||
* @deprecated creative categories no longer exist on the server
|
||||
<!-- * @deprecated use #getCreativeCategories() -->
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated(since = "1.20.6")
|
||||
|
@ -443,7 +443,7 @@ public final class MapPalette {
|
||||
}
|
||||
}
|
||||
|
||||
// Minecraft has 143 colors, some of which have negative byte representations
|
||||
// Minecraft has 248 colors, some of which have negative byte representations
|
||||
return (byte) (index < 128 ? index : -129 + (index - 127));
|
||||
}
|
||||
|
||||
@ -457,7 +457,7 @@ public final class MapPalette {
|
||||
@Deprecated(since = "1.6.2", forRemoval = true) // Paper
|
||||
@NotNull
|
||||
public static Color getColor(byte index) {
|
||||
// Minecraft has 143 colors, some of which have negative byte representations
|
||||
// Minecraft has 248 colors, some of which have negative byte representations
|
||||
return colors[index >= 0 ? index : index + 256];
|
||||
}
|
||||
|
||||
|
@ -1,60 +0,0 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.bukkit.support.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@org.junit.jupiter.api.Disabled // Paper
|
||||
public class BukkitMirrorTest {
|
||||
|
||||
public static Stream<Arguments> data() {
|
||||
return Stream.of(Server.class.getDeclaredMethods())
|
||||
.map(method -> {
|
||||
try {
|
||||
return Arguments.of(
|
||||
method,
|
||||
method.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}"),
|
||||
Bukkit.class.getDeclaredMethod(method.getName(), method.getParameterTypes())
|
||||
);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void isStatic(Method server, String name, Method bukkit) throws Throwable {
|
||||
assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void isDeprecated(Method server, String name, Method bukkit) throws Throwable {
|
||||
assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void returnType(Method server, String name, Method bukkit) throws Throwable {
|
||||
assertThat(bukkit.getReturnType(), is((Object) server.getReturnType()));
|
||||
// assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); // too strict on <T> type generics
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void parameterTypes(Method server, String name, Method bukkit) throws Throwable {
|
||||
// assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); // too strict on <T> type generics
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void declaredException(Method server, String name, Method bukkit) throws Throwable {
|
||||
assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes()));
|
||||
}
|
||||
}
|
@ -29,12 +29,6 @@ public class NamespacedKeyTest {
|
||||
assertNull(NamespacedKey.fromString("foo:bar:bazz"));
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Disabled // Paper - Fixup NamespacedKey handling
|
||||
@Test
|
||||
public void testFromStringEmptyInput() {
|
||||
assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromStringNullInput() {
|
||||
assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(null));
|
||||
@ -75,12 +69,4 @@ public class NamespacedKeyTest {
|
||||
new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas",
|
||||
"loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString();
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Disabled // Paper - Fixup NamespacedKey handling
|
||||
@Test
|
||||
public void testAboveLength() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas",
|
||||
"loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas/"
|
||||
+ "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString());
|
||||
}
|
||||
}
|
||||
|
@ -546,46 +546,6 @@ public abstract class ConfigurationSectionTest {
|
||||
assertFalse(section.isVector("doesntExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@org.junit.jupiter.api.Disabled("ItemStack can't exist without the Server, test moved to server")
|
||||
public void testGetItemStack_String() {
|
||||
ConfigurationSection section = getConfigurationSection();
|
||||
String key = "exists";
|
||||
ItemStack value = new ItemStack(Material.ACACIA_WOOD, 50);
|
||||
|
||||
section.set(key, value);
|
||||
|
||||
assertEquals(value, section.getItemStack(key));
|
||||
assertNull(section.getString("doesntExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@org.junit.jupiter.api.Disabled("ItemStack can't exist without the Server, test moved to server")
|
||||
public void testGetItemStack_String_ItemStack() {
|
||||
ConfigurationSection section = getConfigurationSection();
|
||||
String key = "exists";
|
||||
ItemStack value = new ItemStack(Material.ACACIA_WOOD, 50);
|
||||
ItemStack def = new ItemStack(Material.STONE, 1);
|
||||
|
||||
section.set(key, value);
|
||||
|
||||
assertEquals(value, section.getItemStack(key, def));
|
||||
assertEquals(def, section.getItemStack("doesntExist", def));
|
||||
}
|
||||
|
||||
@Test
|
||||
@org.junit.jupiter.api.Disabled("ItemStack can't exist without the Server, test moved to server")
|
||||
public void testIsItemStack() {
|
||||
ConfigurationSection section = getConfigurationSection();
|
||||
String key = "exists";
|
||||
ItemStack value = new ItemStack(Material.ACACIA_WOOD, 50);
|
||||
|
||||
section.set(key, value);
|
||||
|
||||
assertTrue(section.isItemStack(key));
|
||||
assertFalse(section.isItemStack("doesntExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigurationSection() {
|
||||
ConfigurationSection section = getConfigurationSection();
|
||||
|
@ -1,41 +0,0 @@
|
||||
package org.bukkit.entity.memory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MemoryKeyTest {
|
||||
|
||||
@Test
|
||||
public void shouldContainAllMemories() {
|
||||
List<MemoryKey<?>> memories = Arrays.asList(MemoryKey.HOME, MemoryKey.JOB_SITE, MemoryKey.MEETING_POINT);
|
||||
assertTrue(MemoryKey.values().containsAll(memories));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetMemoryKeyHomeByNamespacedKey() {
|
||||
assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetMemoryKeyJobSiteByNamespacedKey() {
|
||||
assertEquals(MemoryKey.JOB_SITE, MemoryKey.getByKey(NamespacedKey.minecraft("job_site")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetMemoryKeyMeetingPointByNamespacedKey() {
|
||||
assertEquals(MemoryKey.MEETING_POINT, MemoryKey.getByKey(NamespacedKey.minecraft("meeting_point")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullWhenNamespacedKeyisNotPresentAsMemoryKey() {
|
||||
assertNull(MemoryKey.getByKey(NamespacedKey.minecraft("not_present")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullWhenNamespacedKeyisNull() {
|
||||
assertNull(MemoryKey.getByKey(null));
|
||||
}
|
||||
}
|
@ -103,6 +103,7 @@ fun TaskContainer.registerGenerationTask(
|
||||
val projectDirs = args.mapNotNull { project.rootProject.findProject(it)?.projectDir }
|
||||
if (projectDirs.isNotEmpty()) {
|
||||
args(projectDirs)
|
||||
systemProperty("paper.updatingMinecraft", providers.gradleProperty("updatingMinecraft").getOrElse("false").toBoolean())
|
||||
if (rewrite) {
|
||||
systemProperty("typewriter.lexer.ignoreMarkdownDocComments", true)
|
||||
inputs.files(projectDirs.map { it.resolve("src/main/java") })
|
||||
|
@ -1,15 +1,21 @@
|
||||
package io.papermc.generator.rewriter.types.simple;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import io.papermc.typewriter.replace.SearchMetadata;
|
||||
import io.papermc.typewriter.replace.SearchReplaceRewriter;
|
||||
import java.awt.Color;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class MapPaletteRewriter extends SearchReplaceRewriter {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final boolean UPDATING = Boolean.getBoolean("paper.updatingMinecraft");
|
||||
|
||||
@Override
|
||||
protected void insert(SearchMetadata metadata, StringBuilder builder) {
|
||||
int count = 0;
|
||||
for (@Nullable MapColor mapColor : MapColor.MATERIAL_COLORS) {
|
||||
if (mapColor == null) {
|
||||
continue;
|
||||
@ -24,7 +30,12 @@ public class MapPaletteRewriter extends SearchReplaceRewriter {
|
||||
builder.append("new %s(0x%06X),".formatted(color.getClass().getSimpleName(), color.getRGB() & 0x00FFFFFF));
|
||||
}
|
||||
builder.append('\n');
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (UPDATING) {
|
||||
LOGGER.warn("There are {} map colors, check CraftMapView#render for possible change and update md5 hash in CraftMapColorCache", count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import org.bukkit.map.MapPalette;
|
||||
|
||||
public class CraftMapColorCache implements MapPalette.MapColorCache {
|
||||
|
||||
private static final String MD5_CACHE_HASH = "E88EDD068D12D39934B40E8B6B124C83";
|
||||
private static final String MD5_CACHE_HASH = "E88EDD068D12D39934B40E8B6B124C83"; // 248 colors
|
||||
private static final File CACHE_FILE = new File("map-color-cache.dat");
|
||||
private byte[] cache;
|
||||
private final Logger logger;
|
||||
@ -31,10 +31,16 @@ public class CraftMapColorCache implements MapPalette.MapColorCache {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private static CraftMapColorCache dryRun() {
|
||||
CraftMapColorCache mapColorCache = new CraftMapColorCache(Logger.getGlobal());
|
||||
mapColorCache.cache = new byte[256 * 256 * 256];
|
||||
mapColorCache.buildCache();
|
||||
return mapColorCache;
|
||||
}
|
||||
|
||||
// Builds and prints the md5 hash of the cache, this should be run when new map colors are added to update the MD5_CACHE_HASH string
|
||||
public static void main(String[] args) {
|
||||
CraftMapColorCache craftMapColorCache = new CraftMapColorCache(Logger.getGlobal());
|
||||
craftMapColorCache.buildCache();
|
||||
CraftMapColorCache craftMapColorCache = CraftMapColorCache.dryRun();
|
||||
try {
|
||||
byte[] hash = MessageDigest.getInstance("MD5").digest(craftMapColorCache.cache);
|
||||
System.out.println("MD5_CACHE_HASH: " + CraftMapColorCache.bytesToString(hash));
|
||||
@ -151,7 +157,7 @@ public class CraftMapColorCache implements MapPalette.MapColorCache {
|
||||
|
||||
@Override
|
||||
public byte matchColor(Color color) {
|
||||
Preconditions.checkState(this.isCached(), "Cache not build jet");
|
||||
Preconditions.checkState(this.isCached(), "Cache not build yet");
|
||||
|
||||
return this.cache[this.toInt(color)];
|
||||
}
|
||||
|
@ -1,29 +1,19 @@
|
||||
package org.bukkit.craftbukkit.scoreboard;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.RenderType;
|
||||
|
||||
public final class CraftScoreboardTranslations {
|
||||
static final int MAX_DISPLAY_SLOT = 19;
|
||||
@Deprecated // Paper
|
||||
static final ImmutableBiMap<DisplaySlot, String> SLOTS = ImmutableBiMap.<DisplaySlot, String>builder()
|
||||
.put(DisplaySlot.BELOW_NAME, "below_name")
|
||||
.put(DisplaySlot.PLAYER_LIST, "list")
|
||||
.put(DisplaySlot.SIDEBAR, "sidebar")
|
||||
.buildOrThrow();
|
||||
|
||||
private CraftScoreboardTranslations() {}
|
||||
|
||||
public static DisplaySlot toBukkitSlot(net.minecraft.world.scores.DisplaySlot minecraft) {
|
||||
if (true) return DisplaySlot.NAMES.value(minecraft.getSerializedName()); // Paper
|
||||
return CraftScoreboardTranslations.SLOTS.inverse().get(minecraft.getSerializedName());
|
||||
return DisplaySlot.NAMES.value(minecraft.getSerializedName()); // Paper
|
||||
}
|
||||
|
||||
public static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) {
|
||||
if (true) return net.minecraft.world.scores.DisplaySlot.CODEC.byName(slot.getId()); // Paper
|
||||
return net.minecraft.world.scores.DisplaySlot.CODEC.byName(CraftScoreboardTranslations.SLOTS.get(slot));
|
||||
return net.minecraft.world.scores.DisplaySlot.CODEC.byName(slot.getId()); // Paper
|
||||
}
|
||||
|
||||
static RenderType toBukkitRender(ObjectiveCriteria.RenderType display) {
|
||||
|
@ -9,6 +9,7 @@ import io.github.classgraph.ScanResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.bukkit.support.environment.Normal;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
@ -26,7 +27,7 @@ public class EntitySetItemSlotSilentOverrideTest {
|
||||
.whitelistPackages("net.minecraft")
|
||||
.scan()
|
||||
) {
|
||||
for (final ClassInfo subclass : scanResult.getSubclasses("net.minecraft.world.entity.LivingEntity")) {
|
||||
for (final ClassInfo subclass : scanResult.getSubclasses(LivingEntity.class.getName())) {
|
||||
final MethodInfoList setItemSlot = subclass.getDeclaredMethodInfo("setItemSlot");
|
||||
if (!setItemSlot.isEmpty()) {
|
||||
classInfo.add(subclass);
|
||||
|
@ -1,26 +0,0 @@
|
||||
package io.papermc.paper.scoreboard;
|
||||
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardTranslations;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.support.environment.Normal;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@Normal
|
||||
public class DisplaySlotTest {
|
||||
|
||||
@Test
|
||||
public void testBukkitToMinecraftDisplaySlots() {
|
||||
for (DisplaySlot bukkitSlot : DisplaySlot.values()) {
|
||||
assertNotNull(CraftScoreboardTranslations.fromBukkitSlot(bukkitSlot));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinecraftToBukkitDisplaySlots() {
|
||||
for (net.minecraft.world.scores.DisplaySlot nmsSlot : net.minecraft.world.scores.DisplaySlot.values()) {
|
||||
assertNotNull(CraftScoreboardTranslations.toBukkitSlot(nmsSlot));
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import io.github.classgraph.ScanResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.bukkit.support.environment.Normal;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
@ -26,7 +27,7 @@ public class BlockPlayerDestroyOverrideTest {
|
||||
.whitelistPackages("net.minecraft")
|
||||
.scan()
|
||||
) {
|
||||
for (final ClassInfo subclass : scanResult.getSubclasses("net.minecraft.world.level.block.Block")) {
|
||||
for (final ClassInfo subclass : scanResult.getSubclasses(Block.class.getName())) {
|
||||
final MethodInfoList playerDestroy = subclass.getDeclaredMethodInfo("playerDestroy");
|
||||
if (!playerDestroy.isEmpty()) {
|
||||
classInfo.add(subclass);
|
||||
|
@ -1,56 +0,0 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.support.environment.VanillaFeature;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@VanillaFeature
|
||||
public class ArtTest {
|
||||
|
||||
public static Stream<Arguments> widthData() {
|
||||
return Stream.of(Arguments.of(Art.KEBAB, 1),
|
||||
Arguments.of(Art.WANDERER, 1),
|
||||
Arguments.of(Art.POOL, 2),
|
||||
Arguments.of(Art.MATCH, 2),
|
||||
Arguments.of(Art.BOUQUET, 3),
|
||||
Arguments.of(Art.BACKYARD, 3),
|
||||
Arguments.of(Art.FIGHTERS, 4),
|
||||
Arguments.of(Art.SKELETON, 4),
|
||||
Arguments.of(Art.POINTER, 4));
|
||||
}
|
||||
|
||||
public static Stream<Arguments> heightData() {
|
||||
return Stream.of(Arguments.of(Art.KEBAB, 1),
|
||||
Arguments.of(Art.WANDERER, 2),
|
||||
Arguments.of(Art.POOL, 1),
|
||||
Arguments.of(Art.MATCH, 2),
|
||||
Arguments.of(Art.BOUQUET, 3),
|
||||
Arguments.of(Art.BACKYARD, 4),
|
||||
Arguments.of(Art.FIGHTERS, 2),
|
||||
Arguments.of(Art.SKELETON, 3),
|
||||
Arguments.of(Art.POINTER, 4));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("widthData")
|
||||
public void testWidth(Art art, int expected) {
|
||||
assertEquals(expected, art.getBlockWidth(), """
|
||||
Art '%s' does not have the correct width.
|
||||
This can be caused by either a change in the Implementation.
|
||||
Or the width for this specific art was changed in which case the test needs to be updated.
|
||||
""".formatted(art.getKey()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("heightData")
|
||||
public void testHeight(Art art, int expected) {
|
||||
assertEquals(expected, art.getBlockHeight(), """
|
||||
Art '%s' does not have the correct height.
|
||||
This can be caused by either a change in the Implementation.
|
||||
Or the height for this specific art was changed in which case the test needs to be updated.
|
||||
""".formatted(art.getKey()));
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.block.CraftBiome;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class BiomeTest {
|
||||
|
||||
@Test
|
||||
public void testBukkitToMinecraft() {
|
||||
for (Biome biome : Biome.values()) {
|
||||
if (biome == Biome.CUSTOM) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assertNotNull(CraftBiome.bukkitToMinecraftHolder(biome), "No NMS mapping for " + biome);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinecraftToBukkit() {
|
||||
for (net.minecraft.world.level.biome.Biome biomeBase : CraftRegistry.getMinecraftRegistry(Registries.BIOME)) {
|
||||
Biome biome = CraftBiome.minecraftToBukkit(biomeBase);
|
||||
assertTrue(biome != null && biome != Biome.CUSTOM, "No Bukkit mapping for " + biomeBase);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,9 +12,7 @@ import java.util.Set;
|
||||
import net.minecraft.world.level.block.LevelEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class EffectTest {
|
||||
|
@ -1,25 +0,0 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class EnchantmentTest {
|
||||
|
||||
@Test
|
||||
public void verifyMapping() {
|
||||
for (ResourceLocation key : CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).keySet()) {
|
||||
net.minecraft.world.item.enchantment.Enchantment nms = CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).getValue(key);
|
||||
|
||||
Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key));
|
||||
|
||||
assertFalse(bukkitById.getName().startsWith("UNKNOWN"), "Unknown enchant name for " + key);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class GameEventTest {
|
||||
|
||||
@Test
|
||||
public void toBukkit() {
|
||||
for (net.minecraft.world.level.gameevent.GameEvent nms : BuiltInRegistries.GAME_EVENT) {
|
||||
GameEvent bukkit = GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.GAME_EVENT.getKey(nms)));
|
||||
|
||||
assertNotNull(bukkit, "Bukkit should not be null " + nms);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,21 +3,9 @@ package org.bukkit;
|
||||
import static org.bukkit.support.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.Map;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.equipment.Equippable;
|
||||
import net.minecraft.world.level.EmptyBlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Fallable;
|
||||
import net.minecraft.world.level.block.FireBlock;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
@ -26,92 +14,17 @@ import org.bukkit.enchantments.EnchantmentTarget;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.support.LegacyHelper;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
@AllFeatures
|
||||
public class PerMaterialTest {
|
||||
private static Map<Block, Integer> fireValues;
|
||||
|
||||
@BeforeAll
|
||||
public static void getFireValues() {
|
||||
PerMaterialTest.fireValues = ((FireBlock) Blocks.FIRE).igniteOdds;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isBlock(Material material) {
|
||||
if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) {
|
||||
assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material) == null)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isSolid(Material material) {
|
||||
if (material == Material.AIR) {
|
||||
assertFalse(material.isSolid());
|
||||
} else if (material.isBlock()) {
|
||||
assertThat(material.isSolid(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().blocksMotion()));
|
||||
} else {
|
||||
assertFalse(material.isSolid());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isEdible(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertFalse(material.isEdible());
|
||||
} else {
|
||||
assertThat(material.isEdible(), is(CraftMagicNumbers.getItem(material).components().has(DataComponents.FOOD)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isRecord(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertFalse(material.isRecord());
|
||||
} else {
|
||||
assertThat(material.isRecord(), is(CraftMagicNumbers.getItem(material).components().has(DataComponents.JUKEBOX_PLAYABLE)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void maxDurability(Material material) {
|
||||
if (LegacyHelper.getInvalidatedMaterials().contains(material)) return;
|
||||
|
||||
if (material == Material.AIR) {
|
||||
assertThat((int) material.getMaxDurability(), is(0));
|
||||
} else if (material.isBlock()) {
|
||||
Item item = CraftMagicNumbers.getItem(material);
|
||||
assertThat((int) material.getMaxDurability(), is(item.components().getOrDefault(DataComponents.MAX_DAMAGE, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void maxStackSize(Material material) {
|
||||
if (LegacyHelper.getInvalidatedMaterials().contains(material)) return;
|
||||
|
||||
final ItemStack bukkit = new ItemStack(material);
|
||||
final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit);
|
||||
|
||||
// Paper - remove air exception
|
||||
int max = CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
|
||||
assertThat(material.getMaxStackSize(), is(max));
|
||||
assertThat(bukkit.getMaxStackSize(), is(max));
|
||||
assertThat(craft.getMaxStackSize(), is(max));
|
||||
// Paper - remove air exception
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
@Disabled
|
||||
public void isTransparent(Material material) {
|
||||
if (material == Material.AIR) {
|
||||
assertTrue(material.isTransparent());
|
||||
@ -122,47 +35,6 @@ public class PerMaterialTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isFlammable(Material material) {
|
||||
if (material != Material.AIR && material.isBlock()) {
|
||||
assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().ignitedByLava()));
|
||||
} else {
|
||||
assertFalse(material.isFlammable());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isBurnable(Material material) {
|
||||
if (material.isBlock()) {
|
||||
Block block = CraftMagicNumbers.getBlock(material);
|
||||
assertThat(material.isBurnable(), is(PerMaterialTest.fireValues.containsKey(block) && PerMaterialTest.fireValues.get(block) > 0));
|
||||
} else {
|
||||
assertFalse(material.isBurnable());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void isOccluding(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().isRedstoneConductor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)));
|
||||
} else {
|
||||
assertFalse(material.isOccluding());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void hasGravity(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof Fallable));
|
||||
} else {
|
||||
assertFalse(material.hasGravity());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void usesDurability(Material material) {
|
||||
@ -173,104 +45,6 @@ public class PerMaterialTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testDurability(Material material) {
|
||||
if (!material.isBlock()) {
|
||||
assertThat(material.getMaxDurability(), is((short) (int) CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_DAMAGE, 0)));
|
||||
} else {
|
||||
assertThat(material.getMaxDurability(), is((short) 0));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testBlock(Material material) {
|
||||
if (material == Material.AIR) {
|
||||
assertTrue(material.isBlock());
|
||||
} else {
|
||||
assertThat(material.isBlock(), is(equalTo(CraftMagicNumbers.getBlock(material) != null)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testAir(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertThat(material.isAir(), is(equalTo(CraftMagicNumbers.getBlock(material).defaultBlockState().isAir())));
|
||||
} else {
|
||||
assertThat(material.isAir(), is(equalTo(false)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testItem(Material material) {
|
||||
if (material == Material.AIR) {
|
||||
assertTrue(material.isItem());
|
||||
} else {
|
||||
assertThat(material.isItem(), is(equalTo(CraftMagicNumbers.getItem(material) != null)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testInteractable(Material material) throws ReflectiveOperationException {
|
||||
if (material.isBlock()) {
|
||||
Class<?> clazz = CraftMagicNumbers.getBlock(material).getClass();
|
||||
|
||||
boolean hasMethod = this.hasMethod(clazz, "useWithoutItem", BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, BlockHitResult.class)
|
||||
|| this.hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, InteractionHand.class, BlockHitResult.class);
|
||||
|
||||
if (!hasMethod && clazz.getSuperclass() != BlockBehaviour.class) {
|
||||
clazz = clazz.getSuperclass();
|
||||
|
||||
hasMethod = this.hasMethod(clazz, "useWithoutItem", BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, BlockHitResult.class)
|
||||
|| this.hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, InteractionHand.class, BlockHitResult.class);
|
||||
}
|
||||
|
||||
assertThat(material.isInteractable(),
|
||||
is(hasMethod));
|
||||
} else {
|
||||
assertFalse(material.isInteractable());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasMethod(Class<?> clazz, String methodName, Class<?>... params) {
|
||||
boolean hasMethod;
|
||||
try {
|
||||
hasMethod = clazz.getDeclaredMethod(methodName, params) != null;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
hasMethod = false;
|
||||
}
|
||||
|
||||
return hasMethod;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testBlockHardness(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertThat(material.getHardness(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().destroySpeed));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testBlastResistance(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertThat(material.getBlastResistance(), is(CraftMagicNumbers.getBlock(material).getExplosionResistance()));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testSlipperiness(Material material) {
|
||||
if (material.isBlock()) {
|
||||
assertThat(material.getSlipperiness(), is(CraftMagicNumbers.getBlock(material).getFriction()));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testBlockDataCreation(Material material) {
|
||||
@ -279,17 +53,6 @@ public class PerMaterialTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testCraftingRemainingItem(Material material) {
|
||||
if (material.isItem()) {
|
||||
net.minecraft.world.item.ItemStack expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainder();
|
||||
Material expected = expectedItem.isEmpty() ? null : CraftMagicNumbers.getMaterial(expectedItem.getItem());
|
||||
|
||||
assertThat(material.getCraftingRemainingItem(), is(expected));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testEquipmentSlot(Material material) {
|
||||
@ -311,12 +74,4 @@ public class PerMaterialTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE)
|
||||
public void testCreativeCategory(Material material) {
|
||||
if (material.isItem()) {
|
||||
material.getCreativeCategory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,13 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.bukkit.support.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.bukkit.craftbukkit.CraftSound;
|
||||
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class SoundTest {
|
||||
|
||||
@Test
|
||||
public void testGetSound() {
|
||||
for (Sound sound : Sound.values()) {
|
||||
assertThat(CraftSound.bukkitToMinecraft(sound), is(not(nullValue())), sound.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReverse() {
|
||||
for (ResourceLocation effect : BuiltInRegistries.SOUND_EVENT.keySet()) {
|
||||
assertNotNull(Sound.valueOf(effect.getPath().replace('.', '_').toUpperCase(Locale.ROOT)), effect + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory() {
|
||||
for (SoundCategory category : SoundCategory.values()) {
|
||||
|
@ -15,8 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class StatisticsAndAchievementsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void verifyEntityMapping() throws Throwable {
|
||||
public void verifyEntityMapping() {
|
||||
for (Statistic statistic : Statistic.values()) {
|
||||
if (statistic.getType() == Statistic.Type.ENTITY) {
|
||||
for (EntityType entity : EntityType.values()) {
|
||||
@ -30,7 +29,7 @@ public class StatisticsAndAchievementsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void verifyStatisticMapping() throws Throwable {
|
||||
public void verifyStatisticMapping() {
|
||||
HashMultiset<Statistic> statistics = HashMultiset.create();
|
||||
for (StatType wrapper : BuiltInRegistries.STAT_TYPE) {
|
||||
for (Object child : wrapper.getRegistry()) {
|
||||
|
@ -1,42 +0,0 @@
|
||||
package org.bukkit.block.banner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.block.entity.BannerPattern;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class PatternTypeTest {
|
||||
|
||||
@Test
|
||||
public void testToBukkit() {
|
||||
for (BannerPattern nms : MinecraftServer.getDefaultRegistryAccess().lookupOrThrow(Registries.BANNER_PATTERN)) {
|
||||
PatternType bukkit = Registry.BANNER_PATTERN.get(CraftNamespacedKey.fromMinecraft(nms.assetId()));
|
||||
|
||||
assertNotNull(bukkit, "No Bukkit banner pattern for " + nms + " " + nms);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNMS() {
|
||||
net.minecraft.core.Registry<BannerPattern> registry = MinecraftServer.getDefaultRegistryAccess().lookupOrThrow(Registries.BANNER_PATTERN);
|
||||
for (PatternType bukkit : PatternType.values()) {
|
||||
BannerPattern found = null;
|
||||
for (BannerPattern nms : registry) {
|
||||
NamespacedKey nmsKey = CraftNamespacedKey.fromMinecraft(registry.getKey(nms));
|
||||
if (bukkit.getKey().equals(nmsKey)) {
|
||||
found = nms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(found, "No NMS banner pattern for " + bukkit + " " + bukkit.getKey());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +1,13 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class EntityTypesTest {
|
||||
|
||||
@Test
|
||||
public void testMaps() {
|
||||
Set<EntityType> allBukkit = Arrays.stream(EntityType.values()).filter((b) -> b.getName() != null).collect(Collectors.toSet());
|
||||
|
||||
for (net.minecraft.world.entity.EntityType<?> nms : BuiltInRegistries.ENTITY_TYPE) { // Paper - remap fix
|
||||
ResourceLocation key = net.minecraft.world.entity.EntityType.getKey(nms); // Paper - remap fix
|
||||
|
||||
org.bukkit.entity.EntityType bukkit = org.bukkit.entity.EntityType.fromName(key.getPath());
|
||||
assertNotNull(bukkit, "Missing nms->bukkit " + key);
|
||||
|
||||
assertTrue(allBukkit.remove(bukkit), "Duplicate entity nms->" + bukkit);
|
||||
}
|
||||
|
||||
assertTrue(allBukkit.isEmpty(), "Unmapped bukkit entities " + allBukkit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslationKey() {
|
||||
for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) {
|
||||
|
@ -1,33 +0,0 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftPanda;
|
||||
import org.bukkit.support.environment.Normal;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Normal
|
||||
public class PandaGeneTest {
|
||||
|
||||
@Test
|
||||
public void testBukkit() {
|
||||
for (Panda.Gene gene : Panda.Gene.values()) { // Paper - remap fix
|
||||
net.minecraft.world.entity.animal.Panda.Gene nms = CraftPanda.toNms(gene); // Paper - remap fix
|
||||
|
||||
assertNotNull(nms, "NMS gene null for " + gene);
|
||||
assertEquals(gene.isRecessive(), nms.isRecessive(), "Recessive status did not match " + gene);
|
||||
assertEquals(gene, CraftPanda.fromNms(nms), "Gene did not convert back " + gene);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNMS() {
|
||||
for (net.minecraft.world.entity.animal.Panda.Gene gene : net.minecraft.world.entity.animal.Panda.Gene.values()) { // Paper - remap fix
|
||||
org.bukkit.entity.Panda.Gene bukkit = CraftPanda.fromNms(gene);
|
||||
|
||||
assertNotNull(bukkit, "Bukkit gene null for " + gene);
|
||||
assertEquals(gene.isRecessive(), bukkit.isRecessive(), "Recessive status did not match " + gene);
|
||||
assertEquals(gene, CraftPanda.toNms(bukkit), "Gene did not convert back " + gene);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package org.bukkit.entity.memory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class CraftMemoryKeyTest {
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitHomeKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME);
|
||||
assertEquals(MemoryModuleType.HOME, nmsHomeKey, "MemoryModuleType should be HOME");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE);
|
||||
assertEquals(MemoryModuleType.JOB_SITE, nmsHomeKey, "MemoryModuleType should be JOB_SITE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() {
|
||||
MemoryModuleType<GlobalPos> nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT);
|
||||
assertEquals(MemoryModuleType.MEETING_POINT, nmsHomeKey, "MemoryModuleType should be MEETING_POINT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSHomeKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME);
|
||||
assertEquals(MemoryKey.HOME, bukkitHomeKey, "MemoryModuleType should be HOME");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE);
|
||||
assertEquals(MemoryKey.JOB_SITE, bukkitJobSiteKey, "MemoryKey should be JOB_SITE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() {
|
||||
MemoryKey<Location> bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.MEETING_POINT);
|
||||
assertEquals(MemoryKey.MEETING_POINT, bukkitHomeKey, "MemoryKey should be MEETING_POINT");
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package org.bukkit.generator.structure;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class StructureTest {
|
||||
|
||||
@Test
|
||||
public void testBukkitToMinecraftFieldName() {
|
||||
for (Field field : Structure.class.getFields()) {
|
||||
if (field.getType() != Structure.class) {
|
||||
continue;
|
||||
}
|
||||
if (!Modifier.isStatic(field.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = field.getName();
|
||||
assertNotNull(Registry.STRUCTURE.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))), "No structure for field name " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinecraftToBukkitFieldName() {
|
||||
net.minecraft.core.Registry<net.minecraft.world.level.levelgen.structure.Structure> structureBuiltInRegistries = CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE);
|
||||
for (net.minecraft.world.level.levelgen.structure.Structure structure : structureBuiltInRegistries) {
|
||||
ResourceLocation minecraftKey = structureBuiltInRegistries.getKey(structure);
|
||||
|
||||
try {
|
||||
Structure bukkit = (Structure) Structure.class.getField(minecraftKey.getPath().toUpperCase(Locale.ROOT)).get(null);
|
||||
|
||||
assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey()), "Keys are not the same for " + minecraftKey);
|
||||
} catch (NoSuchFieldException e) {
|
||||
fail("No Bukkit default structure for " + minecraftKey);
|
||||
} catch (IllegalAccessException e) {
|
||||
fail("Bukkit field is not access able for " + minecraftKey);
|
||||
} catch (ClassCastException e) {
|
||||
fail("Bukkit field is not of type structure for" + minecraftKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package org.bukkit.generator.structure;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class StructureTypeTest {
|
||||
|
||||
@Test
|
||||
public void testBukkitToMinecraftFieldName() {
|
||||
for (Field field : StructureType.class.getFields()) {
|
||||
if (field.getType() != StructureType.class) {
|
||||
continue;
|
||||
}
|
||||
if (!Modifier.isStatic(field.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = field.getName();
|
||||
assertNotNull(Registry.STRUCTURE_TYPE.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))), "No enchantment for field name " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinecraftToBukkitFieldName() {
|
||||
for (net.minecraft.world.level.levelgen.structure.StructureType<?> structureType : CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE_TYPE)) {
|
||||
ResourceLocation minecraftKey = BuiltInRegistries.STRUCTURE_TYPE.getKey(structureType);
|
||||
|
||||
try {
|
||||
StructureType bukkit = (StructureType) StructureType.class.getField(minecraftKey.getPath().toUpperCase(Locale.ROOT)).get(null);
|
||||
|
||||
assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey()), "Keys are not the same for " + minecraftKey);
|
||||
} catch (NoSuchFieldException e) {
|
||||
fail("No Bukkit default enchantment for " + minecraftKey);
|
||||
} catch (IllegalAccessException e) {
|
||||
fail("Bukkit field is not access able for " + minecraftKey);
|
||||
} catch (ClassCastException e) {
|
||||
fail("Bukkit field is not of type enchantment for" + minecraftKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,11 +3,8 @@ package org.bukkit.map;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.awt.Color;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import org.bukkit.craftbukkit.map.CraftMapColorCache;
|
||||
import org.bukkit.support.environment.Normal;
|
||||
import org.bukkit.support.environment.Slow;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -15,55 +12,6 @@ public class MapTest {
|
||||
|
||||
private static final Logger logger = Logger.getLogger("MapTest");
|
||||
|
||||
private static final int[] modifiers = {180, 220, 255, 135};
|
||||
|
||||
@Test
|
||||
@Normal
|
||||
public void testColors() {
|
||||
MapColor[] nmsColors = MapColor.MATERIAL_COLORS;
|
||||
Color[] bukkitColors = MapPalette.colors;
|
||||
|
||||
boolean fail = false;
|
||||
for (int i = 0; i < nmsColors.length; i++) {
|
||||
if (nmsColors[i] == null) {
|
||||
break;
|
||||
}
|
||||
int rgb = nmsColors[i].col;
|
||||
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
if (i + 1 > bukkitColors.length / 4) {
|
||||
for (int modi : MapTest.modifiers) {
|
||||
int mr = (r * modi) / 255;
|
||||
int mg = (g * modi) / 255;
|
||||
int mb = (b * modi) / 255;
|
||||
MapTest.logger.log(Level.WARNING, "Missing color (check CraftMapView#render and update md5 hash in CraftMapColorCache): c({0}, {1}, {2})", new Object[]{mr, mg, mb});
|
||||
}
|
||||
fail = true;
|
||||
} else {
|
||||
for (int j = 0; j < MapTest.modifiers.length; j++) {
|
||||
int modi = MapTest.modifiers[j];
|
||||
Color bukkit = bukkitColors[i * 4 + j];
|
||||
int mr = (r * modi) / 255;
|
||||
int mg = (g * modi) / 255;
|
||||
int mb = (b * modi) / 255;
|
||||
|
||||
if (bukkit.getRed() != mr || bukkit.getGreen() != mg || bukkit.getBlue() != mb) {
|
||||
MapTest.logger.log(Level.WARNING, "Incorrect color: {6} {7} c({0}, {1}, {2}) != c({3}, {4}, {5})", new Object[]{
|
||||
bukkit.getRed(), bukkit.getGreen(), bukkit.getBlue(),
|
||||
mr, mg, mb,
|
||||
i, j
|
||||
});
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertFalse(fail);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Slow("Test takes around 25 seconds, should be run by changes to the map color conversion")
|
||||
public void testMapColorCacheBuilding() throws ExecutionException, InterruptedException {
|
||||
|
@ -16,23 +16,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
@AllFeatures
|
||||
public class PotionTest {
|
||||
@Test
|
||||
public void testEffectCompleteness() throws Throwable {
|
||||
Map<PotionType, String> effects = new EnumMap(PotionType.class);
|
||||
for (Potion reg : BuiltInRegistries.POTION) {
|
||||
List<MobEffectInstance> eff = reg.getEffects();
|
||||
if (eff.size() != 1) continue;
|
||||
PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(eff.get(0).getEffect());
|
||||
assertNotNull(type, String.valueOf(reg));
|
||||
|
||||
PotionType enumType = PotionType.getByEffect(type);
|
||||
assertNotNull(enumType, type.getName());
|
||||
|
||||
effects.put(enumType, enumType.name());
|
||||
}
|
||||
|
||||
assertEquals(PotionType.values().length - /* PotionTypes with no/shared Effects */ (5 + 22 /* There are 22 new strong / long potion types */), effects.entrySet().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEffectType() {
|
||||
@ -42,7 +25,6 @@ public class PotionTest {
|
||||
PotionEffectType bukkit = CraftPotionEffectType.minecraftToBukkit(nms);
|
||||
|
||||
assertNotNull(bukkit, "No Bukkit type for " + key);
|
||||
assertFalse(bukkit.getName().contains("UNKNOWN"), "No name for " + key);
|
||||
|
||||
PotionEffectType byName = FieldRename.getByName_PotionEffectType(bukkit.getName());
|
||||
assertEquals(bukkit, byName, "Same type not returned by name " + key);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.bukkit.support.extension;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
@ -17,7 +15,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
public class AllFeaturesExtension extends BaseExtension {
|
||||
|
||||
private static final Map<Class<? extends Keyed>, Registry<?>> realRegistries = new HashMap<>();
|
||||
private static final Map<Class<? extends Keyed>, Registry<?>> spyRegistries = new HashMap<>();
|
||||
|
||||
public AllFeaturesExtension() {
|
||||
super("AllFeatures");
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.bukkit.support.extension;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.support.DummyServerHelper;
|
||||
@ -16,8 +10,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
public class LegacyExtension extends BaseExtension {
|
||||
|
||||
private static final Map<Class<? extends Keyed>, Registry<?>> registries = new HashMap<>();
|
||||
|
||||
public LegacyExtension() {
|
||||
super("Legacy");
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.bukkit.support.extension;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.support.DummyServerHelper;
|
||||
@ -16,8 +10,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
public class SlowExtension extends BaseExtension {
|
||||
|
||||
private static final Map<Class<? extends Keyed>, Registry<?>> registries = new HashMap<>();
|
||||
|
||||
public SlowExtension() {
|
||||
super("Slow");
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.bukkit.support.extension;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.support.DummyServerHelper;
|
||||
@ -16,8 +10,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
public class VanillaFeatureExtension extends BaseExtension {
|
||||
|
||||
private static final Map<Class<? extends Keyed>, Registry<?>> registries = new HashMap<>();
|
||||
|
||||
public VanillaFeatureExtension() {
|
||||
super("VanillaFeature");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user