Finally, physics

This commit is contained in:
Shoghi Cervantes
2014-05-25 18:14:01 +02:00
parent 933a28537b
commit 03d7127e33
5 changed files with 213 additions and 48 deletions

View File

@ -22,6 +22,7 @@
namespace pocketmine\entity;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Short;
@ -32,7 +33,6 @@ use pocketmine\Player;
class DroppedItem extends Entity{
protected $age = 0;
protected $owner = null;
protected $thrower = null;
protected $pickupDelay = 0;
@ -65,6 +65,41 @@ class DroppedItem extends Entity{
$this->item = Item::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], min(64, $this->namedtag->Item["Count"]));
}
public function onUpdate(){
$this->entityBaseTick();
//TODO: manage pickupDelay
$this->motionY -= $this->gravity;
$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
$this->move($this->motionX, $this->motionY, $this->motionZ);
$friction = 1 - $this->drag;
if($this->onGround){
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
}
$this->motionX *= $friction;
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;
if($this->onGround){
$this->motionY *= -0.5;
}
if(abs($this->motionX) < 0.01){
$this->motionX = 0;
}
if(abs($this->motionZ) < 0.01){
$this->motionZ = 0;
}
//TODO: update age in base entity tick
//TODO: kill entity if it's old enough
$this->updateMovement();
//$this->server->broadcastMessage("{$this->ticksLived}: ".round($this->x, 2).",".round($this->y, 2).",".round($this->z, 2));
}
public function attack($damage, $source = "generic"){
}