mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Updated with ListTag changes from PocketMine-NBT
This commit is contained in:
parent
4a85311c5f
commit
9abfd54cc1
@ -24,7 +24,7 @@
|
||||
"pocketmine/raklib": "dev-master#9b50878021ca545684fc1fd2d9333911ab2988e1",
|
||||
"pocketmine/pocketmine-spl": "^0.2.0",
|
||||
"pocketmine/pocketmine-binaryutils": "dev-master#a7cd5303a3b215d26bf9be76682ce9311f40e887",
|
||||
"pocketmine/pocketmine-nbt": "dev-master#3bb6fb1b1b7b3aa40939764a5479b2758f3c135e"
|
||||
"pocketmine/pocketmine-nbt": "dev-master#37ad66b279fa8e746ccc68a451eef8ef9421aaa5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
|
15
composer.lock
generated
15
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "08158e4b18863a13bde2505e4b274f0c",
|
||||
"content-hash": "19400d9f6e78537580761ca473974158",
|
||||
"packages": [
|
||||
{
|
||||
"name": "pocketmine/pocketmine-binaryutils",
|
||||
@ -45,12 +45,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pmmp/PocketMine-NBT.git",
|
||||
"reference": "3bb6fb1b1b7b3aa40939764a5479b2758f3c135e"
|
||||
"reference": "37ad66b279fa8e746ccc68a451eef8ef9421aaa5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pmmp/PocketMine-NBT/zipball/3bb6fb1b1b7b3aa40939764a5479b2758f3c135e",
|
||||
"reference": "3bb6fb1b1b7b3aa40939764a5479b2758f3c135e",
|
||||
"url": "https://api.github.com/repos/pmmp/PocketMine-NBT/zipball/37ad66b279fa8e746ccc68a451eef8ef9421aaa5",
|
||||
"reference": "37ad66b279fa8e746ccc68a451eef8ef9421aaa5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -63,6 +63,11 @@
|
||||
"pocketmine\\nbt\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"pocketmine\\nbt\\": "tests/phpunit/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"LGPL-3.0"
|
||||
],
|
||||
@ -71,7 +76,7 @@
|
||||
"source": "https://github.com/pmmp/PocketMine-NBT/tree/master",
|
||||
"issues": "https://github.com/pmmp/PocketMine-NBT/issues"
|
||||
},
|
||||
"time": "2018-02-11T15:53:29+00:00"
|
||||
"time": "2018-02-13T14:33:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pocketmine/pocketmine-spl",
|
||||
|
@ -99,7 +99,7 @@ class StandingBanner extends Transparent{
|
||||
$tile = $this->level->getTile($this);
|
||||
|
||||
$drop = ItemFactory::get(Item::BANNER, ($tile instanceof TileBanner ? $tile->getBaseColor() : 0));
|
||||
if($tile instanceof TileBanner and ($patterns = $tile->namedtag->getListTag(TileBanner::TAG_PATTERNS)) !== null and $patterns->getCount() > 0){
|
||||
if($tile instanceof TileBanner and ($patterns = $tile->namedtag->getListTag(TileBanner::TAG_PATTERNS)) !== null and !$patterns->empty()){
|
||||
$drop->setNamedTagEntry($patterns);
|
||||
}
|
||||
|
||||
|
@ -515,8 +515,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
foreach($inventoryTag as $i => $item){
|
||||
$slot = $item->getByte("Slot");
|
||||
if($slot >= 0 and $slot < 9){ //Hotbar
|
||||
//Old hotbar saving stuff, remove it (useless now)
|
||||
unset($inventoryTag[$i]);
|
||||
//Old hotbar saving stuff, ignore it
|
||||
}elseif($slot >= 100 and $slot < 104){ //Armor
|
||||
$this->armorInventory->setItem($slot - 100, ItemItem::nbtDeserialize($item));
|
||||
}else{
|
||||
@ -647,7 +646,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
for($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot){
|
||||
$item = $this->inventory->getItem($slot - 9);
|
||||
if(!$item->isNull()){
|
||||
$inventoryTag[$slot] = $item->nbtSerialize($slot);
|
||||
$inventoryTag->push($item->nbtSerialize($slot));
|
||||
}
|
||||
}
|
||||
|
||||
@ -655,7 +654,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
for($slot = 100; $slot < 104; ++$slot){
|
||||
$item = $this->armorInventory->getItem($slot - 100);
|
||||
if(!$item->isNull()){
|
||||
$inventoryTag[$slot] = $item->nbtSerialize($slot);
|
||||
$inventoryTag->push($item->nbtSerialize($slot));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,22 +77,17 @@ class Banner extends Item{
|
||||
* @return int ID of pattern.
|
||||
*/
|
||||
public function addPattern(string $pattern, int $color) : int{
|
||||
$patternId = 0;
|
||||
if($this->getPatternCount() !== 0){
|
||||
$patternId = max($this->getPatternIds()) + 1;
|
||||
}
|
||||
|
||||
$patternsTag = $this->getNamedTag()->getListTag(self::TAG_PATTERNS);
|
||||
assert($patternsTag !== null);
|
||||
|
||||
$patternsTag[$patternId] = new CompoundTag("", [
|
||||
$patternsTag->push(new CompoundTag("", [
|
||||
new IntTag(self::TAG_PATTERN_COLOR, $color & 0x0f),
|
||||
new StringTag(self::TAG_PATTERN_NAME, $pattern)
|
||||
]);
|
||||
]));
|
||||
|
||||
$this->setNamedTagEntry($patternsTag);
|
||||
|
||||
return $patternId;
|
||||
return $patternsTag->count() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +99,7 @@ class Banner extends Item{
|
||||
*/
|
||||
public function patternExists(int $patternId) : bool{
|
||||
$this->correctNBT();
|
||||
return isset($this->getNamedTag()->getListTag(self::TAG_PATTERNS)[$patternId]);
|
||||
return $this->getNamedTag()->getListTag(self::TAG_PATTERNS)->isset($patternId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +116,7 @@ class Banner extends Item{
|
||||
|
||||
$patternsTag = $this->getNamedTag()->getListTag(self::TAG_PATTERNS);
|
||||
assert($patternsTag !== null);
|
||||
$pattern = $patternsTag[$patternId];
|
||||
$pattern = $patternsTag->get($patternId);
|
||||
assert($pattern instanceof CompoundTag);
|
||||
|
||||
return [
|
||||
@ -148,10 +143,10 @@ class Banner extends Item{
|
||||
$patternsTag = $this->getNamedTag()->getListTag(self::TAG_PATTERNS);
|
||||
assert($patternsTag !== null);
|
||||
|
||||
$patternsTag[$patternId] = new CompoundTag("", [
|
||||
$patternsTag->set($patternId, new CompoundTag("", [
|
||||
new IntTag(self::TAG_PATTERN_COLOR, $color & 0x0f),
|
||||
new StringTag(self::TAG_PATTERN_NAME, $pattern)
|
||||
]);
|
||||
]));
|
||||
|
||||
$this->setNamedTagEntry($patternsTag);
|
||||
return true;
|
||||
@ -172,7 +167,7 @@ class Banner extends Item{
|
||||
|
||||
$patternsTag = $this->getNamedTag()->getListTag(self::TAG_PATTERNS);
|
||||
if($patternsTag instanceof ListTag){
|
||||
unset($patternsTag[$patternId]);
|
||||
$patternsTag->remove($patternId);
|
||||
$this->setNamedTagEntry($patternsTag);
|
||||
}
|
||||
|
||||
@ -186,12 +181,7 @@ class Banner extends Item{
|
||||
* @return bool indicating whether the banner was empty or not.
|
||||
*/
|
||||
public function deleteTopPattern() : bool{
|
||||
$keys = $this->getPatternIds();
|
||||
if(empty($keys)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->deletePattern(max($keys));
|
||||
return $this->deletePattern($this->getPatternCount() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,27 +191,7 @@ class Banner extends Item{
|
||||
* @return bool indicating whether the banner was empty or not.
|
||||
*/
|
||||
public function deleteBottomPattern() : bool{
|
||||
$keys = $this->getPatternIds();
|
||||
if(empty($keys)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->deletePattern(min($keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all pattern IDs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPatternIds() : array{
|
||||
$this->correctNBT();
|
||||
|
||||
$keys = array_keys((array) ($this->getNamedTag()->getListTag(self::TAG_PATTERNS) ?? []));
|
||||
|
||||
return array_filter($keys, function($key){
|
||||
return is_numeric($key);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
return $this->deletePattern(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,7 +200,7 @@ class Banner extends Item{
|
||||
* @return int
|
||||
*/
|
||||
public function getPatternCount() : int{
|
||||
return count($this->getPatternIds());
|
||||
return $this->getNamedTag()->getListTag(self::TAG_PATTERNS)->count();
|
||||
}
|
||||
|
||||
public function correctNBT() : void{
|
||||
|
@ -345,7 +345,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
/** @var CompoundTag $entry */
|
||||
foreach($ench as $k => $entry){
|
||||
if($entry->getShort("id") === $id and ($level === -1 or $entry->getShort("lvl") === $level)){
|
||||
unset($ench[$k]);
|
||||
$ench->remove($k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -370,10 +370,10 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
/** @var CompoundTag $entry */
|
||||
foreach($ench as $k => $entry){
|
||||
if($entry->getShort("id") === $enchantment->getId()){
|
||||
$ench[$k] = new CompoundTag("", [
|
||||
$ench->set($k, new CompoundTag("", [
|
||||
new ShortTag("id", $enchantment->getId()),
|
||||
new ShortTag("lvl", $enchantment->getLevel())
|
||||
]);
|
||||
]));
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
@ -381,10 +381,10 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
}
|
||||
|
||||
if(!$found){
|
||||
$ench[count($ench)] = new CompoundTag("", [
|
||||
$ench->push(new CompoundTag("", [
|
||||
new ShortTag("id", $enchantment->getId()),
|
||||
new ShortTag("lvl", $enchantment->getLevel())
|
||||
]);
|
||||
]));
|
||||
}
|
||||
|
||||
$this->setNamedTagEntry($ench);
|
||||
|
@ -46,7 +46,7 @@ class WritableBook extends Item{
|
||||
* @return bool
|
||||
*/
|
||||
public function pageExists(int $pageId) : bool{
|
||||
return isset($this->getPages()[$pageId]);
|
||||
return $this->getPagesTag()->isset($pageId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +62,7 @@ class WritableBook extends Item{
|
||||
return null;
|
||||
}
|
||||
|
||||
$page = $pages[$pageId] ?? null;
|
||||
$page = $pages->get($pageId);
|
||||
if($page instanceof CompoundTag){
|
||||
return $page->getString(self::TAG_PAGE_TEXT, "");
|
||||
}
|
||||
@ -85,13 +85,13 @@ class WritableBook extends Item{
|
||||
$created = true;
|
||||
}
|
||||
|
||||
$namedTag = $this->getNamedTag();
|
||||
/** @var CompoundTag[]|ListTag $pages */
|
||||
$pages = $namedTag->getListTag(self::TAG_PAGES);
|
||||
assert($pages instanceof ListTag);
|
||||
$pages[$pageId]->setString(self::TAG_PAGE_TEXT, $pageText);
|
||||
/** @var CompoundTag[]|ListTag $pagesTag */
|
||||
$pagesTag = $this->getPagesTag();
|
||||
/** @var CompoundTag $page */
|
||||
$page = $pagesTag->get($pageId);
|
||||
$page->setString(self::TAG_PAGE_TEXT, $pageText);
|
||||
|
||||
$this->setNamedTag($namedTag);
|
||||
$this->setNamedTagEntry($pagesTag);
|
||||
|
||||
return $created;
|
||||
}
|
||||
@ -107,18 +107,16 @@ class WritableBook extends Item{
|
||||
throw new \InvalidArgumentException("Page number \"$pageId\" is out of range");
|
||||
}
|
||||
|
||||
$pages = $this->getPages();
|
||||
$pagesTag = $this->getPagesTag();
|
||||
|
||||
for($id = 0; $id <= $pageId; $id++){
|
||||
if(!isset($pages[$id])){
|
||||
$pages[$id] = new CompoundTag("", [
|
||||
new StringTag(self::TAG_PAGE_TEXT, ""),
|
||||
new StringTag(self::TAG_PAGE_PHOTONAME, "")
|
||||
]);
|
||||
}
|
||||
for($current = $pagesTag->count(); $current <= $pageId; $current++){
|
||||
$pagesTag->push(new CompoundTag("", [
|
||||
new StringTag(self::TAG_PAGE_TEXT, ""),
|
||||
new StringTag(self::TAG_PAGE_PHOTONAME, "")
|
||||
]));
|
||||
}
|
||||
|
||||
$this->setPages($pages);
|
||||
$this->setNamedTagEntry($pagesTag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,10 +127,9 @@ class WritableBook extends Item{
|
||||
* @return bool indicating success
|
||||
*/
|
||||
public function deletePage(int $pageId) : bool{
|
||||
$pages = $this->getPages();
|
||||
unset($pages[$pageId]);
|
||||
|
||||
$this->setPages(array_values($pages));
|
||||
$pagesTag = $this->getPagesTag();
|
||||
$pagesTag->remove($pageId);
|
||||
$this->setNamedTagEntry($pagesTag);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -146,16 +143,14 @@ class WritableBook extends Item{
|
||||
* @return bool indicating success
|
||||
*/
|
||||
public function insertPage(int $pageId, string $pageText = "") : bool{
|
||||
$pages = $this->getPages();
|
||||
$pagesTag = $this->getPagesTag();
|
||||
|
||||
$this->setPages(array_merge(
|
||||
array_slice($pages, 0, $pageId),
|
||||
[new CompoundTag("", [
|
||||
new StringTag(self::TAG_PAGE_TEXT, $pageText),
|
||||
new StringTag(self::TAG_PAGE_PHOTONAME, "")
|
||||
])],
|
||||
array_slice($pages, $pageId)
|
||||
));
|
||||
$pagesTag->insert($pageId, new CompoundTag("", [
|
||||
new StringTag(self::TAG_PAGE_TEXT, $pageText),
|
||||
new StringTag(self::TAG_PAGE_PHOTONAME, "")
|
||||
]));
|
||||
|
||||
$this->setNamedTagEntry($pagesTag);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -199,6 +194,10 @@ class WritableBook extends Item{
|
||||
return $pages->getValue();
|
||||
}
|
||||
|
||||
protected function getPagesTag() : ListTag{
|
||||
return $this->getNamedTag()->getListTag(self::TAG_PAGES) ?? new ListTag(self::TAG_PAGES, [], NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param CompoundTag[] $pages
|
||||
|
@ -130,18 +130,6 @@ class Banner extends Spawnable implements Nameable{
|
||||
$this->onChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all pattern IDs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPatternIds() : array{
|
||||
$keys = array_keys((array) $this->namedtag->getTag(self::TAG_PATTERNS));
|
||||
return array_filter($keys, function(string $key){
|
||||
return is_numeric($key);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a new pattern on the banner with the given color.
|
||||
*
|
||||
@ -151,20 +139,15 @@ class Banner extends Spawnable implements Nameable{
|
||||
* @return int ID of pattern.
|
||||
*/
|
||||
public function addPattern(string $pattern, int $color) : int{
|
||||
$patternId = 0;
|
||||
if($this->getPatternCount() !== 0){
|
||||
$patternId = max($this->getPatternIds()) + 1;
|
||||
}
|
||||
|
||||
$list = $this->namedtag->getListTag(self::TAG_PATTERNS);
|
||||
assert($list !== null);
|
||||
$list[$patternId] = new CompoundTag("", [
|
||||
$list->push(new CompoundTag("", [
|
||||
new IntTag(self::TAG_PATTERN_COLOR, $color & 0x0f),
|
||||
new StringTag(self::TAG_PATTERN_NAME, $pattern)
|
||||
]);
|
||||
]));
|
||||
|
||||
$this->onChanged();
|
||||
return $patternId;
|
||||
return $list->count() - 1; //Last offset in the list
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,7 +158,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
* @return bool
|
||||
*/
|
||||
public function patternExists(int $patternId) : bool{
|
||||
return isset($this->namedtag->getListTag(self::TAG_PATTERNS)[$patternId]);
|
||||
return $this->namedtag->getListTag(self::TAG_PATTERNS)->isset($patternId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +175,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
|
||||
$list = $this->namedtag->getListTag(self::TAG_PATTERNS);
|
||||
assert($list instanceof ListTag);
|
||||
$patternTag = $list[$patternId];
|
||||
$patternTag = $list->get($patternId);
|
||||
assert($patternTag instanceof CompoundTag);
|
||||
|
||||
return [
|
||||
@ -218,10 +201,10 @@ class Banner extends Spawnable implements Nameable{
|
||||
$list = $this->namedtag->getListTag(self::TAG_PATTERNS);
|
||||
assert($list instanceof ListTag);
|
||||
|
||||
$list[$patternId] = new CompoundTag("", [
|
||||
$list->set($patternId, new CompoundTag("", [
|
||||
new IntTag(self::TAG_PATTERN_COLOR, $color & 0x0f),
|
||||
new StringTag(self::TAG_PATTERN_NAME, $pattern)
|
||||
]);
|
||||
]));
|
||||
|
||||
$this->onChanged();
|
||||
return true;
|
||||
@ -241,7 +224,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
|
||||
$list = $this->namedtag->getListTag(self::TAG_PATTERNS);
|
||||
if($list !== null){
|
||||
unset($list[$patternId]);
|
||||
$list->remove($patternId);
|
||||
}
|
||||
|
||||
$this->onChanged();
|
||||
@ -254,12 +237,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
* @return bool indicating whether the banner was empty or not.
|
||||
*/
|
||||
public function deleteTopPattern() : bool{
|
||||
$keys = $this->getPatternIds();
|
||||
if(empty($keys)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->deletePattern(max($keys));
|
||||
return $this->deletePattern($this->getPatternCount() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,12 +246,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
* @return bool indicating whether the banner was empty or not.
|
||||
*/
|
||||
public function deleteBottomPattern() : bool{
|
||||
$keys = $this->getPatternIds();
|
||||
if(empty($keys)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->deletePattern(min($keys));
|
||||
return $this->deletePattern(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,7 +255,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
* @return int
|
||||
*/
|
||||
public function getPatternCount() : int{
|
||||
return count($this->getPatternIds());
|
||||
return $this->namedtag->getListTag(self::TAG_PATTERNS)->count();
|
||||
}
|
||||
|
||||
protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{
|
||||
|
Loading…
x
Reference in New Issue
Block a user