Add Releasable interface (#3664)

closes #3301
This commit is contained in:
Govdim 2020-06-30 23:09:10 +03:00 committed by GitHub
parent 74a919353f
commit 7f81507ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 4 deletions

View File

@ -34,7 +34,7 @@ use pocketmine\world\sound\BowShootSound;
use function intdiv;
use function min;
class Bow extends Tool{
class Bow extends Tool implements Releasable{
public function getFuelTime() : int{
return 200;

View File

@ -28,7 +28,7 @@ use pocketmine\entity\Consumable;
/**
* Interface implemented by objects that can be consumed by mobs.
*/
interface ConsumableItem extends Consumable{
interface ConsumableItem extends Consumable, Releasable{
/**
* Returns the leftover that this Consumable produces when it is consumed. For Items, this is usually air, but could

31
src/item/Releasable.php Normal file
View File

@ -0,0 +1,31 @@
<?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\item;
/**
* Interface implemented by objects that can be used.
*/
interface Releasable{
}

View File

@ -78,6 +78,7 @@ use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\enchantment\MeleeWeaponEnchantment;
use pocketmine\item\Item;
use pocketmine\item\ItemUseResult;
use pocketmine\item\Releasable;
use pocketmine\lang\Language;
use pocketmine\lang\TranslationContainer;
use pocketmine\math\Vector3;
@ -1476,8 +1477,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->inventory->setItemInHand($item);
}
//TODO: check if item has a release action - if it doesn't, this shouldn't be set
$this->setUsingItem(true);
$this->setUsingItem($item instanceof Releasable);
return true;
}