### 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
// 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;
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 &&
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;
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);
}
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;
v3f getLegitSpeed() const { return m_freecam ? m_legit_speed : m_speed; }
+ v3f getSendSpeed();
+
inline void setLegitPosition(const v3f &position)
{
if (m_freecam)
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
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);