Added support for more NBT data, renaming inventories, fixed tags not being saved, added support for tags in /give

This commit is contained in:
Shoghi Cervantes
2015-08-07 16:27:30 +02:00
parent d1bfb304cb
commit 75b7b03857
42 changed files with 244 additions and 51 deletions

View File

@ -35,7 +35,7 @@ use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String;
class Chest extends Spawnable implements InventoryHolder, Container{
class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
/** @var ChestInventory */
protected $inventory;
@ -182,6 +182,23 @@ class Chest extends Spawnable implements InventoryHolder, Container{
}
}
public function getName(){
return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Chest";
}
public function hasName(){
return isset($this->namedtag->CustomName);
}
public function setName($str){
if($str === ""){
unset($this->namedtag->CustomName);
return;
}
$this->namedtag->CustomName = new String("CustomName", $str);
}
public function isPaired(){
if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){
return false;
@ -248,7 +265,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{
public function getSpawnCompound(){
if($this->isPaired()){
return new Compound("", [
$c = new Compound("", [
new String("id", Tile::CHEST),
new Int("x", (int) $this->x),
new Int("y", (int) $this->y),
@ -257,12 +274,18 @@ class Chest extends Spawnable implements InventoryHolder, Container{
new Int("pairz", (int) $this->namedtag["pairz"])
]);
}else{
return new Compound("", [
$c = new Compound("", [
new String("id", Tile::CHEST),
new Int("x", (int) $this->x),
new Int("y", (int) $this->y),
new Int("z", (int) $this->z)
]);
}
if($this->hasName()){
$c->CustomName = $this->namedtag->CustomName;
}
return $c;
}
}

View File

@ -25,14 +25,38 @@ use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\String;
class EnchantTable extends Spawnable{
class EnchantTable extends Spawnable implements Nameable{
public function getName(){
return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Chest";
}
public function hasName(){
return isset($this->namedtag->CustomName);
}
public function setName($str){
if($str === ""){
unset($this->namedtag->CustomName);
return;
}
$this->namedtag->CustomName = new String("CustomName", $str);
}
public function getSpawnCompound(){
return new Compound("", [
$c = new Compound("", [
new String("id", Tile::ENCHANT_TABLE),
new Int("x", (int) $this->x),
new Int("y", (int) $this->y),
new Int("z", (int) $this->z)
]);
if($this->hasName()){
$c->CustomName = $this->namedtag->CustomName;
}
return $c;
}
}

View File

@ -34,10 +34,11 @@ use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String;
use pocketmine\network\Network;
use pocketmine\network\protocol\ContainerSetDataPacket;
class Furnace extends Tile implements InventoryHolder, Container{
class Furnace extends Tile implements InventoryHolder, Container, Nameable{
/** @var FurnaceInventory */
protected $inventory;
@ -69,6 +70,23 @@ class Furnace extends Tile implements InventoryHolder, Container{
}
}
public function getName(){
return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Chest";
}
public function hasName(){
return isset($this->namedtag->CustomName);
}
public function setName($str){
if($str === ""){
unset($this->namedtag->CustomName);
return;
}
$this->namedtag->CustomName = new String("CustomName", $str);
}
public function close(){
if($this->closed === false){
foreach($this->getInventory()->getViewers() as $player){

View File

@ -0,0 +1,42 @@
<?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/
*
*
*/
namespace pocketmine\tile;
interface Nameable{
/**
* @return string
*/
public function getName();
/**
* @param void $str
*/
public function setName($str);
/**
* @return bool
*/
public function hasName();
}