1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Implement adding velocity to player from Lua

The intended usecase is knockback, but there's potential for more.
This commit is contained in:
sfan5 2019-07-16 14:00:42 +02:00
parent b19400aa74
commit cf64054390
14 changed files with 105 additions and 2 deletions

View file

@ -67,7 +67,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_handler,
{ "TOCLIENT_TIME_OF_DAY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_TimeOfDay }, // 0x29
{ "TOCLIENT_CSM_RESTRICTION_FLAGS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CSMRestrictionFlags }, // 0x2A
null_command_handler,
{ "TOCLIENT_PLAYER_SPEED", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_PlayerSpeed }, // 0x2B
null_command_handler,
null_command_handler,
null_command_handler,

View file

@ -1383,6 +1383,17 @@ void Client::handleCommand_CSMRestrictionFlags(NetworkPacket *pkt)
loadMods();
}
void Client::handleCommand_PlayerSpeed(NetworkPacket *pkt)
{
v3f added_vel;
*pkt >> added_vel;
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
player->addVelocity(added_vel);
}
/*
* Mod channels
*/

View file

@ -194,6 +194,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
New network float format
ContentFeatures version 13
Add full Euler rotations instead of just yaw
Add TOCLIENT_PLAYER_SPEED
*/
#define LATEST_PROTOCOL_VERSION 37
@ -295,6 +296,11 @@ enum ToClientCommand
u32 CSMRestrictionFlags byteflag
*/
TOCLIENT_PLAYER_SPEED = 0x2B,
/*
v3f added_vel
*/
// (oops, there is some gap here)
TOCLIENT_CHAT_MESSAGE = 0x2F,

View file

@ -156,7 +156,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_factory,
{ "TOCLIENT_TIME_OF_DAY", 0, true }, // 0x29
{ "TOCLIENT_CSM_RESTRICTION_FLAGS", 0, true }, // 0x2A
null_command_factory,
{ "TOCLIENT_PLAYER_SPEED", 0, true }, // 0x2B
null_command_factory,
null_command_factory,
null_command_factory,