hotbar will save in creative mode

This commit is contained in:
GameHerobrine 2025-07-19 14:55:40 +03:00
parent 92e1411ed3
commit a61d4936c5
3 changed files with 87 additions and 28 deletions

View file

@ -1,9 +1,9 @@
<?php
class BlockAPI{
public static $creativeHotbarSlots = [];
public static $reverseCreativeLookup = [];
public static $creative = [
//Building
[STONE, 0],
[COBBLESTONE, 0],
@ -201,8 +201,33 @@ class BlockAPI{
private $scheduledUpdates = [];
private $randomUpdates = [];
/**
* @param int $id item id
* @param int $meta item metadata
* @return false|int false if item is not accessible from creative mode, otherwise slot id in BlockAPI::$creative
*/
public static function hasCreativeItem($id, $meta){
$rind = ($id << 24) | ($meta);
return static::$reverseCreativeLookup[$rind] ?? false;
}
function __construct(){
$this->server = ServerAPI::request();
foreach(static::$creative as $slot => [$id, $meta]){
$rind = ($id << 24) | ($meta);
static::$reverseCreativeLookup[$rind] = $slot;
}
self::$creativeHotbarSlots[0] = static::hasCreativeItem(STONE, 0);
self::$creativeHotbarSlots[1] = static::hasCreativeItem(COBBLESTONE, 0);
self::$creativeHotbarSlots[2] = static::hasCreativeItem(DIRT, 0);
self::$creativeHotbarSlots[3] = static::hasCreativeItem(PLANKS, 0);
self::$creativeHotbarSlots[4] = static::hasCreativeItem(PLANKS, 1);
self::$creativeHotbarSlots[5] = static::hasCreativeItem(TORCH, 0);
self::$creativeHotbarSlots[6] = static::hasCreativeItem(BRICK_STAIRS, 0);
self::$creativeHotbarSlots[7] = static::hasCreativeItem(COBBLE_WALL, 0);
self::$creativeHotbarSlots[8] = static::hasCreativeItem(SAPLING, 0);
}
public static function get($id, $meta = 0, $v = false){

View file

@ -429,7 +429,6 @@ class PlayerAPI{
"z" => $this->server->spawn->z,
],
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, [AIR, 0, 0]),
"hotbar" => [0, 1, 2, 3, 4, 5, 6, 7, 8],
"armor" => array_fill(0, 4, [AIR, 0]),
"gamemode" => $this->server->gamemode,
"health" => 20,
@ -439,23 +438,32 @@ class PlayerAPI{
"slot-count" => 7,
"bed-position" => null,
];
if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){
$ev = true;
$sav = false;
if(!file_exists(DATA_PATH . "players/$iname.yml")){
if(PocketMinecraftServer::$SAVE_PLAYER_DATA && $create){
console("[NOTICE] Player data not found for \"" . $iname . "\", creating new profile");
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
$data->save();
console("[NOTICE] Player data not found for \"$iname\", creating new profile");
$data = new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
$sav = true;
}else{
return new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
$data = new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
$ev = false;
}
}else{
$data = new Config(DATA_PATH . "players/$iname.yml", CONFIG_YAML, $default);
}
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
if(($data->get("gamemode") & 0x01) === 1){
$data->set("health", 20);
}
$this->server->handle("player.offline.get", $data);
if(!$data->exists("hotbar")){
if(($data->get("gamemode") & 1) == CREATIVE) $hb = BlockAPI::$creativeHotbarSlots;
else $hb = [0, 1, 2, 3, 4, 5, 6, 7, 8];
$data->set("hotbar", $hb);
}
if($ev) $this->server->handle("player.offline.get", $data);
if($sav) $data->save();
return $data;
}