Skip to content

AbstractMinecart 5.46.0 ​

abstract class · pocketmine\entity\vehicle\AbstractMinecart · source

Extends Entity
Implements DetectorRailActivator

Base of all minecarts: rail physics, damage, activator rails, pushing and the network data shared by every cart.

The rail physics are vanilla's (Java OldMinecartBehavior, the default movement, which Bedrock carts also follow): carts snap onto the rail line, slide down slopes, keep 99.7% (ridden) or 96% (empty) of their speed per tick, powered rails accelerate them by 0.06 per tick (and kick stopped carts away from a solid block), unpowered powered rails brake them, and the top speed is 0.4 blocks per tick (8 m/s), 0.2 in water. Off rails they fall like other entities and keep half of their speed on the ground.

Hits add 10 x the damage to an accumulated "damage" value that decays by 1 per tick: the cart breaks above 40 (a few quick punches), at once when hit by a creative player (without drops).

Constants ​

BOARDING_COOLDOWN_TICKS ​

php
public const BOARDING_COOLDOWN_TICKS = 60

Ticks a passenger ejected by an activator rail can't be picked up again.

BREAK_DAMAGE ​

php
public const BREAK_DAMAGE = 40.0

Accumulated damage above which the cart breaks.

MAX_SPEED ​

php
public const MAX_SPEED = 0.4

MAX_SPEED_IN_WATER ​

php
public const MAX_SPEED_IN_WATER = 0.2

NETWORK_Y_OFFSET ​

php
public const NETWORK_Y_OFFSET = 0.35

Network position of a cart: Bedrock clients place minecarts by their middle, 0.35 above the bottom.

POWERED_RAIL_BOOST ​

php
public const POWERED_RAIL_BOOST = 0.06

Acceleration of a powered rail on a moving cart, per tick.

POWERED_RAIL_START_SPEED ​

php
public const POWERED_RAIL_START_SPEED = 0.02

Speed a powered rail gives a stopped cart next to a solid block.

RESYNC_DISTANCE ​

php
public const RESYNC_DISTANCE = 8.0

Distance of the players for which a standing cart resyncs its position.

RESYNC_INTERVAL ​

php
public const RESYNC_INTERVAL = 40

Ticks between two position resyncs of a standing cart with a player close to it.

SLOPE_ACCELERATION ​

php
public const SLOPE_ACCELERATION = 0.0078125

Speed added down a slope per tick.

TAG_DISPLAY_OFFSET ​

php
public const TAG_DISPLAY_OFFSET = "DisplayOffset"

TAG_DISPLAY_STATE ​

php
public const TAG_DISPLAY_STATE = "DisplayState"

TAG_FLIPPED ​

php
public const TAG_FLIPPED = "FlippedRotation"

Properties ​

$customDisplayBlock protected ​

php
protected ?\pocketmine\block\Block $customDisplayBlock

$customDisplayOffset protected ​

php
protected ?int $customDisplayOffset

$damage protected ​

php
protected float $damage

$flipped protected ​

php
protected bool $flipped

$hurtDirection protected ​

php
protected int $hurtDirection

$hurtTime protected ​

php
protected int $hurtTime

$onRails protected ​

php
protected bool $onRails

Methods ​

animateHurt() protected ​

php
protected function animateHurt() : void

Shakes the cart like a hit does (vanilla hurt animation).

attack() ​

php
public function attack(\pocketmine\event\entity\EntityDamageEvent $source) : void

blockArea() ​

php
public static function blockArea(int $x, int $y, int $z) : \pocketmine\math\AxisAlignedBB

Area used to find the cart in a block space (hoppers, detector rails).

breakCart() ​

php
public function breakCart(bool $drops) : void

Breaks the cart: drops its items (if $drops) and removes it. Container contents are dropped by AbstractMinecart::onDeath() in any case.

canPickUp() protected ​

php
protected function canPickUp(\pocketmine\entity\Entity $entity) : bool

Whether the entity gets in this cart when they bump into each other.

comeOffTrack() protected ​

php
protected function comeOffTrack() : void

Movement without rails (vanilla comeOffTrack()).

create() ​

php
public static function create(\pocketmine\entity\vehicle\MinecartType $type, \pocketmine\entity\Location $location) : \pocketmine\entity\vehicle\AbstractMinecart

Creates a minecart of the given type (not spawned).

createMovementPacket() protected ​

php
protected function createMovementPacket() : \pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket

getCartDrops() ​

php
public function getCartDrops() : array

Returns the items this cart drops when broken by a survival player (Bedrock drops the minecart and the block separately). Container contents are dropped separately.

getCurrentRailPos() ​

php
public function getCurrentRailPos() : array

Block position of the rail the cart is on: the block at its feet, or the one below if that is a rail.

getCustomDisplayBlock() ​

php
public function getCustomDisplayBlock() : ?\pocketmine\block\Block

Returns the custom block shown inside the cart (vanilla DisplayState), or null for the default look.

getCustomDisplayOffset() ​

php
public function getCustomDisplayOffset() : ?int

Height of the display block in sixteenths of a block (vanilla default 6), or null for the default.

getDamage() ​

php
public function getDamage() : float

Returns the accumulated damage (the cart breaks above AbstractMinecart::BREAK_DAMAGE).

getDetectorRailComparatorOutput() ​

php
public function getDetectorRailComparatorOutput() : int

getHeadYaw() ​

php
public function getHeadYaw() : float

getHurtDirection() ​

php
public function getHurtDirection() : int

getHurtTime() ​

php
public function getHurtTime() : int

getInitialDragMultiplier() protected ​

php
protected function getInitialDragMultiplier() : float

getInitialGravity() protected ​

php
protected function getInitialGravity() : float

getInitialSizeInfo() protected ​

php
protected function getInitialSizeInfo() : \pocketmine\entity\EntitySizeInfo

getMaxSpeed() ​

php
public function getMaxSpeed() : float

getMinecartType() ​

php
abstract public function getMinecartType() : \pocketmine\entity\vehicle\MinecartType

Returns the type of this cart.

getOffsetPosition() ​

php
public function getOffsetPosition(\pocketmine\math\Vector3 $vector3) : \pocketmine\math\Vector3

getPassengerPosition() ​

php
public function getPassengerPosition(\pocketmine\entity\Entity $passenger) : \pocketmine\math\Vector3

getPickedItem() ​

php
public function getPickedItem() : ?\pocketmine\item\Item

getPlacementPosition() ​

php
public static function getPlacementPosition(\pocketmine\block\Block $rail) : ?\pocketmine\math\Vector3

Creates the cart at the position of a rail block, like a minecart item used on it (vanilla MinecartItem.useOn()): in the middle of the block, just above the rail (half a block higher on slopes).

getRailPoint() ​

php
public function getRailPoint(float $x, float $y, float $z) : ?\pocketmine\math\Vector3

Point of the rail line under the given position (vanilla OldMinecartBehavior.getPos()), or null if there is no rail there.

getRailShape() ​

php
public static function getRailShape(\pocketmine\block\Block $block) : ?int

Returns the rail shape (BlockLegacyMetadata::RAIL_*) of a rail block, or null if the block isn't a rail.

getRailYaw() ​

php
public static function getRailYaw(\pocketmine\block\Block $rail) : float

Yaw of a cart standing on the given rail: along the rail (carts face along X at yaw 0, like vanilla).

getSlowdownFactor() protected ​

php
protected function getSlowdownFactor(bool $inWater) : float

Fraction of the horizontal speed kept per tick on rails (vanilla applyNaturalSlowdown()).

handleRiderInput() ​

php
public function handleRiderInput(\pocketmine\player\Player $rider, \pocketmine\entity\riding\RiderInput $input) : void

Called every tick with the input of the player riding this cart.

hasMovementUpdate() ​

php
public function hasMovementUpdate() : bool

initEntity() protected ​

php
protected function initEntity(\pocketmine\nbt\tag\CompoundTag $nbt) : void

isBroken() ​

php
public function isBroken() : bool

isFlipped() ​

php
public function isFlipped() : bool

isInWater() ​

php
public function isInWater() : bool

Returns whether the cart is in water (slower, lower top speed).

isOnRails() ​

php
public function isOnRails() : bool

isRideable() ​

php
public function isRideable() : bool

Whether entities can get in this cart (plain minecarts).

isSlope() ​

php
public static function isSlope(int $shape) : bool

Returns whether the rail shape is a slope.

move() protected ​

php
protected function move(float $dx, float $dy, float $dz) : void

Carts move themselves in AbstractMinecart::tryChangeMovement(); the generic movement step of Entity::onUpdate() is skipped.

moveAlongTrack() protected ​

php
protected function moveAlongTrack(int $bx, int $by, int $bz, \pocketmine\block\Block $block, int $shape, bool $inWater) : void

Vanilla OldMinecartBehavior.moveAlongTrack().

onActivatorRail() protected ​

php
protected function onActivatorRail(bool $powered) : void

Called every tick the cart is on an activator rail (vanilla activateMinecart()).

onDamaged() protected ​

php
protected function onDamaged(\pocketmine\event\entity\EntityDamageEvent $source) : bool

Called with an uncancelled damage before it is applied. Returns true if the damage was fully handled (e.g. a TNT minecart exploding).

onDeathUpdate() protected ​

php
protected function onDeathUpdate(int $tickDiff) : bool

onPassengerRemoved() protected ​

php
protected function onPassengerRemoved(\pocketmine\entity\Entity $passenger) : void

pushAndPickupEntities() protected ​

php
protected function pushAndPickupEntities() : void

Vanilla pushAndPickupEntities(), with the Bedrock "pull_in_entities" of the rideable minecart: mobs walking into an empty cart get in.

pushBy() ​

php
public function pushBy(\pocketmine\entity\Entity $entity) : void

Pushes this cart away from the entity (vanilla AbstractMinecart.push(Entity)): carts push each other along their rails, other entities get a quarter of the push.

saveNBT() ​

php
public function saveNBT() : \pocketmine\nbt\tag\CompoundTag

setBoardingCooldown() ​

php
public function setBoardingCooldown(\pocketmine\entity\Entity $entity, int $ticks = self::BOARDING_COOLDOWN_TICKS) : void

Prevents the entity from being picked up by this cart for the given number of ticks.

setCustomDisplayBlock() ​

php
public function setCustomDisplayBlock(?\pocketmine\block\Block $block) : void

setCustomDisplayOffset() ​

php
public function setCustomDisplayOffset(?int $offset) : void

setDamage() ​

php
public function setDamage(float $damage) : void

shouldSourceDestroy() protected ​

php
protected function shouldSourceDestroy(\pocketmine\event\entity\EntityDamageEvent $source) : bool

Whether the damage destroys the cart whatever its accumulated damage.

syncNetworkData() protected ​

php
protected function syncNetworkData(\pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection $properties) : void

tickMinecart() protected ​

php
protected function tickMinecart() : void

One tick of vanilla minecart physics (AbstractMinecart.tick() + OldMinecartBehavior.tick()).

tryChangeMovement() protected ​

php
protected function tryChangeMovement() : void

updateMovement() protected ​

php
protected function updateMovement(bool $teleport = false) : void

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.