mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
Improved NBT IntArray read/write
This commit is contained in:
parent
20e11bd408
commit
84c63c48ca
@ -190,9 +190,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function getXZ($hash, &$x, &$z){
|
public static function getXZ($hash, &$x, &$z){
|
||||||
$d = explode(":", $hash);
|
list($x, $z) = explode(":", $hash);
|
||||||
$x = (int) $d[0];
|
|
||||||
$z = (int) $d[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,36 +33,13 @@ class IntArray extends NamedTag{
|
|||||||
public function read(NBT $nbt){
|
public function read(NBT $nbt){
|
||||||
$this->value = [];
|
$this->value = [];
|
||||||
$size = $nbt->getInt();
|
$size = $nbt->getInt();
|
||||||
$ints = $nbt->get($size * 4);
|
$this->value = unpack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", $nbt->get($size * 4));
|
||||||
$offset = 0;
|
|
||||||
if($nbt->endianness === NBT::LITTLE_ENDIAN){
|
|
||||||
for($i = 0; $i < $size and isset($ints{$offset}); ++$i){
|
|
||||||
$this->value[$i] = Binary::readLInt(substr($ints, $offset, 4));
|
|
||||||
$offset += 4;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
for($i = 0; $i < $size and isset($ints{$offset}); ++$i){
|
|
||||||
$this->value[$i] = Binary::readInt(substr($ints, $offset, 4));
|
|
||||||
$offset += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(NBT $nbt){
|
public function write(NBT $nbt){
|
||||||
$nbt->putInt(count($this->value));
|
$nbt->putInt(count($this->value));
|
||||||
|
$ints = $this->value;
|
||||||
$ints = "";
|
array_unshift($ints, $nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*");
|
||||||
if($nbt->endianness === NBT::LITTLE_ENDIAN){
|
$nbt->put(call_user_func_array("pack", $ints));
|
||||||
foreach($this->value as $v){
|
|
||||||
$ints .= Binary::writeLInt($v);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
foreach($this->value as $v){
|
|
||||||
$ints .= Binary::writeInt($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$nbt->put($ints);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user