Skip to content

@minecraft/server


@minecraft/server / EntityProjectileComponent

Class: EntityProjectileComponent ​

Defined in: @minecraft/server/index.d.ts:11861

The projectile component controls the properties of a projectile entity and allows it to be shot in a given direction. This component is present when the entity has the minecraft:projectile component.

Example ​

shootArrow.ts

typescript
import { DimensionLocation, EntityProjectileComponent } from '@minecraft/server';

function shootArrow(targetLocation: DimensionLocation) {
  const velocity = { x: 0, y: 1, z: 5 };

  const arrow = targetLocation.dimension.spawnEntity('minecraft:arrow', {
    x: targetLocation.x,
    y: targetLocation.y + 2,
    z: targetLocation.z,
  });

  const projectileComp = arrow.getComponent('minecraft:projectile') as EntityProjectileComponent;

  projectileComp?.shoot(velocity);
}

Extends ​

Properties ​

airInertia ​

airInertia: number

Defined in: @minecraft/server/index.d.ts:11871

Remarks ​

The fraction of the projectile's speed maintained every tick while traveling through air.

This property can't be edited in restricted-execution mode.


catchFireOnHurt ​

catchFireOnHurt: boolean

Defined in: @minecraft/server/index.d.ts:11882

Remarks ​

If true, the entity will be set on fire when hurt. The default burn duration is 5 seconds. This duration can be modified via the onFireTime property. The entity will not catch fire if immune or if the entity is wet.

This property can't be edited in restricted-execution mode.


critParticlesOnProjectileHurt ​

critParticlesOnProjectileHurt: boolean

Defined in: @minecraft/server/index.d.ts:11891

Remarks ​

If true, the projectile will spawn crit particles when hit by a player. E.g. Player attacking a Shulker bullet.

This property can't be edited in restricted-execution mode.


destroyOnProjectileHurt ​

destroyOnProjectileHurt: boolean

Defined in: @minecraft/server/index.d.ts:11900

Remarks ​

If true, the projectile will be destroyed when it takes damage. E.g. Player attacking a Shulker bullet.

This property can't be edited in restricted-execution mode.


entity ​

readonly entity: Entity

Defined in: @minecraft/server/index.d.ts:9981

Remarks ​

The entity that owns this component. The entity will be undefined if it has been removed.

Throws ​

This property can throw when used.

InvalidEntityError

Inherited from ​

EntityComponent.entity


gravity ​

gravity: number

Defined in: @minecraft/server/index.d.ts:11912

Remarks ​

The gravity applied to the projectile. When the entity is not on the ground, subtracts this amount from the projectile’s change in vertical position every tick. The higher the value, the faster the projectile falls. If negative, the entity will rise instead of fall.

This property can't be edited in restricted-execution mode.


hitEntitySound? ​

optional hitEntitySound?: string

Defined in: @minecraft/server/index.d.ts:11920

Remarks ​

The sound that plays when the projectile hits an entity.

This property can't be edited in restricted-execution mode.


hitGroundSound? ​

optional hitGroundSound?: string

Defined in: @minecraft/server/index.d.ts:11928

Remarks ​

The sound that plays when the projectile hits a block.

This property can't be edited in restricted-execution mode.


hitParticle? ​

optional hitParticle?: string

Defined in: @minecraft/server/index.d.ts:11936

Remarks ​

The particle that spawns when the projectile hits something.

This property can't be edited in restricted-execution mode.


isValid ​

readonly isValid: boolean

Defined in: @minecraft/server/index.d.ts:6234

Remarks ​

Returns whether the component is valid. A component is considered valid if its owner is valid, in addition to any addition to any additional validation required by the component.

Inherited from ​

EntityComponent.isValid


lightningStrikeOnHit ​

lightningStrikeOnHit: boolean

Defined in: @minecraft/server/index.d.ts:11947

Remarks ​

If true and the weather is thunder and the entity has line of sight to the sky, the entity will be struck by lightning when hit. E.g. A thrown Trident with the Channeling enchantment.

This property can't be edited in restricted-execution mode.


liquidInertia ​

liquidInertia: number

Defined in: @minecraft/server/index.d.ts:11956

Remarks ​

The fraction of the projectile's speed maintained every tick while traveling through a liquid.

This property can't be edited in restricted-execution mode.


onFireTime ​

onFireTime: number

Defined in: @minecraft/server/index.d.ts:11965

Remarks ​

Duration in seconds that the entity hit will be on fire for when catchFireOnHurt is set to true.

This property can't be edited in restricted-execution mode.


owner? ​

optional owner?: Entity

Defined in: @minecraft/server/index.d.ts:11975

Remarks ​

The owner of the projectile. This is used to determine what the projectile can collide with and damage. It also determines which entity is assigned as the attacker.

This property can't be edited in restricted-execution mode.


shouldBounceOnHit ​

shouldBounceOnHit: boolean

Defined in: @minecraft/server/index.d.ts:11984

Remarks ​

If true, the projectile will bounce off mobs when no damage is taken. E.g. A spawning wither.

This property can't be edited in restricted-execution mode.


stopOnHit ​

stopOnHit: boolean

Defined in: @minecraft/server/index.d.ts:11994

Remarks ​

If true, the projectile will stop moving when an entity is hit as thought it had been blocked. E.g. Thrown trident on hit behavior.

This property can't be edited in restricted-execution mode.


typeId ​

readonly typeId: string

Defined in: @minecraft/server/index.d.ts:6240

Remarks ​

Identifier of the component.

Inherited from ​

EntityComponent.typeId


componentId ​

readonly static componentId: "minecraft:projectile" = 'minecraft:projectile'

Defined in: @minecraft/server/index.d.ts:11995

Methods ​

shoot() ​

shoot(velocity, options?): void

Defined in: @minecraft/server/index.d.ts:12011

Parameters ​

velocity ​

Vector3

The velocity to fire the projectile. This controls both the speed and direction which which the projectile will be shot.

options? ​

ProjectileShootOptions

Optional configuration for the shoot.

Returns ​

void

Remarks ​

Shoots the projectile with a given velocity. The projectile will be shot from its current location.

This function can't be called in restricted-execution mode.

Throws ​

Throws if the component or entity no longer exist.