mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
More consistent fluency in Item API
This commit is contained in:
parent
1045088668
commit
d4fe004375
@ -83,9 +83,12 @@ abstract class Armor extends Durable{
|
||||
* Sets the dyed colour of this armour piece. This generally only applies to leather armour.
|
||||
*
|
||||
* @param Color $color
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomColor(Color $color) : void{
|
||||
public function setCustomColor(Color $color) : self{
|
||||
$this->getNamedTag()->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($color->toARGB()));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,8 +77,10 @@ class Banner extends Item{
|
||||
|
||||
/**
|
||||
* @param Deque|BannerPattern[] $patterns
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPatterns(Deque $patterns) : void{
|
||||
public function setPatterns(Deque $patterns) : self{
|
||||
$tag = new ListTag();
|
||||
/** @var BannerPattern $pattern */
|
||||
foreach($patterns as $pattern){
|
||||
@ -88,6 +90,7 @@ class Banner extends Item{
|
||||
);
|
||||
}
|
||||
$this->getNamedTag()->setTag(self::TAG_PATTERNS, $tag);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -48,9 +48,12 @@ abstract class Durable extends Item{
|
||||
* Sets whether the item will take damage when used.
|
||||
*
|
||||
* @param bool $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUnbreakable(bool $value = true) : void{
|
||||
public function setUnbreakable(bool $value = true) : self{
|
||||
$this->getNamedTag()->setByte("Unbreakable", $value ? 1 : 0);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,13 +75,11 @@ class WritableBook extends Item{
|
||||
* @param int $pageId
|
||||
* @param string $pageText
|
||||
*
|
||||
* @return bool indicating whether the page was created or not.
|
||||
* @return $this
|
||||
*/
|
||||
public function setPageText(int $pageId, string $pageText) : bool{
|
||||
$created = false;
|
||||
public function setPageText(int $pageId, string $pageText) : self{
|
||||
if(!$this->pageExists($pageId)){
|
||||
$this->addPage($pageId);
|
||||
$created = true;
|
||||
}
|
||||
|
||||
/** @var CompoundTag[]|ListTag $pagesTag */
|
||||
@ -92,7 +90,7 @@ class WritableBook extends Item{
|
||||
|
||||
$this->getNamedTag()->setTag(self::TAG_PAGES, $pagesTag);
|
||||
|
||||
return $created;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,8 +98,10 @@ class WritableBook extends Item{
|
||||
* Creates a new page for every page between the given ID and existing pages that doesn't yet exist.
|
||||
*
|
||||
* @param int $pageId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addPage(int $pageId) : void{
|
||||
public function addPage(int $pageId) : self{
|
||||
if($pageId < 0){
|
||||
throw new \InvalidArgumentException("Page number \"$pageId\" is out of range");
|
||||
}
|
||||
@ -116,6 +116,7 @@ class WritableBook extends Item{
|
||||
}
|
||||
|
||||
$this->getNamedTag()->setTag(self::TAG_PAGES, $pagesTag);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,13 +124,13 @@ class WritableBook extends Item{
|
||||
*
|
||||
* @param int $pageId
|
||||
*
|
||||
* @return bool indicating success
|
||||
* @return $this
|
||||
*/
|
||||
public function deletePage(int $pageId) : bool{
|
||||
public function deletePage(int $pageId) : self{
|
||||
$pagesTag = $this->getPagesTag();
|
||||
$pagesTag->remove($pageId);
|
||||
|
||||
return true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,9 +139,9 @@ class WritableBook extends Item{
|
||||
* @param int $pageId
|
||||
* @param string $pageText
|
||||
*
|
||||
* @return bool indicating success
|
||||
* @return $this
|
||||
*/
|
||||
public function insertPage(int $pageId, string $pageText = "") : bool{
|
||||
public function insertPage(int $pageId, string $pageText = "") : self{
|
||||
$pagesTag = $this->getPagesTag();
|
||||
|
||||
$pagesTag->insert($pageId, CompoundTag::create()
|
||||
@ -150,7 +151,7 @@ class WritableBook extends Item{
|
||||
|
||||
$this->getNamedTag()->setTag(self::TAG_PAGES, $pagesTag);
|
||||
|
||||
return true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,12 +198,14 @@ class WritableBook extends Item{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param CompoundTag[] $pages
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPages(array $pages) : void{
|
||||
public function setPages(array $pages) : self{
|
||||
$nbt = $this->getNamedTag();
|
||||
$nbt->setTag(self::TAG_PAGES, new ListTag($pages, NBT::TAG_Compound));
|
||||
$this->setNamedTag($nbt);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -56,14 +56,17 @@ class WrittenBook extends WritableBook{
|
||||
* Sets the generation of a book.
|
||||
*
|
||||
* @param int $generation
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setGeneration(int $generation) : void{
|
||||
public function setGeneration(int $generation) : self{
|
||||
if($generation < 0 or $generation > 3){
|
||||
throw new \InvalidArgumentException("Generation \"$generation\" is out of range");
|
||||
}
|
||||
$namedTag = $this->getNamedTag();
|
||||
$namedTag->setInt(self::TAG_GENERATION, $generation);
|
||||
$this->setNamedTag($namedTag);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,11 +84,14 @@ class WrittenBook extends WritableBook{
|
||||
* Sets the author of this book.
|
||||
*
|
||||
* @param string $authorName
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuthor(string $authorName) : void{
|
||||
public function setAuthor(string $authorName) : self{
|
||||
$namedTag = $this->getNamedTag();
|
||||
$namedTag->setString(self::TAG_AUTHOR, $authorName);
|
||||
$this->setNamedTag($namedTag);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,10 +107,13 @@ class WrittenBook extends WritableBook{
|
||||
* Sets the author of this book.
|
||||
*
|
||||
* @param string $title
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTitle(string $title) : void{
|
||||
public function setTitle(string $title) : self{
|
||||
$namedTag = $this->getNamedTag();
|
||||
$namedTag->setString(self::TAG_TITLE, $title);
|
||||
$this->setNamedTag($namedTag);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user