From a4a5f1dfdf57047e1ba1cabec738a88bc5f9bc08 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 15 Nov 2024 11:52:14 +0300 Subject: [PATCH] hotbar fixes --- src/API/PlayerAPI.php | 2 +- src/Player.php | 10 ++++++---- src/entity/Entity.php | 2 +- src/entity/object/ItemEntity.php | 2 +- src/network/protocol/packet/PlayerEquipmentPacket.php | 2 +- src/network/raknet/RakNetDataPacket.php | 7 ++++++- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 89e53f42..613c0736 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -365,7 +365,7 @@ class PlayerAPI{ "z" => $this->server->spawn->z, ], "inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, [AIR, 0, 0]), - "hotbar" => [0, -1, -1, -1, -1, -1, -1, -1, -1], + "hotbar" => [0, 1, 2, 3, 4, 5, 6, 7, 8], "armor" => array_fill(0, 4, [AIR, 0]), "gamemode" => $this->server->gamemode, "health" => 20, diff --git a/src/Player.php b/src/Player.php index ff5ccc79..d78b3567 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1682,7 +1682,10 @@ class Player{ $this->slot = 0; $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; } - + for($i = 0; $i < count($this->hotbar); ++$i){ + if($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe? + if($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; + } if($this->data->exists("slot-count")){ $this->slotCount = $this->data->get("slot-count"); }else{ @@ -1827,7 +1830,7 @@ class Player{ $this->slot = -1; } break; - }else{ + }else if($packet->slot > 0){ $packet->slot -= 9; } @@ -1878,8 +1881,7 @@ class Player{ if(Player::$experimentalHotbar) { $this->slot = $packet->slot; $this->hotbar[$this->curHotbarIndex] = $packet->slot; - } - else{ + }else{ $this->curHotbarIndex = 0; array_pop($this->hotbar); array_unshift($this->hotbar, $this->slot); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 5b80a66b..8d0b0561 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1279,7 +1279,7 @@ class Entity extends Position $this->speedMeasure = array(0, 0, 0, 0, 0, 0, 0); } - public function getSpeed() //TODO rename to getBaseSpeed + public function getSpeed() { return $this->speed; } diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 00f41ac8..6e67ad9a 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -192,7 +192,7 @@ class ItemEntity extends Entity{ $this->speedZ = (lcg_value() - lcg_value()) * 0.2; } - //$this->searchForOtherItemsNearby(); //not in vanilla 0.8.1, TODO reenable after fixing not correct count in inv + //$this->searchForOtherItemsNearby(); //not in vanilla 0.8.1 } if($this->closed) return; diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php index ab9bf9f0..06e65fee 100644 --- a/src/network/protocol/packet/PlayerEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -14,7 +14,7 @@ class PlayerEquipmentPacket extends RakNetDataPacket{ $this->eid = $this->getInt(); $this->item = $this->getShort(); $this->meta = $this->getShort(); - $this->slot = $this->getByte(); + $this->slot = $this->getSignedByte(); } public function encode(){ diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index c9e22aaf..5f64ac47 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -123,7 +123,12 @@ abstract class RakNetDataPacket extends stdClass{ protected function getShort($unsigned = false){ return Utils::readShort($this->get(2), $unsigned); } - + + public function getSignedByte(){ + $b = ord($this->get(1)); + return $b >= 0x80 ? ($b-256) : $b; + } + protected function getByte(){ return ord($this->get(1)); }