[Lua API] Key definition: OK. Can't be remapped yet.
This commit is contained in:
parent
ea38e6d397
commit
fc3fafc1a8
@ -8,7 +8,7 @@ mod:key {
|
|||||||
name = "Inventory",
|
name = "Inventory",
|
||||||
default_key = "E"
|
default_key = "E"
|
||||||
|
|
||||||
key_callback = function(client, screen_width, screen_height, gui_scale)
|
callback = function(client, screen_width, screen_height, gui_scale)
|
||||||
show_inventory(client, screen_width, screen_height, gui_scale)
|
show_inventory(client, screen_width, screen_height, gui_scale)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@ -16,6 +16,17 @@ mod:key {
|
|||||||
|
|
||||||
## Attributes
|
## Attributes
|
||||||
|
|
||||||
|
### `callback`
|
||||||
|
|
||||||
|
Function called when the key is pressed.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```lua
|
||||||
|
callback = function(client, screen_width, screen_height, gui_scale)
|
||||||
|
show_inventory(client, screen_width, screen_height, gui_scale)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### `default_key`
|
### `default_key`
|
||||||
|
|
||||||
Keyboard key mapped to this key by default.
|
Keyboard key mapped to this key by default.
|
||||||
@ -25,6 +36,8 @@ Example:
|
|||||||
default_key = "E"
|
default_key = "E"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Names are defined [here](https://github.com/Unarelith/GameKit/blob/master/source/core/input/KeyboardUtils.cpp).
|
||||||
|
|
||||||
### `name`
|
### `name`
|
||||||
|
|
||||||
Name of the key. Optional field, uses `id` if not defined.
|
Name of the key. Optional field, uses `id` if not defined.
|
||||||
|
@ -26,7 +26,12 @@
|
|||||||
--
|
--
|
||||||
mod = openminer.mod_loader:register_mod("creative_inventory")
|
mod = openminer.mod_loader:register_mod("creative_inventory")
|
||||||
|
|
||||||
function show_creative_window(client, screen_width, screen_height, gui_scale)
|
mod:key {
|
||||||
|
id = "creative_inventory",
|
||||||
|
name = "Creative window",
|
||||||
|
default_key = "H",
|
||||||
|
|
||||||
|
callback = function(client, screen_width, screen_height, gui_scale)
|
||||||
items = {}
|
items = {}
|
||||||
for k, v in pairs(openminer.registry:items()) do
|
for k, v in pairs(openminer.registry:items()) do
|
||||||
if k ~= 1 and not v:has_group("group:ci_ignore") then
|
if k ~= 1 and not v:has_group("group:ci_ignore") then
|
||||||
@ -102,5 +107,6 @@ function show_creative_window(client, screen_width, screen_height, gui_scale)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui:show(client);
|
gui:show(client);
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,12 @@
|
|||||||
--
|
--
|
||||||
local modpath = mod:path()
|
local modpath = mod:path()
|
||||||
|
|
||||||
function show_inventory(client, screen_width, screen_height, gui_scale)
|
mod:key {
|
||||||
|
id = "inventory",
|
||||||
|
name = "Inventory",
|
||||||
|
default_key = "E",
|
||||||
|
|
||||||
|
callback = function(client, screen_width, screen_height, gui_scale)
|
||||||
local gui = LuaGUI.new()
|
local gui = LuaGUI.new()
|
||||||
|
|
||||||
gui:set_size(176, 166)
|
gui:set_size(176, 166)
|
||||||
@ -88,15 +93,6 @@ function show_inventory(client, screen_width, screen_height, gui_scale)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui:show(client)
|
gui:show(client)
|
||||||
end
|
|
||||||
|
|
||||||
mod:key {
|
|
||||||
id = "inventory",
|
|
||||||
name = "Inventory",
|
|
||||||
default_key = "E",
|
|
||||||
|
|
||||||
key_callback = function(client, screen_width, screen_height, gui_scale)
|
|
||||||
show_inventory(client, screen_width, screen_height, gui_scale)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +48,6 @@ KeyboardHandler::KeyboardHandler() {
|
|||||||
addKey(GameKey::Dig, "Dig", sf::Keyboard::L);
|
addKey(GameKey::Dig, "Dig", sf::Keyboard::L);
|
||||||
addKey(GameKey::Use, "Use", sf::Keyboard::M);
|
addKey(GameKey::Use, "Use", sf::Keyboard::M);
|
||||||
|
|
||||||
addKey(GameKey::Inventory, "Inventory", sf::Keyboard::E);
|
|
||||||
addKey(GameKey::CreativeWindow, "CreativeWindow", sf::Keyboard::H);
|
|
||||||
|
|
||||||
addKey(GameKey::Chat, "Chat", sf::Keyboard::T);
|
addKey(GameKey::Chat, "Chat", sf::Keyboard::T);
|
||||||
addKey(GameKey::Command, "Command", sf::Keyboard::Divide);
|
addKey(GameKey::Command, "Command", sf::Keyboard::Divide);
|
||||||
|
|
||||||
|
@ -89,20 +89,6 @@ void ClientCommandHandler::sendPlayerPlaceBlock(s32 x, s32 y, s32 z, u32 block)
|
|||||||
m_client.send(packet);
|
m_client.send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientCommandHandler::sendPlayerInventoryRequest() {
|
|
||||||
Network::Packet packet;
|
|
||||||
packet << Network::Command::PlayerInventory
|
|
||||||
<< u16(Config::screenWidth) << u16(Config::screenHeight) << u8(Config::guiScale);
|
|
||||||
m_client.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientCommandHandler::sendPlayerCreativeWindowRequest() {
|
|
||||||
Network::Packet packet;
|
|
||||||
packet << Network::Command::PlayerCreativeWindow
|
|
||||||
<< u16(Config::screenWidth) << u16(Config::screenHeight) << u8(Config::guiScale);
|
|
||||||
m_client.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientCommandHandler::sendPlayerHeldItemChanged(u8 hotbarSlot, u16 itemID) {
|
void ClientCommandHandler::sendPlayerHeldItemChanged(u8 hotbarSlot, u16 itemID) {
|
||||||
Network::Packet packet;
|
Network::Packet packet;
|
||||||
packet << Network::Command::PlayerHeldItemChanged
|
packet << Network::Command::PlayerHeldItemChanged
|
||||||
@ -144,6 +130,13 @@ void ClientCommandHandler::sendChatMessage(const std::string &message) {
|
|||||||
m_client.send(packet);
|
m_client.send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientCommandHandler::sendKeyPressed(u16 keyID) {
|
||||||
|
Network::Packet packet;
|
||||||
|
packet << Network::Command::KeyPressed << keyID
|
||||||
|
<< Config::screenWidth << Config::screenHeight << Config::guiScale;
|
||||||
|
m_client.send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ComponentType>
|
template<typename ComponentType>
|
||||||
static void addComponentCommandCallback(Network::Command command, Client &client, ClientCommandHandler::EntityMap &entityMap, ClientWorld &world) {
|
static void addComponentCommandCallback(Network::Command command, Client &client, ClientCommandHandler::EntityMap &entityMap, ClientWorld &world) {
|
||||||
client.setCommandCallback(command, [&](Network::Packet &packet) {
|
client.setCommandCallback(command, [&](Network::Packet &packet) {
|
||||||
|
@ -51,13 +51,12 @@ class ClientCommandHandler {
|
|||||||
void sendPlayerRotUpdate();
|
void sendPlayerRotUpdate();
|
||||||
void sendPlayerDigBlock(const glm::ivec4 &selectedBlock);
|
void sendPlayerDigBlock(const glm::ivec4 &selectedBlock);
|
||||||
void sendPlayerPlaceBlock(s32 x, s32 y, s32 z, u32 block);
|
void sendPlayerPlaceBlock(s32 x, s32 y, s32 z, u32 block);
|
||||||
void sendPlayerInventoryRequest();
|
|
||||||
void sendPlayerCreativeWindowRequest();
|
|
||||||
void sendPlayerHeldItemChanged(u8 hotbarSlot, u16 itemID);
|
void sendPlayerHeldItemChanged(u8 hotbarSlot, u16 itemID);
|
||||||
void sendBlockActivated(const glm::ivec4 &selectedBlock);
|
void sendBlockActivated(const glm::ivec4 &selectedBlock);
|
||||||
void sendBlockInvUpdate(Inventory &inventory);
|
void sendBlockInvUpdate(Inventory &inventory);
|
||||||
void sendChunkRequest(s32 chunkX, s32 chunkY, s32 chunkZ);
|
void sendChunkRequest(s32 chunkX, s32 chunkY, s32 chunkZ);
|
||||||
void sendChatMessage(const std::string &message);
|
void sendChatMessage(const std::string &message);
|
||||||
|
void sendKeyPressed(u16 keyID);
|
||||||
|
|
||||||
void setupCallbacks();
|
void setupCallbacks();
|
||||||
|
|
||||||
|
@ -118,6 +118,13 @@ void GameState::onEvent(const sf::Event &event) {
|
|||||||
gk::Mouse::setCursorGrabbed(true);
|
gk::Mouse::setCursorGrabbed(true);
|
||||||
gk::Mouse::setCursorVisible(false);
|
gk::Mouse::setCursorVisible(false);
|
||||||
}
|
}
|
||||||
|
else if (event.type == sf::Event::KeyPressed) {
|
||||||
|
for (auto &key : m_registry.keys()) {
|
||||||
|
if (event.key.code == key.defaultKeyCode()) {
|
||||||
|
m_clientCommandHandler.sendKeyPressed(key.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_hud.onEvent(event);
|
m_hud.onEvent(event);
|
||||||
}
|
}
|
||||||
@ -140,13 +147,6 @@ void GameState::update() {
|
|||||||
|
|
||||||
if (!m_stateStack->empty() && &m_stateStack->top() == this) {
|
if (!m_stateStack->empty() && &m_stateStack->top() == this) {
|
||||||
m_player.processInputs();
|
m_player.processInputs();
|
||||||
|
|
||||||
if (gk::GamePad::isKeyPressedOnce(GameKey::Inventory)) {
|
|
||||||
m_clientCommandHandler.sendPlayerInventoryRequest();
|
|
||||||
}
|
|
||||||
else if (gk::GamePad::isKeyPressedOnce(GameKey::CreativeWindow)) {
|
|
||||||
m_clientCommandHandler.sendPlayerCreativeWindowRequest();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_player.updatePosition(m_world);
|
m_player.updatePosition(m_world);
|
||||||
|
@ -221,8 +221,6 @@ void SettingsMenuState::addInputButtons() {
|
|||||||
{GameKey::Sprint, "Sprint"},
|
{GameKey::Sprint, "Sprint"},
|
||||||
// {GameKey::Dig, "Dig"},
|
// {GameKey::Dig, "Dig"},
|
||||||
// {GameKey::Use, "Use"},
|
// {GameKey::Use, "Use"},
|
||||||
{GameKey::Inventory, "Inventory"},
|
|
||||||
{GameKey::CreativeWindow, "Creative window"},
|
|
||||||
{GameKey::Chat, "Chat"},
|
{GameKey::Chat, "Chat"},
|
||||||
{GameKey::Command, "Command"},
|
{GameKey::Command, "Command"},
|
||||||
};
|
};
|
||||||
|
@ -44,9 +44,6 @@ namespace GameKey {
|
|||||||
Dig,
|
Dig,
|
||||||
Use,
|
Use,
|
||||||
|
|
||||||
Inventory,
|
|
||||||
CreativeWindow,
|
|
||||||
|
|
||||||
Chat,
|
Chat,
|
||||||
Command,
|
Command,
|
||||||
|
|
||||||
|
@ -48,8 +48,6 @@ std::string Network::commandToString(Network::Command command) {
|
|||||||
{Network::Command::PlayerPosUpdate, "PlayerPosUpdate"},
|
{Network::Command::PlayerPosUpdate, "PlayerPosUpdate"},
|
||||||
{Network::Command::PlayerRotUpdate, "PlayerRotUpdate"},
|
{Network::Command::PlayerRotUpdate, "PlayerRotUpdate"},
|
||||||
{Network::Command::PlayerSpawn, "PlayerSpawn"},
|
{Network::Command::PlayerSpawn, "PlayerSpawn"},
|
||||||
{Network::Command::PlayerInventory, "PlayerInventory"},
|
|
||||||
{Network::Command::PlayerCreativeWindow, "PlayerCreativeWindow"},
|
|
||||||
{Network::Command::PlayerChangeDimension, "PlayerChangeDimension"},
|
{Network::Command::PlayerChangeDimension, "PlayerChangeDimension"},
|
||||||
{Network::Command::PlayerHeldItemChanged, "PlayerHeldItemChanged"},
|
{Network::Command::PlayerHeldItemChanged, "PlayerHeldItemChanged"},
|
||||||
|
|
||||||
@ -69,6 +67,8 @@ std::string Network::commandToString(Network::Command command) {
|
|||||||
{Network::Command::EntityRotation, "EntityRotation"},
|
{Network::Command::EntityRotation, "EntityRotation"},
|
||||||
{Network::Command::EntityAnimation, "EntityRotation"},
|
{Network::Command::EntityAnimation, "EntityRotation"},
|
||||||
{Network::Command::EntityDrawableDef, "EntityDrawableDef"},
|
{Network::Command::EntityDrawableDef, "EntityDrawableDef"},
|
||||||
|
|
||||||
|
{Network::Command::KeyPressed, "KeyPressed"},
|
||||||
};
|
};
|
||||||
|
|
||||||
return commandNames[command];
|
return commandNames[command];
|
||||||
|
@ -53,31 +53,32 @@ namespace Network {
|
|||||||
PlayerPosUpdate = 0x0a, // <TCP> [NetworkCommand][u16 client id][s32 x, y, z][bool isTeleportation] (both) // FIXME
|
PlayerPosUpdate = 0x0a, // <TCP> [NetworkCommand][u16 client id][s32 x, y, z][bool isTeleportation] (both) // FIXME
|
||||||
PlayerRotUpdate = 0x0b, // <TCP> [NetworkCommand][u16 client id][float yaw][float pitch] (from Client only)
|
PlayerRotUpdate = 0x0b, // <TCP> [NetworkCommand][u16 client id][float yaw][float pitch] (from Client only)
|
||||||
PlayerSpawn = 0x0c, // <TCP> [NetworkCommand][u16 client id][s32 x, y, z] (from Server only)
|
PlayerSpawn = 0x0c, // <TCP> [NetworkCommand][u16 client id][s32 x, y, z] (from Server only)
|
||||||
PlayerInventory = 0x0d, // <TCP> [NetworkCommand][u16 screenWidth, screenHeight][u8 guiScale] (from Client only)
|
PlayerChangeDimension = 0x0d, // <TCP> [NetworkCommand][u16 client id][s32 x, y, z][u16 dimension] (from Server only)
|
||||||
PlayerCreativeWindow = 0x0e, // <TCP> [NetworkCommand][u16 screenWidth, screenHeight][u8 guiScale] (from Client only)
|
PlayerHeldItemChanged = 0x0e, // <TCP> [NetworkCommand][u8 hotbar slot][u16 item id (to check match with server)] (from Client only)
|
||||||
PlayerChangeDimension = 0x0f, // <TCP> [NetworkCommand][u16 client id][s32 x, y, z][u16 dimension] (from Server only)
|
|
||||||
PlayerHeldItemChanged = 0x10, // <TCP> [NetworkCommand][u8 hotbar slot][u16 item id (to check match with server)] (from Client only)
|
|
||||||
|
|
||||||
// Block commands
|
// Block commands
|
||||||
BlockUpdate = 0x11, // <TCP> [NetworkCommand][s32 x, y, z][u32 block] (from Server only)
|
BlockUpdate = 0x0f, // <TCP> [NetworkCommand][s32 x, y, z][u32 block] (from Server only)
|
||||||
BlockActivated = 0x12, // <TCP> [NetworkCommand][s32 x, y, z][u16 screenWidth, screenHeight][u8 guiScale] (from Client only)
|
BlockActivated = 0x10, // <TCP> [NetworkCommand][s32 x, y, z][u16 screenWidth, screenHeight][u8 guiScale] (from Client only)
|
||||||
BlockGUIData = 0x13, // <TCP> [NetworkCommand][LuaGUIData data] (from Server only)
|
BlockGUIData = 0x11, // <TCP> [NetworkCommand][LuaGUIData data] (from Server only)
|
||||||
BlockInvUpdate = 0x14, // <TCP> [NetworkCommand][s32 x, y, z][[std::string item][u16 amount][u8 x, y]...] (both) [FIXME]
|
BlockInvUpdate = 0x12, // <TCP> [NetworkCommand][s32 x, y, z][[std::string item][u16 amount][u8 x, y]...] (both) [FIXME]
|
||||||
BlockDataUpdate = 0x15, // <TCP> [NetworkCommand][s32 x, y, z][u64 data] (both) [FIXME]
|
BlockDataUpdate = 0x13, // <TCP> [NetworkCommand][s32 x, y, z][u64 data] (both) [FIXME]
|
||||||
|
|
||||||
// Registry commands
|
// Registry commands
|
||||||
RegistryData = 0x16, // <TCP> [NetworkCommand][Block block] (from Server only)
|
RegistryData = 0x14, // <TCP> [NetworkCommand][Block block] (from Server only)
|
||||||
|
|
||||||
// Chat commands
|
// Chat commands
|
||||||
ChatMessage = 0x17, // <TCP> [NetworkCommand][u16 client id][std::string message] (both)
|
ChatMessage = 0x15, // <TCP> [NetworkCommand][u16 client id][std::string message] (both)
|
||||||
|
|
||||||
// Entity commands
|
// Entity commands
|
||||||
EntitySpawn = 0x18, // <TCP> [NetworkCommand][u32 entity id] (from Server only)
|
EntitySpawn = 0x16, // <TCP> [NetworkCommand][u32 entity id] (from Server only)
|
||||||
EntityDespawn = 0x19, // <TCP> [NetworkCommand][u32 entity id] (from Server only)
|
EntityDespawn = 0x17, // <TCP> [NetworkCommand][u32 entity id] (from Server only)
|
||||||
EntityPosition = 0x1a, // <TCP> [NetworkCommand][u32 entity id][double x, double y, double z] (from Server only)
|
EntityPosition = 0x18, // <TCP> [NetworkCommand][u32 entity id][double x, double y, double z] (from Server only)
|
||||||
EntityRotation = 0x1b, // <TCP> [NetworkCommand][u32 entity id][float w, float x, float y, float z] (from Server only)
|
EntityRotation = 0x19, // <TCP> [NetworkCommand][u32 entity id][float w, float x, float y, float z] (from Server only)
|
||||||
EntityAnimation = 0x1c, // <TCP> [NetworkCommand][u32 entity id][AnimationComponent anim] (from Server only)
|
EntityAnimation = 0x1a, // <TCP> [NetworkCommand][u32 entity id][AnimationComponent anim] (from Server only)
|
||||||
EntityDrawableDef = 0x1d, // <TCP> [NetworkCommand][u32 entity id][DrawableDef def] (from Server only)
|
EntityDrawableDef = 0x1b, // <TCP> [NetworkCommand][u32 entity id][DrawableDef def] (from Server only)
|
||||||
|
|
||||||
|
// Key commands
|
||||||
|
KeyPressed = 0x1c, // <TCP> [NetworkCommand][u16 key id][u16 screenWidth, screenHeight][u8 guiScale] (from Client only)
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string commandToString(Command command);
|
std::string commandToString(Command command);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <gk/core/IntTypes.hpp>
|
#include <gk/core/IntTypes.hpp>
|
||||||
|
#include <gk/core/input/KeyboardUtils.hpp>
|
||||||
|
|
||||||
#include <sol/sol.hpp>
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
@ -42,17 +43,24 @@ class Key : public ISerializable {
|
|||||||
Key(u16 id, const std::string &stringID, const std::string &name)
|
Key(u16 id, const std::string &stringID, const std::string &name)
|
||||||
: m_id(id), m_stringID(stringID), m_name(name) {}
|
: m_id(id), m_stringID(stringID), m_name(name) {}
|
||||||
|
|
||||||
void serialize(sf::Packet &packet) const override { packet << m_id << m_stringID << m_name << m_defaultKey; }
|
void serialize(sf::Packet &packet) const override {
|
||||||
void deserialize(sf::Packet &packet) override { packet >> m_id >> m_stringID >> m_name >> m_defaultKey; }
|
packet << m_id << m_stringID << m_name << m_defaultKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserialize(sf::Packet &packet) override {
|
||||||
|
packet >> m_id >> m_stringID >> m_name >> m_defaultKey;
|
||||||
|
m_defaultKeyCode = gk::KeyboardUtils::getKeyFromName(m_defaultKey);
|
||||||
|
}
|
||||||
|
|
||||||
u16 id() const { return m_id; }
|
u16 id() const { return m_id; }
|
||||||
|
|
||||||
const std::string &stringID() const { return m_stringID; }
|
const std::string &stringID() const { return m_stringID; }
|
||||||
const std::string &name() const { return m_name; }
|
const std::string &name() const { return m_name; }
|
||||||
|
|
||||||
const std::string &defaultKey() const { return m_defaultKey; }
|
sf::Keyboard::Key defaultKeyCode() const { return m_defaultKeyCode; }
|
||||||
void setDefaultKey(const std::string &defaultKey) { m_defaultKey = defaultKey; }
|
void setDefaultKey(const std::string &defaultKey) { m_defaultKey = defaultKey; }
|
||||||
|
|
||||||
|
const sol::unsafe_function &callback() const { return m_callback; }
|
||||||
void setCallback(const sol::unsafe_function &callback) { m_callback = callback; }
|
void setCallback(const sol::unsafe_function &callback) { m_callback = callback; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -62,6 +70,7 @@ class Key : public ISerializable {
|
|||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
std::string m_defaultKey;
|
std::string m_defaultKey;
|
||||||
|
sf::Keyboard::Key m_defaultKeyCode = sf::Keyboard::Unknown;
|
||||||
|
|
||||||
sol::unsafe_function m_callback;
|
sol::unsafe_function m_callback;
|
||||||
};
|
};
|
||||||
|
@ -296,36 +296,6 @@ void ServerCommandHandler::setupCallbacks() {
|
|||||||
gkError() << ("Failed to dig block using player " + std::to_string(client.id) + ": Player not found").c_str();
|
gkError() << ("Failed to dig block using player " + std::to_string(client.id) + ": Player not found").c_str();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_server.setCommandCallback(Network::Command::PlayerInventory, [this](ClientInfo &client, Network::Packet &packet) {
|
|
||||||
u16 screenWidth, screenHeight;
|
|
||||||
u8 guiScale;
|
|
||||||
packet >> screenWidth >> screenHeight >> guiScale;
|
|
||||||
|
|
||||||
sol::unsafe_function func = m_scriptEngine.lua()["show_inventory"];
|
|
||||||
|
|
||||||
try {
|
|
||||||
func(client, screenWidth, screenHeight, guiScale);
|
|
||||||
}
|
|
||||||
catch (const sol::error &error) {
|
|
||||||
gkError() << "Failed to send inventory GUI: " << error.what();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_server.setCommandCallback(Network::Command::PlayerCreativeWindow, [this](ClientInfo &client, Network::Packet &packet) {
|
|
||||||
u16 screenWidth, screenHeight;
|
|
||||||
u8 guiScale;
|
|
||||||
packet >> screenWidth >> screenHeight >> guiScale;
|
|
||||||
|
|
||||||
sol::unsafe_function func = m_scriptEngine.lua()["show_creative_window"];
|
|
||||||
|
|
||||||
try {
|
|
||||||
func(client, screenWidth, screenHeight, guiScale);
|
|
||||||
}
|
|
||||||
catch (const sol::error &error) {
|
|
||||||
gkError() << "Failed to send creative window GUI: " << error.what();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_server.setCommandCallback(Network::Command::PlayerHeldItemChanged, [this](ClientInfo &client, Network::Packet &packet) {
|
m_server.setCommandCallback(Network::Command::PlayerHeldItemChanged, [this](ClientInfo &client, Network::Packet &packet) {
|
||||||
ServerPlayer *player = m_players.getPlayer(client.id);
|
ServerPlayer *player = m_players.getPlayer(client.id);
|
||||||
if (player) {
|
if (player) {
|
||||||
@ -398,6 +368,14 @@ void ServerCommandHandler::setupCallbacks() {
|
|||||||
m_chatCommandHandler.parseCommand(message.substr(1), client);
|
m_chatCommandHandler.parseCommand(message.substr(1), client);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_server.setCommandCallback(Network::Command::KeyPressed, [this](ClientInfo &client, Network::Packet &packet) {
|
||||||
|
u16 keyID, screenWidth, screenHeight;
|
||||||
|
u8 guiScale;
|
||||||
|
packet >> keyID >> screenWidth >> screenHeight >> guiScale;
|
||||||
|
|
||||||
|
m_registry.getKey(keyID).callback()(client, screenWidth, screenHeight, guiScale);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerCommandHandler::setPlayerPosition(u16 clientID, s32 x, s32 y, s32 z) {
|
void ServerCommandHandler::setPlayerPosition(u16 clientID, s32 x, s32 y, s32 z) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user