Script API - v26.70.24
    Preparing search index...

    Class Potions

    Used for accessing all potion effect types, delivery types, and creating potions.

    export class Potions {
    private constructor();
    static getAllDeliveryTypes(): PotionDeliveryType[];
    static getAllEffectTypes(): PotionEffectType[];
    static getDeliveryType(potionDeliveryId: string): PotionDeliveryType | undefined;
    static getEffectType(potionEffectId: string): PotionEffectType | undefined;
    static resolve(
    potionEffectType: PotionEffectType | string,
    potionDeliveryType: PotionDeliveryType | string,
    ): ItemStack;
    }
    Index
    • Parameters

      • potionDeliveryId: string

      Returns PotionDeliveryType | undefined

      A type handle wrapping the valid delivery id, or undefined for an invalid delivery id.

      Retrieves a type handle for a specified potion delivery id.

      This function can't be called in early-execution mode.

    • Parameters

      • potionEffectId: string

        A valid potion effect id. See @minecraft/vanilla-data.MinecraftPotionEffectTypes

      Returns PotionEffectType | undefined

      A type handle wrapping the valid effect id, or undefined for an invalid effect id.

      Retrieves a type handle for a specified potion effect id.

      This function can't be called in early-execution mode.

    • Parameters

      Returns ItemStack

      Creates a potion given an effect and delivery type.

      This function can't be called in early-execution mode.

      import { Player, Potions, system } from "@minecraft/server";

      // Run `/scriptevent example:giveharmingsplashpotion` in chat to get a splash potion of harming.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:giveharmingsplashpotion" || !(sourceEntity instanceof Player)) return;

      const inventory = sourceEntity.getComponent("minecraft:inventory");
      if (!inventory?.container) return;

      const effectType = Potions.getEffectType("minecraft:harming");
      const deliveryType = Potions.getDeliveryType("ThrownSplash");
      if (!effectType || !deliveryType) return;

      const potion = Potions.resolve(effectType, deliveryType);
      inventory.container.addItem(potion);
      sourceEntity.sendMessage("You received a splash potion of harming.");
      });
      import { Player, Potions, system } from "@minecraft/server";

      // Run `/scriptevent example:giveregularfireresistancepotion` in chat to get a fire resistance potion.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:giveregularfireresistancepotion" || !(sourceEntity instanceof Player)) return;

      const inventory = sourceEntity.getComponent("minecraft:inventory");
      if (!inventory?.container) return;

      const effectType = Potions.getEffectType("minecraft:fire_resistance");
      const deliveryType = Potions.getDeliveryType("Consume");
      if (!effectType || !deliveryType) return;

      const potion = Potions.resolve(effectType, deliveryType);
      inventory.container.addItem(potion);
      sourceEntity.sendMessage("You received a potion of fire resistance.");
      });
      import { Player, Potions, system } from "@minecraft/server";

      // Run `/scriptevent example:giveregularwaterbreathingpotion` in chat to get a water breathing potion.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:giveregularwaterbreathingpotion" || !(sourceEntity instanceof Player)) return;

      const inventory = sourceEntity.getComponent("minecraft:inventory");
      if (!inventory?.container) return;

      const effectType = Potions.getEffectType("minecraft:water_breathing");
      const deliveryType = Potions.getDeliveryType("Consume");
      if (!effectType || !deliveryType) return;

      const potion = Potions.resolve(effectType, deliveryType);
      inventory.container.addItem(potion);
      sourceEntity.sendMessage("You received a potion of water breathing.");
      });