added nbt+made world actually load

This commit is contained in:
GameHerobrine 2023-02-21 08:14:25 +03:00
parent a9be309de9
commit 8226712597
18 changed files with 1059 additions and 4 deletions

View file

@ -459,8 +459,8 @@ class Player{
}
$pk = new FullChunkDataPacket;
$pk->putInt($X);
$pk->putInt($Z);
$pk->buffer .= Utils::writeInt($X);
$pk->buffer .= Utils::writeInt($Z);
$pk->chunkX = $X;
$pk->chunkZ = $Z;
$pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex);
@ -522,10 +522,10 @@ class Player{
$Yndex |= 1 << $iY;
}
}
$pk = new ChunkDataPacket;
$pk = new FullChunkDataPacket;
$pk->chunkX = $X;
$pk->chunkZ = $Z;
$pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex);
$pk->data = $this->level->getOrderedFullChunk($X, $Z);
$cnt = $this->dataPacket($pk);
if($cnt === false){
return false;

View file

@ -94,6 +94,7 @@ require_once(FILE_PATH . "/src/astarnavigator/providers/MCBlockedProvider.php");
require_once(FILE_PATH . "/src/astarnavigator/ITileNavigator.php");
require_once(FILE_PATH . "/src/astarnavigator/TileNavigator.php");
require_once(FILE_PATH . "/src/nbt/tag/NamedTag.php");
require_once(FILE_PATH . "/src/entity/ai/tasks/TaskBase.php");
require_once(FILE_PATH. "/src/entity/ai/tasks/TaskTempt.php");

241
src/nbt/NBT_new.php Normal file
View file

@ -0,0 +1,241 @@
<?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/
*
*
*/
/**
* Named Binary Tag handling classes
*/
/**
* Named Binary Tag encoder/decoder
*/
class NBT_new{
const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1;
const TAG_End = 0;
const TAG_Byte = 1;
const TAG_Short = 2;
const TAG_Int = 3;
const TAG_Long = 4;
const TAG_Float = 5;
const TAG_Double = 6;
const TAG_ByteArray = 7;
const TAG_String = 8;
const TAG_Enum = 9;
const TAG_Compound = 10;
const TAG_IntArray = 11;
private $buffer;
private $offset;
private $endianness;
private $data;
public function get($len){
if($len < 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}elseif($len === true){
return substr($this->buffer, $this->offset);
}
if($len > 1024){
return substr($this->buffer, ($this->offset += $len) - $len, $len);
}
$buffer = "";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= @$this->buffer[$this->offset];
}
return $buffer;
}
public function put($v){
$this->buffer .= $v;
}
public function feof(){
return !isset($this->buffer{$this->offset});
}
public function __construct($endianness = self::LITTLE_ENDIAN){
$this->offset = 0;
$this->endianness = $endianness & 0x01;
}
public function read($buffer){
$this->offset = 0;
$this->buffer = $buffer;
$this->data = $this->readTag();
$this->buffer = "";
}
public function readCompressed($buffer, $compression = ZLIB_ENCODING_GZIP){
$this->read(zlib_decode($buffer));
}
public function write(){
$this->offset = 0;
if($this->data instanceof Compound){
$this->writeTag($this->data);
return $this->buffer;
}else{
return false;
}
}
public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7){
if(($write = $this->write()) !== false){
return zlib_encode($write, $compression, $level);
}
return false;
}
public function readTag(){
switch($this->getByte()){
case NBT::TAG_Byte:
$tag = new Byte($this->getString());
$tag->read($this);
break;
case NBT::TAG_Short:
$tag = new Short($this->getString());
$tag->read($this);
break;
case NBT::TAG_Int:
$tag = new Int($this->getString());
$tag->read($this);
break;
case NBT::TAG_Long:
$tag = new Long($this->getString());
$tag->read($this);
break;
case NBT::TAG_Float:
$tag = new Float($this->getString());
$tag->read($this);
break;
case NBT::TAG_Double:
$tag = new Double($this->getString());
$tag->read($this);
break;
case NBT::TAG_ByteArray:
$tag = new ByteArray($this->getString());
$tag->read($this);
break;
case NBT::TAG_String:
$tag = new String($this->getString());
$tag->read($this);
break;
case NBT::TAG_Enum:
$tag = new Enum($this->getString());
$tag->read($this);
break;
case NBT::TAG_Compound:
$tag = new Compound($this->getString());
$tag->read($this);
break;
case NBT::TAG_IntArray:
$tag = new IntArray($this->getString());
$tag->read($this);
break;
case NBT::TAG_End: //No named tag
default:
$tag = new End;
break;
}
return $tag;
}
public function writeTag(Tag $tag){
$this->putByte($tag->getType());
if($tag instanceof NamedTAG){
$this->putString($tag->getName());
}
$tag->write($this);
}
public function getByte($signed = false){
return Utils::readByte($this->get(1), $signed);
}
public function putByte($v){
$this->buffer .= Utils::writeByte($v);
}
public function getShort(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readShort($this->get(2)) : Utils::readLShort($this->get(2));
}
public function putShort($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeShort($v) : Utils::writeLShort($v);
}
public function getInt(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readInt($this->get(4)) : Utils::readLInt($this->get(4));
}
public function putInt($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeInt($v) : Utils::writeLInt($v);
}
public function getLong(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readLong($this->get(8)) : Utils::readLLong($this->get(8));
}
public function putLong($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeLong($v) : Utils::writeLLong($v);
}
public function getFloat(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readFloat($this->get(4)) : Utils::readLFloat($this->get(4));
}
public function putFloat($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeFloat($v) : Utils::writeLFloat($v);
}
public function getDouble(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readDouble($this->get(8)) : Utils::readLDouble($this->get(8));
}
public function putDouble($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeDouble($v) : Utils::writeLDouble($v);
}
public function getString(){
return $this->get($this->getShort());
}
public function putString($v){
$this->putShort(strlen($v));
$this->buffer .= $v;
}
public function getData(){
return $this->data;
}
public function setData(Compound $data){
$this->data = $data;
}
}

