Class ConjureItemSpell

java.lang.Object
com.binaris.wizardry.api.content.spell.Spell
com.binaris.wizardry.content.spell.abstr.ConjureItemSpell
Direct Known Subclasses:
ConjureArmor, Flamecatcher, FlamingAxe, FrostAxe

public class ConjureItemSpell extends Spell
Base class for spells that conjure items. This class provides the core functionality for conjuring an item and managing its lifetime through the use of ConjureData. It also includes a static set of supported items that can be conjured, and utility methods for checking if an item is summonable or currently summoned (you normally won't use this directly when creating a spell). This can only be used by player casts.

Adding an item to conjure by this spell makes it to always contain a ConjureData.

Check Spells.CONJURE_SWORD and Spells.FLAMECATCHER for examples of how to create conjure item spells.

You must override the properties() to return an actual instance of SpellProperties for this spell or use Spell.assignProperties(SpellProperties), otherwise the spell will have no properties and may not function as intended.

See Also:
  • Field Details

    • SUPPORTED_ITEMS

      public static Set<net.minecraft.world.item.Item> SUPPORTED_ITEMS
  • Constructor Details

    • ConjureItemSpell

      public ConjureItemSpell(net.minecraft.world.item.Item item)
  • Method Details

    • cast

      public boolean cast(PlayerCastContext ctx)
      Description copied from class: Spell
      This cast method is meant to be used for spells that are cast by a player source. This is useful for spells that are meant to be cast by players, as it provides more information about the caster and the context of the cast.

      Override this method to implement the casting behavior for spells that are meant to be cast by players.

      Specified by:
      cast in class Spell
      Parameters:
      ctx - The context of the spell cast, containing information about the world, caster, hand used, modifiers, etc.
      Returns:
      true if the spell was successfully cast, false otherwise. If this returns false, the spell will not be considered as having been cast, so no cooldown will be applied.
    • conjureItem

      protected boolean conjureItem(PlayerCastContext ctx)
      Conjures the item for the caster. This method creates an ItemStack of the specified item, gets the conjure data for it and establishes the duration and expiration time based on the spell properties and modifiers. The conjure data is then associated with the item stack, and the item is added to the caster's inventory. If the caster's inventory is full, a message is sent to the player and the method returns false.
      Parameters:
      ctx - the context of the spell cast, containing information about the caster, the world, and the spell modifiers
      Returns:
      true if the item was successfully conjured and added to the caster's inventory, false otherwise
      See Also:
    • isSummoned

      public static boolean isSummoned(net.minecraft.world.item.ItemStack stack)
      Checks if the given item stack is currently summoned (i.e. conjured and not expired). The item must also be part of the supported conjure items inside the mod. For a check of whether an item is part of the supported conjure items (not checking if it is summoned), use isSummonableItem(ItemStack).
      Parameters:
      stack - the item stack to check
      Returns:
      true if the item stack is currently summoned, false otherwise
    • isSummonableItem

      public static boolean isSummonableItem(net.minecraft.world.item.Item item)
      Checks if the given item is part of the supported conjure items inside the mod. For a better check of whether an item is actually summoned, use isSummoned(ItemStack).
      Parameters:
      item - the item to check
      Returns:
      true if the item is part of the supported conjure items, false otherwise
    • isSummonableItem

      public static boolean isSummonableItem(net.minecraft.world.item.ItemStack stack)
      Checks if the given item stack is part of the supported conjure items inside the mod. For a better check of whether an item is actually summoned, use isSummoned(ItemStack).
      Parameters:
      stack - the item stack to check
      Returns:
      true if the item stack is part of the supported conjure items, false otherwise
    • registerSupportedItem

      public static void registerSupportedItem(net.minecraft.world.item.Item item)
      Registers an item as a supported conjure item. This should be called in the constructor of any spell that conjures an item or in your mod's common setup. If an item is not registered as a supported conjure item, it will not be recognized as a valid and won't have the conjure data associated with it.
      Parameters:
      item - the item to register as a supported conjure item
    • spawnParticles

      protected void spawnParticles(PlayerCastContext ctx)
      Spawns spark particles around the caster. This is a client-side visual effect that is called when the spell is cast. The particles are spawned in a random pattern around the caster's head and have a light blue color.

      You could override this to change the particle effect.

      Parameters:
      ctx - the context of the spell cast, containing information about the caster and the world
    • addItemExtras

      protected net.minecraft.world.item.ItemStack addItemExtras(PlayerCastContext ctx, net.minecraft.world.item.ItemStack stack)
      Adds extra properties or NBT data to the conjured item stack before it is given to the caster. This method is called during the conjuration process and allows you to customize the item stack based on the spell context. By default, this method returns the original item stack without any modifications.
      Parameters:
      ctx - the context of the spell cast, containing information about the caster, the world, and the spell modifiers
      stack - the original item stack that is about to be conjured
      Returns:
      the modified item stack with any additional properties or NBT data added
    • properties

      @NotNull protected @NotNull SpellProperties properties()
      Description copied from class: Spell
      This method is where you should set the default properties for your spell when creating a new spell class. This method is called in the constructor of the Spell class, and the properties returned by this method are assigned to the spell's properties field.
      Specified by:
      properties in class Spell
      Returns:
      A SpellProperties object with the default properties for your spell.