Merge master into api3/network

This commit is contained in:
Dylan K. Taylor 2017-04-01 19:37:15 +01:00
commit 202bac28fc
7 changed files with 56 additions and 10 deletions

View File

@ -392,21 +392,38 @@ abstract class Entity extends Location implements Metadatable{
public function setNameTagAlwaysVisible($value = true){
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value);
}
/**
* @return float
*/
public function getScale(): float{
public function getScale() : float{
return $this->getDataProperty(self::DATA_SCALE);
}
/**
* @param float $value
*/
public function setScale(float $value){
$multiplier = $value / $this->getScale();
$this->width *= $multiplier;
$this->height *= $multiplier;
$halfWidth = $this->width / 2;
$this->boundingBox->setBounds(
$this->x - $halfWidth,
$this->y,
$this->z - $halfWidth,
$this->x + $halfWidth,
$this->y + $this->height,
$this->z + $halfWidth
);
$this->setDataProperty(self::DATA_SCALE, self::DATA_TYPE_FLOAT, $value);
$this->setDataProperty(self::DATA_BOUNDING_BOX_WIDTH, self::DATA_TYPE_FLOAT, $this->width);
$this->setDataProperty(self::DATA_BOUNDING_BOX_HEIGHT, self::DATA_TYPE_FLOAT, $this->height);
}
public function isSneaking(){
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING);
}

View File

@ -46,12 +46,22 @@ class Item implements ItemIds, \JsonSerializable{
private static $cachedParser = null;
private static function parseCompoundTag(string $tag) : CompoundTag{
if(strlen($tag) === 0){
throw new \InvalidArgumentException("No NBT data found in supplied string");
}
if(self::$cachedParser === null){
self::$cachedParser = new NBT(NBT::LITTLE_ENDIAN);
}
self::$cachedParser->read($tag);
return self::$cachedParser->getData();
$data = self::$cachedParser->getData();
if(!($data instanceof CompoundTag)){
throw new \InvalidArgumentException("Invalid item NBT string given, it could not be deserialized");
}
return $data;
}
private static function writeCompoundTag(CompoundTag $tag) : string{

View File

@ -307,7 +307,7 @@ class Chunk{
* @param int $level 0-15
*/
public function setBlockSkyLight(int $x, int $y, int $z, int $level){
if($this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){
if($this->getSubChunk($y >> 4, true)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){
$this->hasChanged = true;
}
}
@ -334,7 +334,7 @@ class Chunk{
* @param int $level 0-15
*/
public function setBlockLight(int $x, int $y, int $z, int $level){
if($this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level)){
if($this->getSubChunk($y >> 4, true)->setBlockLight($x, $y & 0x0f, $z, $level)){
$this->hasChanged = true;
}
}

View File

@ -47,8 +47,11 @@ class SubChunk{
}
public function isEmpty() : bool{
assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids));
return substr_count($this->ids, "\x00") === 4096;
return (
substr_count($this->ids, "\x00") === 4096 and
substr_count($this->skyLight, "\xff") === 2048 and
substr_count($this->blockLight, "\x00") === 2048
);
}
public function getBlockId(int $x, int $y, int $z) : int{

View File

@ -111,4 +111,12 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
}
return $str . "}";
}
public function __clone(){
foreach($this as $key => $tag){
if($tag instanceof Tag){
$this->{$key} = clone $tag;
}
}
}
}

View File

@ -220,4 +220,12 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{
}
return $str . "}";
}
public function __clone(){
foreach($this as $key => $tag){
if($tag instanceof Tag){
$this->{$key} = clone $tag;
}
}
}
}

View File

@ -183,7 +183,7 @@ auto-updater:
timings:
#Choose the host to use for viewing your timings results.
host: mcpetimings.com
host: timings.pmmp.io
console:
#Choose whether to enable server stats reporting on the console title.