Spear 5.46.0
Extends TieredTool
Implements Releasable
Spears (https://minecraft.wiki/w/Spear). Jab = normal attack; holding "use" charges and hits whatever the spear points at, dealing damage proportional to the relative speed.
Bedrock stats per tier (jab damage / durability / enchantability = the tier's sword damage - 3 / tool durability / tool enchantability): wooden 2/60/15, stone 3/132/5, copper 3/191/13, iron 4/251/14, golden 2/33/22, diamond 5/1562/10, netherite 6/2032/15. The jab starts a use cooldown shared by all spears (13/15/17/19/19/21/23 ticks).
Charge attack: after an activation delay the spear is "engaged" (damage + knockback, and the target is knocked off its mount), then "tired" (damage + knockback), then "disengaged" (damage only), then the charge ends. Damage = tier multiplier * relative speed in blocks/second, not affected by Strength or Weakness; Bedrock waits 10 ticks between charge hits. Not documented for Bedrock, so Java values are used: minimum speed for damage 4.6 b/s and for knockback 5.1 b/s (wooden spear values, applied to every tier); durability loss per hit (1, like swords).
Lunge (https://minecraft.wiki/w/Lunge): each jab pushes the player 0.458 blocks/tick per level horizontally along where it looks, costs 4 exhaustion per level and 1 durability; needs at least 7 hunger points and doesn't work while gliding or in water.
Constants
CHARGE_HIT_INTERVAL_TICKS
public const CHARGE_HIT_INTERVAL_TICKS = 10CHARGE_MIN_DAMAGE_SPEED
public const CHARGE_MIN_DAMAGE_SPEED = 4.6CHARGE_MIN_KNOCKBACK_SPEED
public const CHARGE_MIN_KNOCKBACK_SPEED = 5.1CHARGE_REACH
public const CHARGE_REACH = 4.0LUNGE_EXHAUSTION_PER_LEVEL
public const LUNGE_EXHAUSTION_PER_LEVEL = 4.0LUNGE_IMPULSE_PER_LEVEL
public const LUNGE_IMPULSE_PER_LEVEL = 0.458LUNGE_MIN_FOOD
public const LUNGE_MIN_FOOD = 7STAGE_DISENGAGED
public const STAGE_DISENGAGED = 3STAGE_ENDED
public const STAGE_ENDED = 4STAGE_ENGAGED
public const STAGE_ENGAGED = 1STAGE_NONE
public const STAGE_NONE = 0STAGE_TIRED
public const STAGE_TIRED = 2Methods
calculateChargeDamage()
public function calculateChargeDamage(float $relativeSpeed) : floatReturns the damage of a charge hit at the given relative speed (blocks/second), or 0 if too slow.
canChargeKnockBack()
public static function canChargeKnockBack(int $stage, float $relativeSpeed) : boolcanStartUsingItem()
public function canStartUsingItem(\pocketmine\player\Player $player) : boolgetAttackPoints()
public function getAttackPoints() : intgetChargeDamageMultiplier()
public function getChargeDamageMultiplier() : floatReturns the charge damage per block/second of relative speed.
getChargeStage()
public function getChargeStage(int $useDuration) : intReturns the charge stage (STAGE_*) after holding the spear for the given number of ticks.
getChargeTimings()
public function getChargeTimings() : arrayReturns the ticks the use button must be held before the charge starts hitting, followed by the durations of the engaged, tired and disengaged stages.
getCooldownTag()
public function getCooldownTag() : ?stringgetJabCooldownTicks()
public function getJabCooldownTicks() : intReturns the use cooldown started by a jab, in ticks (Bedrock).
getLungeImpulse()
public function getLungeImpulse() : floatReturns the horizontal speed (blocks/tick) a jab with Lunge gives, or 0 without Lunge.
isValidRepairMaterial()
public function isValidRepairMaterial(\pocketmine\item\Item $item) : boolReturns whether the given item can repair this spear in an anvil.
onAttackEntity()
public function onAttackEntity(\pocketmine\entity\Entity $victim, array &$returnedItems) : boolonDestroyBlock()
public function onDestroyBlock(\pocketmine\block\Block $block, array &$returnedItems) : bool