Class WandItem
java.lang.Object
net.minecraft.world.item.Item
com.binaris.wizardry.content.item.WandItem
- All Implemented Interfaces:
IElementValue,IManaStoringItem,ISpellCastingItem,ITierValue,IWizardryItem,IWorkbenchItem,net.fabricmc.fabric.api.item.v1.FabricItem,net.minecraft.world.flag.FeatureElement,net.minecraft.world.level.ItemLike
public class WandItem
extends net.minecraft.world.item.Item
implements ISpellCastingItem, IManaStoringItem, IWorkbenchItem, IWizardryItem, ITierValue, IElementValue
Where the magic (normally) happens!! Most of the functions and logic for this item are handled on various utils
classes (e.g.
WandHelper and CastUtils), so refer to those for more details on specific aspects of
wand functionality.
A wand is a spell-casting item that can store mana, hold multiple spells, and be upgraded in various ways. Wands can cast both instant and continuous spells, with mechanics for charging, cooldowns, and mana consumption. They can be upgraded using special items to enhance their capabilities, such as increasing mana capacity or adding spell slots.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class net.minecraft.world.item.Item
net.minecraft.world.item.Item.Properties -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intCooldown applied when a spell cast is canceled by forfeit (or any listener from SpellPreCast/SpellTickCast)static final intMaximum use duration for continuous spells.Fields inherited from class net.minecraft.world.item.Item
BASE_ATTACK_DAMAGE_UUID, BASE_ATTACK_SPEED_UUID, BY_BLOCK, EAT_DURATION, MAX_BAR_WIDTH, MAX_STACK_SIZEFields inherited from interface net.minecraft.world.flag.FeatureElement
FILTERED_REGISTRIES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplySpecialUpgrade(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.ItemStack upgrade) Applies a special upgrade to the wand, such as storage or attunement upgrades.protected net.minecraft.world.item.ItemStackapplyTierUpgrade(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.ItemStack tomeStack) Applies a tier upgrade to the wand if the tome's tier is higher than the wand's current tier.net.minecraft.world.item.ItemStackapplyUpgrade(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.ItemStack upgrade) protected booleanapplyUpgradeSlot(net.minecraft.world.entity.player.Player player, net.minecraft.world.inventory.Slot centre, net.minecraft.world.inventory.Slot upgrade) Applies an upgrade from the workbench upgrade slot to the wand in the centre slot.protected intcalculateCharge(Spell spell, PlayerCastContext ctx) Calculates the charge time required for a spell based on the spell's base charge and the player's spell modifiers.booleancanCast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx) The items implementing this interface are responsible about how to use this.booleancast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx) The items implementing this interface are responsible about how to use this.protected voidcheckLevelUp(PlayerCastContext ctx, net.minecraft.world.item.ItemStack stack, int progression) Checks if the wand has enough progression to level up and notifies the player if it has.protected PlayerCastContextcreateContext(net.minecraft.world.level.Level level, net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int tick, net.minecraft.world.item.ItemStack stack, Spell spell) Creates a PlayerCastContext for the given parameters, calculating spell modifiers based on the tick count.protected voidexpandSpellSlots(net.minecraft.world.item.ItemStack wand) Expands the spell slots on the wand when an attunement upgrade is applied.protected static intgetAccumulatedCost(Spell spell, int castingTick, int totalCost) Calculates the accumulated mana cost for a continuous spell based on the casting ticks.intgetBarColor(net.minecraft.world.item.ItemStack stack) intgetCurrentCooldown(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.intgetCurrentMaxCooldown(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 SpellgetCurrentSpell(net.minecraft.world.item.ItemStack stack) This gets the actual item that's on the ItemStack, normally you won't use this.Gets the element associated with this item.intgetMana(net.minecraft.world.item.ItemStack stack) intgetManaCapacity(net.minecraft.world.item.ItemStack stack) intgetMaxDamage(net.minecraft.world.item.ItemStack stack) @NotNull net.minecraft.network.chat.ComponentgetName(@NotNull net.minecraft.world.item.ItemStack stack) @NotNull SpellgetNextSpell(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 next spell on list, by default it just gets the current spell saved.@NotNull SpellgetPreviousSpell(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.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.intgetSpellSlotCount(net.minecraft.world.item.ItemStack stack) getTier(net.minecraft.world.item.ItemStack stack) Gets the tier associated with this item.intgetUseDuration(@NotNull net.minecraft.world.item.ItemStack stack) protected voidhandleInstantSpellTick(PlayerCastContext ctx, Spell spell, net.minecraft.world.item.ItemStack stack, int useTick, int charge) Handles the logic for instant spell casting onuseTick.protected voidhandleProgression(PlayerCastContext ctx, Spell spell, net.minecraft.world.item.ItemStack stack) Handles wand progression when a spell is cast.@NotNull net.minecraft.world.InteractionResultinteractLivingEntity(@NotNull net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.world.entity.LivingEntity interactionTarget, @NotNull net.minecraft.world.InteractionHand usedHand) voidinventoryTick(@NotNull net.minecraft.world.item.ItemStack stack, @NotNull net.minecraft.world.level.Level world, @NotNull net.minecraft.world.entity.Entity entity, int slot, boolean isHeldInMainhand) booleanbooleanisFoil(@NotNull net.minecraft.world.item.ItemStack stack) booleanonApplyButtonPressed(net.minecraft.world.entity.player.Player player, net.minecraft.world.inventory.Slot centre, net.minecraft.world.inventory.Slot crystals, net.minecraft.world.inventory.Slot upgrade, net.minecraft.world.inventory.Slot[] spellBooks) voidonClearButtonPressed(net.minecraft.world.entity.player.Player player, net.minecraft.world.inventory.Slot centre, net.minecraft.world.inventory.Slot crystals, net.minecraft.world.inventory.Slot upgrade, net.minecraft.world.inventory.Slot[] spellBooks) voidonUseTick(@NotNull net.minecraft.world.level.Level level, @NotNull net.minecraft.world.entity.LivingEntity user, @NotNull net.minecraft.world.item.ItemStack stack, int timeLeft) voidreleaseUsing(@NotNull net.minecraft.world.item.ItemStack stack, @NotNull net.minecraft.world.level.Level level, @NotNull net.minecraft.world.entity.LivingEntity livingEntity, int timeCharged) voidselectNextSpell(net.minecraft.world.item.ItemStack stack) Selects the next spell bound to the given ItemStack.voidselectPreviousSpell(net.minecraft.world.item.ItemStack stack) Selects the previous spell bound to the given itemstack.booleanselectSpell(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.voidsetDamage(net.minecraft.world.item.ItemStack stack, int damage) voidsetMana(net.minecraft.world.item.ItemStack stack, int mana) booleanshowSpellHUD(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.booleanshowTooltip(net.minecraft.world.item.ItemStack stack) @NotNull net.minecraft.world.InteractionResultHolder<net.minecraft.world.item.ItemStack>use(@NotNull net.minecraft.world.level.Level level, net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.world.InteractionHand hand) booleanDetermines if this item is valid for use in a receptacle.Methods inherited from class net.minecraft.world.item.Item
appendHoverText, asItem, builtInRegistryHolder, byBlock, byId, canAttackBlock, canBeDepleted, canBeHurtBy, canFitInsideContainerItems, finishUsingItem, getBarWidth, getCraftingRemainingItem, getDefaultAttributeModifiers, getDefaultInstance, getDescription, getDescriptionId, getDescriptionId, getDestroySpeed, getDrinkingSound, getEatingSound, getEnchantmentValue, getFoodProperties, getId, getMaxDamage, getMaxStackSize, getOrCreateDescriptionId, getPlayerPOVHitResult, getRarity, getTooltipImage, getUseAnimation, hasCraftingRemainingItem, hurtEnemy, isBarVisible, isComplex, isCorrectToolForDrops, isEdible, isEnchantable, isFireResistant, isValidRepairItem, mineBlock, onCraftedBy, onDestroyed, overrideOtherStackedOnMe, overrideStackedOnOther, requiredFeatures, shouldOverrideMultiplayerNbt, toString, useOn, useOnRelease, verifyTagAfterLoadMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.fabricmc.fabric.api.item.v1.FabricItem
allowContinuingBlockBreaking, allowNbtUpdateAnimation, getAttributeModifiers, getRecipeRemainder, isSuitableForMethods inherited from interface net.minecraft.world.flag.FeatureElement
isEnabledMethods inherited from interface com.binaris.wizardry.api.content.item.IManaStoringItem
consumeMana, getFullness, isManaEmpty, isManaFull, rechargeMana, showManaInWorkbenchMethods inherited from interface com.binaris.wizardry.api.content.item.ISpellCastingItem
showSpellsInWorkbenchMethods inherited from interface com.binaris.wizardry.api.content.item.IWorkbenchItem
canPlace
-
Field Details
-
BASE_SPELL_SLOTS
public static final int BASE_SPELL_SLOTS- See Also:
-
COOLDOWN_FORFEIT_TICKS
public static final int COOLDOWN_FORFEIT_TICKSCooldown applied when a spell cast is canceled by forfeit (or any listener from SpellPreCast/SpellTickCast)- See Also:
-
MAX_USE_DURATION
public static final int MAX_USE_DURATIONMaximum use duration for continuous spells.- See Also:
-
-
Constructor Details
-
WandItem
-
-
Method Details
-
use
@NotNull public @NotNull net.minecraft.world.InteractionResultHolder<net.minecraft.world.item.ItemStack> use(@NotNull @NotNull net.minecraft.world.level.Level level, net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.world.InteractionHand hand) - Overrides:
usein classnet.minecraft.world.item.Item
-
onUseTick
public void onUseTick(@NotNull @NotNull net.minecraft.world.level.Level level, @NotNull @NotNull net.minecraft.world.entity.LivingEntity user, @NotNull @NotNull net.minecraft.world.item.ItemStack stack, int timeLeft) - Overrides:
onUseTickin classnet.minecraft.world.item.Item
-
canCast
public boolean canCast(net.minecraft.world.item.ItemStack stack, Spell spell, PlayerCastContext ctx) Description copied from interface:ISpellCastingItemThe items implementing this interface are responsible about how to use this. Normally you would call the eventsSpellCastEvent.PreandSpellCastEvent.Tickin order to know when to allow the spell to run.
You could also add some custom to logic (like special cooldowns or handling specific spells) if you want to.
- Specified by:
canCastin interfaceISpellCastingItem
-
getAccumulatedCost
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
-
isFoil
public boolean isFoil(@NotNull @NotNull net.minecraft.world.item.ItemStack stack) - Overrides:
isFoilin classnet.minecraft.world.item.Item
-
cast
Description copied from interface:ISpellCastingItemThe items implementing this interface are responsible about how to use this. This is where you make all the spell cast handling (normally just instant spells). For doing the continuous spells you should useItem.onUseTick(Level, LivingEntity, ItemStack, int)- Specified by:
castin interfaceISpellCastingItem
-
interactLivingEntity
@NotNull public @NotNull net.minecraft.world.InteractionResult interactLivingEntity(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.world.entity.LivingEntity interactionTarget, @NotNull @NotNull net.minecraft.world.InteractionHand usedHand) - Overrides:
interactLivingEntityin classnet.minecraft.world.item.Item
-
releaseUsing
public void releaseUsing(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, @NotNull @NotNull net.minecraft.world.level.Level level, @NotNull @NotNull net.minecraft.world.entity.LivingEntity livingEntity, int timeCharged) - Overrides:
releaseUsingin classnet.minecraft.world.item.Item
-
onApplyButtonPressed
public boolean onApplyButtonPressed(net.minecraft.world.entity.player.Player player, net.minecraft.world.inventory.Slot centre, net.minecraft.world.inventory.Slot crystals, net.minecraft.world.inventory.Slot upgrade, net.minecraft.world.inventory.Slot[] spellBooks) - Specified by:
onApplyButtonPressedin interfaceIWorkbenchItem
-
applyUpgrade
public net.minecraft.world.item.ItemStack applyUpgrade(@Nullable @Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.ItemStack upgrade) - Specified by:
applyUpgradein interfaceIWorkbenchItem
-
inventoryTick
public void inventoryTick(@NotNull @NotNull net.minecraft.world.item.ItemStack stack, @NotNull @NotNull net.minecraft.world.level.Level world, @NotNull @NotNull net.minecraft.world.entity.Entity entity, int slot, boolean isHeldInMainhand) - Overrides:
inventoryTickin classnet.minecraft.world.item.Item
-
onClearButtonPressed
public void onClearButtonPressed(net.minecraft.world.entity.player.Player player, net.minecraft.world.inventory.Slot centre, net.minecraft.world.inventory.Slot crystals, net.minecraft.world.inventory.Slot upgrade, net.minecraft.world.inventory.Slot[] spellBooks) - Specified by:
onClearButtonPressedin interfaceIWorkbenchItem
-
handleInstantSpellTick
protected void handleInstantSpellTick(PlayerCastContext ctx, Spell spell, net.minecraft.world.item.ItemStack stack, int useTick, int charge) Handles the logic for instant spell casting onuseTick. If the currentuseTickmatches the requiredcharge, it checks if the spell can be cast, consumes mana, sets cooldown, and casts the spell. Finally, it stops the player's item use.- Parameters:
stack- The wand item stackspell- The spell being castctx- The player cast contextuseTick- The current use tickcharge- The required charge time for the spell
-
createContext
protected PlayerCastContext createContext(net.minecraft.world.level.Level level, net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int tick, net.minecraft.world.item.ItemStack stack, Spell spell) Creates a PlayerCastContext for the given parameters, calculating spell modifiers based on the tick count.- Parameters:
level- The current levelplayer- The player casting the spellhand- The hand used to cast the spelltick- The current tick count of the casting processstack- The wand item stackspell- The spell being cast- Returns:
- A PlayerCastContext with the appropriate modifiers
-
calculateCharge
Calculates the charge time required for a spell based on the spell's base charge and the player's spell modifiers.- Parameters:
spell- The spell being castctx- The player cast context- Returns:
- The calculated charge time
-
applyUpgradeSlot
protected boolean applyUpgradeSlot(net.minecraft.world.entity.player.Player player, net.minecraft.world.inventory.Slot centre, net.minecraft.world.inventory.Slot upgrade) Applies an upgrade from the workbench upgrade slot to the wand in the centre slot.- Parameters:
player- The player applying the upgrade (can be null)centre- The workbench slot containing the wandupgrade- The workbench slot containing the upgrade item- Returns:
- true if the wand was changed, false otherwise
-
applyTierUpgrade
protected net.minecraft.world.item.ItemStack applyTierUpgrade(@Nullable @Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.ItemStack tomeStack) Applies a tier upgrade to the wand if the tome's tier is higher than the wand's current tier. This method checks if the player has enough progression to upgrade and updates the wand's tier and progression accordingly.- Parameters:
player- The player applying the upgrade (can be null)wand- The wand item stack to apply the upgrade totomeStack- The arcane tome item stack being used for the upgrade- Returns:
- The upgraded wand item stack, or the original wand if no upgrade was applied
-
applySpecialUpgrade
protected void applySpecialUpgrade(@Nullable @Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.ItemStack upgrade) Applies a special upgrade to the wand, such as storage or attunement upgrades. This method checks for upgrade limits and applies the upgrade effects accordingly.- Parameters:
player- The player applying the upgrade (can be null)wand- The wand item stack to apply the upgrade toupgrade- The upgrade item stack being applied
-
expandSpellSlots
protected void expandSpellSlots(net.minecraft.world.item.ItemStack wand) Expands the spell slots on the wand when an attunement upgrade is applied. This method adjusts the spell list to accommodate the new slot count.- Parameters:
wand- The wand item stack to expand spell slots for
-
handleProgression
protected void handleProgression(PlayerCastContext ctx, Spell spell, net.minecraft.world.item.ItemStack stack) Handles wand progression when a spell is cast. Progression is only added for non-instant spells and for wands below master tier. Progression is added every second (20 ticks) during casting.- Parameters:
ctx- The player cast contextspell- The spell being caststack- The wand item stack
-
checkLevelUp
protected void checkLevelUp(PlayerCastContext ctx, net.minecraft.world.item.ItemStack stack, int progression) Checks if the wand has enough progression to level up and notifies the player if it has. This method is called after progression is added to the wand.- Parameters:
ctx- The player cast contextstack- The wand item stackprogression- The amount of progression just added
-
getName
@NotNull public @NotNull net.minecraft.network.chat.Component getName(@NotNull @NotNull net.minecraft.world.item.ItemStack stack) - Overrides:
getNamein classnet.minecraft.world.item.Item
-
selectNextSpell
public void selectNextSpell(net.minecraft.world.item.ItemStack stack) Description copied from interface:ISpellCastingItemSelects the next spell bound to the given ItemStack. The given ItemStack will be of this item.- Specified by:
selectNextSpellin interfaceISpellCastingItem
-
selectPreviousSpell
public void selectPreviousSpell(net.minecraft.world.item.ItemStack stack) Description copied from interface:ISpellCastingItemSelects the previous spell bound to the given itemstack. The given itemstack will be of this item.- Specified by:
selectPreviousSpellin interfaceISpellCastingItem
-
getMaxDamage
public int getMaxDamage(net.minecraft.world.item.ItemStack stack) - Specified by:
getMaxDamagein interfaceIWizardryItem
-
setDamage
public void setDamage(net.minecraft.world.item.ItemStack stack, int damage) - Specified by:
setDamagein interfaceIWizardryItem
-
getBarColor
public int getBarColor(net.minecraft.world.item.ItemStack stack) - Overrides:
getBarColorin classnet.minecraft.world.item.Item
-
getUseDuration
public int getUseDuration(@NotNull @NotNull net.minecraft.world.item.ItemStack stack) - Overrides:
getUseDurationin classnet.minecraft.world.item.Item
-
isClearable
public boolean isClearable()- Specified by:
isClearablein interfaceIWorkbenchItem
-
showTooltip
public boolean showTooltip(net.minecraft.world.item.ItemStack stack) - Specified by:
showTooltipin interfaceIWorkbenchItem
-
selectSpell
public boolean selectSpell(net.minecraft.world.item.ItemStack stack, int index) Description copied from interface:ISpellCastingItemIf 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.- Specified by:
selectSpellin interfaceISpellCastingItem
-
getCurrentCooldown
public int getCurrentCooldown(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level level) Description copied from interface:ISpellCastingItemReturns the current cooldown to display on the spell HUD for the given ItemStack.- Specified by:
getCurrentCooldownin interfaceISpellCastingItem
-
getCurrentMaxCooldown
public int getCurrentMaxCooldown(net.minecraft.world.item.ItemStack stack) Description copied from interface:ISpellCastingItemReturns the max cooldown of the current spell to display on the spell HUD for the given ItemStack.- Specified by:
getCurrentMaxCooldownin interfaceISpellCastingItem
-
showSpellHUD
public boolean showSpellHUD(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack) Description copied from interface:ISpellCastingItemReturns whether the spell HUD should be shown when a player is holding this item. Only called client-side.- Specified by:
showSpellHUDin interfaceISpellCastingItem
-
getMana
public int getMana(net.minecraft.world.item.ItemStack stack) - Specified by:
getManain interfaceIManaStoringItem
-
getManaCapacity
public int getManaCapacity(net.minecraft.world.item.ItemStack stack) - Specified by:
getManaCapacityin interfaceIManaStoringItem
-
setMana
public void setMana(net.minecraft.world.item.ItemStack stack, int mana) - Specified by:
setManain interfaceIManaStoringItem
-
getSpellSlotCount
public int getSpellSlotCount(net.minecraft.world.item.ItemStack stack) - Specified by:
getSpellSlotCountin interfaceIWorkbenchItem
-
getCurrentSpell
Description copied from interface:ISpellCastingItemThis gets the actual item that's on the ItemStack, normally you won't use this. Used by the Spell GUI to get the actual spell icon and some client related features- Specified by:
getCurrentSpellin interfaceISpellCastingItem
-
getNextSpell
Description copied from interface:ISpellCastingItemIf your item will have more than just one spell loaded you need to override this in order to have a next 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- Specified by:
getNextSpellin interfaceISpellCastingItem
-
getPreviousSpell
Description copied from interface:ISpellCastingItemIf 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- Specified by:
getPreviousSpellin interfaceISpellCastingItem
-
getSpells
Description copied from interface:ISpellCastingItemIf 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- Specified by:
getSpellsin interfaceISpellCastingItem
-
getElement
Description copied from interface:IElementValueGets the element associated with this item.- Specified by:
getElementin interfaceIElementValue- Returns:
- The element of the item.
-
validForReceptacle
public boolean validForReceptacle()Description copied from interface:IElementValueDetermines if this item is valid for use in a receptacle.- Specified by:
validForReceptaclein interfaceIElementValue- Returns:
- true if the item can be used in a receptacle, false otherwise.
-
getTier
Description copied from interface:ITierValueGets the tier associated with this item.- Specified by:
getTierin interfaceITierValue- Returns:
- The tier of the item.
-