Custom Potion Mixes

== AT ==
public-f net.minecraft.server.MinecraftServer potionBrewing
This commit is contained in:
Jake Potrebic
2021-10-07 14:34:55 -07:00
parent 299d7beee0
commit 0b5d7ad8d6
8 changed files with 286 additions and 34 deletions

View File

@@ -0,0 +1,56 @@
package io.papermc.paper.potion;
import com.google.common.base.Preconditions;
import java.util.Collection;
import net.minecraft.server.MinecraftServer;
import org.bukkit.NamespacedKey;
import org.bukkit.potion.PotionBrewer;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class PaperPotionBrewer implements PotionBrewer {
private final MinecraftServer minecraftServer;
public PaperPotionBrewer(final MinecraftServer minecraftServer) {
this.minecraftServer = minecraftServer;
}
@Override
@Deprecated(forRemoval = true)
public Collection<PotionEffect> getEffects(PotionType type, boolean upgraded, boolean extended) {
final org.bukkit.NamespacedKey key = type.getKey();
Preconditions.checkArgument(!key.getKey().startsWith("strong_"), "Strong potion type cannot be used directly, got %s", key);
Preconditions.checkArgument(!key.getKey().startsWith("long_"), "Extended potion type cannot be used directly, got %s", key);
org.bukkit.NamespacedKey effectiveKey = key;
if (upgraded) {
effectiveKey = new org.bukkit.NamespacedKey(key.namespace(), "strong_" + key.key());
} else if (extended) {
effectiveKey = new org.bukkit.NamespacedKey(key.namespace(), "long_" + key.key());
}
final org.bukkit.potion.PotionType effectivePotionType = org.bukkit.Registry.POTION.get(effectiveKey);
Preconditions.checkNotNull(type, "Unknown potion type from data " + effectiveKey.asMinimalString()); // Legacy error message in 1.20.4
return effectivePotionType.getPotionEffects();
}
@Override
public void addPotionMix(final PotionMix potionMix) {
this.minecraftServer.potionBrewing().addPotionMix(potionMix);
}
@Override
public void removePotionMix(final NamespacedKey key) {
this.minecraftServer.potionBrewing.removePotionMix(key);
}
@Override
public void resetPotionMixes() {
this.minecraftServer.potionBrewing = this.minecraftServer.potionBrewing().reload(this.minecraftServer.getWorldData().enabledFeatures());
}
}

View File

@@ -0,0 +1,21 @@
package io.papermc.paper.potion;
import java.util.function.Predicate;
import net.minecraft.world.item.ItemStack;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftRecipe;
import org.bukkit.inventory.RecipeChoice;
public record PaperPotionMix(ItemStack result, Predicate<ItemStack> input, Predicate<ItemStack> ingredient) {
public PaperPotionMix(PotionMix potionMix) {
this(CraftItemStack.asNMSCopy(potionMix.getResult()), convert(potionMix.getInput()), convert(potionMix.getIngredient()));
}
static Predicate<ItemStack> convert(final RecipeChoice choice) {
if (choice instanceof PredicateRecipeChoice predicateRecipeChoice) {
return stack -> predicateRecipeChoice.test(CraftItemStack.asBukkitCopy(stack));
}
return CraftRecipe.toIngredient(choice, true);
}
}

View File

@@ -311,6 +311,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 io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes
static {
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
@@ -394,6 +395,7 @@ public final class CraftServer implements Server {
if (this.configuration.getBoolean("settings.use-map-color-cache")) {
MapPalette.setMapColorCache(new CraftMapColorCache(this.logger));
}
this.potionBrewer = new io.papermc.paper.potion.PaperPotionBrewer(console); // Paper - custom potion mixes
datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper
}
@@ -3076,5 +3078,9 @@ public final class CraftServer implements Server {
return datapackManager;
}
@Override
public io.papermc.paper.potion.PaperPotionBrewer getPotionBrewer() {
return this.potionBrewer;
}
// Paper end
}

View File

@@ -23,6 +23,11 @@ public interface CraftRecipe extends Recipe {
}
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) {