35
src/nbt/tag/Byte.php Normal file
View file

@ -0,0 +1,35 @@
<?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/
*
*
*/
class Byte extends NamedTag{
public function getType(){
return NBT_new::TAG_Byte;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->getByte(true);
}
public function write(NBT_new $NBT_new){
$NBT_new->putByte($this->value);
}
}

36
src/nbt/tag/ByteArray.php Normal file
View file

@ -0,0 +1,36 @@
<?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/
*
*
*/
class ByteArray extends NamedTag{
public function getType(){
return NBT_new::TAG_ByteArray;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->get($NBT_new->getInt());
}
public function write(NBT_new $NBT_new){
$NBT_new->putInt(strlen($this->value));
$NBT_new->put($this->value);
}
}

81
src/nbt/tag/Compound.php Normal file
View file

@ -0,0 +1,81 @@
<?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/
*
*
*/
class Compound extends NamedTag implements \ArrayAccess{
public function __construct($name = "", $value = []){
$this->name = $name;
foreach($value as $tag){
$this->{$tag->getName()} = $tag;
}
}
public function offsetExists($offset){
return isset($this->{$offset});
}
public function offsetGet($offset){
if($this->{$offset} instanceof Tag){
if($this->{$offset} instanceof \ArrayAccess){
return $this->{$offset};
}else{
return $this->{$offset}->getValue();
}
}
return null;
}
public function offsetSet($offset, $value){
if($value instanceof Tag){
$this->{$offset} = $value;
}elseif(isset($this->{$offset}) and $this->{$offset} instanceof Tag){
$this->{$offset}->setValue($value);
}
}
public function offsetUnset($offset){
unset($this->{$offset});
}
public function getType(){
return NBT_new::TAG_Compound;
}
public function read(NBT_new $NBT_new){
$this->value = [];
do{
$tag = $NBT_new->readTag();
if($tag instanceof NamedTag and $tag->getName() !== ""){
$this->{$tag->getName()} = $tag;
}
}while(!($tag instanceof End) and !$NBT_new->feof());
}
public function write(NBT_new $NBT_new){
foreach($this as $tag){
if($tag instanceof Tag and !($tag instanceof End)){
$NBT_new->writeTag($tag);
}
}
$NBT_new->writeTag(new End);
}
}

35
src/nbt/tag/Double.php Normal file
View file

@ -0,0 +1,35 @@
<?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/
*
*
*/
class Double extends NamedTag{
public function getType(){
return NBT_new::TAG_Double;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->getDouble();
}
public function write(NBT_new $NBT_new){
$NBT_new->putDouble($this->value);
}
}

35
src/nbt/tag/End.php Normal file
View file

@ -0,0 +1,35 @@
<?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/
*
*
*/
class End extends Tag{
public function getType(){
return NBT_new::TAG_End;
}
public function read(NBT_new $NBT_new){
}
public function write(NBT_new $NBT_new){
}
}

189
src/nbt/tag/Enum.php Normal file
View file

