From 908cff1317b87ef3dbd2d3db0450d04b8451d1d1 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 14 Feb 2024 04:22:20 +0300 Subject: [PATCH] fixed packet spam, removed item merging, various fixes --- src/Player.php | 33 ++++++++++++------- src/entity/Entity.php | 6 ++-- src/entity/animal/Chicken.php | 2 +- src/entity/object/ItemEntity.php | 6 +++- .../protocol/packet/LevelEventPacket.php | 4 +++ src/world/Level.php | 17 ++++++---- src/world/generator/WorldGenerator.php | 2 ++ 7 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/Player.php b/src/Player.php index 5caa83f5..2007b54a 100755 --- a/src/Player.php +++ b/src/Player.php @@ -594,8 +594,6 @@ class Player{ } public function sendInventorySlot($s){ - $this->sendInventory(); - return; $s = (int) $s; if(!isset($this->inventory[$s])){ $pk = new ContainerSetSlotPacket; @@ -754,7 +752,7 @@ class Player{ $pk->target = $data["entity"]->eid; $this->dataPacket($pk); if(($this->gamemode & 0x01) === 0x00){ - $this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack, false); + $this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack, true); } switch($data["entity"]->type){ case WOOD: @@ -916,6 +914,15 @@ class Player{ } if($m !== ""){ + + /*$pk = new LevelEventPacket(); + $pk->evid = LevelEventPacket::EVENT_OPEN_DOOR_SOUND; + $pk->x = $this->entity->x; + $pk->y = $this->entity->y; + $pk->z = $this->entity->z; + $pk->data = 0; + $this->dataPacket($pk);*/ + $pk = new MessagePacket; $pk->source = ($author instanceof Player) ? $author->username : $author; $pk->message = TextFormat::clean($m); //Colors not implemented :( @@ -1207,15 +1214,17 @@ class Player{ $moveSent = false; $headSent = false; if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ - $motion = new SetEntityMotionPacket(); - $motion->eid = $e->eid; - $motion->speedX = $e->speedX; - $motion->speedY = $e->speedY; - $motion->speedZ = $e->speedZ; - $motion->encode(); - $len += 1 + strlen($motion->buffer); - ++$packets; - $motionSent = true; + if(!($e->speedY < 0 && $e->onGround)){ + $motion = new SetEntityMotionPacket(); + $motion->eid = $e->eid; + $motion->speedX = $e->speedX; + $motion->speedY = $e->speedY; + $motion->speedZ = $e->speedZ; + $motion->encode(); + $len += 1 + strlen($motion->buffer); + ++$packets; + $motionSent = true; + } } if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){ $move = new MoveEntityPacket_PosRot(); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 23e16b43..aa7882f1 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -441,7 +441,7 @@ class Entity extends Position if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix for($i = 0; $i < 8; ++$i){ $x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8; - $y= ((($i >> 1) % 2) - 0.5) * 0.1; + $y = ((($i >> 1) % 2) - 0.5) * 0.1; $z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8; $blockX = (int) ($this->x + $x); @@ -609,8 +609,8 @@ class Entity extends Position $z1 = floor($aABB->maxZ + 1); for($x = $x0; $x < $x1; ++$x){ - for($y = $y0; $y < $y1; ++$y){ - for($z = $z0; $z < $z1; ++$z){ + for($z = $z0; $z < $z1; ++$z){ + for($y = $y0 - 1; $y < $y1; ++$y){ $b = $this->level->level->getBlockID($x, $y, $z); if($b != 0){ $blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 5fd27a3a..0cc62f63 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -24,7 +24,7 @@ class Chicken extends Animal{ public function updateEntityMovement(){ parent::updateEntityMovement(); - if($this->onGround && $this->speedY < 0) $this->speedY *= 0.6; + if(!$this->onGround && $this->speedY < 0) $this->speedY *= 0.6; if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ $this->dropAnEgg(); diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 7e8d711d..60bac8eb 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -94,7 +94,7 @@ class ItemEntity extends Entity{ $this->speedZ = (lcg_value() - lcg_value()) * 0.2; } - $this->searchForOtherItemsNearby(); //not in vanilla 0.8.1 + //$this->searchForOtherItemsNearby(); //not in vanilla 0.8.1, TODO reenable after fixing not correct count in inv } if($this->closed) return; @@ -112,6 +112,10 @@ class ItemEntity extends Entity{ if($this->onGround) $this->speedY *= -0.5; + 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->age; //TODO despawn after age >= 6000 ?; } diff --git a/src/network/protocol/packet/LevelEventPacket.php b/src/network/protocol/packet/LevelEventPacket.php index dcddd653..50727e45 100644 --- a/src/network/protocol/packet/LevelEventPacket.php +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -1,6 +1,10 @@ true, FARMLAND => true, @@ -150,15 +152,15 @@ class Level{ public function getCubes(Entity $e, AxisAlignedBB $aABB) { $aABBs = []; $x0 = floor($aABB->minX); - $x1 = ceil($aABB->maxX); + $x1 = floor($aABB->maxX + 1); $y0 = floor($aABB->minY); - $y1 = ceil($aABB->maxY); + $y1 = floor($aABB->maxY + 1); $z0 = floor($aABB->minZ); - $z1 = ceil($aABB->maxZ); + $z1 = floor($aABB->maxZ + 1); - for($x = $x0; $x <= $x1; ++$x) { - for($y = $y0; $y <= $y1; ++$y) { - for($z = $z0; $z <= $z1; ++$z) { + for($x = $x0; $x < $x1; ++$x) { + for($z = $z0; $z < $z1; ++$z) { + for($y = $y0 - 1; $y < $y1; ++$y) { $bid = $this->level->getBlockID($x, $y, $z); if($bid > 0){ $blockBounds = Block::$class[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); @@ -541,7 +543,8 @@ class Level{ } public function addBlockToSendQueue($x, $y, $z, $id, $meta){ - $this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta]; + if(!$this->forceDisableBlockQueue) + $this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta]; } public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){ diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index b0f2978b..18c0d1d7 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -29,6 +29,7 @@ class WorldGenerator{ } public function generate(){ + $this->level->forceDisableBlockQueue = true; $this->generator->init($this->level, $this->random); for($Z = 0; $Z < $this->width; ++$Z){ for($X = 0; $X < $this->width; ++$X){ @@ -49,6 +50,7 @@ class WorldGenerator{ $this->level->setSpawn($this->generator->getSpawn()); $this->level->save(true, true); + $this->level->forceDisableBlockQueue = false; } public function close(){