Class CastUtils
java.lang.Object
com.binaris.wizardry.api.content.util.CastUtils
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 cancelled/forfeited.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 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 cancelled (cast should be blocked)
-
applyCooldownForfeit
public static void applyCooldownForfeit(net.minecraft.world.entity.player.Player caster, int cooldownTicks) Applies cooldown when a cast is cancelled/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
-