@ -0,0 +1,189 @@
<?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/
*
*
*/
class Enum extends NamedTag implements \ArrayAccess, \Countable{
private $tagType;
public function __construct($name = "", $value = []){
$this->name = $name;
foreach($value as $k => $v){
$this->{$k} = $v;
}
}
public function &getValue(){
$value = [];
foreach($this as $k => $v){
if($v instanceof Tag){
$value[$k] = $v;
}
}
return $value;
}
public function offsetExists($offset){
return isset($this->{$offset});
}
public function offsetGet($offset){
if($this->{$offset} instanceof Tag){
if($this->{$offset} instanceof \ArrayAccess){
return $this->{$offset};
}else{
return $this->{$offset}->getValue();
}
}
return null;
}
public function offsetSet($offset, $value){
if($value instanceof Tag){
$this->{$offset} = $value;
}elseif($this->{$offset} instanceof Tag){
$this->{$offset}->setValue($value);
}
}
public function offsetUnset($offset){
unset($this->{$offset});
}
public function count($mode = COUNT_NORMAL){
for($i = 0; true; $i++){
if(!isset($this->{$i})){
return $i;
}
if($mode === COUNT_RECURSIVE){
if($this->{$i} instanceof \Countable){
$i += count($this->{$i});
}
}
}
}
public function getType(){
return NBT_new::TAG_Enum;
}
public function setTagType($type){
$this->tagType = $type;
}
public function getTagType(){
return $this->tagType;
}
public function read(NBT_new $NBT_new){
$this->value = [];
$this->tagType = $NBT_new->getByte();
$size = $NBT_new->getInt();
for($i = 0; $i < $size and !$NBT_new->feof(); ++$i){
switch($this->tagType){
case NBT_new::TAG_Byte:
$tag = new Byte(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Short:
$tag = new Short(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Int:
$tag = new Int(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Long:
$tag = new Long(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Float:
$tag = new Float(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Double:
$tag = new Double(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_ByteArray:
$tag = new ByteArray(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_String:
$tag = new String(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Enum:
$tag = new $this(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_Compound:
$tag = new Compound(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
case NBT_new::TAG_IntArray:
$tag = new IntArray(false);
$tag->read($NBT_new);
$this->{$i} = $tag;
break;
}
}
}
public function write(NBT_new $NBT_new){
if(!isset($this->tagType)){
foreach($this as $tag){
if($tag instanceof Tag){
if(!isset($id)){
$id = $tag->getType();
}elseif($id !== $tag->getType()){
return false;
}
}
}
$this->tagType = @$id;
}
$NBT_new->putByte($this->tagType);
/** @var Tag[] $tags */
$tags = [];
foreach($this as $tag){
if($tag instanceof Tag){
$tags[] = $tag;
}
}
$NBT_new->putInt(count($tags));
foreach($tags as $tag){
$tag->write($NBT_new);
}
}
}

35
src/nbt/tag/Float.php Normal file
View file

@ -0,0 +1,35 @@
<?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/
*
*
*/
class FloatTag extends NamedTag{
public function getType(){
return NBT_new::TAG_Float;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->getFloat();
}
public function write(NBT_new $NBT_new){
$NBT_new->putFloat($this->value);
}
}

35
src/nbt/tag/Int.php Normal file
View file

@ -0,0 +1,35 @@
<?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/
*
*
*/
class IntTag extends NamedTag{
public function getType(){
return NBT_new::TAG_Int;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->getInt();
}
public function write(NBT_new $NBT_new){
$NBT_new->putInt($this->value);
}
}

42
src/nbt/tag/IntArray.php Normal file
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/
*
*
*/
class IntArray extends NamedTag{
public function getType(){
return NBT_new::TAG_IntArray;
}
public function read(NBT_new $NBT_new){
$this->value = [];
$size = $NBT_new->getInt();
for($i = 0; $i < $size and !$NBT_new->feof(); ++$i){
$this->value[] = $NBT_new->getInt();
}
}
public function write(NBT_new $NBT_new){
$NBT_new->putInt(count($this->value));
foreach($this->value as $v){
$NBT_new->putInt($v);
}
}
}

35
src/nbt/tag/Long.php Normal file
View file

@ -0,0 +1,35 @@
<?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/
*
*
*/
class Long extends NamedTag{
public function getType(){
return NBT_new::TAG_Long;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->getLong();
}
public function write(NBT_new $NBT_new){
$NBT_new->putLong($this->value);
}
}

45
src/nbt/tag/NamedTag.php Normal file
View file

@ -0,0 +1,45 @@
<?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/
*
*
*/
require_once(FILE_PATH . "/src/nbt/tag/Tag.php");
abstract class NamedTag extends Tag{
protected $name;
/**
* @param string $name
* @param bool|float|double|int|byte|short|array|Compound|Enum|string $value
*/
public function __construct($name = "", $value = false){
$this->name = $name;
if($value !== false){
$this->value = $value;
}
}
public function getName(){
return $this->name === false ? "" : $this->name;
}
public function setName($name){
$this->name = $name;
}
}

36
src/nbt/tag/Short.php Normal file
View file

@ -0,0 +1,36 @@
<?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/
*
*
*/
class Short extends NamedTag{
public function getType(){
return NBT_new::TAG_Short;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->getShort();
}
public function write(NBT_new $NBT_new){
$NBT_new->putShort($this->value);
}
}

36
src/nbt/tag/String.php Normal file
View file

@ -0,0 +1,36 @@
<?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/
*
*
*/
class StringTag extends NamedTag{
public function getType(){
return NBT_new::TAG_String;
}
public function read(NBT_new $NBT_new){
$this->value = $NBT_new->get($NBT_new->getShort());
}
public function write(NBT_new $NBT_new){
$NBT_new->putShort(strlen($this->value));
$NBT_new->put($this->value);
}
}

47
src/nbt/tag/Tag.php Normal file
View file

@ -0,0 +1,47 @@
<?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/
*
*
*/
/**
* All the NBT_new Tags
*/
abstract class Tag extends \stdClass{
protected $value;
public function &getValue(){
return $this->value;
}
public abstract function getType();
public function setValue($value){
$this->value = $value;
}
abstract public function write(NBT_new $NBT_new);
abstract public function read(NBT_new $NBT_new);
public final function __toString(){
return $this->value;
}
}

View file

@ -81,6 +81,97 @@ class Level{
unset($this->mobSpawner->level);
}
public function getOrderedFullChunk($X, $Z){
//todo: make asynchronous
if(!isset($this->level)){
return false;
}
/*if(ADVANCED_CACHE == true){
$identifier = "world:{$this->name}:$X:$Z";
if(($cache = Cache::get($identifier)) !== false){
return $cache;
}
}*/
$orderedIds = "";
$orderedData = "";
$orderedSkyLight = str_repeat("\x00", 16*16*64);
$orderedLight = str_repeat("\x00", 16*16*64);
$orderedBiomeIds = str_repeat("\x01", 16*16); //all plains, according to PocketMine 1.4 source
$orderedBiomeColors = str_repeat("\x00\x85\xb2\x4a", 256); // also PM 1.4
$tileEntities = "";
$this->level->loadChunk($X, $Z);
$miniChunks = [];
for($y = 0; $y < 8; ++$y){
$miniChunks[$y] = $this->level->getMiniChunk($X, $Z, $y);
}
for ($i = 0; $i < 16; $i++){
for ($j = 0; $j < 16; $j++){
$bIndex = ($i << 5) + ($j << 9);
foreach($miniChunks as $chunk){
$orderedIds .= substr($chunk, $bIndex, 16);
$orderedData .= substr($chunk, $bIndex + 16, 8);
}
}
}
$chunkTiles = [];
$tiles = $this->server->query("SELECT ID FROM tiles WHERE spawnable = 1 AND level = '".$this->getName()."' AND x >= ".($X * 16 - 1)." AND x < ".($X * 16 + 17)." AND z >= ".($Z * 16 - 1)." AND z < ".($Z * 16 + 17).";");
if($tiles !== false and $tiles !== true){
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
$tile = $this->server->api->tile->getByID($tile["ID"]);
if($tile instanceof Tile){
$chunkTiles[] = $tile;
}
}
}
$nbt = new NBT_new(NBT_new::LITTLE_ENDIAN);
foreach($chunkTiles as $tile){
switch($tile->class){
case "Sign":
$text = $tile->getText();
$nbt->setData(new Compound("", array(
new String("Text1", $text[0]),
new String("Text2", $text[1]),
new String("Text3", $text[2]),
new String("Text4", $text[3]),
new String("id", "Sign"),
new Int("x", (int) $tile->x),
new Int("y", (int) $tile->y),
new Int("z", (int) $tile->z)
)));
$tileEntities .= $nbt->write();
break;
case "Furnace":
//nutting, not spawnable :D
break;
case "Chest":
$nbt->setData(new Compound("", array(
new String("id", "Chest"),
new Int("x", (int) $tile->x),
new Int("y", (int) $tile->y),
new Int("z", (int) $tile->z)
)));
$tileEntities .= $nbt->write();
break;
}
}
$orderedUncompressed = Utils::writeLInt($X) . Utils::writeLInt($Z) .
$orderedIds . $orderedData . $orderedSkyLight . $orderedLight .
$orderedBiomeIds . $orderedBiomeColors . $tileEntities;
$ordered = zlib_encode($orderedUncompressed, ZLIB_ENCODING_DEFLATE, 6);
/*if(ADVANCED_CACHE == true){
Cache::add($identifier, $ordered, 60);
}*/
return $ordered;
}
public function isDay(){
return $this->getTime() % 19200 < TimeAPI::$phases["sunset"];
}