mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
162 lines
4.2 KiB
PHP
162 lines
4.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\block;
|
|
|
|
use pocketmine\block\utils\HorizontalFacingOption;
|
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
|
use pocketmine\entity\Entity;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\math\Facing;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\player\Player;
|
|
use pocketmine\world\BlockTransaction;
|
|
use function array_intersect_key;
|
|
use function count;
|
|
use function spl_object_id;
|
|
|
|
class Vine extends Flowable{
|
|
|
|
/** @var HorizontalFacingOption[] */
|
|
protected array $faces = [];
|
|
|
|
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
|
$w->enumSet($this->faces, HorizontalFacingOption::cases());
|
|
}
|
|
|
|
/** @return HorizontalFacingOption[] */
|
|
public function getFaces() : array{ return $this->faces; }
|
|
|
|
public function hasFace(HorizontalFacingOption $face) : bool{
|
|
return isset($this->faces[spl_object_id($face)]);
|
|
}
|
|
|
|
/**
|
|
* @param HorizontalFacingOption[] $faces
|
|
* @return $this
|
|
*/
|
|
public function setFaces(array $faces) : self{
|
|
$uniqueFaces = [];
|
|
foreach($faces as $face){
|
|
if(!$face instanceof HorizontalFacingOption){
|
|
throw new \InvalidArgumentException("Expected array of HorizontalFacingOption");
|
|
}
|
|
$uniqueFaces[spl_object_id($face)] = $face;
|
|
}
|
|
$this->faces = $uniqueFaces;
|
|
return $this;
|
|
}
|
|
|
|
/** @return $this */
|
|
public function setFace(HorizontalFacingOption $face, bool $value) : self{
|
|
if($value){
|
|
$this->faces[spl_object_id($face)] = $face;
|
|
}else{
|
|
unset($this->faces[spl_object_id($face)]);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function hasEntityCollision() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function canClimb() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function canBeReplaced() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function onEntityInside(Entity $entity) : bool{
|
|
$entity->resetFallDistance();
|
|
return true;
|
|
}
|
|
|
|
protected function recalculateCollisionBoxes() : array{
|
|
return [];
|
|
}
|
|
|
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
$oppositeFace = Facing::opposite($face);
|
|
$hzFacing = HorizontalFacingOption::tryFromFacing($oppositeFace);
|
|
if($hzFacing === null || !$blockReplace->getSide($oppositeFace)->isFullCube()){
|
|
return false;
|
|
}
|
|
|
|
$this->faces = $blockReplace instanceof Vine ? $blockReplace->faces : [];
|
|
$this->faces[spl_object_id($hzFacing)] = $hzFacing;
|
|
|
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
}
|
|
|
|
public function onNearbyBlockChange() : void{
|
|
$changed = false;
|
|
|
|
$up = $this->getSide(Facing::UP);
|
|
//check which faces have corresponding vines in the block above
|
|
$supportedFaces = $up instanceof Vine ? array_intersect_key($this->faces, $up->faces) : [];
|
|
|
|
foreach($this->faces as $face){
|
|
if(!isset($supportedFaces[spl_object_id($face)]) && !$this->getSide($face->toFacing())->isSolid()){
|
|
unset($this->faces[spl_object_id($face)]);
|
|
$changed = true;
|
|
}
|
|
}
|
|
|
|
if($changed){
|
|
$world = $this->position->getWorld();
|
|
if(count($this->faces) === 0){
|
|
$world->useBreakOn($this->position);
|
|
}else{
|
|
$world->setBlock($this->position, $this);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function ticksRandomly() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function onRandomTick() : void{
|
|
//TODO: vine growth
|
|
}
|
|
|
|
public function getDrops(Item $item) : array{
|
|
if(($item->getBlockToolType() & BlockToolType::SHEARS) !== 0){
|
|
return $this->getDropsForCompatibleTool($item);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public function getFlameEncouragement() : int{
|
|
return 15;
|
|
}
|
|
|
|
public function getFlammability() : int{
|
|
return 100;
|
|
}
|
|
}
|