Skip to content

Instantly share code, notes, and snippets.

@SmallJoker
Last active June 15, 2025 13:13
Show Gist options
  • Save SmallJoker/cb89c3f9e4be27a0e8bc10ced1c5fc31 to your computer and use it in GitHub Desktop.
Save SmallJoker/cb89c3f9e4be27a0e8bc10ced1c5fc31 to your computer and use it in GitHub Desktop.
Minetest - Replace deprecated function calls
#!/bin/bash
# License: CC0
# How to use:
# 1) Open the terminal in the target mod directory
# 2) Call the script
#
# This script modifies your Lua files. Use a CVS (Code Versioning System)
# such as Git to undo incorrect changes!
files=$(find . -name "*.lua")
# Escape special characters for the replacement '.:'
escape()
{
echo "$1" | sed -r 's/([.()/])/\\\1/g'
}
# Replace `old(` with `new(`
std_call()
{
# Arg 1: Source value (i.e. deprecated string)
# Arg 2: Destination value
_inp=$(escape "$1")
_out=$(escape "$2")
sed -i "s/${_inp}(/${_out}(/g" "$f"
}
# Replace `:old(` with `:new(`
ref_call()
{
std_call ":$1" ":$2"
}
for f in $files; do
# `minetest.env:` superseded by `minetest.` or `core.`
sed -i 's/\.env:/\./g' "$f"
std_call "nodeupdate" "core.check_for_falling" # Removed in 2017
# l_object.cpp
ref_call "getacceleration" "get_acceleration" # Since 2017
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 "settexturemod" "set_texture_mod"
ref_call "setsprite" "set_sprite"
ref_call "moveto" "move_to"
ref_call "get_player_velocity" "get_velocity" # Since 2020
ref_call "set_player_velocity" "set_velocity"
ref_call "add_player_velocity" "add_velocity"
_a=$(escape ":get_entity_name()") # WARNING: '\(\)' is not replaced by sed. Why?
_b=$(escape ":get_luaentity().name")
sed -i "s/${_a}/${_b}/g" "$f"
# 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"
# PerlinNoise was renamed to ValueNoise, but it's as of now too early to replace them in mods.
# l_settings.cpp
std_call ".setting_get" ".settings:get"
std_call ".setting_set" ".settings:set"
std_call ".setting_getbool" ".settings:get_bool"
std_call ".setting_setbool" ".settings:set_bool"
std_call ".setting_save" ".settings:write"
# c_content.cpp
_b=$(escape '[core.features.hud_def_type_field and "type" or "hud_elem_type"]')
sed -i "s/hud_elem_type[ ]*=[ ]*/${_b} = /g" "$f" # Since 2023
done
exit $?
# Test file:
# ==============================
local a = minetest.env:setting_get("mysetting") or "test"
local vm
local slice = vm:getMapSlice(nil)
nodeupdate(slice["garbage_code"])
local name = myobj:get_entity_name()
hud_elem_type="type1",
hud_elem_type = "type2"
@rubenwardy
Copy link

Good job!!11!!!!!

@SmallJoker
Copy link
Author

Thank you!!!!!11¨!4¨!!2424!!!

@Wuzzy2
Copy link

Wuzzy2 commented Mar 7, 2019

Please add setspriteset_sprite.

@SmallJoker
Copy link
Author

@Wuzzy2 Sorry for the delay. Added it among other deprecated function calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment