aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-01-17 01:56:50 +0100
committersfan5 <sfan5@live.de>2021-01-29 17:34:41 +0100
commit83229921e5f378625d9ef63ede3dffbe778e1798 (patch)
tree8189436795cad017e2eb858b5d2cc23c16a55f46 /src/script
parentedd8c3c664ad005eb32e1968ce80091851ffb817 (diff)
downloadminetest-83229921e5f378625d9ef63ede3dffbe778e1798.tar.gz
minetest-83229921e5f378625d9ef63ede3dffbe778e1798.tar.bz2
minetest-83229921e5f378625d9ef63ede3dffbe778e1798.zip
Rework use_texture_alpha to provide three opaque/clip/blend modes
The change that turns nodeboxes and meshes opaque when possible is kept, as is the compatibility code that warns modders to adjust their nodedefs.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp32
-rw-r--r--src/script/cpp_api/s_node.cpp8
-rw-r--r--src/script/cpp_api/s_node.h1
3 files changed, 32 insertions, 9 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 5d29422af..ecab7baa1 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -618,25 +618,39 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
}
lua_pop(L, 1);
+ /* alpha & use_texture_alpha */
+ // This is a bit complicated due to compatibility
+
+ f.setDefaultAlphaMode();
+
warn_if_field_exists(L, index, "alpha",
- "Obsolete, only limited compatibility provided");
+ "Obsolete, only limited compatibility provided; "
+ "replaced by \"use_texture_alpha\"");
if (getintfield_default(L, index, "alpha", 255) != 255)
- f.alpha = 0;
+ f.alpha = ALPHAMODE_BLEND;
+
+ lua_getfield(L, index, "use_texture_alpha");
+ if (lua_isboolean(L, -1)) {
+ warn_if_field_exists(L, index, "use_texture_alpha",
+ "Boolean values are deprecated; use the new choices");
+ if (lua_toboolean(L, -1))
+ f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND;
+ } else if (check_field_or_nil(L, -1, LUA_TSTRING, "use_texture_alpha")) {
+ int result = f.alpha;
+ string_to_enum(ScriptApiNode::es_TextureAlphaMode, result,
+ std::string(lua_tostring(L, -1)));
+ f.alpha = static_cast<enum AlphaMode>(result);
+ }
+ lua_pop(L, 1);
- bool usealpha = getboolfield_default(L, index,
- "use_texture_alpha", false);
- if (usealpha)
- f.alpha = 0;
+ /* Other stuff */
- // Read node color.
lua_getfield(L, index, "color");
read_color(L, -1, &f.color);
lua_pop(L, 1);
getstringfield(L, index, "palette", f.palette_name);
- /* Other stuff */
-
lua_getfield(L, index, "post_effect_color");
read_color(L, -1, &f.post_effect_color);
lua_pop(L, 1);
diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp
index e0f9bcd78..269ebacb2 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -93,6 +93,14 @@ struct EnumString ScriptApiNode::es_NodeBoxType[] =
{0, NULL},
};
+struct EnumString ScriptApiNode::es_TextureAlphaMode[] =
+ {
+ {ALPHAMODE_OPAQUE, "opaque"},
+ {ALPHAMODE_CLIP, "clip"},
+ {ALPHAMODE_BLEND, "blend"},
+ {0, NULL},
+ };
+
bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node,
ServerActiveObject *puncher, const PointedThing &pointed)
{
diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h
index 81b44f0f0..3f771c838 100644
--- a/src/script/cpp_api/s_node.h
+++ b/src/script/cpp_api/s_node.h
@@ -54,4 +54,5 @@ public:
static struct EnumString es_ContentParamType2[];
static struct EnumString es_LiquidType[];
static struct EnumString es_NodeBoxType[];
+ static struct EnumString es_TextureAlphaMode[];
};