This commit is contained in:
PEMapModder 2016-02-22 16:29:41 +08:00
parent 17c73e9764
commit 1574a823d4

View File

@ -25,23 +25,18 @@
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\Fence;
use pocketmine\block\Flower;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\Squid;
use pocketmine\entity\Villager;
use pocketmine\entity\Zombie;
use pocketmine\inventory\Fuel; use pocketmine\inventory\Fuel;
use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\Enchantment;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\NBT;
use pocketmine\utils\Config;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\Config;
class Item{ class Item{
@ -643,7 +638,7 @@ class Item{
$creativeItems = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/creativeitems.json", Config::JSON, []); $creativeItems = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/creativeitems.json", Config::JSON, []);
foreach($creativeItems->getAll() as $item) { foreach($creativeItems->getAll() as $item){
self::addCreativeItem(Item::get($item["ID"], $item["Damage"])); self::addCreativeItem(Item::get($item["ID"], $item["Damage"]));
} }
} }
@ -679,6 +674,7 @@ class Item{
/** /**
* @param $index * @param $index
*
* @return Item * @return Item
*/ */
public static function getCreativeItem(int $index){ public static function getCreativeItem(int $index){
@ -712,7 +708,8 @@ class Item{
/** /**
* @param string $str * @param string $str
* @param bool $multiple * @param bool $multiple
*
* @return Item[]|Item * @return Item[]|Item
*/ */
public static function fromString(string $str, bool $multiple = false){ public static function fromString(string $str, bool $multiple = false){
@ -772,7 +769,7 @@ class Item{
public function getCompoundTag(){ public function getCompoundTag(){
return $this->tags; return $this->tags;
} }
public function hasCompoundTag() : bool{ public function hasCompoundTag() : bool{
return $this->tags !== "" and $this->tags !== null; return $this->tags !== "" and $this->tags !== null;
} }
@ -851,6 +848,7 @@ class Item{
/** /**
* @param $id * @param $id
*
* @return Enchantment|null * @return Enchantment|null
*/ */
public function getEnchantment(int $id){ public function getEnchantment(int $id){
@ -963,7 +961,7 @@ class Item{
$this->clearCustomName(); $this->clearCustomName();
} }
if(!$this->hasCompoundTag()){ if(!($hadCompoundTag = $this->hasCompoundTag())){
$tag = new CompoundTag("", []); $tag = new CompoundTag("", []);
}else{ }else{
$tag = $this->getNamedTag(); $tag = $this->getNamedTag();
@ -977,6 +975,10 @@ class Item{
]); ]);
} }
if(!$hadCompoundTag){
$this->setCompoundTag($tag);
}
return $this; return $this;
} }
@ -1130,7 +1132,7 @@ class Item{
} }
final public function __toString() : string{ final public function __toString() : string{
return "Item " . $this->name . " (" . $this->id . ":" . ($this->meta === null ? "?" : $this->meta) . ")x" . $this->count . ($this->hasCompoundTag() ? " tags:0x".bin2hex($this->getCompoundTag()) : ""); return "Item " . $this->name . " (" . $this->id . ":" . ($this->meta === null ? "?" : $this->meta) . ")x" . $this->count . ($this->hasCompoundTag() ? " tags:0x" . bin2hex($this->getCompoundTag()) : "");
} }
public function getDestroySpeed(Block $block, Player $player){ public function getDestroySpeed(Block $block, Player $player){