From 403eb71aa6ae897fc38b4d7165c2d49eec1264d1 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 9 Jan 2024 10:49:17 +0300 Subject: [PATCH] fixed item and tnt movement(kinda) --- src/Player.php | 2 +- src/entity/object/ItemEntity.php | 34 ++++++++++++++++++++++++++ src/entity/object/PrimedTNT.php | 41 ++++++++++++++++++++++++++++---- 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/Player.php b/src/Player.php index 647092d7..049d0d26 100755 --- a/src/Player.php +++ b/src/Player.php @@ -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; diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index bc1120c3..81488e33 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -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; + } } diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index 27768a05..ee0a2ded 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -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;