item pickup method from vanilla

This commit is contained in:
GameHerobrine 2023-10-27 12:46:20 +03:00
parent 9a530b9dd1
commit df54826e4c

View file

@ -338,22 +338,27 @@ class Entity extends Position
$hasUpdate = $this->class === ENTITY_MOB; // force true for mobs $hasUpdate = $this->class === ENTITY_MOB; // force true for mobs
$time = microtime(true); $time = microtime(true);
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){ if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){
foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){ //TODO vanilla method of searching/radius $myBB = $this->boundingBox->grow(1, 0.5, 1);
foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){
if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup == 0){ if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup == 0){
if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( if($item->boundingBox->intersectsWith($myBB)){
"eid" => $this->player->eid, if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array(
"player" => $this->player, "eid" => $this->player->eid,
"entity" => $item, "player" => $this->player,
"block" => $item->type, "entity" => $item,
"meta" => $item->meta, "block" => $item->type,
"target" => $item->eid "meta" => $item->meta,
)) !== false){ "target" => $item->eid
$item->close(); )) !== false){
// $item->spawntime = 0; $item->close();
// $this->server->schedule(15, array($item, "close")); // $item->spawntime = 0;
// $this->server->schedule(15, array($item, "close"));
}
} }
} }
} }
unset($myBB);
} elseif($this->class === ENTITY_ITEM){ } elseif($this->class === ENTITY_ITEM){
if(($time - $this->spawntime) >= 300){ if(($time - $this->spawntime) >= 300){
$this->close(); // Despawn timer $this->close(); // Despawn timer