Class LivingGetProjectileEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.living.LivingGetProjectileEvent

public class LivingGetProjectileEvent extends LivingEvent
This event is fired when a living entity attempts to get a projectile with the LivingEntity.getProjectile(ItemStack) method. The item stack given is usually the item stack of a ProjectileWeaponItem and the item stack returned is usually the item stack of a Projectile.

This event is not ICancellableEvent.

This event does not have a result.

invalid reference
net.neoforged.bus.api.Event.HasResult

This event is fired on the NeoForge.EVENT_BUS.

  • Field Details

    • projectileWeaponItemStack

      private final ItemStack projectileWeaponItemStack
    • projectileItemStack

      private ItemStack projectileItemStack
  • Constructor Details

  • Method Details

    • getProjectileWeaponItemStack

      public ItemStack getProjectileWeaponItemStack()
      Returns:
      The itemstack of the itrm that is looking for a projectile. With vanilla behavior, this usually returns an itemstack of a ProjectileWeaponItem, but it's possible for that to not be the case if modder uses a different implementation of LivingEntity.getProjectile(ItemStack).
    • getProjectileItemStack

      public ItemStack getProjectileItemStack()
      Returns:
      The itemstack of the projectile found. Initially this is set to the projectile found by vanilla behaviour, but it's possible for thatnot to be the case if a modder uses a different implementation of LivingEntity.getProjectile(ItemStack).
    • setProjectileItemStack

      public void setProjectileItemStack(ItemStack projectileItemStack)
      Sets the projectile itemstack to be used.

      If the entity is a player: whenever the projectile is fired/consumed the stack will be shrunk by one. To disable this behaviour you can copy the stack before giving it to the event. For bows, you can use ArrowLooseEvent to remove the arrow yourself.

      Be aware that since this event fires every time a living entity gets a projectile, whether or not its Entity.level is client-side, you will want to make a conditional to always set the item stack to what you'd want it to be to avoid client-server desyncs.