Dylan K. Taylor 7b6d76871c Block: add face and clickVector to onActivate() parameters, closes #267
this is an old old old issue, i don't know why it wasn't addressed sooner.
2019-02-13 14:29:59 +00:00

113 lines
2.9 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\BlockDataValidator;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\tile\ItemFrame as TileItemFrame;
use function lcg_value;
class ItemFrame extends Flowable{
protected $id = Block::ITEM_FRAME_BLOCK;
protected $itemId = Item::ITEM_FRAME;
/** @var int */
protected $facing = Facing::NORTH;
public function __construct(){
}
protected function writeStateToMeta() : int{
return 5 - $this->facing;
}
public function readStateFromMeta(int $meta) : void{
$this->facing = BlockDataValidator::readHorizontalFacing(5 - $meta);
}
public function getStateBitmask() : int{
return 0b11;
}
protected function getTileClass() : ?string{
return TileItemFrame::class;
}
public function getName() : string{
return "Item Frame";
}
public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$tile = $this->level->getTile($this);
if($tile instanceof TileItemFrame){
if($tile->hasItem()){
$tile->setItemRotation(($tile->getItemRotation() + 1) % 8);
}elseif(!$item->isNull()){
$tile->setItem($item->pop());
}
}
return true;
}
public function onNearbyBlockChange() : void{
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){
$this->level->useBreakOn($this);
}
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Facing::DOWN or $face === Facing::UP or !$blockClicked->isSolid()){
return false;
}
$this->facing = $face;
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function getDropsForCompatibleTool(Item $item) : array{
$drops = parent::getDropsForCompatibleTool($item);
$tile = $this->level->getTile($this);
if($tile instanceof TileItemFrame){
$tileItem = $tile->getItem();
if(lcg_value() <= $tile->getItemDropChance() and !$tileItem->isNull()){
$drops[] = $tileItem;
}
}
return $drops;
}
public function isAffectedBySilkTouch() : bool{
return false;
}
}