Paper/patches/server/0803-Custom-Potion-Mixes.patch
Nassim Jahnke efd47e3a68
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188)
* Updated Upstream (Bukkit/CraftBukkit/Spigot)

Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe
c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor
201399fb PR-853: Add API for directly setting Display transformation matrices
ecfa559a PR-849: Add InventoryView#setTitle
653d7edb SPIGOT-519: Add TNTPrimeEvent
22fccc09 PR-846: Add method to get chunk load level
a070a52c PR-844: Add methods to convert Vector to and from JOML vectors
cc7111fe PR-276: Add accessors to Wither's invulnerability ticks
777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown
ccb2d01b SPIGOT-6308: Deprecate the location name property of map items
cd04a31b PR-780: Add PlayerSpawnChangeEvent
7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock
5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments
2e13cff7 PR-589: Expand the FishHook API
2c7d3da5 PR-279: Minor edits to various Javadocs

CraftBukkit Changes:
01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting
7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor
bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices
a7cfc778f PR-1176: Add InventoryView#setTitle
563d42226 SPIGOT-519: Add TNTPrimeEvent
ccbc6abca Add test for Chunk.LoadLevel mirroring
2926e0513 PR-1171: Add method to get chunk load level
63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks
bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown
f92a41c39 PR-1181: Consolidate Location conversion code
10f866759 SPIGOT-6308: Deprecate the location name property of map items
82f7b658a PR-1095: Add PlayerSpawnChangeEvent
b421af7e4 PR-808: Expand the FishHook API
598ad7b3f Increase outdated build delay

Spigot Changes:
d1bd3bd2 Rebuild patches
e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities

* Work around javac bug

* Call PlayerSpawnChangeEvent

* Updated Upstream (Bukkit/CraftBukkit/Spigot)

Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe
c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor
201399fb PR-853: Add API for directly setting Display transformation matrices

CraftBukkit Changes:
01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting
7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor
bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices

Spigot Changes:
7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00

