diff --git a/src/client/tile.h b/src/client/tile.h index ffbe78bac..3293b4dd1 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -191,8 +191,6 @@ struct TileSpec bool world_aligned = false; //! Tile rotation. TileRotation rotation = TileRotation::None; - //! This much light does the tile emit. - u8 emissive_light = 0; //! The first is base texture, the second is overlay. TileLayer layers[MAX_TILE_LAYERS]; }; diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index e4d94b3fc..91aa5b405 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -56,9 +56,16 @@ void read_item_definition(lua_State* L, int index, if (index < 0) index = lua_gettop(L) + 1 + index; - def.type = (ItemType)getenumfield(L, index, "type", - es_ItemType, ITEM_NONE); + def.name.clear(); getstringfield(L, index, "name", def.name); + + { + auto str = getstringfield_default(L, index, "type", ""); + if (!string_to_enum(es_ItemType, def.type, str)) + warningstream << "Item " << def.name + << " has unknown type \"" << str << '"' << std::endl; + } + getstringfield(L, index, "description", def.description); getstringfield(L, index, "short_description", def.short_description); getstringfield(L, index, "inventory_image", def.inventory_image); @@ -605,9 +612,6 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special) case NDT_PLANTLIKE: case NDT_FIRELIKE: default_tiling = false; - // "break" is omitted here intentionaly, as PLANTLIKE - // FIRELIKE drawtype both should default to having - // backface_culling to false. [[fallthrough]]; case NDT_MESH: case NDT_LIQUID: @@ -621,7 +625,6 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special) break; } - // key at index -2 and value at index if(lua_isstring(L, index)){ // "default_lava.png" tiledef.name = lua_tostring(L, index); @@ -634,7 +637,10 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special) // name="default_lava.png" tiledef.name.clear(); getstringfield(L, index, "name", tiledef.name); - getstringfield(L, index, "image", tiledef.name); // MaterialSpec compat. + warn_if_field_exists(L, index, "image", "TileDef", + "Deprecated: new name is \"name\"."); + getstringfield(L, index, "image", tiledef.name); + tiledef.backface_culling = getboolfield_default( L, index, "backface_culling", default_culling); tiledef.tileable_horizontal = getboolfield_default( @@ -659,6 +665,9 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special) lua_getfield(L, index, "animation"); tiledef.animation = read_animation_definition(L, -1); lua_pop(L, 1); + } else if (!lua_isnil(L, index)) { + // TODO: should be an error + errorstream << "TileDef: Invalid type! (expected string or table)" << std::endl; } return tiledef; @@ -672,13 +681,13 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) /* Cache existence of some callbacks */ lua_getfield(L, index, "on_construct"); - if(!lua_isnil(L, -1)) f.has_on_construct = true; + f.has_on_construct = !lua_isnil(L, -1); lua_pop(L, 1); lua_getfield(L, index, "on_destruct"); - if(!lua_isnil(L, -1)) f.has_on_destruct = true; + f.has_on_destruct = !lua_isnil(L, -1); lua_pop(L, 1); lua_getfield(L, index, "after_destruct"); - if(!lua_isnil(L, -1)) f.has_after_destruct = true; + f.has_after_destruct = !lua_isnil(L, -1); lua_pop(L, 1); lua_getfield(L, index, "on_rightclick"); @@ -695,8 +704,13 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) /* Visual definition */ - f.drawtype = (NodeDrawType)getenumfield(L, index, "drawtype", - ScriptApiNode::es_DrawType,NDT_NORMAL); + { + auto str = getstringfield_default(L, index, "drawtype", ""); + if (!string_to_enum(ScriptApiNode::es_DrawType, f.drawtype, str)) + warningstream << "Node " << f.name + << " has unknown drawtype \"" << str << '"' << std::endl; + } + getfloatfield(L, index, "visual_scale", f.visual_scale); /* Meshnode model filename */ @@ -796,10 +810,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) 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(result); + string_to_enum(ScriptApiNode::es_TextureAlphaMode, f.alpha, lua_tostring(L, -1)); } lua_pop(L, 1); @@ -817,10 +828,18 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) getboolfield(L, index, "post_effect_color_shaded", f.post_effect_color_shaded); - f.param_type = (ContentParamType)getenumfield(L, index, "paramtype", - ScriptApiNode::es_ContentParamType, CPT_NONE); - f.param_type_2 = (ContentParamType2)getenumfield(L, index, "paramtype2", - ScriptApiNode::es_ContentParamType2, CPT2_NONE); + { + auto str = getstringfield_default(L, index, "paramtype", ""); + if (!string_to_enum(ScriptApiNode::es_ContentParamType, f.param_type, str)) + warningstream << "Node " << f.name + << " has unknown paramtype \"" << str << '"' << std::endl; + } + { + auto str = getstringfield_default(L, index, "paramtype2", ""); + if (!string_to_enum(ScriptApiNode::es_ContentParamType2, f.param_type_2, str)) + warningstream << "Node " << f.name + << " has unknown paramtype2 \"" << str << '"' << std::endl; + } if (!f.palette_name.empty() && !(f.param_type_2 == CPT2_COLOR || @@ -855,8 +874,12 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) // Liquids flow into and replace node getboolfield(L, index, "floodable", f.floodable); // Whether the node is non-liquid, source liquid or flowing liquid - f.liquid_type = (LiquidType)getenumfield(L, index, "liquidtype", - ScriptApiNode::es_LiquidType, LIQUID_NONE); + { + auto str = getstringfield_default(L, index, "liquidtype", ""); + if (!string_to_enum(ScriptApiNode::es_LiquidType, f.liquid_type, str)) + warningstream << "Node " << f.name + << " has unknown liquidtype \"" << str << '"' << std::endl; + } // If the content is liquid, this is the flowing version of the liquid. getstringfield(L, index, "liquid_alternative_flowing", f.liquid_alternative_flowing); @@ -915,7 +938,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) lua_pushnil(L); while (lua_next(L, table) != 0) { // Value at -1 - std::string side(lua_tostring(L, -1)); + std::string_view side(lua_tostring(L, -1)); // Note faces are flipped to make checking easier if (side == "top") f.connect_sides |= 2; @@ -986,6 +1009,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) } else if(lua_isnil(L, -1)) { f.liquid_move_physics = f.liquid_type != LIQUID_NONE; } else { + // TODO: should be an error errorstream << "Field \"liquid_move_physics\": Invalid type!" << std::endl; } lua_pop(L, 1); @@ -1805,10 +1829,8 @@ WearBarParams read_wear_bar_params( auto blend = WearBarParams::BLEND_MODE_CONSTANT; lua_getfield(L, stack_idx, "blend"); if (check_field_or_nil(L, -1, LUA_TSTRING, "blend")) { - int blendInt; - if (!string_to_enum(WearBarParams::es_BlendMode, blendInt, std::string(lua_tostring(L, -1)))) + if (!string_to_enum(WearBarParams::es_BlendMode, blend, lua_tostring(L, -1))) throw LuaError("Invalid wear bar color blend mode"); - blend = static_cast(blendInt); } lua_pop(L, 1); @@ -2395,14 +2417,9 @@ void push_hud_element(lua_State *L, HudElement *elem) bool read_hud_change(lua_State *L, HudElementStat &stat, HudElement *elem, void **value) { std::string statstr = lua_tostring(L, 3); - { - int statint; - if (!string_to_enum(es_HudElementStat, statint, statstr)) { - script_log_unique(L, "Unknown HUD stat type: " + statstr, warningstream); - return false; - } - - stat = static_cast(statint); + if (!string_to_enum(es_HudElementStat, stat, statstr)) { + script_log_unique(L, "Unknown HUD stat type: " + statstr, warningstream); + return false; } switch (stat) { diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h index bf4dc6af5..2c7133df1 100644 --- a/src/script/cpp_api/s_node.h +++ b/src/script/cpp_api/s_node.h @@ -38,7 +38,6 @@ 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[]; };