1.21.6 dev
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
This commit is contained in:
committed by
Nassim Jahnke
parent
39203a65e0
commit
a24f9b204c
@@ -0,0 +1,38 @@
|
||||
package io.papermc.paper.contract;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.InsideBlockEffectApplier.StepBasedCollector;
|
||||
import net.minecraft.world.entity.InsideBlockEffectType;
|
||||
import net.minecraft.world.entity.animal.Pig;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* Simple test ensuring that the {@link StepBasedCollector} executes calls to {@link StepBasedCollector#runBefore(InsideBlockEffectType, Consumer)}
|
||||
* even if the effect is never registered.
|
||||
* <p>
|
||||
* Paper relies on this implementation detail to perform some events, specifically
|
||||
* - net.minecraft.world.level.block.LayeredCauldronBlock#entityInside
|
||||
*/
|
||||
@AllFeatures
|
||||
public class StepBasedCollectorRunBeforeTest {
|
||||
|
||||
@Test
|
||||
public void testExecuteRunBeforeWithoutEffect() {
|
||||
final StepBasedCollector stepBasedCollector = new StepBasedCollector();
|
||||
final AtomicBoolean triggered = new AtomicBoolean(false);
|
||||
final Entity entity = Mockito.mock(Entity.class);
|
||||
Mockito.when(entity.isAlive()).thenReturn(true);
|
||||
|
||||
stepBasedCollector.runBefore(InsideBlockEffectType.EXTINGUISH, e -> triggered.set(true));
|
||||
stepBasedCollector.applyAndClear(entity);
|
||||
|
||||
Assertions.assertTrue(triggered.get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import io.papermc.paper.registry.entry.RegistryEntryMeta;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.support.RegistryHelper;
|
||||
@@ -32,7 +31,7 @@ class RegistryBuilderTest {
|
||||
<M, T extends Keyed> void testEquality(final RegistryEntryMeta.Buildable<M, T, ?> registryEntry) { // TODO remove Keyed
|
||||
final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(registryEntry.mcKey());
|
||||
for (final Map.Entry<ResourceKey<M>, M> entry : registry.entrySet()) {
|
||||
final M built = registryEntry.builderFiller().fill(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), entry.getValue()).build();
|
||||
final M built = registryEntry.builderFiller().fill(Conversions.global(), entry.getValue()).build();
|
||||
assertEquals(entry.getValue(), built);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class ParticleTest {
|
||||
}
|
||||
|
||||
private <T extends ParticleOptions> void testVibration(Particle bukkit, net.minecraft.core.particles.ParticleType<T> minecraft) {
|
||||
Vibration vibration = new Vibration(new Location(null, 3, 1, 4), new Vibration.Destination.BlockDestination(new Location(null, 1, 5, 9)), 265);
|
||||
Vibration vibration = new Vibration(new Vibration.Destination.BlockDestination(new Location(null, 1, 5, 9)), 265);
|
||||
VibrationParticleOption param = this.createAndTest(bukkit, minecraft, vibration, VibrationParticleOption.class);
|
||||
|
||||
assertEquals(265, param.getArrivalInTicks(), String.format("""
|
||||
|
||||
@@ -12,6 +12,8 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.StandingAndWallBlockItem;
|
||||
import net.minecraft.world.level.block.AbstractBannerBlock;
|
||||
import net.minecraft.world.level.block.AbstractSkullBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -174,9 +176,8 @@ public class ItemMetaTest {
|
||||
if (block != null) {
|
||||
ItemStack stack = CraftItemStack.asNewCraftStack(Item.byBlock(block));
|
||||
|
||||
// Command blocks aren't unit testable atm
|
||||
if (stack.getType() == Material.COMMAND_BLOCK || stack.getType() == Material.CHAIN_COMMAND_BLOCK || stack.getType() == Material.REPEATING_COMMAND_BLOCK) {
|
||||
return;
|
||||
if (block instanceof AbstractSkullBlock || block instanceof AbstractBannerBlock) {
|
||||
continue; // those blocks have a special meta
|
||||
}
|
||||
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
|
||||
@@ -94,8 +94,8 @@ public class YamlSerializationTest {
|
||||
count: 1
|
||||
components:
|
||||
minecraft:unbreakable: '{}'
|
||||
minecraft:enchantments: '{"minecraft:sharpness":2}'
|
||||
minecraft:tooltip_display: '{hidden_components:["minecraft:enchantments","minecraft:unbreakable"]}'
|
||||
minecraft:enchantments: '{"minecraft:sharpness":2}'
|
||||
schema_version: 1
|
||||
""".formatted(Bukkit.getUnsafe().getDataVersion()));
|
||||
}
|
||||
|
||||
@@ -137,6 +137,10 @@ public class LegacyTest {
|
||||
Material.RESIN_BRICK, Material.POTTED_OPEN_EYEBLOSSOM, Material.POTTED_CLOSED_EYEBLOSSOM,
|
||||
// 1.21.5
|
||||
Material.WILDFLOWERS, Material.LEAF_LITTER, Material.TEST_BLOCK, Material.TEST_INSTANCE_BLOCK, Material.BUSH, Material.FIREFLY_BUSH, Material.SHORT_DRY_GRASS, Material.TALL_DRY_GRASS, Material.CACTUS_FLOWER, Material.BLUE_EGG, Material.BROWN_EGG,
|
||||
// 1.21.6
|
||||
Material.BLACK_HARNESS, Material.BLUE_HARNESS, Material.BROWN_HARNESS, Material.CYAN_HARNESS, Material.DRIED_GHAST, Material.GRAY_HARNESS, Material.GREEN_HARNESS, Material.HAPPY_GHAST_SPAWN_EGG, Material.LIGHT_BLUE_HARNESS, Material.LIGHT_GRAY_HARNESS,
|
||||
Material.LIME_HARNESS, Material.MAGENTA_HARNESS, Material.ORANGE_HARNESS, Material.PINK_HARNESS, Material.PURPLE_HARNESS, Material.RED_HARNESS, Material.WHITE_HARNESS, Material.YELLOW_HARNESS,
|
||||
Material.MUSIC_DISC_TEARS,
|
||||
//
|
||||
Material.LEGACY_AIR, Material.LEGACY_DEAD_BUSH, Material.LEGACY_BURNING_FURNACE, Material.LEGACY_WALL_SIGN, Material.LEGACY_REDSTONE_TORCH_OFF, Material.LEGACY_SKULL, Material.LEGACY_REDSTONE_COMPARATOR_ON, Material.LEGACY_WALL_BANNER, Material.LEGACY_MONSTER_EGG));
|
||||
|
||||
|
||||
@@ -69,9 +69,9 @@ public class ApiVersionTest {
|
||||
public void testCurrentVersionUpdated() {
|
||||
ApiVersion apiVersionOne = null;
|
||||
try {
|
||||
apiVersionOne = ApiVersion.getOrCreateVersion(SharedConstants.getCurrentVersion().getName());
|
||||
apiVersionOne = ApiVersion.getOrCreateVersion(SharedConstants.getCurrentVersion().name());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
if (!SharedConstants.getCurrentVersion().isStable()) {
|
||||
if (!SharedConstants.getCurrentVersion().stable()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.registry;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -9,12 +10,12 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.support.environment.AllFeatures;
|
||||
import org.bukkit.support.provider.RegistryArgumentProvider;
|
||||
import org.bukkit.support.test.RegistriesTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
@@ -43,6 +44,12 @@ public class RegistryConversionTest {
|
||||
|
||||
private static final Set<Class<? extends Keyed>> IMPLEMENT_HANDLE_ABLE = new HashSet<>();
|
||||
|
||||
public static Stream<? extends Arguments> getValues(RegistryKey<? extends Keyed> registryType) { // Paper
|
||||
Registry<?> registry = RegistryAccess.registryAccess().getRegistry(registryType); // Paper
|
||||
return registry.stream().map(keyed -> (Handleable<?>) keyed)
|
||||
.map(handleAble -> Arguments.of(handleAble, handleAble.getHandle()));
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@RegistriesTest
|
||||
public void testHandleableImplementation(io.papermc.paper.registry.RegistryKey<? extends Keyed> type, Class<? extends Keyed> clazz) { // Paper
|
||||
@@ -210,7 +217,7 @@ public class RegistryConversionTest {
|
||||
Map<Object, Object> notMatching = new HashMap<>();
|
||||
Method method = RegistryConversionTest.MINECRAFT_TO_BUKKIT_METHODS.get(clazz);
|
||||
|
||||
RegistryArgumentProvider.getValues(type).map(Arguments::get).forEach(arguments -> { // Paper
|
||||
getValues(type).map(Arguments::get).forEach(arguments -> { // Paper
|
||||
Keyed bukkit = (Keyed) arguments[0];
|
||||
Object minecraft = arguments[1];
|
||||
|
||||
@@ -241,7 +248,7 @@ public class RegistryConversionTest {
|
||||
Map<Object, Object> notMatching = new HashMap<>();
|
||||
Method method = RegistryConversionTest.BUKKIT_TO_MINECRAFT_METHODS.get(clazz);
|
||||
|
||||
RegistryArgumentProvider.getValues(type).map(Arguments::get).forEach(arguments -> { // Paper
|
||||
getValues(type).map(Arguments::get).forEach(arguments -> { // Paper
|
||||
Keyed bukkit = (Keyed) arguments[0];
|
||||
Object minecraft = arguments[1];
|
||||
|
||||
@@ -263,7 +270,7 @@ public class RegistryConversionTest {
|
||||
Joiner.on('\n').withKeyValueSeparator(" got: ").join(notMatching)));
|
||||
}
|
||||
|
||||
static final Set<RegistryKey<?>> IGNORE_FOR_DIRECT_HOLDER = Set.of(RegistryKey.TRIM_MATERIAL, RegistryKey.TRIM_PATTERN, RegistryKey.INSTRUMENT, RegistryKey.PAINTING_VARIANT, RegistryKey.BANNER_PATTERN, RegistryKey.SOUND_EVENT); // Paper
|
||||
static final Set<RegistryKey<?>> IGNORE_FOR_DIRECT_HOLDER = Set.of(RegistryKey.TRIM_MATERIAL, RegistryKey.TRIM_PATTERN, RegistryKey.INSTRUMENT, RegistryKey.BANNER_PATTERN, RegistryKey.SOUND_EVENT); // Paper
|
||||
|
||||
/**
|
||||
* Minecraft registry can return a default key / value
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.bukkit.support.provider;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.support.test.RegistryTest;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider;
|
||||
import org.junit.jupiter.params.support.AnnotationConsumer;
|
||||
|
||||
public class RegistryArgumentProvider implements ArgumentsProvider, AnnotationConsumer<RegistryTest> {
|
||||
|
||||
private Class<? extends Keyed> registryType;
|
||||
|
||||
@Override
|
||||
public void accept(RegistryTest registryTest) {
|
||||
this.registryType = registryTest.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception {
|
||||
return RegistryArgumentProvider.getValues(io.papermc.paper.registry.PaperRegistryAccess.byType(this.registryType)); // Paper
|
||||
}
|
||||
|
||||
public static Stream<? extends Arguments> getValues(io.papermc.paper.registry.RegistryKey<? extends Keyed> registryType) { // Paper
|
||||
Registry<?> registry = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(registryType); // Paper
|
||||
return registry.stream().map(keyed -> (Handleable<?>) keyed)
|
||||
.map(handleAble -> Arguments.of(handleAble, handleAble.getHandle()));
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.bukkit.support.test;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.support.provider.RegistryArgumentProvider;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ArgumentsSource(RegistryArgumentProvider.class)
|
||||
@ParameterizedTest
|
||||
public @interface RegistryTest {
|
||||
|
||||
Class<? extends Keyed> value();
|
||||
}
|
||||
Reference in New Issue
Block a user