Interface ICastItem

All Known Implementing Classes:
ScrollItem, WandItem

public interface ICastItem
Offers a template for spell casting items to handle the base spell casting logic, cooldown, spell selection, cast verification and spell casting. Implementing this interface allows you to have a better integration with EBWR Ecosystem and order how the spell casting works in your item.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canCast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx)
    Normally you would call the events SpellCastEvent.Pre and SpellCastEvent.Tick in order to know when to allow the spell to run, but here you also handle any other conditions to allow casting.
    boolean
    cast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx)
    This is where you make all the spell cast handling (normally just instant spells).
    default int
    getCurrentCooldown(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level level)
    Returns the current cooldown to display on the spell HUD for the given ItemStack.
    default int
    getCurrentMaxCooldown(net.minecraft.world.item.ItemStack stack)
    Returns the max cooldown of the current spell to display on the spell HUD for the given ItemStack.
    @NotNull Spell
    getCurrentSpell(net.minecraft.world.item.ItemStack stack)
    Gets the current spell selected in the ItemStack.
    default @NotNull Spell
    getNextSpell(net.minecraft.world.item.ItemStack stack)
    Gets the next spell in the list of spells.
    default @NotNull Spell
    getPreviousSpell(net.minecraft.world.item.ItemStack stack)
    If your item will have more than just one spell loaded you need to override this in order to have a previous spell on list, by default it just gets the current spell saved.
    default Spell[]
    getSpells(net.minecraft.world.item.ItemStack stack)
    If your item will have more than just one spell loaded you need to override this in order to have a list of spells saved, by default it just sends a list with just the current spell.
    default void
    selectNextSpell(net.minecraft.world.item.ItemStack stack)
    Selects the next spell bound to the given ItemStack.
    default void
    selectPreviousSpell(net.minecraft.world.item.ItemStack stack)
    Selects the previous spell bound to the given itemstack.
    default boolean
    selectSpell(net.minecraft.world.item.ItemStack stack, int index)
    If your item will have more than just one spell loaded you need to override this in order to have the possibility to switch between the spell list.
    boolean
    showSpellHUD(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
    Returns whether the spell HUD should be shown when a player is holding this item.
    default boolean
    showSpellsInWorkbench(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
    Returns whether this item's spells should be displayed in the arcane workbench tooltip.
  • Method Details

    • canCast

      boolean canCast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx)
      Normally you would call the events SpellCastEvent.Pre and SpellCastEvent.Tick in order to know when to allow the spell to run, but here you also handle any other conditions to allow casting.
      Parameters:
      stack - The ItemStack to cast the spell from
      spell - The spell to cast
      ctx - The context of the cast
      Returns:
      Whether the spell can be cast or not
    • cast

      boolean cast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx)
      This is where you make all the spell cast handling (normally just instant spells). For doing the continuous spells you could use Item.onUseTick(Level, LivingEntity, ItemStack, int)
      Parameters:
      stack - The ItemStack to cast the spell from
      spell - The spell to cast
      ctx - The context of the cast
      Returns:
      Whether the spell was cast successfully or not
    • getCurrentSpell

      @NotNull @NotNull Spell getCurrentSpell(net.minecraft.world.item.ItemStack stack)
      Gets the current spell selected in the ItemStack. This is used for client-side rendering or spell selection utils.
      Parameters:
      stack - The ItemStack to get the current spell from
      Returns:
      The current spell selected in the ItemStack
    • getNextSpell

      @NotNull default @NotNull Spell getNextSpell(net.minecraft.world.item.ItemStack stack)
      Gets the next spell in the list of spells. By default, it just returns the current spell.
      Parameters:
      stack - The ItemStack to get the next spell from
      Returns:
      The next spell in the list of spells or the current spell if there is only one spell allowed
    • getPreviousSpell

      @NotNull default @NotNull Spell getPreviousSpell(net.minecraft.world.item.ItemStack stack)
      If your item will have more than just one spell loaded you need to override this in order to have a previous spell on list, by default it just gets the current spell saved. Used by the Spell GUI to get the actual spell icon and some client related features
    • getSpells

      default Spell[] getSpells(net.minecraft.world.item.ItemStack stack)
      If your item will have more than just one spell loaded you need to override this in order to have a list of spells saved, by default it just sends a list with just the current spell. Used by the Spell GUI to get all the needed spells to show
    • selectNextSpell

      default void selectNextSpell(net.minecraft.world.item.ItemStack stack)
      Selects the next spell bound to the given ItemStack. The given ItemStack will be of this item.
    • selectPreviousSpell

      default void selectPreviousSpell(net.minecraft.world.item.ItemStack stack)
      Selects the previous spell bound to the given itemstack. The given itemstack will be of this item.
    • selectSpell

      default boolean selectSpell(net.minecraft.world.item.ItemStack stack, int index)
      If your item will have more than just one spell loaded you need to override this in order to have the possibility to switch between the spell list.
    • getCurrentCooldown

      default int getCurrentCooldown(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level level)
      Returns the current cooldown to display on the spell HUD for the given ItemStack.
    • getCurrentMaxCooldown

      default int getCurrentMaxCooldown(net.minecraft.world.item.ItemStack stack)
      Returns the max cooldown of the current spell to display on the spell HUD for the given ItemStack.
    • showSpellHUD

      boolean showSpellHUD(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
      Returns whether the spell HUD should be shown when a player is holding this item. Only called client-side.
    • showSpellsInWorkbench

      default boolean showSpellsInWorkbench(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
      Returns whether this item's spells should be displayed in the arcane workbench tooltip. Only called client-side. Ignore this method if you don't want to use it on the Arcane Workbench.