For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/EntityRideableComponent.md.

Class: EntityRideableComponent

entity component

Beta

当添加时,此组件添加了实体可以被另一个实体骑乘的能力。

When added, this component adds the capability that an entity can be ridden by another entity.

Example

minibiomes.ts

import { EntityComponentTypes } from '@minecraft/server';
import { Test, register } from '@minecraft/server-gametest';
import { MinecraftBlockTypes, MinecraftEntityTypes } from '@minecraft/vanilla-data';

function minibiomes(test: Test) {
  const minecart = test.spawn(MinecraftEntityTypes.Minecart, { x: 9, y: 7, z: 7 });
  const pig = test.spawn(MinecraftEntityTypes.Pig, { x: 9, y: 7, z: 7 });

  test.setBlockType(MinecraftBlockTypes.Cobblestone, { x: 10, y: 7, z: 7 });

  const minecartRideableComp = minecart.getComponent(EntityComponentTypes.Rideable);

  minecartRideableComp?.addRider(pig);

  test.succeedWhenEntityPresent(MinecraftEntityTypes.Pig, { x: 8, y: 3, z: 1 }, true);
}
register('ChallengeTests', 'minibiomes', minibiomes).structureName('gametests:minibiomes').maxTicks(160);

Extends

Properties

controllingSeat

readonly controllingSeat: number

Beta

Remarks

可用于控制此实体的座位(从零开始索引)。

Zero-based index of the seat that can used to control this entity.

Throws

This property can throw when used.


crouchingSkipInteract

readonly crouchingSkipInteract: boolean

Beta

Remarks

确定当实体蹲下时是否不支持交互。

Determines whether interactions are not supported if the entity is crouching.

Throws

This property can throw when used.


entity

readonly entity: Entity

Beta

Remarks

拥有此组件的实体。如果实体已被移除,则实体将为 undefined

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


interactText

readonly interactText: string

Beta

Remarks

当玩家看着要骑乘此实体时应该显示的一组文本(通常用于触摸屏控制)。

Set of text that should be displayed when a player is looking to ride on this entity (commonly with touch-screen controls).

Throws

This property can throw when used.


isValid

readonly isValid: boolean

Beta

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


passengerMaxWidth

readonly passengerMaxWidth: number

Beta

Remarks

可成为乘客的生物的最大宽度。

The max width a mob can be to be a passenger.

Throws

This property can throw when used.


pullInEntities

readonly pullInEntities: boolean

Beta

Remarks

如果为 true,此实体将把具有正确 family_types 的实体拉入任何可用座位。

If true, this entity will pull in entities that are in the correct family_types into any available seat.

Throws

This property can throw when used.


riderCanInteract

readonly riderCanInteract: boolean

Beta

Remarks

如果为 true,骑乘者看着此实体时可以被拾取。

If true, this entity will be picked when looked at by the rider.

Throws

This property can throw when used.


seatCount

readonly seatCount: number

Beta

Remarks

为此实体定义的骑乘者座位数量。

Number of seats for riders defined for this entity.

Throws

This property can throw when used.


typeId

readonly typeId: string

Beta

Remarks

组件的标识符。

Identifier of the component.

Inherited from

EntityComponent.typeId


componentId

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

Beta

Methods

addRider()

addRider(rider): boolean

World Mutation Beta

Parameters

rider

Entity

将成为此实体骑乘者的实体。

Entity that will become the rider of this entity.

Returns

boolean

如果骑乘者实体成功添加,则返回 true

True if the rider entity was successfully added.

Remarks

向此实体添加一个骑乘者实体。

Adds an entity to this entity as a rider.

Throws

This function can throw errors.

Example

minibiomes.ts

import { EntityComponentTypes } from '@minecraft/server';
import { Test, register } from '@minecraft/server-gametest';
import { MinecraftBlockTypes, MinecraftEntityTypes } from '@minecraft/vanilla-data';

function minibiomes(test: Test) {
  const minecart = test.spawn(MinecraftEntityTypes.Minecart, { x: 9, y: 7, z: 7 });
  const pig = test.spawn(MinecraftEntityTypes.Pig, { x: 9, y: 7, z: 7 });

  test.setBlockType(MinecraftBlockTypes.Cobblestone, { x: 10, y: 7, z: 7 });

  const minecartRideableComp = minecart.getComponent(EntityComponentTypes.Rideable);

  minecartRideableComp?.addRider(pig);

  test.succeedWhenEntityPresent(MinecraftEntityTypes.Pig, { x: 8, y: 3, z: 1 }, true);
}
register('ChallengeTests', 'minibiomes', minibiomes).structureName('gametests:minibiomes').maxTicks(160);

ejectRider()

ejectRider(rider): void

World Mutation Beta

Parameters

rider

Entity

应从此实体弹射的实体。

Entity that should be ejected from this entity.

Returns

void

Remarks

弹射此实体的指定骑乘者。

Ejects the specified rider of this entity.

Throws

This function can throw errors.


ejectRiders()

ejectRiders(): void

World Mutation Beta

Returns

void

Remarks

弹射此实体的所有骑乘者。

Ejects all riders of this entity.

Throws

This function can throw errors.


getFamilyTypes()

getFamilyTypes(): string[]

Beta

Returns

string[]

Remarks

此实体支持的作为骑乘者的实体类型字符串列表。

A string-list of entity types that this entity can support as riders.

Throws

This function can throw errors.


getRiders()

getRiders(): Entity[]

Beta

Returns

Entity[]

Remarks

获取当前骑乘此实体的所有实体列表。

Gets a list of the all the entities currently riding this entity.

Throws

This function can throw errors.


getSeats()

getSeats(): Seat[]

Beta

Returns

Seat[]

Remarks

获取骑乘此实体的每个位置的位置和骑乘者数量列表。

Gets a list of positions and number of riders for each position for entities riding this entity.

Throws

This function can throw errors.

同领域相关