29    private array $properties = [];
 
   34    private array $dirtyProperties = [];
 
   36    public function __construct(){
 
   40    public function setByte(
int $key, 
int $value, 
bool $force = 
false) : 
void{
 
   45    public function setShort(
int $key, 
int $value, 
bool $force = 
false) : 
void{
 
   49    public function setInt(
int $key, 
int $value, 
bool $force = 
false) : 
void{
 
   53    public function setFloat(
int $key, 
float $value, 
bool $force = 
false) : 
void{
 
   57    public function setString(
int $key, 
string $value, 
bool $force = 
false) : 
void{
 
   68    public function setBlockPos(
int $key, ?
BlockPosition $value, 
bool $force = 
false) : void{
 
   72    public function setLong(
int $key, 
int $value, 
bool $force = 
false) : void{
 
   73        $this->set($key, new LongMetadataProperty($value), $force);
 
   76    public function setVector3(
int $key, ?
Vector3 $value, 
bool $force = 
false) : void{
 
   77        $this->set($key, new Vec3MetadataProperty($value ?? new 
Vector3(0, 0, 0)), $force);
 
   80    public function set(
int $key, 
MetadataProperty $value, 
bool $force = 
false) : 
void{
 
   81        if(!$force and isset($this->properties[$key]) and !($this->properties[$key] instanceof $value)){
 
   82            throw new \InvalidArgumentException(
"Can't overwrite property with mismatching types (have " . get_class($this->properties[$key]) . 
")");
 
   84        if(!isset($this->properties[$key]) or !$this->properties[$key]->equals($value)){
 
   85            $this->properties[$key] = $this->dirtyProperties[$key] = $value;
 
   95    public function setAtomicBatch(array $properties, 
bool $force = 
false) : void{
 
   98            foreach($properties as $key => $value){
 
   99                if(isset($this->properties[$key]) and !($this->properties[$key] instanceof $value)){
 
  100                    throw new \InvalidArgumentException(
"Can't overwrite " . get_class($this->properties[$key]) . 
" with " . get_debug_type($value));
 
  104        foreach($properties as $key => $value){
 
  105            if(!isset($this->properties[$key]) or !$this->properties[$key]->equals($value)){
 
  111            foreach($properties as $key => $value){
 
  112                $this->properties[$key] = $this->dirtyProperties[$key] = $value;
 
 
  117    public function setGenericFlag(
int $flagId, 
bool $value) : void{
 
  118        $propertyId = $flagId >= 64 ? EntityMetadataProperties::FLAGS2 : EntityMetadataProperties::FLAGS;
 
  119        $realFlagId = $flagId % 64;
 
  120        $flagSetProp = $this->properties[$propertyId] ?? 
null;
 
  121        if($flagSetProp === 
null){
 
  123        }elseif($flagSetProp instanceof LongMetadataProperty){
 
  124            $flagSet = $flagSetProp->getValue();
 
  126            throw new \InvalidArgumentException(
"Wrong type found for flags, want long, but have " . get_class($flagSetProp));
 
  129        if((($flagSet >> $realFlagId) & 1) !== ($value ? 1 : 0)){
 
  130            $flagSet ^= (1 << $realFlagId);
 
  131            $this->setLong($propertyId, $flagSet);
 
  135    public function setPlayerFlag(
int $flagId, 
bool $value) : void{
 
  136        $flagSetProp = $this->properties[EntityMetadataProperties::PLAYER_FLAGS] ?? null;
 
  137        if($flagSetProp === 
null){
 
  139        }elseif($flagSetProp instanceof ByteMetadataProperty){
 
  140            $flagSet = $flagSetProp->getValue();
 
  142            throw new \InvalidArgumentException(
"Wrong type found for flags, want byte, but have " . get_class($flagSetProp));
 
  144        if((($flagSet >> $flagId) & 1) !== ($value ? 1 : 0)){
 
  145            $flagSet ^= (1 << $flagId);
 
  146            $this->setByte(EntityMetadataProperties::PLAYER_FLAGS, $flagSet);
 
  157        return $this->properties;
 
 
  167        return $this->dirtyProperties;
 
 
  174        $this->dirtyProperties = [];
 
 
  181        if(isset($this->properties[$key])){
 
  182            $this->dirtyProperties[$key] = $this->properties[$key];
 
 
  190        $this->dirtyProperties = $this->properties;