mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Added support for more NBT data, renaming inventories, fixed tags not being saved, added support for tags in /give
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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){
|
||||
|
42
src/pocketmine/tile/Nameable.php
Normal file
42
src/pocketmine/tile/Nameable.php
Normal 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();
|
||||
}
|
Reference in New Issue
Block a user