fixed item and tnt movement(kinda)

This commit is contained in:
GameHerobrine 2024-01-09 10:49:17 +03:00
parent 2636aa985d
commit 403eb71aa6
3 changed files with 72 additions and 5 deletions

View file

@ -1218,7 +1218,7 @@ class Player{
$move = new MoveEntityPacket_PosRot();
$move->eid = $e->eid;
$move->x = $e->x;
$move->y = $e instanceof ItemEntity ? $e->boundingBox->maxY : $e->y; //TODO fix items getting into farmland in client side somehow else
$move->y = $e->y; //TODO fix items getting into farmland in client side somehow else
$move->z = $e->z;
$move->yaw = $e->yaw;
$move->pitch = $e->pitch;

View file

@ -24,4 +24,38 @@ class ItemEntity extends Entity{
$this->delayBeforePickup = 20;
$this->stepHeight = 0;
}
public function updateEntityMovement(){
//TODO it is weird on client side for some reason
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
$this->speedY -= 0.04;
$this->noClip = false; //TODO pushOutofBlocks
$this->move($this->speedX, $this->speedY, $this->speedZ);
$var1 = (int)$this->x != (int)$this->lastX || (int)$this->y != (int)$this->lastY || (int)$this->z != (int)$this->lastZ;
if($var1/* || $this->ticksExisted % 25 == 0*/){ //TODO ticksExisted(should be alternative in nc already)
//TODO check material
//TODO search for other items
}
$friction = 0.98;
if($this->onGround){
$friction = 0.588;
$v3 = $this->level->level->getBlockID($this->x, floor($this->boundingBox->minY) - 1, $this->z);
if($v3 > 0) $friction = StaticBlock::getSlipperiness($v3);
}
$this->speedX *= $friction;
$this->speedY *= 0.98;
$this->speedZ *= $friction;
//if($this->onGround) $this->speedY *= -0.5;
//TODO ++age; despawn after age >= 6000;
}
}

View file

@ -13,12 +13,12 @@ class PrimedTNT extends Entity{
$this->setSize(0.98, 0.98);
$this->yOffset = $this->height / 2;
$this->setHealth(10000000, "generic");
$this->server->schedule(5, [$this, "updateFuse"], [], true);
//$this->server->schedule(5, [$this, "updateFuse"], [], true);
}
public function getMetadata(){
$d = parent::getMetadata();
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
$d[16]["value"] = (int) $this->data["fuse"];
return $d;
}
public function createSaveData(){
@ -29,7 +29,40 @@ class PrimedTNT extends Entity{
return $data;
}
public function updateFuse(){
public function update($now){
if($this->closed) return;
$this->lastX = $this->x;
$this->lastY = $this->y;
$this->lastZ = $this->z;
$this->speedY -= 0.04;
$this->move($this->speedX, $this->speedY, $this->speedZ);
$this->speedX *- 0.98;
$this->speedY *= 0.98;
$this->speedZ *= 0.98;
if($this->onGround){
$this->speedX *= 0.6;
$this->speedZ *= 0.6;
$this->speedY *= -0.5;
}
$tickDiff = ($now - $this->lastUpdate) / 0.05;
$this->data["fuse"] -= $tickDiff;
$this->updateMetadata();
if($this->data["fuse"] <= 0){
$this->close();
$explosion = new Explosion($this, $this->data["power"]);
$explosion->explode();
}
$this->lastUpdate = $now;
}
/*public function updateFuse(){
if($this->closed === true){
return false;
}
@ -41,7 +74,7 @@ class PrimedTNT extends Entity{
$explosion->explode();
}
}
}
}*/
public function spawn($player){
$pk = new AddEntityPacket;