fix(heights): support Purpur 26.3
This commit is contained in:
1 parent
a6c80e7ac9
commit
68d4a854c3
9 files changed
+140
-49
No files matched your search
@@ -15,9 +15,10 @@ import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import io.papermc.paper.plugin.manager.PaperPluginManagerImpl;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.item.alchemy.PotionBrewing;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -25,10 +26,11 @@ import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.craftbukkit.inventory.CraftBrewingRecipe;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemFactory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -55,12 +57,12 @@ import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
/** Real 2618 brewing ticks, items, metadata, recipes, event dispatch and ingredient consumption. */
|
||||
/** Real build-2651 brewing ticks, items, metadata, recipes, event dispatch and ingredient consumption. */
|
||||
class NativeBrewingTest {
|
||||
private static PluginManager events;
|
||||
private static Plugin plugin;
|
||||
private PotionRecipes recipes;
|
||||
private PotionBrewing engine;
|
||||
private RecipeManager engine;
|
||||
|
||||
@BeforeAll
|
||||
static void bootstrap() throws Exception {
|
||||
@@ -70,8 +72,8 @@ class NativeBrewingTest {
|
||||
when(server.getUnsafe()).thenReturn(CraftMagicNumbers.INSTANCE);
|
||||
when(server.getLogger()).thenReturn(Logger.getLogger("NativeBrewingTest"));
|
||||
when(server.getName()).thenReturn("NativeBrewingTest");
|
||||
when(server.getVersion()).thenReturn("26.2-2618");
|
||||
when(server.getBukkitVersion()).thenReturn("26.2-2618");
|
||||
when(server.getVersion()).thenReturn("26.3-2651");
|
||||
when(server.getBukkitVersion()).thenReturn("26.3-2651");
|
||||
when(server.isPrimaryThread()).thenReturn(true);
|
||||
events = new PaperPluginManagerImpl(server, new SimpleCommandMap(server, new HashMap<>()), null);
|
||||
when(server.getPluginManager()).thenReturn(events);
|
||||
@@ -88,13 +90,23 @@ class NativeBrewingTest {
|
||||
@BeforeEach
|
||||
void registerActualRecipesAndListener() {
|
||||
HandlerList.unregisterAll();
|
||||
engine = PotionBrewing.bootstrap(FeatureFlags.VANILLA_SET);
|
||||
engine = NativeRuntime.recipes();
|
||||
recipes = new PotionRecipes(null, new NamespacedKey("spigotheights", "stature_potion"), ItemStack::new);
|
||||
PotionBrewer brewer = (PotionBrewer) Proxy.newProxyInstance(PotionBrewer.class.getClassLoader(),
|
||||
new Class<?>[] {PotionBrewer.class}, (proxy, method, args) -> {
|
||||
switch (method.getName()) {
|
||||
case "addPotionMix" -> engine.addPotionMix((io.papermc.paper.potion.PotionMix) args[0]);
|
||||
case "removePotionMix" -> engine.removePotionMix((NamespacedKey) args[0]);
|
||||
case "addPotionMix" -> {
|
||||
var mix = (io.papermc.paper.potion.PotionMix) args[0];
|
||||
var recipe = new org.bukkit.inventory.BrewingRecipe(
|
||||
mix.getKey(), mix.getResult(), mix.getInput(), mix.getIngredient());
|
||||
engine.recipes.addRecipe(CraftBrewingRecipe.fromBukkitRecipe(recipe).toMinecraftRecipe());
|
||||
engine.finalizeRecipeLoading(FeatureFlags.VANILLA_SET);
|
||||
}
|
||||
case "removePotionMix" -> {
|
||||
engine.recipes.removeRecipe(CraftNamespacedKey.toResourceKey(
|
||||
Registries.RECIPE, (NamespacedKey) args[0]));
|
||||
engine.finalizeRecipeLoading(FeatureFlags.VANILLA_SET);
|
||||
}
|
||||
default -> throw new UnsupportedOperationException(method.getName());
|
||||
}
|
||||
return null;
|
||||
@@ -103,6 +115,20 @@ class NativeBrewingTest {
|
||||
events.registerEvents(new StatureBrewing(recipes), plugin);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(StaturePotion.class)
|
||||
void purpur26_3ConvertsBaseLessStaturePotionsWithoutTheBuild2618Correction(StaturePotion kind) {
|
||||
HandlerList.unregisterAll();
|
||||
NativeStand stand = new NativeStand();
|
||||
stand.inventory.setItem(0, recipes.create(kind));
|
||||
stand.inventory.setIngredient(new ItemStack(Material.GUNPOWDER));
|
||||
stand.completeCycle();
|
||||
ItemStack result = stand.inventory.getItem(0);
|
||||
assertEquals(Material.SPLASH_POTION, result.getType());
|
||||
assertEquals(kind, recipes.identify(result));
|
||||
assertTrue(stand.getItem(3).isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(StaturePotion.class)
|
||||
void gunpowderActuallyConvertsEveryAuthenticatedDrinkable(StaturePotion kind) {
|
||||
@@ -127,7 +153,8 @@ class NativeBrewingTest {
|
||||
ItemStack result = stand.inventory.getItem(0);
|
||||
assertEquals(Material.LINGERING_POTION, result.getType());
|
||||
assertEquals(kind, recipes.identify(result));
|
||||
assertTrue(stand.getItem(3).isEmpty(), "one successful conversion spends one dragon's breath");
|
||||
assertEquals(new ItemStack(Material.GLASS_BOTTLE), stand.inventory.getIngredient(),
|
||||
"one successful conversion spends one dragon's breath and retains its bottle");
|
||||
assertLingeringApplies(result, kind);
|
||||
}
|
||||
|
||||
@@ -143,7 +170,7 @@ class NativeBrewingTest {
|
||||
stand.completeCycle();
|
||||
assertEquals(Material.LINGERING_POTION, stand.inventory.getItem(0).getType());
|
||||
assertEquals(kind, recipes.identify(stand.inventory.getItem(0)));
|
||||
assertTrue(stand.getItem(3).isEmpty());
|
||||
assertEquals(new ItemStack(Material.GLASS_BOTTLE), stand.inventory.getIngredient());
|
||||
assertEquals(18, stand.fuel);
|
||||
}
|
||||
|
||||
@@ -271,7 +298,8 @@ class NativeBrewingTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("conversionEdits")
|
||||
void inPlaceResultEditsCannotMutateInputOrBypassIngredientSafety(Material ingredient, boolean removeIdentity) {
|
||||
void nativeResultEditsRemainDetachedAndIdentityRemovalCannotSpendIngredients(
|
||||
Material ingredient, boolean removeIdentity) {
|
||||
events.registerEvent(BrewEvent.class, new Listener() {}, EventPriority.NORMAL, (listener, event) -> {
|
||||
ItemStack result = ((BrewEvent) event).getResults().get(0);
|
||||
result.editMeta(meta -> {
|
||||
@@ -288,13 +316,27 @@ class NativeBrewingTest {
|
||||
stand.inventory.setItem(0, original);
|
||||
stand.inventory.setIngredient(new ItemStack(ingredient));
|
||||
stand.completeCycle();
|
||||
assertEquals(new ItemStack(ingredient), stand.inventory.getIngredient(),
|
||||
"in-place output conflicts cannot spend ingredients");
|
||||
assertEquals(original, stand.inventory.getItem(0), "cancelled result edits must not mutate the input inventory");
|
||||
if (removeIdentity) {
|
||||
assertEquals(new ItemStack(ingredient), stand.inventory.getIngredient(),
|
||||
"identity removal cannot spend ingredients");
|
||||
assertEquals(original, stand.inventory.getItem(0),
|
||||
"cancelled identity removal must not mutate the input inventory");
|
||||
} else {
|
||||
assertEquals(ingredient == Material.GUNPOWDER ? null : new ItemStack(Material.GLASS_BOTTLE),
|
||||
stand.inventory.getIngredient());
|
||||
ItemStack result = stand.inventory.getItem(0);
|
||||
assertEquals(ingredient == Material.GUNPOWDER ? Material.SPLASH_POTION : Material.LINGERING_POTION,
|
||||
result.getType());
|
||||
assertEquals(StaturePotion.GROWTH, recipes.identify(result));
|
||||
assertEquals(net.kyori.adventure.text.Component.text("Other plugin's conflicting edit"),
|
||||
result.getItemMeta().displayName());
|
||||
assertEquals(StaturePotion.GROWTH, recipes.identify(original),
|
||||
"native result edits must stay detached from the input object");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void resultConstructionFailureDoesNotSpendTheIngredient() {
|
||||
void purpur26_3NativeOutputDoesNotNeedTheCorrectionFactory() {
|
||||
HandlerList.unregisterAll();
|
||||
PotionRecipes brokenFactory = new PotionRecipes(null, new NamespacedKey("spigotheights", "stature_potion"),
|
||||
material -> { throw new IllegalStateException("simulated item factory failure"); });
|
||||
@@ -304,8 +346,9 @@ class NativeBrewingTest {
|
||||
stand.inventory.setItem(0, original);
|
||||
stand.inventory.setIngredient(new ItemStack(Material.GUNPOWDER));
|
||||
stand.completeCycle();
|
||||
assertEquals(original, stand.inventory.getItem(0));
|
||||
assertEquals(new ItemStack(Material.GUNPOWDER), stand.inventory.getIngredient());
|
||||
assertEquals(Material.SPLASH_POTION, stand.inventory.getItem(0).getType());
|
||||
assertEquals(StaturePotion.GROWTH, recipes.identify(stand.inventory.getItem(0)));
|
||||
assertTrue(stand.getItem(3).isEmpty());
|
||||
}
|
||||
|
||||
private void assertSplashApplies(ItemStack result, StaturePotion expected) {
|
||||
@@ -354,11 +397,11 @@ class NativeBrewingTest {
|
||||
|
||||
private final class NativeStand extends BrewingStandBlockEntity {
|
||||
private final CraftInventoryBrewer inventory = new CraftInventoryBrewer(this);
|
||||
private final Level level = mock(Level.class);
|
||||
private final ServerLevel level = mock(ServerLevel.class);
|
||||
|
||||
NativeStand() {
|
||||
super(BlockPos.ZERO, Blocks.BREWING_STAND.defaultBlockState());
|
||||
when(level.potionBrewing()).thenReturn(engine);
|
||||
when(level.recipeAccess()).thenReturn(engine);
|
||||
fuel = 20;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
/** Actual Purpur 2618 listener discovery, distinct handler lists and Paper event dispatch.
|
||||
/** Actual Purpur build-2651 listener discovery, distinct handler lists and Paper event dispatch.
|
||||
* Only server/player boundaries are doubled; no listening server or client packets. */
|
||||
class NativeCarryRoutingTest {
|
||||
private static Server previousServer;
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.server.permissions.LevelBasedPermissionSet;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraft.world.level.WorldDataConfiguration;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
@@ -28,6 +29,7 @@ import org.bukkit.craftbukkit.CraftRegistry;
|
||||
/** Loads vanilla registries/tags/components using the same path as the server's own tests. */
|
||||
final class NativeRuntime {
|
||||
private static boolean bootstrapped;
|
||||
private static RecipeManager recipes;
|
||||
|
||||
private NativeRuntime() {}
|
||||
|
||||
@@ -44,12 +46,12 @@ final class NativeRuntime {
|
||||
try (var resources = new MultiPackResourceManager(PackType.SERVER_DATA, packs.openAllSelected())) {
|
||||
LayeredRegistryAccess<RegistryLayer> layers = RegistryLayer.createRegistryAccess();
|
||||
List<Registry.PendingTags<?>> tags = TagLoader.loadTagsForExistingRegistries(resources, layers.getLayer(RegistryLayer.STATIC));
|
||||
List<HolderLookup.RegistryLookup<?>> lookups = TagLoader.buildUpdatedLookups(layers.getAccessForLoading(RegistryLayer.WORLDGEN), tags);
|
||||
RegistryAccess.Frozen worldgen = RegistryDataLoader.load(resources, lookups,
|
||||
RegistryDataLoader.WORLDGEN_REGISTRIES, Util.backgroundExecutor()).join();
|
||||
layers = layers.replaceFrom(RegistryLayer.WORLDGEN, worldgen);
|
||||
List<HolderLookup.RegistryLookup<?>> lookups = TagLoader.buildUpdatedLookups(layers.getAccessForLoading(RegistryLayer.WORLD), tags);
|
||||
RegistryAccess.Frozen world = RegistryDataLoader.load(resources, lookups,
|
||||
RegistryDataLoader.WORLD_REGISTRIES, Util.backgroundExecutor()).join();
|
||||
layers = layers.replaceFrom(RegistryLayer.WORLD, world);
|
||||
RegistryAccess.Frozen dimensions = RegistryDataLoader.load(resources,
|
||||
Stream.concat(lookups.stream(), worldgen.listRegistries()).toList(),
|
||||
Stream.concat(lookups.stream(), world.listRegistries()).toList(),
|
||||
RegistryDataLoader.DIMENSION_REGISTRIES, Util.backgroundExecutor()).join();
|
||||
layers = layers.replaceFrom(RegistryLayer.DIMENSIONS, dimensions);
|
||||
Class.forName(org.bukkit.Registry.class.getName());
|
||||
@@ -58,7 +60,16 @@ final class NativeRuntime {
|
||||
Util.backgroundExecutor(), Runnable::run).join();
|
||||
datapack.updateComponentsAndStaticRegistryTags();
|
||||
CraftRegistry.setMinecraftRegistry(layers.compositeAccess().freeze());
|
||||
recipes = datapack.getRecipeManager();
|
||||
recipes.finalizeRecipeLoading(flags);
|
||||
bootstrapped = true;
|
||||
}
|
||||
}
|
||||
|
||||
static RecipeManager recipes() {
|
||||
if (!bootstrapped) {
|
||||
throw new IllegalStateException("Native runtime has not been bootstrapped");
|
||||
}
|
||||
return recipes;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user