mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +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){
|
||||
$d = explode(":", $hash);
|
||||
$x = (int) $d[0];
|
||||
$z = (int) $d[1];
|
||||
list($x, $z) = explode(":", $hash);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,36 +33,13 @@ class IntArray extends NamedTag{
|
||||
public function read(NBT $nbt){
|
||||
$this->value = [];
|
||||
$size = $nbt->getInt();
|
||||
$ints = $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;
|
||||
}
|
||||
}
|
||||
|
||||
$this->value = unpack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", $nbt->get($size * 4));
|
||||
}
|
||||
|
||||
public function write(NBT $nbt){
|
||||
$nbt->putInt(count($this->value));
|
||||
|
||||
$ints = "";
|
||||
if($nbt->endianness === NBT::LITTLE_ENDIAN){
|
||||
foreach($this->value as $v){
|
||||
$ints .= Binary::writeLInt($v);
|
||||
}
|
||||
}else{
|
||||
foreach($this->value as $v){
|
||||
$ints .= Binary::writeInt($v);
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->put($ints);
|
||||
$ints = $this->value;
|
||||
array_unshift($ints, $nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*");
|
||||
$nbt->put(call_user_func_array("pack", $ints));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user