Add minetest.get_send_speed
This commit is contained in:
parent
d082423166
commit
96a37aed31
@ -674,6 +674,11 @@ Minetest namespace reference
|
||||
### Global callback registration functions
|
||||
Call these functions only at load time!
|
||||
|
||||
* `minetest.get_send_speed(speed)`
|
||||
* This function is called every time the player's speed is sent to server
|
||||
* The `speed` argument is the actual speed of the player
|
||||
* If you define it, you can return a modified `speed`. This speed will be
|
||||
sent to server instead.
|
||||
* `minetest.open_enderchest()`
|
||||
* This function is called if the client uses the Keybind for it (by default "O")
|
||||
* You can override it
|
||||
|
@ -913,9 +913,9 @@ void Client::Send(NetworkPacket* pkt)
|
||||
|
||||
// Will fill up 12 + 12 + 4 + 4 + 4 bytes
|
||||
void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt)
|
||||
{
|
||||
{
|
||||
v3f pf = myplayer->getLegitPosition() * 100;
|
||||
v3f sf = myplayer->getLegitSpeed() * 100;
|
||||
v3f sf = myplayer->getSendSpeed() * 100;
|
||||
s32 pitch = myplayer->getPitch() * 100;
|
||||
s32 yaw = myplayer->getYaw() * 100;
|
||||
u32 keyPressed = myplayer->keyPressed;
|
||||
@ -1286,7 +1286,7 @@ void Client::sendPlayerPos(v3f pos)
|
||||
|
||||
if (
|
||||
player->last_position == pos &&
|
||||
player->last_speed == player->getLegitSpeed() &&
|
||||
player->last_speed == player->getSendSpeed() &&
|
||||
player->last_pitch == player->getPitch() &&
|
||||
player->last_yaw == player->getYaw() &&
|
||||
player->last_keyPressed == player->keyPressed &&
|
||||
@ -1295,7 +1295,7 @@ void Client::sendPlayerPos(v3f pos)
|
||||
return;
|
||||
|
||||
player->last_position = pos;
|
||||
player->last_speed = player->getLegitSpeed();
|
||||
player->last_speed = player->getSendSpeed();
|
||||
player->last_pitch = player->getPitch();
|
||||
player->last_yaw = player->getYaw();
|
||||
player->last_keyPressed = player->keyPressed;
|
||||
@ -1645,17 +1645,17 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur
|
||||
void Client::updateAllMapBlocks()
|
||||
{
|
||||
v3s16 currentBlock = getNodeBlockPos(floatToInt(m_env.getLocalPlayer()->getPosition(), BS));
|
||||
|
||||
|
||||
for (s16 X = currentBlock.X - 2; X <= currentBlock.X + 2; X++)
|
||||
for (s16 Y = currentBlock.Y - 2; Y <= currentBlock.Y + 2; Y++)
|
||||
for (s16 Z = currentBlock.Z - 2; Z <= currentBlock.Z + 2; Z++)
|
||||
addUpdateMeshTask(v3s16(X, Y, Z), false, true);
|
||||
|
||||
|
||||
Map &map = m_env.getMap();
|
||||
|
||||
|
||||
std::vector<v3s16> positions;
|
||||
map.listAllLoadedBlocks(positions);
|
||||
|
||||
|
||||
for (v3s16 p : positions) {
|
||||
addUpdateMeshTask(p, false, false);
|
||||
}
|
||||
|
@ -709,6 +709,16 @@ v3s16 LocalPlayer::getLightPosition() const
|
||||
return floatToInt(m_position + v3f(0.0f, BS * 1.5f, 0.0f), BS);
|
||||
}
|
||||
|
||||
v3f LocalPlayer::getSendSpeed()
|
||||
{
|
||||
v3f speed = getLegitSpeed();
|
||||
|
||||
if (m_client->modsLoaded())
|
||||
speed = m_client->getScript()->get_send_speed(speed);
|
||||
|
||||
return speed;
|
||||
}
|
||||
|
||||
v3f LocalPlayer::getEyeOffset() const
|
||||
{
|
||||
float eye_height = camera_barely_in_ceiling ? m_eye_height - 0.125f : m_eye_height;
|
||||
|
@ -143,6 +143,8 @@ public:
|
||||
|
||||
v3f getLegitSpeed() const { return m_freecam ? m_legit_speed : m_speed; }
|
||||
|
||||
v3f getSendSpeed();
|
||||
|
||||
inline void setLegitPosition(const v3f &position)
|
||||
{
|
||||
if (m_freecam)
|
||||
|
@ -365,6 +365,27 @@ void ScriptApiClient::open_enderchest()
|
||||
lua_pcall(L, 0, 0, error_handler);
|
||||
}
|
||||
|
||||
v3f ScriptApiClient::get_send_speed(v3f speed)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
PUSH_ERROR_HANDLER(L);
|
||||
int error_handler = lua_gettop(L) - 1;
|
||||
lua_insert(L, error_handler);
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "get_send_speed");
|
||||
if (lua_isfunction(L, -1)) {
|
||||
speed /= BS;
|
||||
push_v3f(L, speed);
|
||||
lua_pcall(L, 1, 1, error_handler);
|
||||
speed = read_v3f(L, -1);
|
||||
speed *= BS;
|
||||
}
|
||||
|
||||
return speed;
|
||||
}
|
||||
|
||||
void ScriptApiClient::set_node_def(const ContentFeatures &f)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
@ -70,6 +70,8 @@ public:
|
||||
bool on_inventory_open(Inventory *inventory);
|
||||
void open_enderchest();
|
||||
|
||||
v3f get_send_speed(v3f speed);
|
||||
|
||||
void set_node_def(const ContentFeatures &f);
|
||||
void set_item_def(const ItemDefinition &i);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user