MT-replace-deprecated.sh

This is a shell script for finding and replacing most deprecated function calls of mod code from old Minetest versions (0.4.x) to update them to Minetest 5.0.0.

See also: https://forum.minetest.net/viewtopic.php?f=18&t=20403


 * 1) !/bin/bash
 * 2) License: CC0


 * 1) How to use:
 * 2) 1) Open the terminal in the target mod directory
 * 3) 2) Call the script

files=$(find . -name "*.lua")

ref_call {	sed -i "s/:$1(/:$2(/g" "$f" }

for f in $files; do	sed -i 's/\.env:/\./g' "$f";

sed -i "s/nodeupdate(/minetest\.check_for_falling(/g" "$f"

# l_object.cpp ref_call "getacceleration" "get_acceleration" ref_call "setacceleration" "set_acceleration"

ref_call "getpos" "get_pos" ref_call "setpos" "set_pos"

ref_call "getvelocity" "get_velocity" ref_call "setvelocity" "set_velocity"

ref_call "getyaw" "get_yaw" ref_call "setyaw" "set_yaw"

ref_call "moveto" "move_to"

ref_call "setsprite" "set_sprite"

# l_noise.cpp ref_call "get2dMap" "get_2d_map" ref_call "get3dMap" "get_3d_map"

ref_call "get2dMap_flat" "get_2d_map_flat" ref_call "get3dMap_flat" "get_3d_map_flat"

ref_call "calc2dMap" "calc_2d_map" ref_call "calc3dMap" "calc_3d_map"

ref_call "get2d" "get_2d" ref_call "get3d" "get_3d" ref_call "getMapSlice" "get_map_slice"

# l_settings.cpp sed -i 's/\.setting_get(/\.settings:get(/g' "$f"; sed -i 's/\.setting_set(/\.settings:set(/g' "$f";

sed -i 's/\.setting_getbool/\.settings:get_bool/g' "$f"; sed -i 's/\.setting_setbool/\.settings:set_bool/g' "$f";

sed -i 's/\.setting_save/\.settings:write/g' "$f"; done