mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
hotbar is limited to 7 slots by default, changeable with /hotbar
This commit is contained in:
parent
99954b67d6
commit
ae59d3da59
2 changed files with 37 additions and 2 deletions
|
|
@ -18,7 +18,8 @@ class PlayerAPI{
|
|||
$this->registerCmd("spawn");
|
||||
$this->registerCmd("ping");
|
||||
$this->registerCmd("loc");
|
||||
|
||||
$this->registerCmd("hotbar", "<slotcount>");
|
||||
|
||||
$this->server->api->console->alias("lag", "ping");
|
||||
$this->server->api->console->alias("gm", "gamemode");
|
||||
$this->server->api->console->alias("who", "list");
|
||||
|
|
@ -31,6 +32,7 @@ class PlayerAPI{
|
|||
$this->server->api->console->cmdWhitelist("ping");
|
||||
$this->server->api->console->cmdWhitelist("spawn");
|
||||
$this->server->api->console->cmdWhitelist("loc");
|
||||
$this->server->api->console->cmdWhitelist("hotbar");
|
||||
}
|
||||
|
||||
public function registerCmd($cmd, $help = ""){
|
||||
|
|
@ -119,6 +121,21 @@ class PlayerAPI{
|
|||
|
||||
$target->setSpawn($spawn);
|
||||
return "Spawnpoint set correctly!\n";
|
||||
case "hotbar":
|
||||
if(!($issuer instanceof Player)) return "Please run this command in-game.";
|
||||
if(count($args) < 1) return "Slots in hotbar on server: {$issuer->slotCount}";
|
||||
|
||||
$scrw = $args[0];
|
||||
if(is_numeric($scrw)){
|
||||
$sc = (int)$scrw;
|
||||
if($sc < 5 || $sc > 9) return "Slot count must be between 5 and 9.";
|
||||
|
||||
$issuer->slotCount = $sc;
|
||||
$issuer->sendInventory();
|
||||
return "Changed slot count to $sc";
|
||||
}else{
|
||||
return "Usage: /$cmd <slotcount>";
|
||||
}
|
||||
case "spawn":
|
||||
if(!($issuer instanceof Player)){
|
||||
return "Please run this command in-game.";
|
||||
|
|
@ -375,6 +392,7 @@ class PlayerAPI{
|
|||
"lastIP" => "",
|
||||
"lastID" => 0,
|
||||
"achievements" => [],
|
||||
"slot-count" => 7
|
||||
];
|
||||
|
||||
if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ class Player{
|
|||
private $chunkCount = [];
|
||||
private $received = [];
|
||||
|
||||
public $slotCount = 7;
|
||||
|
||||
public $entityMovementQueue;
|
||||
public $entityMovementQueueLength = 0;
|
||||
|
|
@ -1617,6 +1618,13 @@ class Player{
|
|||
$this->slot = -1;//0
|
||||
$this->hotbar = [-1, -1, -1, -1, -1, -1, -1, -1, -1];
|
||||
}
|
||||
|
||||
if($this->data->exists("slot-count")){
|
||||
$this->slotCount = $this->data->get("slot-count");
|
||||
}else{
|
||||
$this->data->set("slot-count", $this->slotCount);
|
||||
}
|
||||
|
||||
$this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]);
|
||||
$this->eid = $this->entity->eid;
|
||||
$this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";");
|
||||
|
|
@ -1786,7 +1794,16 @@ class Player{
|
|||
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||
$this->slot = $packet->slot;
|
||||
if(($this->gamemode & 0x01) === SURVIVAL){
|
||||
if(!in_array($this->slot, $this->hotbar)){
|
||||
|
||||
$has = false;
|
||||
for($i = 0; $i < $this->slotCount; ++$i){
|
||||
if($this->slot == $this->hotbar[$i]){
|
||||
$has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$has){
|
||||
array_pop($this->hotbar);
|
||||
array_unshift($this->hotbar, $this->slot);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue