GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
DataPacket Class Reference

Public Member Functions

 pid ()
 
 encode ()
 
 decode ()
 
 reset ()
 
 clean ()
 
 __debugInfo ()
 
 getEntityMetadata (bool $types=true)
 
 putEntityMetadata (array $metadata)
 
 getName ()
 
- Public Member Functions inherited from BinaryStream
 __construct ($buffer="", $offset=0)
 
 reset ()
 
 setBuffer ($buffer=null, $offset=0)
 
 getOffset ()
 
 getBuffer ()
 
 get ($len)
 
 put ($str)
 
 getBool ()
 
 putBool ($v)
 
 getLong ()
 
 putLong ($v)
 
 getInt ()
 
 putInt ($v)
 
 getLLong ()
 
 putLLong ($v)
 
 getLInt ()
 
 putLInt ($v)
 
 getSignedShort ()
 
 putShort ($v)
 
 getShort ()
 
 putSignedShort ($v)
 
 getFloat (int $accuracy=-1)
 
 putFloat ($v)
 
 getLShort ($signed=true)
 
 putLShort ($v)
 
 getLFloat (int $accuracy=-1)
 
 putLFloat ($v)
 
 getTriad ()
 
 putTriad ($v)
 
 getLTriad ()
 
 putLTriad ($v)
 
 getByte ()
 
 putByte ($v)
 
 getUUID ()
 
 putUUID (UUID $uuid)
 
 getSlot ()
 
 putSlot (Item $item)
 
 getString ()
 
 putString ($v)
 
 getUnsignedVarInt ()
 
 putUnsignedVarInt ($v)
 
 getVarInt ()
 
 putVarInt ($v)
 
 getEntityId ()
 
 putEntityId ($v)
 
 getBlockCoords (&$x, &$y, &$z)
 
 putBlockCoords ($x, $y, $z)
 
 getVector3f (&$x, &$y, &$z)
 
 putVector3f ($x, $y, $z)
 
 feof ()
 

Data Fields

const NETWORK_ID = 0
 
 $isEncoded = false
 
- Data Fields inherited from BinaryStream
 $offset
 
 $buffer
 

Member Function Documentation

◆ __debugInfo()

__debugInfo ( )
Returns
array
73  {
74  $data = [];
75  foreach($this as $k => $v){
76  if($k === "buffer"){
77  $data[$k] = bin2hex($v);
78  }elseif(is_string($v) or (is_object($v) and method_exists($v, "__toString"))){
79  $data[$k] = Utils::printable((string) $v);
80  }else{
81  $data[$k] = $v;
82  }
83  }
84 
85  return $data;
86  }

◆ clean()

clean ( )
Returns
$this
62  {
63  $this->buffer = null;
64  $this->isEncoded = false;
65  $this->offset = 0;
66 
67  return $this;
68  }

◆ decode()

decode ( )
abstract
Returns
mixed

◆ encode()

encode ( )
abstract
Returns
mixed

◆ getEntityMetadata()

getEntityMetadata ( bool  $types = true)
Parameters
bool$types
Returns
array
93  : array{
94  $count = $this->getUnsignedVarInt();
95  $data = [];
96  for($i = 0; $i < $count; ++$i){
97  $key = $this->getUnsignedVarInt();
98  $type = $this->getUnsignedVarInt();
99  $value = null;
100  switch($type){
102  $value = $this->getByte();
103  break;
105  $value = $this->getLShort(true); //signed
106  break;
108  $value = $this->getVarInt();
109  break;
111  $value = $this->getLFloat();
112  break;
114  $value = $this->getString();
115  break;
117  //TODO: use objects directly
118  $value = [];
119  $item = $this->getSlot();
120  $value[0] = $item->getId();
121  $value[1] = $item->getCount();
122  $value[2] = $item->getDamage();
123  break;
125  $value = [];
126  $value[0] = $this->getVarInt(); //x
127  $value[1] = $this->getVarInt(); //y (SIGNED)
128  $value[2] = $this->getVarInt(); //z
129  break;
131  $value = $this->getVarInt(); //TODO: varint64 proper support
132  break;
134  $value = [0.0, 0.0, 0.0];
135  $this->getVector3f($value[0], $value[1], $value[2]);
136  break;
137  default:
138  $value = [];
139  }
140  if($types === true){
141  $data[$key] = [$value, $type];
142  }else{
143  $data[$key] = $value;
144  }
145  }
146 
147  return $data;
148  }

◆ getName()

getName ( )
Returns
PacketName|string
197  {
198  return "DataPacket";
199  }

◆ pid()

pid ( )
Returns
int
40  {
41  return $this::NETWORK_ID;
42  }

◆ putEntityMetadata()

putEntityMetadata ( array  $metadata)
Parameters
array$metadata
153  {
154  $this->putUnsignedVarInt(count($metadata));
155  foreach($metadata as $key => $d){
156  $this->putUnsignedVarInt($key); //data key
157  $this->putUnsignedVarInt($d[0]); //data type
158  switch($d[0]){
160  $this->putByte($d[1]);
161  break;
163  $this->putLShort($d[1]); //SIGNED short!
164  break;
166  $this->putVarInt($d[1]);
167  break;
169  $this->putLFloat($d[1]);
170  break;
172  $this->putString($d[1]);
173  break;
175  //TODO: change this implementation (use objects)
176  $this->putSlot(Item::get($d[1][0], $d[1][2], $d[1][1])); //ID, damage, count
177  break;
179  //TODO: change this implementation (use objects)
180  $this->putVarInt($d[1][0]); //x
181  $this->putVarInt($d[1][1]); //y (SIGNED)
182  $this->putVarInt($d[1][2]); //z
183  break;
185  $this->putVarInt($d[1]); //TODO: varint64 support
186  break;
188  //TODO: change this implementation (use objects)
189  $this->putVector3f($d[1][0], $d[1][1], $d[1][2]); //x, y, z
190  }
191  }
192  }

◆ reset()

reset ( )
54  {
55  $this->buffer = chr($this::NETWORK_ID);
56  $this->offset = 0;
57  }

Field Documentation

◆ $isEncoded

$isEncoded = false

◆ NETWORK_ID

const NETWORK_ID = 0

The documentation for this class was generated from the following file: