mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Save items properly on several places, added NBT::getItemHelper() and NBT::putItemHelper()
This commit is contained in:
@ -1039,6 +1039,15 @@ class Item{
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNamedTagEntry($name){
|
||||
$tag = $this->getNamedTag();
|
||||
if($tag !== null){
|
||||
return isset($tag->{$name}) ? $tag->{$name} : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getNamedTag(){
|
||||
if(!$this->hasCompoundTag()){
|
||||
|
@ -24,6 +24,7 @@ namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
|
||||
abstract class Tool extends Item{
|
||||
const TIER_WOODEN = 1;
|
||||
@ -55,6 +56,10 @@ abstract class Tool extends Item{
|
||||
* @return bool
|
||||
*/
|
||||
public function useOn($object){
|
||||
if($this->isUnbreakable()){
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->isHoe()){
|
||||
if(($object instanceof Block) and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)){
|
||||
$this->meta++;
|
||||
@ -101,6 +106,11 @@ abstract class Tool extends Item{
|
||||
return $levels[$type];
|
||||
}
|
||||
|
||||
public function isUnbreakable(){
|
||||
$tag = $this->getNamedTagEntry("Unbreakable");
|
||||
return $tag instanceof Byte and $tag->getValue() > 0;
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user