Class CastItemUtils
java.lang.Object
com.binaris.wizardry.api.content.util.CastItemUtils
A utility class for handling various aspects of spell casting, including event firing, cooldown application,
spell tracking, and network packet sending. This class is created from
WandItem and ScrollItem shared
casting logic to avoid code duplication.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyCooldownForfeit(net.minecraft.world.entity.player.Player caster, int cooldownTicks) Applies cooldown when a cast is canceled/forfeited.static intcalcCastCooldown(Spell spell, SpellModifiers modifiers) Calculates the cooldown of a spell based on its base cooldown and the given spell modifiers.static intcalcCastCost(Spell spell, SpellModifiers modifiers) Calculates the mana cost of a spell based on its base cost and the given spell modifiers.static intcalcCastProgression(Spell spell, SpellModifiers modifiers) Calculates the progression of a spell based on its base cost and the given spell modifiers.static intcalcCharge(Spell spell, SpellModifiers modifiers) Calculates the charge time required for a spell based on the spell's base charge and the given spell modifiers.static SpellModifierscalculateModifiers(net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, Spell spell) Calculates the spell modifiers provided by the stack for the given spell and player.static booleanexecuteSpellCast(SpellCastEvent.Source source, Spell spell, PlayerCastContext ctx) Executes the spell cast and fires post-cast event.static booleanfireSpellCastEvent(SpellCastEvent.Source source, Spell spell, PlayerCastContext ctx) Fires the appropriate spell cast event based on casting ticks.static intgetAccumulatedCastCost(Spell spell, int castingTick, int totalCost) Calculates the accumulated mana cost for a continuous spell based on the casting ticks.static intgetDistributedCastCost(int cost, int castingTick) Calculates the distributed cost of a spell being cast over multiple ticks.static voidsendSpellCastPacket(net.minecraft.world.entity.player.Player caster, Spell spell, PlayerCastContext ctx) Sends spell cast packet to other clients if needed (for non-instant spells).static voidtrackSpellUsage(net.minecraft.world.entity.player.Player caster, Spell spell) Tracks the spell in wizard data for recent spell tracking.
-
Method Details
-
fireSpellCastEvent
public static boolean fireSpellCastEvent(SpellCastEvent.Source source, Spell spell, PlayerCastContext ctx) Fires the appropriate spell cast event based on casting ticks.- Parameters:
source- The source of the spell castspell- The spell being castctx- The casting context- Returns:
- true if the event was canceled (cast should be blocked)
-
applyCooldownForfeit
public static void applyCooldownForfeit(net.minecraft.world.entity.player.Player caster, int cooldownTicks) Applies cooldown when a cast is canceled/forfeited.- Parameters:
caster- The player casting the spellcooldownTicks- The cooldown duration in ticks
-
trackSpellUsage
Tracks the spell in wizard data for recent spell tracking.- Parameters:
caster- The player casting the spellspell- The spell being cast
-
executeSpellCast
public static boolean executeSpellCast(SpellCastEvent.Source source, Spell spell, PlayerCastContext ctx) Executes the spell cast and fires post-cast event.- Parameters:
source- The source of the spell castspell- The spell being castctx- The casting context- Returns:
- true if the spell was successfully cast
-
sendSpellCastPacket
public static void sendSpellCastPacket(net.minecraft.world.entity.player.Player caster, Spell spell, PlayerCastContext ctx) Sends spell cast packet to other clients if needed (for non-instant spells).- Parameters:
caster- The player casting the spellspell- The spell being castctx- The casting context
-
calculateModifiers
public static SpellModifiers calculateModifiers(net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, Spell spell) Calculates the spell modifiers provided by the stack for the given spell and player.- Parameters:
stack- The ItemStack.player- The player casting the spell.spell- The spell being cast.- Returns:
- The calculated spell modifiers.
-
getAccumulatedCastCost
Calculates the accumulated mana cost for a continuous spell based on the casting ticks.- Parameters:
spell- The spell being castcastingTick- The number of ticks the spell has been cast fortotalCost- The total mana cost of the spell- Returns:
- The accumulated mana cost for the given casting ticks
-
getDistributedCastCost
public static int getDistributedCastCost(int cost, int castingTick) Calculates the distributed cost of a spell being cast over multiple ticks. The cost is halved at 10 ticks and again at 20 ticks, with any remainder added to the first half.- Parameters:
cost- The total cost of the spell.castingTick- The current tick of casting.- Returns:
- The distributed cost for the current tick.
-
calcCastProgression
Calculates the progression of a spell based on its base cost and the given spell modifiers. This could result in negative values! Always try to check the result before using it.- Parameters:
spell- The spell being castmodifiers- The spell modifiers affecting the cast- Returns:
- The calculated progression
-
calcCastCooldown
Calculates the cooldown of a spell based on its base cooldown and the given spell modifiers.- Parameters:
spell- The spell being castmodifiers- The spell modifiers affecting the cast- Returns:
- The calculated cooldown
-
calcCastCost
Calculates the mana cost of a spell based on its base cost and the given spell modifiers.- Parameters:
spell- The spell being castmodifiers- The spell modifiers affecting the cast- Returns:
- The calculated mana cost
-
calcCharge
Calculates the charge time required for a spell based on the spell's base charge and the given spell modifiers.- Parameters:
spell- The spell being castmodifiers- The spell modifiers affecting the cast- Returns:
- The calculated charge time
-