aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorWuzzy <wuzzy2@mail.ru>2021-10-01 14:21:24 +0000
committerGitHub <noreply@github.com>2021-10-01 16:21:24 +0200
commit21113ad4105dd3fb181b3d0638b907af94a352ab (patch)
tree9cd1346f6aff8968c23e2447e50d4469b888b01b /src/script
parentf5040707fe7cf9f24274379598527d6298c5818c (diff)
downloadminetest-21113ad4105dd3fb181b3d0638b907af94a352ab.tar.gz
minetest-21113ad4105dd3fb181b3d0638b907af94a352ab.tar.bz2
minetest-21113ad4105dd3fb181b3d0638b907af94a352ab.zip
Split liquid_viscosity to liquid_viscosity and move_resistance (#10810)
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp22
-rw-r--r--src/script/cpp_api/s_node.h1
-rw-r--r--src/script/lua_api/l_localplayer.cpp7
-rw-r--r--src/script/lua_api/l_localplayer.h3
4 files changed, 29 insertions, 4 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 5a095fd8f..8a5a3fe71 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -719,6 +719,9 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
// the slowest possible
f.liquid_viscosity = getintfield_default(L, index,
"liquid_viscosity", f.liquid_viscosity);
+ // If move_resistance is not set explicitly,
+ // move_resistance is equal to liquid_viscosity
+ f.move_resistance = f.liquid_viscosity;
f.liquid_range = getintfield_default(L, index,
"liquid_range", f.liquid_range);
f.leveled = getintfield_default(L, index, "leveled", f.leveled);
@@ -822,6 +825,21 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
getstringfield(L, index, "node_dig_prediction",
f.node_dig_prediction);
+ // How much the node slows down players, ranging from 1 to 7,
+ // the higher, the slower.
+ f.move_resistance = getintfield_default(L, index,
+ "move_resistance", f.move_resistance);
+
+ // Whether e.g. players in this node will have liquid movement physics
+ lua_getfield(L, index, "liquid_move_physics");
+ if(lua_isboolean(L, -1)) {
+ f.liquid_move_physics = lua_toboolean(L, -1);
+ } else if(lua_isnil(L, -1)) {
+ f.liquid_move_physics = f.liquid_type != LIQUID_NONE;
+ } else {
+ errorstream << "Field \"liquid_move_physics\": Invalid type!" << std::endl;
+ }
+ lua_pop(L, 1);
}
void push_content_features(lua_State *L, const ContentFeatures &c)
@@ -949,6 +967,10 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
lua_setfield(L, -2, "legacy_wallmounted");
lua_pushstring(L, c.node_dig_prediction.c_str());
lua_setfield(L, -2, "node_dig_prediction");
+ lua_pushnumber(L, c.move_resistance);
+ lua_setfield(L, -2, "move_resistance");
+ lua_pushboolean(L, c.liquid_move_physics);
+ lua_setfield(L, -2, "liquid_move_physics");
}
/******************************************************************************/
diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h
index 3f771c838..3c6a8445b 100644
--- a/src/script/cpp_api/s_node.h
+++ b/src/script/cpp_api/s_node.h
@@ -53,6 +53,7 @@ public:
static struct EnumString es_ContentParamType[];
static struct EnumString es_ContentParamType2[];
static struct EnumString es_LiquidType[];
+ static struct EnumString es_LiquidMoveType[];
static struct EnumString es_NodeBoxType[];
static struct EnumString es_TextureAlphaMode[];
};
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp
index 9f3569ecc..bdbe98cb0 100644
--- a/src/script/lua_api/l_localplayer.cpp
+++ b/src/script/lua_api/l_localplayer.cpp
@@ -128,11 +128,11 @@ int LuaLocalPlayer::l_is_in_liquid_stable(lua_State *L)
return 1;
}
-int LuaLocalPlayer::l_get_liquid_viscosity(lua_State *L)
+int LuaLocalPlayer::l_get_move_resistance(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
- lua_pushinteger(L, player->liquid_viscosity);
+ lua_pushinteger(L, player->move_resistance);
return 1;
}
@@ -466,7 +466,6 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, is_touching_ground),
luamethod(LuaLocalPlayer, is_in_liquid),
luamethod(LuaLocalPlayer, is_in_liquid_stable),
- luamethod(LuaLocalPlayer, get_liquid_viscosity),
luamethod(LuaLocalPlayer, is_climbing),
luamethod(LuaLocalPlayer, swimming_vertical),
luamethod(LuaLocalPlayer, get_physics_override),
@@ -488,5 +487,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, hud_change),
luamethod(LuaLocalPlayer, hud_get),
+ luamethod(LuaLocalPlayer, get_move_resistance),
+
{0, 0}
};
diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h
index 4413f2bdb..041545a49 100644
--- a/src/script/lua_api/l_localplayer.h
+++ b/src/script/lua_api/l_localplayer.h
@@ -51,7 +51,6 @@ private:
static int l_is_touching_ground(lua_State *L);
static int l_is_in_liquid(lua_State *L);
static int l_is_in_liquid_stable(lua_State *L);
- static int l_get_liquid_viscosity(lua_State *L);
static int l_is_climbing(lua_State *L);
static int l_swimming_vertical(lua_State *L);
@@ -96,6 +95,8 @@ private:
// hud_get(self, id)
static int l_hud_get(lua_State *L);
+ static int l_get_move_resistance(lua_State *L);
+
LocalPlayer *m_localplayer = nullptr;
public: