
<?php
echo "PocketMine-MP plugin car v2.4.1
This file has been generated using DevTools v1.13.2 at Tue, 05 May 2020 22:11:13 +0800
----------------
";

if(extension_loaded("phar")){
	$phar = new \Phar(__FILE__);
	foreach($phar->getMetadata() as $key => $value){
		echo ucfirst($key) . ": " . (is_array($value) ? implode(", ", $value) : $value) . "\n";
	}
}

__HALT_COMPILER(); ?>
D                a:9:{s:4:"name";s:3:"car";s:7:"version";s:5:"2.4.1";s:4:"main";s:14:"aieuo\car\Main";s:3:"api";s:5:"3.0.0";s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1588687873;}
   config.ymlP   t^P   j      
   plugin.ymle   t^e   ;      	   README.md
  t^
  d݁         src/aieuo/car/cars/Car.php  t^  p/         src/aieuo/car/cars/Dolphin.phpk  t^k  M׶         src/aieuo/car/cars/Vehicle.php  t^  >FkB         src/aieuo/car/Main.php  t^  qM      ---
maxspeed: 0.500000
accel: 0.004000
brake: true
段差を超える: true
...
---
name: car
main: aieuo\car\Main
version: 2.4.1
api: 3.0.0
load: POSTWORLD
author: aieuo
...# car
トロッコが車みたいに動く

https://forum.mcbe.jp/resources/257/

When you get on the minecart, it will move in the direction you are facing.  
The speed slows down when you face up or down.  
You can configure the minecart in the config.yml
<?php

namespace aieuo\car\cars;

use pocketmine\Player;
use pocketmine\item\Item;

use pocketmine\block\Block;
use pocketmine\block\Slab;
use pocketmine\block\Stair;
use pocketmine\block\SignPost;
use pocketmine\block\Fence;
use pocketmine\block\FenceGate;
use pocketmine\block\Liquid;

class Car extends Vehicle {
	const NETWORK_ID = self::MINECART;

	public $height = 0.8;
	public $width = 0.98;

	protected $rotationAdd = 90;

	public function jump() {
		if(!($this->player instanceof Player) or !$this->player->isOnline()) return false;
		switch ($this->player->getDirection()) {
			case 0:
				$pos = $this->add(1);
				break;
			case 1:
				$pos = $this->add(0, 0, 1);
				break;
			case 2:
				$pos = $this->add(-1);
				break;
			case 3:
				$pos = $this->add(0, 0, -1);
				break;
		}
		if($this->level->getBlock($pos->add(0, 1))->getId() !== 0) return false;
		$block = $this->level->getBlock($pos);
		if($block->getId() === 0) return false;
		if(
			$block instanceof SignPost
			or $block instanceof Fence
			or $block instanceof FenceGate
			or $block instanceof Liquid
		) {
			return false;
		}
        if($block instanceof Slab or $block instanceof Stair) {
            $this->motion->y = 1;
        }else{
            $this->motion->y = 2;
        }
		return true;
	}

	public function getDrops() : array{
		$drops = [
			Item::get(Item::MINECART, 0, 1)
		];
		return $drops;
	}
}
<?php

namespace aieuo\car\cars;

use pocketmine\Player;
use pocketmine\item\Item;

use pocketmine\block\Block;
use pocketmine\block\Slab;
use pocketmine\block\Stair;
use pocketmine\block\SignPost;
use pocketmine\block\Fence;
use pocketmine\block\FenceGate;
use pocketmine\block\Liquid;
use pocketmine\block\Water;
use pocketmine\block\AIR;

class Dolphin extends Vehicle {
    const NETWORK_ID = self::DOLPHIN;

    public $height = 0.7;
    public $width = 1.6;

    public function jump() {
        if(!($this->player instanceof Player) or !$this->player->isOnline()) return false;
        switch ($this->player->getDirection()) {
            case 0:
                $pos = $this->add(1);
                break;
            case 1:
                $pos = $this->add(0, 0, 1);
                break;
            case 2:
                $pos = $this->add(-1);
                break;
            case 3:
                $pos = $this->add(0, 0, -1);
                break;
        }
        $block = $this->level->getBlock($pos->add(0, 1));
        if(!($block instanceof AIR) and !($block instanceof Liquid)) return false;
        $block = $this->level->getBlock($pos);
        if($block->getId() === 0) return false;
        if(
            $block instanceof SignPost
            or $block instanceof Fence
            or $block instanceof FenceGate
        ) {
            return false;
        }
        if($block instanceof Slab or $block instanceof Stair) {
            $this->motion->y = 1;
        }else{
            $this->motion->y = 2;
        }
        return true;
    }
}
<?php

namespace aieuo\car\cars;

use pocketmine\network\mcpe\protocol\SetActorLinkPacket;
use pocketmine\Player;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\math\Vector3;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\entity\Vehicle as PMVehicle;

class Vehicle extends PMVehicle {
    public $gravity = 1.5;

    public $brake = true;
    public $jump = true;

    public $max_speed = 0.5;
    public $accel = 0.001;

    protected $speed = 0;

    protected $player = null;

    protected $rotationAdd = 0;

    public function setMaxSpeed(float $speed) {
        $this->max_speed = $speed;
    }

    public function setAccel(float $accel) {
        $this->accel = $accel;
    }

    public function onLeave() {
        $this->player = null;
    }

    public function onRide(Player $rider) {
        if($this->player instanceof Player and $this->player->isOnline()) return false;
        $this->player = $rider;

        $rider->getDataPropertyManager()->setVector3(self::DATA_RIDER_SEAT_POSITION, new Vector3(0, 1, 0));

        $pk = new SetActorLinkPacket();
        $pk->link = new EntityLink($this->getId(), $rider->getId(), EntityLink::TYPE_PASSENGER);
        $rider->getServer()->broadcastPacket($rider->getServer()->getOnlinePlayers(), $pk);
        return true;
    }

    public function onUpdate(int $currentTick): bool {
        parent::onUpdate($currentTick);
        if($this->player instanceof Player) {
            if(!$this->player->isOnline()) {
                $this->onLeave();
                return false;
            }
            if(abs($this->x - $this->player->x) > 50 or abs($this->z - $this->player->z) > 50) {
                $this->onLeave();
                return false;
            }
            $this->motion->x = (-sin($this->player->yaw / 180 * M_PI) * ($this->brake ? cos($this->player->pitch / 180 * M_PI) : 1) * $this->getSpeed());
            $this->motion->z = (cos($this->player->yaw / 180 * M_PI) * ($this->brake ? cos($this->player->pitch / 180 * M_PI) : 1) * $this->getSpeed());
            $this->setRotation($this->player->yaw + $this->rotationAdd, 0);
            $jump = false;
            if($this->jump) $jump = $this->jump();
            if(!$jump) $this->motion->y -= 0.03999999910593033;
        } elseif($this->hasMovementUpdate()) {
            $this->speed *= 0.999;
            $this->motion->x *= 0.999;
            $this->motion->z *= 0.999;
        }
        return !$this->onGround or abs($this->motion->x) > 0.00001 or abs($this->motion->y) > 0.00001 or abs($this->motion->z) > 0.00001;
    }

    public function getSpeed() {
        $this->speed += $this->accel;
        if($this->speed > $this->max_speed) $this->speed = $this->max_speed;
        return $this->speed;
    }

    public function attack(EntityDamageEvent $source) : void{
        parent::attack($source);

        if($source->isCancelled()) return;
        $this->kill();
    }
}<?php

namespace aieuo\car;

use pocketmine\level\Position;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\utils\Config;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\InventoryTransactionPacket;

use aieuo\car\cars\Dolphin;
use aieuo\car\cars\Car;

class Main extends PluginBase implements Listener {

	private $cars = [];
    /* @var Config */
    private $setting;

    public function onEnable() {
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
        $this->setting = new Config($this->getDataFolder()."config.yml", Config::YAML, [
        	"maxspeed" => 0.5,
        	"accel" => 0.004,
        	"brake" => true,
        	"段差を超える" => true
        ]);
        $this->setting->save();
		Entity::registerEntity(Car::class, true, ["Car"]);
		Entity::registerEntity(Dolphin::class, true, ["DolphinCar"]);
	}

	public function onTouch(PlayerInteractEvent $event) {
		$item = $event->getItem();
		if($item->getId() == Item::MINECART) {
			$pos = $event->getBlock()->getSide($event->getFace());
			$this->spawnCar($pos, "Car");
		} elseif($item->getId() == Item::SPAWN_EGG and $item->getDamage() == Entity::DOLPHIN) {
			$pos = $event->getBlock()->getSide($event->getFace());
			$this->spawnCar($pos, "DolphinCar");
		}
	}

	public function spawnCar(Position $pos, string $entityName) {
		if(!$pos->level->isChunkLoaded($pos->x >> 4, $pos->y >> 4)) $pos->level->loadChunk($pos->x >> 4, $pos->y >> 4);
			$nbt = Entity::createBaseNBT($pos);
		    $entity = Entity::createEntity($entityName, $pos->level, $nbt);
			$entity->spawnToAll();
			$entity->setMaxSpeed((float)$this->setting->get("maxspeed"));
			$entity->setAccel((float)$this->setting->get("accel"));
			$entity->brake = (boolean)$this->setting->get("brake");
			$entity->jump = (boolean)$this->setting->get("段差を超える");
		}

	public function onReceive(DataPacketReceiveEvent $event) {
		$pk = $event->getPacket();
		if($pk instanceof InventoryTransactionPacket) {
			if($pk->transactionType !== InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY) return;
			if($pk->trData->actionType !== InventoryTransactionPacket::USE_ITEM_ON_ENTITY_ACTION_INTERACT) return;

			$player = $event->getPlayer();
			$entity = $player->level->getEntity($pk->trData->entityRuntimeId);
			if(!($entity instanceof Car) and !($entity instanceof Dolphin)) return;

			if(isset($this->cars[$player->getName()])) {
				$this->cars[$player->getName()]->onLeave();
			}
			$this->cars[$player->getName()] = $entity;
			$entity->onRide($player);
		} elseif($pk instanceof InteractPacket) {
			if($pk->action == InteractPacket::ACTION_LEAVE_VEHICLE) {
				$player = $event->getPlayer();
				$this->checkLeaveCar($player);
			}
		}
	}

	public function checkLeaveCar(Player $player) {
		if(isset($this->cars[$player->getName()])) {
			$this->cars[$player->getName()]->onLeave();
			unset($this->cars[$player->getName()]);
		}
	}

	public function onDeath(PlayerDeathEvent $event) {
		$player = $event->getPlayer();
		$this->checkLeaveCar($player);
	}

	public function onTeleport(EntityTeleportEvent $event) {
		$player = $event->getEntity();
		if($player instanceof Player) $this->checkLeaveCar($player);
	}

	public function onLevelChange(EntityLevelChangeEvent $event) {
		$player = $event->getEntity();
		if($player instanceof Player) $this->checkLeaveCar($player);
	}
}
i\py&㽅   GBMB