240 lines
12 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 7 Oct 2021 14:34:55 -0700
Subject: [PATCH] Custom Potion Mixes
diff --git a/src/main/java/io/papermc/paper/potion/PaperPotionMix.java b/src/main/java/io/papermc/paper/potion/PaperPotionMix.java
new file mode 100644
index 0000000000000000000000000000000000000000..6b0bed550763f34e18c9e92f9a47ec0c945b2c8b
--- /dev/null
+++ b/src/main/java/io/papermc/paper/potion/PaperPotionMix.java
@@ -0,0 +1,13 @@
+package io.papermc.paper.potion;
+
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.crafting.Ingredient;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+
+public record PaperPotionMix(ItemStack result, Ingredient input, Ingredient ingredient) {
+
+ public PaperPotionMix(PotionMix potionMix) {
+ this(CraftItemStack.asNMSCopy(potionMix.getResult()), CraftRecipe.toIngredient(potionMix.getInput(), true), CraftRecipe.toIngredient(potionMix.getIngredient(), true));
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index a30c61e176501d1cbd2e330f85d5d258cc030180..3e59620c84b3aa93d8ce41b0e9901a1621bb48df 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -2059,6 +2059,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.worldData.setDataConfiguration(worlddataconfiguration);
this.resources.managers.updateRegistryTags(this.registryAccess());
+ net.minecraft.world.item.alchemy.PotionBrewing.reload(); // Paper
// Paper start
if (Thread.currentThread() != this.serverThread) {
return;
diff --git a/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java b/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java
index 9fe5a680c0ad5624cebcd61fd8812e88d29fc209..6f5246f3cfc6b6757fad2a634299921df9d10223 100644
--- a/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java
@@ -168,7 +168,7 @@ public class BrewingStandMenu extends AbstractContainerMenu {
}
public static boolean mayPlaceItem(ItemStack stack) {
- return stack.is(Items.POTION) || stack.is(Items.SPLASH_POTION) || stack.is(Items.LINGERING_POTION) || stack.is(Items.GLASS_BOTTLE);
+ return stack.is(Items.POTION) || stack.is(Items.SPLASH_POTION) || stack.is(Items.LINGERING_POTION) || stack.is(Items.GLASS_BOTTLE) || PotionBrewing.isCustomInput(stack); // Paper
}
}
diff --git a/src/main/java/net/minecraft/world/item/alchemy/PotionBrewing.java b/src/main/java/net/minecraft/world/item/alchemy/PotionBrewing.java
index 421c2131fec0b7266c773c3f1983308f6921df6b..12d9556a11ac4ef2e7a62fcd2686d868904bc010 100644
--- a/src/main/java/net/minecraft/world/item/alchemy/PotionBrewing.java
+++ b/src/main/java/net/minecraft/world/item/alchemy/PotionBrewing.java
@@ -14,6 +14,7 @@ public class PotionBrewing {
public static final int BREWING_TIME_SECONDS = 20;
private static final List<PotionBrewing.Mix<Potion>> POTION_MIXES = Lists.newArrayList();
private static final List<PotionBrewing.Mix<Item>> CONTAINER_MIXES = Lists.newArrayList();
+ private static final it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<org.bukkit.NamespacedKey, io.papermc.paper.potion.PaperPotionMix> CUSTOM_MIXES = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>(); // Paper
private static final List<Ingredient> ALLOWED_CONTAINERS = Lists.newArrayList();
private static final Predicate<ItemStack> ALLOWED_CONTAINER = (stack) -> {
for(Ingredient ingredient : ALLOWED_CONTAINERS) {
@@ -26,7 +27,7 @@ public class PotionBrewing {
};
public static boolean isIngredient(ItemStack stack) {
- return isContainerIngredient(stack) || isPotionIngredient(stack);
+ return isContainerIngredient(stack) || isPotionIngredient(stack) || isCustomIngredient(stack); // Paper
}
protected static boolean isContainerIngredient(ItemStack stack) {
@@ -66,6 +67,11 @@ public class PotionBrewing {
}
public static boolean hasMix(ItemStack input, ItemStack ingredient) {
+ // Paper start
+ if (hasCustomMix(input, ingredient)) {
+ return true;
+ }
+ // Paper end
if (!ALLOWED_CONTAINER.test(input)) {
return false;
} else {
@@ -103,6 +109,13 @@ public class PotionBrewing {
public static ItemStack mix(ItemStack ingredient, ItemStack input) {
if (!input.isEmpty()) {
+ // Paper start
+ for (var mix : CUSTOM_MIXES.values()) {
+ if (mix.input().test(input) && mix.ingredient().test(ingredient)) {
+ return mix.result().copy();
+ }
+ }
+ // Paper end
Potion potion = PotionUtils.getPotion(input);
Item item = input.getItem();
int i = 0;
@@ -127,6 +140,54 @@ public class PotionBrewing {
return input;
}
+ // Paper start
+ public static boolean isCustomIngredient(ItemStack stack) {
+ for (var mix : CUSTOM_MIXES.values()) {
+ if (mix.ingredient().test(stack)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isCustomInput(ItemStack stack) {
+ for (var mix : CUSTOM_MIXES.values()) {
+ if (mix.input().test(stack)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean hasCustomMix(ItemStack input, ItemStack ingredient) {
+ for (var mix : CUSTOM_MIXES.values()) {
+ if (mix.input().test(input) && mix.ingredient().test(ingredient)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void addPotionMix(io.papermc.paper.potion.PotionMix mix) {
+ if (CUSTOM_MIXES.containsKey(mix.getKey())) {
+ throw new IllegalArgumentException("Duplicate recipe ignored with ID " + mix.getKey());
+ }
+ CUSTOM_MIXES.putAndMoveToFirst(mix.getKey(), new io.papermc.paper.potion.PaperPotionMix(mix));
+ }
+
+ public static boolean removePotionMix(org.bukkit.NamespacedKey key) {
+ return CUSTOM_MIXES.remove(key) != null;
+ }
+
+ public static void reload() {
+ POTION_MIXES.clear();
+ CONTAINER_MIXES.clear();
+ ALLOWED_CONTAINERS.clear();
+ CUSTOM_MIXES.clear();
+ bootStrap();
+ }
+ // Paper end
+
public static void bootStrap() {
addContainer(Items.POTION);
addContainer(Items.SPLASH_POTION);
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
index 424406d2692856cfd82b6f3b7b6228fa3bd20c2f..c57efcb9a79337ec791e4e8f6671612f0a82b441 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
@@ -341,7 +341,7 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
@Override
public boolean canPlaceItem(int slot, ItemStack stack) {
- return slot == 3 ? PotionBrewing.isIngredient(stack) : (slot == 4 ? stack.is(Items.BLAZE_POWDER) : (stack.is(Items.POTION) || stack.is(Items.SPLASH_POTION) || stack.is(Items.LINGERING_POTION) || stack.is(Items.GLASS_BOTTLE)) && this.getItem(slot).isEmpty());
+ return slot == 3 ? PotionBrewing.isIngredient(stack) : (slot == 4 ? stack.is(Items.BLAZE_POWDER) : (stack.is(Items.POTION) || stack.is(Items.SPLASH_POTION) || stack.is(Items.LINGERING_POTION) || stack.is(Items.GLASS_BOTTLE) || PotionBrewing.isCustomInput(stack)) && this.getItem(slot).isEmpty()); // Paper
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 4736b0f3ac468be99a42b5c0e62cffbbe2149610..fc088b26c3fab1afcfbcacfd19dc8a3b6111e94c 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -295,6 +295,7 @@ public final class CraftServer implements Server {
private final io.papermc.paper.datapack.PaperDatapackManager datapackManager; // Paper
public static Exception excessiveVelEx; // Paper - Velocity warnings
private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher(); // Paper
+ private final CraftPotionBrewer potionBrewer = new CraftPotionBrewer(); // Paper
static {
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
@@ -321,7 +322,7 @@ public final class CraftServer implements Server {
Enchantments.SHARPNESS.getClass();
org.bukkit.enchantments.Enchantment.stopAcceptingRegistrations();
- Potion.setPotionBrewer(new CraftPotionBrewer());
+ Potion.setPotionBrewer(potionBrewer); // Paper
MobEffects.BLINDNESS.getClass();
PotionEffectType.stopAcceptingRegistrations();
// Ugly hack :(
@@ -2901,5 +2902,10 @@ public final class CraftServer implements Server {
return datapackManager;
}
+ @Override
+ public CraftPotionBrewer getPotionBrewer() {
+ return this.potionBrewer;
+ }
+
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
index 4d17fa834c0bb602fa104e660a8e7fbe5a02f0a4..8563fcf77eef0e1e354857b9a4256d78a523a8d0 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
@@ -15,6 +15,11 @@ public interface CraftRecipe extends Recipe {
void addToCraftingManager();
default Ingredient toNMS(RecipeChoice bukkit, boolean requireNotEmpty) {
+ // Paper start
+ return toIngredient(bukkit, requireNotEmpty);
+ }
+ static Ingredient toIngredient(RecipeChoice bukkit, boolean requireNotEmpty) {
+ // Paper end
Ingredient stack;
if (bukkit == null) {
diff --git a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java
index 8fdc9a3bb2f1b6bdc6c2c96f8ade7e9cd88ea4e0..a0b0c64b819b8f713eeea78210e276664e30e66e 100644
--- a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java
+++ b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java
@@ -49,4 +49,21 @@ public class CraftPotionBrewer implements PotionBrewer {
public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier) {
return new PotionEffect(potion, potion.isInstant() ? 1 : (int) (duration * potion.getDurationModifier()), amplifier);
}
+
+ // Paper start
+ @Override
+ public void addPotionMix(io.papermc.paper.potion.PotionMix potionMix) {
+ net.minecraft.world.item.alchemy.PotionBrewing.addPotionMix(potionMix);
+ }
+
+ @Override
+ public void removePotionMix(org.bukkit.NamespacedKey key) {
+ net.minecraft.world.item.alchemy.PotionBrewing.removePotionMix(key);
+ }
+
+ @Override
+ public void resetPotionMixes() {
+ net.minecraft.world.item.alchemy.PotionBrewing.reload();
+ }
+ // Paper end
}