41 private array $canPlaceOn,
42 private array $canDestroy
49 return $this->canPlaceOn;
56 return $this->canDestroy;
63 public static function read(ByteBufferReader $in) : self{
64 $nbtLen = LE::readSignedShort($in);
69 $nbtDataVersion = Byte::readUnsigned($in);
70 if($nbtDataVersion !== 1){
73 $offset = $in->getOffset();
75 $compound = (
new LittleEndianNbtSerializer())->read($in->getData(), $offset, 512)->mustGetCompoundTag();
76 }
catch(NbtDataException $e){
77 throw PacketDecodeException::wrap($e,
"Failed decoding NBT root");
79 $in->setOffset($offset);
81 }elseif($nbtLen !== 0){
82 throw new PacketDecodeException(
"Unexpected fake NBT length $nbtLen");
87 for($i = 0, $canPlaceOnCount = LE::readUnsignedInt($in); $i < $canPlaceOnCount; ++$i){
88 $canPlaceOn[] = $in->readByteArray(LE::readUnsignedShort($in));
92 for($i = 0, $canDestroyCount = LE::readUnsignedInt($in); $i < $canDestroyCount; ++$i){
93 $canDestroy[] = $in->readByteArray(LE::readUnsignedShort($in));
96 return new self($compound, $canPlaceOn, $canDestroy);
99 public function write(ByteBufferWriter $out) : void{
100 if($this->nbt !== null){
101 LE::writeSignedShort($out, 0xffff);
102 Byte::writeUnsigned($out, 1);
103 $out->writeByteArray((
new LittleEndianNbtSerializer())->write(
new TreeRoot($this->nbt)));
105 LE::writeSignedShort($out, 0);
108 LE::writeUnsignedInt($out, count($this->canPlaceOn));
109 foreach($this->canPlaceOn as $entry){
110 LE::writeUnsignedShort($out, strlen($entry));
111 $out->writeByteArray($entry);
113 LE::writeUnsignedInt($out, count($this->canDestroy));
114 foreach($this->canDestroy as $entry){
115 LE::writeUnsignedShort($out, strlen($entry));
116 $out->writeByteArray($entry);