public interface ISpellHelper
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    consumeReagents(net.minecraft.world.entity.LivingEntity entity, Collection<ItemFilter> reagents)
    Consumes the reagents.
    int
    getColor(List<ISpellModifier> modifiers, ISpell spell, net.minecraft.world.entity.LivingEntity caster, int index, int defaultColor)
    Returns the color for the current part.
    float
    getModifiedStat(float baseValue, ISpellPartStat stat, List<ISpellModifier> modifiers, ISpell spell, net.minecraft.world.entity.LivingEntity caster, @Nullable net.minecraft.world.phys.HitResult target, int componentIndex)
    Get the stat value modified by the modifiers.
    @Nullable net.minecraft.world.entity.Entity
    getPointedEntity(net.minecraft.world.entity.Entity entity, double range)
    Performs a ray trace and returns the entity the given entity is currently looking at.
    getSpell(net.minecraft.world.item.ItemStack stack)
     
    Optional<net.minecraft.resources.ResourceLocation>
    getSpellIcon(net.minecraft.world.item.ItemStack stack)
     
    net.minecraft.world.item.ItemStack
    getSpellItemStackFromEntity(net.minecraft.world.entity.LivingEntity entity)
    Returns the item stack containing the spell the given entity is currently using, taking spell books into consideration.
    net.minecraft.world.item.ItemStack
    getSpellItemStackInHand(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.InteractionHand hand)
    Returns the item stack the given entity is currently holding in the given hand if said stack is a spell, taking spell books into consideration.
    Optional<net.minecraft.network.chat.Component>
    getSpellName(net.minecraft.world.item.ItemStack stack)
     
    boolean
    hasReagents(net.minecraft.world.entity.LivingEntity entity, Collection<ItemFilter> reagents)
     
    invoke(ISpell spell, net.minecraft.world.entity.LivingEntity caster, net.minecraft.world.level.Level level, @Nullable net.minecraft.world.phys.HitResult target, int castingTicks, int index, boolean awardXp)
    Casts the spell.
    void
    nextShapeGroup(net.minecraft.world.item.ItemStack stack)
    Selects the next shape group of the given spell item stack, wrapping around.
    void
    prevShapeGroup(net.minecraft.world.item.ItemStack stack)
    Selects the previous shape group of the given spell item stack, wrapping around.
    void
    Registers a spell particle spawner for a given component.
    void
    setSpell(net.minecraft.world.item.ItemStack stack, ISpell spell)
    Sets the given spell to the given stack.
    void
    setSpellIcon(net.minecraft.world.item.ItemStack stack, net.minecraft.resources.ResourceLocation icon)
    Sets the given icon to the given stack.
    void
    setSpellName(net.minecraft.world.item.ItemStack stack, String name)
    Sets the given name to the given stack.
    void
    setSpellName(net.minecraft.world.item.ItemStack stack, net.minecraft.network.chat.Component name)
    Sets the given name to the given stack.
    void
    spawnParticles(ISpellComponent component, ISpell spell, net.minecraft.world.entity.LivingEntity caster, net.minecraft.world.phys.HitResult hit, net.minecraft.util.RandomSource random, int color)
    Spawns spell particles for the given component.
    net.minecraft.world.phys.HitResult
    trace(net.minecraft.world.entity.Entity entity, net.minecraft.world.level.Level level, double range, boolean entities, boolean targetNonSolid)
    Performs a ray trace.
  • Method Details

    • getSpell

      ISpell getSpell(net.minecraft.world.item.ItemStack stack)
      Parameters:
      stack - The stack to get the spell for.
      Returns:
      An optional containing the spell, or an empty optional if the given stack does not have a spell.
    • setSpell

      void setSpell(net.minecraft.world.item.ItemStack stack, ISpell spell)
      Sets the given spell to the given stack.
      Parameters:
      stack - The stack to set the spell on.
      spell - The spell to set.
    • getSpellItemStackFromEntity

      net.minecraft.world.item.ItemStack getSpellItemStackFromEntity(net.minecraft.world.entity.LivingEntity entity)
      Returns the item stack containing the spell the given entity is currently using, taking spell books into consideration. Returns empty if the entity is not currently holding anything that can be interpreted as a spell. This is needed e.g. when using a spell's shift-right click action.
      Parameters:
      entity - The entity to get the spell item stack from.
      Returns:
      The item stack containing the spell the given entity is currently using.
    • getSpellItemStackInHand

      net.minecraft.world.item.ItemStack getSpellItemStackInHand(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.InteractionHand hand)
      Returns the item stack the given entity is currently holding in the given hand if said stack is a spell, taking spell books into consideration. Returns empty if the stack is not actually anything that can be interpreted as a spell.
      Parameters:
      entity - The entity to get the spell item stack from.
      hand - The hand to get the spell item stack from.
      Returns:
      The spell item stack the given entity is currently holding in the given hand.
    • getSpellName

      Optional<net.minecraft.network.chat.Component> getSpellName(net.minecraft.world.item.ItemStack stack)
      Parameters:
      stack - The stack to get the spell name for.
      Returns:
      An optional containing the spell name, or an empty optional if the given stack does not have a spell name.
    • setSpellName

      void setSpellName(net.minecraft.world.item.ItemStack stack, String name)
      Sets the given name to the given stack.
      Parameters:
      stack - The stack to set the name on.
      name - The name to set.
    • setSpellName

      void setSpellName(net.minecraft.world.item.ItemStack stack, net.minecraft.network.chat.Component name)
      Sets the given name to the given stack.
      Parameters:
      stack - The stack to set the name on.
      name - The name to set.
    • getSpellIcon

      Optional<net.minecraft.resources.ResourceLocation> getSpellIcon(net.minecraft.world.item.ItemStack stack)
      Parameters:
      stack - The stack to get the spell icon for.
      Returns:
      An optional containing the spell icon id, or an empty optional if the given stack does not have a spell icon.
    • setSpellIcon

      void setSpellIcon(net.minecraft.world.item.ItemStack stack, net.minecraft.resources.ResourceLocation icon)
      Sets the given icon to the given stack.
      Parameters:
      stack - The stack to set the icon on.
      icon - The icon to set.
    • hasReagents

      boolean hasReagents(net.minecraft.world.entity.LivingEntity entity, Collection<ItemFilter> reagents)
      Parameters:
      entity - The entity to check on.
      reagents - The reagents to search for.
      Returns:
      Whether the given entity has the required reagents in their inventory or not.
    • consumeReagents

      void consumeReagents(net.minecraft.world.entity.LivingEntity entity, Collection<ItemFilter> reagents)
      Consumes the reagents.
      Parameters:
      entity - The entity to consume the ingredients from.
      reagents - The reagents to consume.
    • registerParticleSpawner

      void registerParticleSpawner(ISpellComponent component, ISpellParticleSpawner particleSpawner)
      Registers a spell particle spawner for a given component. This is only required on the client and may thus be left untouched on the server.
      Parameters:
      component - The component to register a particle spawner for.
      particleSpawner - The particle spawner to register.
    • spawnParticles

      void spawnParticles(ISpellComponent component, ISpell spell, net.minecraft.world.entity.LivingEntity caster, net.minecraft.world.phys.HitResult hit, net.minecraft.util.RandomSource random, int color)
      Spawns spell particles for the given component. This should only ever be called on the client!
      Parameters:
      component - The component to spawn spell particles for.
      spell - The spell that spawned the particles.
      caster - The entity that cast the spell.
      hit - The hit result to use.
      color - The color to use. May be -1, which indicates that no color should be used.
    • getPointedEntity

      @Nullable @Nullable net.minecraft.world.entity.Entity getPointedEntity(net.minecraft.world.entity.Entity entity, double range)
      Performs a ray trace and returns the entity the given entity is currently looking at.
      Parameters:
      entity - The entity to start the ray trace from.
      range - The range of the ray trace.
      Returns:
      The entity the given entity is currently looking at, or null if no entity was found.
    • trace

      net.minecraft.world.phys.HitResult trace(net.minecraft.world.entity.Entity entity, net.minecraft.world.level.Level level, double range, boolean entities, boolean targetNonSolid)
      Performs a ray trace.
      Parameters:
      entity - The entity to start the ray trace from.
      level - The level to perform the ray trace in.
      range - The range of the ray trace.
      entities - Whether to include entities. If false, only checks blocks.
      targetNonSolid - False if non-solid blocks and fluids should block the ray trace, true if non-solid blocks and fluids should be ignored.
      Returns:
      A hit result, representing the ray trace.
    • getModifiedStat

      float getModifiedStat(float baseValue, ISpellPartStat stat, List<ISpellModifier> modifiers, ISpell spell, net.minecraft.world.entity.LivingEntity caster, @Nullable @Nullable net.minecraft.world.phys.HitResult target, int componentIndex)
      Get the stat value modified by the modifiers.
      Parameters:
      baseValue - The base value for the stat.
      stat - The stat that is modified.
      spell - The spell that the part belongs to.
      caster - The entity casting the spell.
      target - The target of the spell cast.
      componentIndex - The 1 based index of the currently invoked part.
      Returns:
      The modified value of the stat.
    • invoke

      SpellCastResult invoke(ISpell spell, net.minecraft.world.entity.LivingEntity caster, net.minecraft.world.level.Level level, @Nullable @Nullable net.minecraft.world.phys.HitResult target, int castingTicks, int index, boolean awardXp)
      Casts the spell.
      Parameters:
      spell - The spell to cast.
      caster - The entity casting the spell.
      level - The level the spell is cast in.
      target - The target of the spell cast.
      castingTicks - How long the spell has already been cast.
      index - The 1 based index of the currently invoked part.
      awardXp - The magic xp awarded for casting this spell.
      Returns:
      A SpellCastResult that represents the spell casting outcome.
    • nextShapeGroup

      void nextShapeGroup(net.minecraft.world.item.ItemStack stack)
      Selects the next shape group of the given spell item stack, wrapping around.
      Parameters:
      stack - The spell item stack to select the next shape group of.
    • prevShapeGroup

      void prevShapeGroup(net.minecraft.world.item.ItemStack stack)
      Selects the previous shape group of the given spell item stack, wrapping around.
      Parameters:
      stack - The spell item stack to select the next shape group of.
    • getColor

      int getColor(List<ISpellModifier> modifiers, ISpell spell, net.minecraft.world.entity.LivingEntity caster, int index, int defaultColor)
      Returns the color for the current part.
      Parameters:
      modifiers - The list of modifiers for the currently invoked part.
      spell - The spell being cast.
      caster - The entity casting the spell.
      index - The 1 based index of the currently invoked part.
      defaultColor - The default color to use as fallback.
      Returns:
      the color for the current part