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,8 +338,10 @@ 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($item->boundingBox->intersectsWith($myBB)){
if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array(
"eid" => $this->player->eid, "eid" => $this->player->eid,
"player" => $this->player, "player" => $this->player,
@ -353,7 +355,10 @@ class Entity extends Position
// $this->server->schedule(15, array($item, "close")); // $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