From 7f25823bd4f1a822449eb783ee555651a89ce9de Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 21 Jan 2021 00:51:24 +0100 Subject: Allow "liquid" and "flowingliquid" drawtypes even if liquidtype=none (#10737) --- games/devtest/mods/testnodes/drawtypes.lua | 107 ++++++++++++++-------------- games/devtest/mods/testnodes/liquids.lua | 8 --- games/devtest/mods/testnodes/properties.lua | 2 - 3 files changed, 54 insertions(+), 63 deletions(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index b3ab2b322..d71c3a121 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -350,68 +350,72 @@ minetest.register_node("testnodes:plantlike_rooted_degrotate", { }) -- Demonstrative liquid nodes, source and flowing form. -minetest.register_node("testnodes:liquid", { - description = S("Source Liquid Drawtype Test Node"), - drawtype = "liquid", - paramtype = "light", - tiles = { - "testnodes_liquidsource.png", - }, - special_tiles = { - {name="testnodes_liquidsource.png", backface_culling=false}, - {name="testnodes_liquidsource.png", backface_culling=true}, - }, - use_texture_alpha = true, - - - walkable = false, - liquidtype = "source", - liquid_range = 1, - liquid_viscosity = 0, - liquid_alternative_flowing = "testnodes:liquid_flowing", - liquid_alternative_source = "testnodes:liquid", - groups = { dig_immediate = 3 }, -}) -minetest.register_node("testnodes:liquid_flowing", { - description = S("Flowing Liquid Drawtype Test Node"), - drawtype = "flowingliquid", - paramtype = "light", - paramtype2 = "flowingliquid", - tiles = { - "testnodes_liquidflowing.png", - }, - special_tiles = { - {name="testnodes_liquidflowing.png", backface_culling=false}, - {name="testnodes_liquidflowing.png", backface_culling=false}, - }, - use_texture_alpha = true, +-- DRAWTYPE ONLY, NO LIQUID PHYSICS! +-- Liquid ranges 0 to 8 +for r = 0, 8 do + minetest.register_node("testnodes:liquid_"..r, { + description = S("Source Liquid Drawtype Test Node, Range @1", r), + drawtype = "liquid", + paramtype = "light", + tiles = { + "testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", + }, + special_tiles = { + {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false}, + {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=true}, + }, + use_texture_alpha = true, + + + walkable = false, + liquid_range = r, + liquid_viscosity = 0, + liquid_alternative_flowing = "testnodes:liquid_flowing_"..r, + liquid_alternative_source = "testnodes:liquid_"..r, + groups = { dig_immediate = 3 }, + }) + minetest.register_node("testnodes:liquid_flowing_"..r, { + description = S("Flowing Liquid Drawtype Test Node, Range @1", r), + drawtype = "flowingliquid", + paramtype = "light", + paramtype2 = "flowingliquid", + tiles = { + "testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", + }, + special_tiles = { + {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false}, + {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false}, + }, + use_texture_alpha = true, + + + walkable = false, + liquid_range = r, + liquid_viscosity = 0, + liquid_alternative_flowing = "testnodes:liquid_flowing_"..r, + liquid_alternative_source = "testnodes:liquid_"..r, + groups = { dig_immediate = 3 }, + }) +end - walkable = false, - liquidtype = "flowing", - liquid_range = 1, - liquid_viscosity = 0, - liquid_alternative_flowing = "testnodes:liquid_flowing", - liquid_alternative_source = "testnodes:liquid", - groups = { dig_immediate = 3 }, -}) +-- Waving liquid test (drawtype only) minetest.register_node("testnodes:liquid_waving", { description = S("Waving Source Liquid Drawtype Test Node"), drawtype = "liquid", paramtype = "light", tiles = { - "testnodes_liquidsource.png^[brighten", + "testnodes_liquidsource.png^[colorize:#0000FF:127", }, special_tiles = { - {name="testnodes_liquidsource.png^[brighten", backface_culling=false}, - {name="testnodes_liquidsource.png^[brighten", backface_culling=true}, + {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=false}, + {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=true}, }, use_texture_alpha = true, waving = 3, walkable = false, - liquidtype = "source", liquid_range = 1, liquid_viscosity = 0, liquid_alternative_flowing = "testnodes:liquid_flowing_waving", @@ -424,18 +428,17 @@ minetest.register_node("testnodes:liquid_flowing_waving", { paramtype = "light", paramtype2 = "flowingliquid", tiles = { - "testnodes_liquidflowing.png^[brighten", + "testnodes_liquidflowing.png^[colorize:#0000FF:127", }, special_tiles = { - {name="testnodes_liquidflowing.png^[brighten", backface_culling=false}, - {name="testnodes_liquidflowing.png^[brighten", backface_culling=false}, + {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false}, + {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false}, }, use_texture_alpha = true, waving = 3, walkable = false, - liquidtype = "flowing", liquid_range = 1, liquid_viscosity = 0, liquid_alternative_flowing = "testnodes:liquid_flowing_waving", @@ -443,8 +446,6 @@ minetest.register_node("testnodes:liquid_flowing_waving", { groups = { dig_immediate = 3 }, }) - - -- Invisible node minetest.register_node("testnodes:airlike", { description = S("Airlike Drawtype Test Node"), diff --git a/games/devtest/mods/testnodes/liquids.lua b/games/devtest/mods/testnodes/liquids.lua index e316782ad..abef9e0b7 100644 --- a/games/devtest/mods/testnodes/liquids.lua +++ b/games/devtest/mods/testnodes/liquids.lua @@ -12,8 +12,6 @@ for d=0, 8 do alpha = 192, paramtype = "light", walkable = false, - pointable = false, - diggable = false, buildable_to = true, is_ground_content = false, liquidtype = "source", @@ -34,8 +32,6 @@ for d=0, 8 do paramtype = "light", paramtype2 = "flowingliquid", walkable = false, - pointable = false, - diggable = false, buildable_to = true, is_ground_content = false, liquidtype = "flowing", @@ -56,8 +52,6 @@ for d=0, 8 do alpha = 192, paramtype = "light", walkable = false, - pointable = false, - diggable = false, buildable_to = true, is_ground_content = false, liquidtype = "source", @@ -78,8 +72,6 @@ for d=0, 8 do paramtype = "light", paramtype2 = "flowingliquid", walkable = false, - pointable = false, - diggable = false, buildable_to = true, is_ground_content = false, liquidtype = "flowing", diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua index 01846a5f0..c6331a6ed 100644 --- a/games/devtest/mods/testnodes/properties.lua +++ b/games/devtest/mods/testnodes/properties.lua @@ -118,7 +118,6 @@ minetest.register_node("testnodes:liquid_nojump", { paramtype = "light", pointable = false, liquids_pointable = true, - diggable = false, buildable_to = true, is_ground_content = false, post_effect_color = {a = 70, r = 255, g = 0, b = 200}, @@ -148,7 +147,6 @@ minetest.register_node("testnodes:liquidflowing_nojump", { paramtype2 = "flowingliquid", pointable = false, liquids_pointable = true, - diggable = false, buildable_to = true, is_ground_content = false, post_effect_color = {a = 70, r = 255, g = 0, b = 200}, -- cgit v1.2.3 From 009e39e73b9aa003c369fe6bc88f366fdc91610e Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Sat, 23 Jan 2021 12:46:19 -0800 Subject: FormSpec: Add list spacing, slot size, and noclip (#10083) * Add list spacing, slot size, and noclip * Simplify StyleSpec * Add test cases Co-authored-by: rubenwardy --- doc/lua_api.txt | 8 ++++- games/devtest/mods/testformspec/formspec.lua | 15 ++++++++- src/gui/StyleSpec.h | 47 +++++++++++++++++++--------- src/gui/guiFormSpecMenu.cpp | 30 +++++++++++++++--- 4 files changed, 78 insertions(+), 22 deletions(-) (limited to 'games/devtest/mods') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 317bbe577..f751eb512 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2226,7 +2226,8 @@ Elements * Show an inventory list if it has been sent to the client. Nothing will be shown if the inventory list is of size 0. * **Note**: With the new coordinate system, the spacing between inventory - slots is one-fourth the size of an inventory slot. + slots is one-fourth the size of an inventory slot by default. Also see + [Styling Formspecs] for changing the size of slots and spacing. ### `list[;;,;,;]` @@ -2809,6 +2810,7 @@ Some types may inherit styles from parent types. * image_button * item_image_button * label +* list * model * pwdfield, inherits from field * scrollbar @@ -2896,6 +2898,10 @@ Some types may inherit styles from parent types. * font - Sets font type. See button `font` property for more information. * font_size - Sets font size. See button `font_size` property for more information. * noclip - boolean, set to true to allow the element to exceed formspec bounds. +* list + * noclip - boolean, set to true to allow the element to exceed formspec bounds. + * size - 2d vector, sets the size of inventory slots in coordinates. + * spacing - 2d vector, sets the space between inventory slots in coordinates. * image_button (additional properties) * fgimg - standard image. Defaults to none. * fgimg_hovered - image when hovered. Defaults to fgimg when not provided. diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua index 5495896ce..0eef859a9 100644 --- a/games/devtest/mods/testformspec/formspec.lua +++ b/games/devtest/mods/testformspec/formspec.lua @@ -33,6 +33,15 @@ local tabheaders_fs = [[ tabheader[8,6;10,1.5;tabs_size2;Height=1.5;1;false;false] ]] +local inv_style_fs = [[ + style_type[list;noclip=true] + list[current_player;main;-1.125,-1.125;2,2] + style_type[list;spacing=.25,.125;size=.75,.875] + list[current_player;main;3,.5;3,3] + style_type[list;spacing=0;size=1] + list[current_player;main;.5,4;8,4] +]] + local hypertext_basic = [[ Normal test This is a normal text. @@ -310,6 +319,10 @@ local pages = { "size[12,13]real_coordinates[true]" .. "container[0.5,1.5]" .. tabheaders_fs .. "container_end[]", + -- Inv + "size[12,13]real_coordinates[true]" .. + "container[0.5,1.5]" .. inv_style_fs .. "container_end[]", + -- Animation [[ formspec_version[3] @@ -341,7 +354,7 @@ Number] local function show_test_formspec(pname, page_id) page_id = page_id or 2 - local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Anim,ScrollC;" .. page_id .. ";false;false]" + local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Anim,ScrollC;" .. page_id .. ";false;false]" minetest.show_formspec(pname, "testformspec:formspec", fs) end diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h index f2844ce28..fc92a861b 100644 --- a/src/gui/StyleSpec.h +++ b/src/gui/StyleSpec.h @@ -55,6 +55,8 @@ public: BORDERCOLORS, BORDERWIDTHS, SOUND, + SPACING, + SIZE, NUM_PROPERTIES, NONE }; @@ -119,6 +121,10 @@ public: return BORDERWIDTHS; } else if (name == "sound") { return SOUND; + } else if (name == "spacing") { + return SPACING; + } else if (name == "size") { + return SIZE; } else { return NONE; } @@ -259,27 +265,40 @@ public: return rect; } - irr::core::vector2d getVector2i(Property prop, irr::core::vector2d def) const + v2f32 getVector2f(Property prop, v2f32 def) const { const auto &val = properties[prop]; if (val.empty()) return def; - irr::core::vector2d vec; - if (!parseVector2i(val, &vec)) + v2f32 vec; + if (!parseVector2f(val, &vec)) return def; return vec; } - irr::core::vector2d getVector2i(Property prop) const + v2s32 getVector2i(Property prop, v2s32 def) const + { + const auto &val = properties[prop]; + if (val.empty()) + return def; + + v2f32 vec; + if (!parseVector2f(val, &vec)) + return def; + + return v2s32(vec.X, vec.Y); + } + + v2s32 getVector2i(Property prop) const { const auto &val = properties[prop]; FATAL_ERROR_IF(val.empty(), "Unexpected missing property"); - irr::core::vector2d vec; - parseVector2i(val, &vec); - return vec; + v2f32 vec; + parseVector2f(val, &vec); + return v2s32(vec.X, vec.Y); } gui::IGUIFont *getFont() const @@ -432,22 +451,20 @@ private: return true; } - bool parseVector2i(const std::string &value, irr::core::vector2d *parsed_vec) const + bool parseVector2f(const std::string &value, v2f32 *parsed_vec) const { - irr::core::vector2d vec; + v2f32 vec; std::vector v_vector = split(value, ','); if (v_vector.size() == 1) { - s32 x = stoi(v_vector[0]); + f32 x = stof(v_vector[0]); vec.X = x; vec.Y = x; } else if (v_vector.size() == 2) { - s32 x = stoi(v_vector[0]); - s32 y = stoi(v_vector[1]); - vec.X = x; - vec.Y = y; + vec.X = stof(v_vector[0]); + vec.Y = stof(v_vector[1]); } else { - warningstream << "Invalid vector2d string format: \"" << value + warningstream << "Invalid 2d vector string format: \"" << value << "\"" << std::endl; return false; } diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 4415bdd3a..7b37de6f8 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -497,20 +497,40 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) 3 ); - v2f32 slot_spacing = data->real_coordinates ? - v2f32(imgsize.X * 1.25f, imgsize.Y * 1.25f) : spacing; + auto style = getDefaultStyleForElement("list", spec.fname); - v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) - : getElementBasePos(&v_pos); + v2f32 slot_scale = style.getVector2f(StyleSpec::SIZE, v2f32(0, 0)); + v2s32 slot_size( + slot_scale.X <= 0 ? imgsize.X : slot_scale.X * imgsize.X, + slot_scale.Y <= 0 ? imgsize.Y : slot_scale.Y * imgsize.Y + ); + + v2f32 slot_spacing = style.getVector2f(StyleSpec::SPACING, v2f32(-1, -1)); + if (data->real_coordinates) { + slot_spacing.X = slot_spacing.X < 0 ? imgsize.X * 1.25f : + slot_spacing.X * imgsize.X + imgsize.X; + slot_spacing.Y = slot_spacing.Y < 0 ? imgsize.Y * 1.25f : + slot_spacing.Y * imgsize.Y + imgsize.Y; + } else { + slot_spacing.X = slot_spacing.X < 0 ? spacing.X : + slot_spacing.X * spacing.X; + slot_spacing.Y = slot_spacing.Y < 0 ? spacing.Y : + slot_spacing.Y * spacing.Y; + } + + v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) : + getElementBasePos(&v_pos); core::rect rect = core::rect(pos.X, pos.Y, pos.X + (geom.X - 1) * slot_spacing.X + imgsize.X, pos.Y + (geom.Y - 1) * slot_spacing.Y + imgsize.Y); GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent, - spec.fid, rect, m_invmgr, loc, listname, geom, start_i, imgsize, + spec.fid, rect, m_invmgr, loc, listname, geom, start_i, slot_size, slot_spacing, this, data->inventorylist_options, m_font); + e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); + m_inventorylists.push_back(e); m_fields.push_back(spec); return; -- cgit v1.2.3 From 6a55c03dabf7b5337233fc80078a300d485fcec4 Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Sat, 23 Jan 2021 14:48:57 -0800 Subject: Make hypertext and textarea have proper scroll event propagation. (#10860) --- games/devtest/mods/testformspec/formspec.lua | 2 ++ src/gui/guiEditBox.cpp | 1 + src/gui/guiHyperText.cpp | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua index 0eef859a9..62578b740 100644 --- a/games/devtest/mods/testformspec/formspec.lua +++ b/games/devtest/mods/testformspec/formspec.lua @@ -220,6 +220,8 @@ local scroll_fs = "tooltip[0,11;3,2;Buz;#f00;#000]".. "box[0,11;3,2;#00ff00]".. "hypertext[3,13;3,3;;" .. hypertext_basic .. "]" .. + "hypertext[3,17;3,3;;Hypertext with no scrollbar\\; the scroll container should scroll.]" .. + "textarea[3,21;3,1;textarea;;More scroll within scroll]" .. "container[0,18]".. "box[1,2;3,2;#0a0a]".. "scroll_container[1,2;3,2;scrbar2;horizontal;0.06]".. diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp index 1214125a8..79979dbc3 100644 --- a/src/gui/guiEditBox.cpp +++ b/src/gui/guiEditBox.cpp @@ -787,6 +787,7 @@ bool GUIEditBox::processMouse(const SEvent &event) s32 pos = m_vscrollbar->getPos(); s32 step = m_vscrollbar->getSmallStep(); m_vscrollbar->setPos(pos - event.MouseInput.Wheel * step); + return true; } break; default: diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 88931cdf9..ccfdcb81d 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -1088,7 +1088,7 @@ bool GUIHyperText::OnEvent(const SEvent &event) if (event.MouseInput.Event == EMIE_MOUSE_MOVED) checkHover(event.MouseInput.X, event.MouseInput.Y); - if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { + if (event.MouseInput.Event == EMIE_MOUSE_WHEEL && m_vscrollbar->isVisible()) { m_vscrollbar->setPos(m_vscrollbar->getPos() - event.MouseInput.Wheel * m_vscrollbar->getSmallStep()); m_text_scrollpos.Y = -m_vscrollbar->getPos(); -- cgit v1.2.3 From edd8c3c664ad005eb32e1968ce80091851ffb817 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 16 Jan 2021 22:16:04 +0100 Subject: Drop never documented 'alpha' property from nodedef Includes minimal support code for practical reasons. We'll need it for a slightly different purpose next commit. --- builtin/game/item.lua | 1 - games/devtest/mods/testnodes/textures.lua | 15 ++++----------- src/nodedef.cpp | 20 -------------------- src/nodedef.h | 9 --------- src/script/common/c_content.cpp | 5 ++++- 5 files changed, 8 insertions(+), 42 deletions(-) (limited to 'games/devtest/mods') diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 0df25b455..63f8d50e5 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -715,7 +715,6 @@ core.nodedef_default = { -- {name="", backface_culling=true}, -- {name="", backface_culling=true}, --}, - alpha = 255, post_effect_color = {a=0, r=0, g=0, b=0}, paramtype = "none", paramtype2 = "none", diff --git a/games/devtest/mods/testnodes/textures.lua b/games/devtest/mods/testnodes/textures.lua index e0724c229..af3b7f468 100644 --- a/games/devtest/mods/testnodes/textures.lua +++ b/games/devtest/mods/testnodes/textures.lua @@ -51,23 +51,16 @@ for a=1,#alphas do groups = { dig_immediate = 3 }, }) - -- Transparency set via "alpha" parameter + -- Transparency set via texture modifier minetest.register_node("testnodes:alpha_"..alpha, { description = S("Alpha Test Node (@1)", alpha), - -- It seems that only the liquid drawtype supports the alpha parameter - drawtype = "liquid", + drawtype = "glasslike", paramtype = "light", tiles = { - "testnodes_alpha.png", + "testnodes_alpha.png^[opacity:" .. alpha, }, - alpha = alpha, - + use_texture_alpha = true, - liquidtype = "source", - liquid_range = 0, - liquid_viscosity = 0, - liquid_alternative_source = "testnodes:alpha_"..alpha, - liquid_alternative_flowing = "testnodes:alpha_"..alpha, groups = { dig_immediate = 3 }, }) end diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 1740b010a..b2cfd1f87 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -491,21 +491,6 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const writeU8(os, leveled_max); } -void ContentFeatures::correctAlpha(TileDef *tiles, int length) -{ - // alpha == 0 means that the node is using texture alpha - if (alpha == 0 || alpha == 255) - return; - - for (int i = 0; i < length; i++) { - if (tiles[i].name.empty()) - continue; - std::stringstream s; - s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha); - tiles[i].name = s.str(); - } -} - void ContentFeatures::deSerialize(std::istream &is) { // version detection @@ -874,11 +859,6 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc } if (is_liquid) { - // Vertex alpha is no longer supported, correct if necessary. - correctAlpha(tdef, 6); - correctAlpha(tdef_overlay, 6); - correctAlpha(tdef_spec, CF_SPECIAL_COUNT); - if (waving == 3) { material_type = (alpha == 255) ? TILE_MATERIAL_WAVING_LIQUID_OPAQUE : TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT; diff --git a/src/nodedef.h b/src/nodedef.h index 66c21cc07..63b9474b9 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -418,15 +418,6 @@ struct ContentFeatures void serialize(std::ostream &os, u16 protocol_version) const; void deSerialize(std::istream &is); - /*! - * Since vertex alpha is no longer supported, this method - * adds opacity directly to the texture pixels. - * - * \param tiles array of the tile definitions. - * \param length length of tiles - */ - void correctAlpha(TileDef *tiles, int length); - #ifndef SERVER /* * Checks if any tile texture has any transparent pixels. diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 4316f412d..5d29422af 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -618,7 +618,10 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) } lua_pop(L, 1); - f.alpha = getintfield_default(L, index, "alpha", 255); + warn_if_field_exists(L, index, "alpha", + "Obsolete, only limited compatibility provided"); + if (getintfield_default(L, index, "alpha", 255) != 255) + f.alpha = 0; bool usealpha = getboolfield_default(L, index, "use_texture_alpha", false); -- cgit v1.2.3 From 5c005ad081a23a1c048ef2c1066f60e0e041c956 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 17 Jan 2021 02:25:33 +0100 Subject: devtest: Fix deprecated alpha usage --- games/devtest/mods/basenodes/init.lua | 36 ++++++++++++++++------------- games/devtest/mods/soundstuff/init.lua | 11 +++++---- games/devtest/mods/testnodes/drawtypes.lua | 8 +++---- games/devtest/mods/testnodes/liquids.lua | 8 +++---- games/devtest/mods/testnodes/properties.lua | 4 ++-- games/devtest/mods/testnodes/textures.lua | 4 ++-- 6 files changed, 38 insertions(+), 33 deletions(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/basenodes/init.lua b/games/devtest/mods/basenodes/init.lua index 0cb85d808..2c808c35e 100644 --- a/games/devtest/mods/basenodes/init.lua +++ b/games/devtest/mods/basenodes/init.lua @@ -1,4 +1,4 @@ -local WATER_ALPHA = 160 +local WATER_ALPHA = "^[opacity:" .. 160 local WATER_VISC = 1 local LAVA_VISC = 7 @@ -128,12 +128,12 @@ minetest.register_node("basenodes:water_source", { "Drowning damage: 1", drawtype = "liquid", waving = 3, - tiles = {"default_water.png"}, + tiles = {"default_water.png"..WATER_ALPHA}, special_tiles = { - {name = "default_water.png", backface_culling = false}, - {name = "default_water.png", backface_culling = true}, + {name = "default_water.png"..WATER_ALPHA, backface_culling = false}, + {name = "default_water.png"..WATER_ALPHA, backface_culling = true}, }, - alpha = WATER_ALPHA, + use_texture_alpha = "blend", paramtype = "light", walkable = false, pointable = false, @@ -156,10 +156,12 @@ minetest.register_node("basenodes:water_flowing", { waving = 3, tiles = {"default_water_flowing.png"}, special_tiles = { - {name = "default_water_flowing.png", backface_culling = false}, - {name = "default_water_flowing.png", backface_culling = false}, + {name = "default_water_flowing.png"..WATER_ALPHA, + backface_culling = false}, + {name = "default_water_flowing.png"..WATER_ALPHA, + backface_culling = false}, }, - alpha = WATER_ALPHA, + use_texture_alpha = "blend", paramtype = "light", paramtype2 = "flowingliquid", walkable = false, @@ -181,12 +183,12 @@ minetest.register_node("basenodes:river_water_source", { "Drowning damage: 1", drawtype = "liquid", waving = 3, - tiles = { "default_river_water.png" }, + tiles = { "default_river_water.png"..WATER_ALPHA }, special_tiles = { - {name = "default_river_water.png", backface_culling = false}, - {name = "default_river_water.png", backface_culling = true}, + {name = "default_river_water.png"..WATER_ALPHA, backface_culling = false}, + {name = "default_river_water.png"..WATER_ALPHA, backface_culling = true}, }, - alpha = WATER_ALPHA, + use_texture_alpha = "blend", paramtype = "light", walkable = false, pointable = false, @@ -209,12 +211,14 @@ minetest.register_node("basenodes:river_water_flowing", { "Drowning damage: 1", drawtype = "flowingliquid", waving = 3, - tiles = {"default_river_water_flowing.png"}, + tiles = {"default_river_water_flowing.png"..WATER_ALPHA}, special_tiles = { - {name = "default_river_water_flowing.png", backface_culling = false}, - {name = "default_river_water_flowing.png", backface_culling = false}, + {name = "default_river_water_flowing.png"..WATER_ALPHA, + backface_culling = false}, + {name = "default_river_water_flowing.png"..WATER_ALPHA, + backface_culling = false}, }, - alpha = WATER_ALPHA, + use_texture_alpha = "blend", paramtype = "light", paramtype2 = "flowingliquid", walkable = false, diff --git a/games/devtest/mods/soundstuff/init.lua b/games/devtest/mods/soundstuff/init.lua index 40ad8f562..b263a3f35 100644 --- a/games/devtest/mods/soundstuff/init.lua +++ b/games/devtest/mods/soundstuff/init.lua @@ -60,11 +60,13 @@ minetest.register_node("soundstuff:footstep_liquid", { description = "Liquid Footstep Sound Node", drawtype = "liquid", tiles = { - "soundstuff_node_sound.png^[colorize:#0000FF:127", + "soundstuff_node_sound.png^[colorize:#0000FF:127^[opacity:190", }, special_tiles = { - {name = "soundstuff_node_sound.png^[colorize:#0000FF:127", backface_culling = false}, - {name = "soundstuff_node_sound.png^[colorize:#0000FF:127", backface_culling = true}, + {name = "soundstuff_node_sound.png^[colorize:#0000FF:127^[opacity:190", + backface_culling = false}, + {name = "soundstuff_node_sound.png^[colorize:#0000FF:127^[opacity:190", + backface_culling = true}, }, liquids_pointable = true, liquidtype = "source", @@ -73,7 +75,7 @@ minetest.register_node("soundstuff:footstep_liquid", { liquid_renewable = false, liquid_range = 0, liquid_viscosity = 0, - alpha = 190, + use_texture_alpha = "blend", paramtype = "light", walkable = false, pointable = false, @@ -92,7 +94,6 @@ minetest.register_node("soundstuff:footstep_climbable", { tiles = { "soundstuff_node_climbable.png", }, - alpha = 120, paramtype = "light", sunlight_propagates = true, walkable = false, diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index d71c3a121..ff970144d 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -364,7 +364,7 @@ for r = 0, 8 do {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false}, {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=true}, }, - use_texture_alpha = true, + use_texture_alpha = "blend", walkable = false, @@ -386,7 +386,7 @@ for r = 0, 8 do {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false}, {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false}, }, - use_texture_alpha = true, + use_texture_alpha = "blend", walkable = false, @@ -411,7 +411,7 @@ minetest.register_node("testnodes:liquid_waving", { {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=false}, {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=true}, }, - use_texture_alpha = true, + use_texture_alpha = "blend", waving = 3, @@ -434,7 +434,7 @@ minetest.register_node("testnodes:liquid_flowing_waving", { {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false}, {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false}, }, - use_texture_alpha = true, + use_texture_alpha = "blend", waving = 3, diff --git a/games/devtest/mods/testnodes/liquids.lua b/games/devtest/mods/testnodes/liquids.lua index abef9e0b7..3d2ea17f5 100644 --- a/games/devtest/mods/testnodes/liquids.lua +++ b/games/devtest/mods/testnodes/liquids.lua @@ -9,7 +9,7 @@ for d=0, 8 do {name = "testnodes_liquidsource_r"..d..".png", backface_culling = false}, {name = "testnodes_liquidsource_r"..d..".png", backface_culling = true}, }, - alpha = 192, + use_texture_alpha = "blend", paramtype = "light", walkable = false, buildable_to = true, @@ -28,7 +28,7 @@ for d=0, 8 do {name = "testnodes_liquidflowing_r"..d..".png", backface_culling = false}, {name = "testnodes_liquidflowing_r"..d..".png", backface_culling = false}, }, - alpha = 192, + use_texture_alpha = "blend", paramtype = "light", paramtype2 = "flowingliquid", walkable = false, @@ -49,7 +49,7 @@ for d=0, 8 do {name = "testnodes_liquidsource_r"..d..".png"..mod, backface_culling = false}, {name = "testnodes_liquidsource_r"..d..".png"..mod, backface_culling = true}, }, - alpha = 192, + use_texture_alpha = "blend", paramtype = "light", walkable = false, buildable_to = true, @@ -68,7 +68,7 @@ for d=0, 8 do {name = "testnodes_liquidflowing_r"..d..".png"..mod, backface_culling = false}, {name = "testnodes_liquidflowing_r"..d..".png"..mod, backface_culling = false}, }, - alpha = 192, + use_texture_alpha = "blend", paramtype = "light", paramtype2 = "flowingliquid", walkable = false, diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua index c6331a6ed..a52cd1d6f 100644 --- a/games/devtest/mods/testnodes/properties.lua +++ b/games/devtest/mods/testnodes/properties.lua @@ -114,7 +114,7 @@ minetest.register_node("testnodes:liquid_nojump", { {name = "testnodes_liquidsource.png^[colorize:#FF0000:127", backface_culling = false}, {name = "testnodes_liquidsource.png^[colorize:#FF0000:127", backface_culling = true}, }, - use_texture_alpha = true, + use_texture_alpha = "blend", paramtype = "light", pointable = false, liquids_pointable = true, @@ -142,7 +142,7 @@ minetest.register_node("testnodes:liquidflowing_nojump", { {name = "testnodes_liquidflowing.png^[colorize:#FF0000:127", backface_culling = false}, {name = "testnodes_liquidflowing.png^[colorize:#FF0000:127", backface_culling = false}, }, - use_texture_alpha = true, + use_texture_alpha = "blend", paramtype = "light", paramtype2 = "flowingliquid", pointable = false, diff --git a/games/devtest/mods/testnodes/textures.lua b/games/devtest/mods/testnodes/textures.lua index af3b7f468..a508b6a4d 100644 --- a/games/devtest/mods/testnodes/textures.lua +++ b/games/devtest/mods/testnodes/textures.lua @@ -46,7 +46,7 @@ for a=1,#alphas do tiles = { "testnodes_alpha"..alpha..".png", }, - use_texture_alpha = true, + use_texture_alpha = "blend", groups = { dig_immediate = 3 }, }) @@ -59,7 +59,7 @@ for a=1,#alphas do tiles = { "testnodes_alpha.png^[opacity:" .. alpha, }, - use_texture_alpha = true, + use_texture_alpha = "blend", groups = { dig_immediate = 3 }, }) -- cgit v1.2.3 From f227e40180b2035f33059749b14287478bab374a Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Tue, 2 Feb 2021 11:55:13 -0800 Subject: Fix list spacing and size (again) (#10869) --- games/devtest/mods/testformspec/formspec.lua | 30 +++++++++++++++++----- src/gui/guiFormSpecMenu.cpp | 38 +++++++++++++--------------- src/gui/guiInventoryList.cpp | 2 -- 3 files changed, 42 insertions(+), 28 deletions(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua index 62578b740..bb178e1b3 100644 --- a/games/devtest/mods/testformspec/formspec.lua +++ b/games/devtest/mods/testformspec/formspec.lua @@ -35,11 +35,30 @@ local tabheaders_fs = [[ local inv_style_fs = [[ style_type[list;noclip=true] - list[current_player;main;-1.125,-1.125;2,2] + list[current_player;main;-0.75,0.75;2,2] + + real_coordinates[false] + list[current_player;main;1.5,0;3,2] + real_coordinates[true] + + real_coordinates[false] + style_type[list;size=1.1;spacing=0.1] + list[current_player;main;5,0;3,2] + real_coordinates[true] + + style_type[list;size=.001;spacing=0] + list[current_player;main;7,3.5;8,4] + + box[3,3.5;1,1;#000000] + box[5,3.5;1,1;#000000] + box[4,4.5;1,1;#000000] + box[3,5.5;1,1;#000000] + box[5,5.5;1,1;#000000] style_type[list;spacing=.25,.125;size=.75,.875] - list[current_player;main;3,.5;3,3] - style_type[list;spacing=0;size=1] - list[current_player;main;.5,4;8,4] + list[current_player;main;3,3.5;3,3] + + style_type[list;spacing=0;size=1.1] + list[current_player;main;.5,7;8,4] ]] local hypertext_basic = [[ @@ -322,8 +341,7 @@ local pages = { "container[0.5,1.5]" .. tabheaders_fs .. "container_end[]", -- Inv - "size[12,13]real_coordinates[true]" .. - "container[0.5,1.5]" .. inv_style_fs .. "container_end[]", + "size[12,13]real_coordinates[true]" .. inv_style_fs, -- Animation [[ diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index e4678bcd1..88ea77812 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include +#include #include #include #include @@ -500,37 +501,34 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) auto style = getDefaultStyleForElement("list", spec.fname); v2f32 slot_scale = style.getVector2f(StyleSpec::SIZE, v2f32(0, 0)); - v2s32 slot_size( - slot_scale.X <= 0 ? imgsize.X : slot_scale.X * imgsize.X, - slot_scale.Y <= 0 ? imgsize.Y : slot_scale.Y * imgsize.Y + v2f32 slot_size( + slot_scale.X <= 0 ? imgsize.X : std::max(slot_scale.X * imgsize.X, 1), + slot_scale.Y <= 0 ? imgsize.Y : std::max(slot_scale.Y * imgsize.Y, 1) ); v2f32 slot_spacing = style.getVector2f(StyleSpec::SPACING, v2f32(-1, -1)); - if (data->real_coordinates) { - slot_spacing.X = slot_spacing.X < 0 ? imgsize.X * 0.25f : - imgsize.X * slot_spacing.X; - slot_spacing.Y = slot_spacing.Y < 0 ? imgsize.Y * 0.25f : - imgsize.Y * slot_spacing.Y; + v2f32 default_spacing = data->real_coordinates ? + v2f32(imgsize.X * 0.25f, imgsize.Y * 0.25f) : + v2f32(spacing.X - imgsize.X, spacing.Y - imgsize.Y); - slot_spacing.X += slot_size.X; - slot_spacing.Y += slot_size.Y; - } else { - slot_spacing.X = slot_spacing.X < 0 ? spacing.X : - slot_spacing.X * spacing.X; - slot_spacing.Y = slot_spacing.Y < 0 ? spacing.Y : - slot_spacing.Y * spacing.Y; - } + slot_spacing.X = slot_spacing.X < 0 ? default_spacing.X : + imgsize.X * slot_spacing.X; + slot_spacing.Y = slot_spacing.Y < 0 ? default_spacing.Y : + imgsize.Y * slot_spacing.Y; + + slot_spacing += slot_size; v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) : getElementBasePos(&v_pos); core::rect rect = core::rect(pos.X, pos.Y, - pos.X + (geom.X - 1) * slot_spacing.X + imgsize.X, - pos.Y + (geom.Y - 1) * slot_spacing.Y + imgsize.Y); + pos.X + (geom.X - 1) * slot_spacing.X + slot_size.X, + pos.Y + (geom.Y - 1) * slot_spacing.Y + slot_size.Y); GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent, - spec.fid, rect, m_invmgr, loc, listname, geom, start_i, slot_size, - slot_spacing, this, data->inventorylist_options, m_font); + spec.fid, rect, m_invmgr, loc, listname, geom, start_i, + v2s32(slot_size.X, slot_size.Y), slot_spacing, this, + data->inventorylist_options, m_font); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index dfdb60448..183d72165 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -104,8 +104,6 @@ void GUIInventoryList::draw() && m_invmgr->getInventory(selected_item->inventoryloc) == inv && selected_item->listname == m_listname && selected_item->i == item_i; - core::rect clipped_rect(rect); - clipped_rect.clipAgainst(AbsoluteClippingRect); bool hovering = m_hovered_i == item_i; ItemRotationKind rotation_kind = selected ? IT_ROT_SELECTED : (hovering ? IT_ROT_HOVERED : IT_ROT_NONE); -- cgit v1.2.3 From 9b64834c6a2ae6eb254e486c87864e6116cfafa1 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 4 Feb 2021 20:43:29 +0000 Subject: Devtest: Remove bumpmap/parallax occl. test nodes (#10902) --- games/devtest/mods/testnodes/textures.lua | 48 --------------------- .../textures/testnodes_height_pyramid.png | Bin 90 -> 0 bytes .../textures/testnodes_height_pyramid_normal.png | Bin 239 -> 0 bytes .../textures/testnodes_parallax_extruded.png | Bin 591 -> 0 bytes .../testnodes_parallax_extruded_normal.png | Bin 143 -> 0 bytes 5 files changed, 48 deletions(-) delete mode 100644 games/devtest/mods/testnodes/textures/testnodes_height_pyramid.png delete mode 100644 games/devtest/mods/testnodes/textures/testnodes_height_pyramid_normal.png delete mode 100644 games/devtest/mods/testnodes/textures/testnodes_parallax_extruded.png delete mode 100644 games/devtest/mods/testnodes/textures/testnodes_parallax_extruded_normal.png (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testnodes/textures.lua b/games/devtest/mods/testnodes/textures.lua index a508b6a4d..f6e6a0c2a 100644 --- a/games/devtest/mods/testnodes/textures.lua +++ b/games/devtest/mods/testnodes/textures.lua @@ -65,51 +65,3 @@ for a=1,#alphas do }) end - --- Bumpmapping and Parallax Occlusion - --- This node has a normal map which corresponds to a pyramid with sides tilted --- by an angle of 45°, i.e. the normal map contains four vectors which point --- diagonally away from the surface (e.g. (0.7, 0.7, 0)), --- and the heights in the height map linearly increase towards the centre, --- so that the surface corresponds to a simple pyramid. --- The node can help to determine if e.g. tangent space transformations work --- correctly. --- If, for example, the light comes from above, then the (tilted) pyramids --- should look like they're lit from this light direction on all node faces. --- The white albedo texture has small black indicators which can be used to see --- how it is transformed ingame (and thus see if there's rotation around the --- normal vector). -minetest.register_node("testnodes:height_pyramid", { - description = "Bumpmapping and Parallax Occlusion Tester (height pyramid)", - tiles = {"testnodes_height_pyramid.png"}, - groups = {dig_immediate = 3}, -}) - --- The stairs nodes should help to validate if shading works correctly for --- rotated nodes (which have rotated textures). -stairs.register_stair_and_slab("height_pyramid", "experimantal:height_pyramid", - {dig_immediate = 3}, - {"testnodes_height_pyramid.png"}, - "Bumpmapping and Parallax Occlusion Tester Stair (height pyramid)", - "Bumpmapping and Parallax Occlusion Tester Slab (height pyramid)") - --- This node has a simple heightmap for parallax occlusion testing and flat --- normalmap. --- When parallax occlusion is enabled, the yellow scrawl should stick out of --- the texture when viewed at an angle. -minetest.register_node("testnodes:parallax_extruded", { - description = "Parallax Occlusion Tester", - tiles = {"testnodes_parallax_extruded.png"}, - groups = {dig_immediate = 3}, -}) - --- Analogously to the height pyramid stairs nodes, --- these nodes should help to validate if parallax occlusion works correctly for --- rotated nodes (which have rotated textures). -stairs.register_stair_and_slab("parallax_extruded", - "experimantal:parallax_extruded", - {dig_immediate = 3}, - {"testnodes_parallax_extruded.png"}, - "Parallax Occlusion Tester Stair", - "Parallax Occlusion Tester Slab") diff --git a/games/devtest/mods/testnodes/textures/testnodes_height_pyramid.png b/games/devtest/mods/testnodes/textures/testnodes_height_pyramid.png deleted file mode 100644 index 8c787b740..000000000 Binary files a/games/devtest/mods/testnodes/textures/testnodes_height_pyramid.png and /dev/null differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_height_pyramid_normal.png b/games/devtest/mods/testnodes/textures/testnodes_height_pyramid_normal.png deleted file mode 100644 index 5ab7865f2..000000000 Binary files a/games/devtest/mods/testnodes/textures/testnodes_height_pyramid_normal.png and /dev/null differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_parallax_extruded.png b/games/devtest/mods/testnodes/textures/testnodes_parallax_extruded.png deleted file mode 100644 index 7e1c32398..000000000 Binary files a/games/devtest/mods/testnodes/textures/testnodes_parallax_extruded.png and /dev/null differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_parallax_extruded_normal.png b/games/devtest/mods/testnodes/textures/testnodes_parallax_extruded_normal.png deleted file mode 100644 index b134699d0..000000000 Binary files a/games/devtest/mods/testnodes/textures/testnodes_parallax_extruded_normal.png and /dev/null differ -- cgit v1.2.3 From 6591597430c8a06c579e2631fcdbb022ae12160d Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Mon, 8 Feb 2021 00:04:38 +0000 Subject: Fix animation_image support in scroll containers --- games/devtest/mods/testformspec/formspec.lua | 1 + src/gui/guiFormSpecMenu.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua index bb178e1b3..2a2bdad60 100644 --- a/games/devtest/mods/testformspec/formspec.lua +++ b/games/devtest/mods/testformspec/formspec.lua @@ -227,6 +227,7 @@ local scroll_fs = "box[1,1;8,6;#00aa]".. "scroll_container[1,1;8,6;scrbar;vertical]".. "button[0,1;1,1;lorem;Lorem]".. + "animated_image[0,1;4.5,1;clip_animated_image;testformspec_animation.png;4;100]" .. "button[0,10;1,1;ipsum;Ipsum]".. "pwdfield[2,2;1,1;lorem2;Lorem]".. "list[current_player;main;4,4;1,5;]".. diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 88ea77812..5aa6dc9ae 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -928,7 +928,7 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el core::rect rect = core::rect(pos, pos + geom); - GUIAnimatedImage *e = new GUIAnimatedImage(Environment, this, spec.fid, + GUIAnimatedImage *e = new GUIAnimatedImage(Environment, data->current_parent, spec.fid, rect, texture_name, frame_count, frame_duration, m_tsrc); if (parts.size() >= 7) -- cgit v1.2.3 From a8f6befd398cb8f962f3bb1fab092d6355bfe015 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 17 Feb 2021 18:53:44 +0000 Subject: Fix short_description fallback order (#10943) --- builtin/game/register.lua | 4 ---- doc/lua_api.txt | 13 +++++++------ games/devtest/mods/unittests/itemdescription.lua | 11 +++++++++-- src/script/common/c_content.cpp | 6 ++++-- 4 files changed, 20 insertions(+), 14 deletions(-) (limited to 'games/devtest/mods') diff --git a/builtin/game/register.lua b/builtin/game/register.lua index b006957e9..1cff85813 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -118,10 +118,6 @@ function core.register_item(name, itemdef) end itemdef.name = name - -- default short_description to first line of description - itemdef.short_description = itemdef.short_description or - (itemdef.description or ""):gsub("\n.*","") - -- Apply defaults and add to registered_* table if itemdef.type == "node" then -- Use the nodebox as selection box if it's not set manually diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 7b7825614..a09b98924 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6039,18 +6039,18 @@ an itemstring, a table or `nil`. stack). * `set_metadata(metadata)`: (DEPRECATED) Returns true. * `get_description()`: returns the description shown in inventory list tooltips. - * The engine uses the same as this function for item descriptions. + * The engine uses this when showing item descriptions in tooltips. * Fields for finding the description, in order: * `description` in item metadata (See [Item Metadata].) * `description` in item definition * item name -* `get_short_description()`: returns the short description. +* `get_short_description()`: returns the short description or nil. * Unlike the description, this does not include new lines. - * The engine uses the same as this function for short item descriptions. * Fields for finding the short description, in order: * `short_description` in item metadata (See [Item Metadata].) * `short_description` in item definition - * first line of the description (See `get_description()`.) + * first line of the description (From item meta or def, see `get_description()`.) + * Returns nil if none of the above are set * `clear()`: removes all items from the stack, making it empty. * `replace(item)`: replace the contents of this stack. * `item` can also be an itemstring or table. @@ -7171,8 +7171,9 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and short_description = "Steel Axe", -- Must not contain new lines. - -- Defaults to the first line of description. - -- See also: `get_short_description` in [`ItemStack`] + -- Defaults to nil. + -- Use an [`ItemStack`] to get the short description, eg: + -- ItemStack(itemname):get_short_description() groups = {}, -- key = name, value = rating; rating = 1..3. diff --git a/games/devtest/mods/unittests/itemdescription.lua b/games/devtest/mods/unittests/itemdescription.lua index 1d0826545..d6ee6551a 100644 --- a/games/devtest/mods/unittests/itemdescription.lua +++ b/games/devtest/mods/unittests/itemdescription.lua @@ -26,15 +26,22 @@ minetest.register_chatcommand("item_description", { }) function unittests.test_short_desc() + local function get_short_description(item) + return ItemStack(item):get_short_description() + end + local stack = ItemStack("unittests:colorful_pick") assert(stack:get_short_description() == "Colorful Pickaxe") - assert(stack:get_short_description() == minetest.registered_items["unittests:colorful_pick"].short_description) + assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe") + assert(minetest.registered_items["unittests:colorful_pick"].short_description == nil) assert(stack:get_description() == full_description) assert(stack:get_description() == minetest.registered_items["unittests:colorful_pick"].description) stack:get_meta():set_string("description", "Hello World") - assert(stack:get_short_description() == "Colorful Pickaxe") + assert(stack:get_short_description() == "Hello World") assert(stack:get_description() == "Hello World") + assert(get_short_description(stack) == "Hello World") + assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe") stack:get_meta():set_string("short_description", "Foo Bar") assert(stack:get_short_description() == "Foo Bar") diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index ecab7baa1..2f9fbd74b 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -140,8 +140,10 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i) lua_setfield(L, -2, "name"); lua_pushstring(L, i.description.c_str()); lua_setfield(L, -2, "description"); - lua_pushstring(L, i.short_description.c_str()); - lua_setfield(L, -2, "short_description"); + if (!i.short_description.empty()) { + lua_pushstring(L, i.short_description.c_str()); + lua_setfield(L, -2, "short_description"); + } lua_pushstring(L, type.c_str()); lua_setfield(L, -2, "type"); lua_pushstring(L, i.inventory_image.c_str()); -- cgit v1.2.3 From f85e9ab9254e2ae4ac13170f9edea00fb8d931a2 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 17 Feb 2021 19:51:28 +0000 Subject: Add nametag background setting and object property (#10937) --- .clang-format | 1 + builtin/settingtypes.txt | 4 ++ doc/lua_api.txt | 18 +++++-- games/devtest/mods/testentities/visuals.lua | 16 +++++- src/activeobjectmgr.h | 3 +- src/client/camera.cpp | 33 +++++-------- src/client/camera.h | 47 +++++++++++++----- src/client/content_cao.cpp | 12 +++-- src/defaultsettings.cpp | 1 + src/object_properties.cpp | 22 +++++++++ src/object_properties.h | 2 + src/script/common/c_content.cpp | 18 +++++++ src/script/common/helper.cpp | 24 ++++++--- src/script/common/helper.h | 3 +- src/script/lua_api/l_object.cpp | 29 +++++++++-- src/util/Optional.h | 77 +++++++++++++++++++++++++++++ src/util/serialize.h | 2 +- 17 files changed, 254 insertions(+), 58 deletions(-) create mode 100644 src/util/Optional.h (limited to 'games/devtest/mods') diff --git a/.clang-format b/.clang-format index dc7380ffd..0db8ab167 100644 --- a/.clang-format +++ b/.clang-format @@ -29,3 +29,4 @@ AlignAfterOpenBracket: DontAlign ContinuationIndentWidth: 16 ConstructorInitializerIndentWidth: 16 BreakConstructorInitializers: AfterColon +AlwaysBreakTemplateDeclarations: Yes diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 8b6227b37..f800f71ab 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -451,6 +451,10 @@ keymap_decrease_viewing_range_min (View range decrease key) key - [**Basic] +# Whether nametag backgrounds should be shown by default. +# Mods may still set a background. +show_nametag_backgrounds (Show nametag backgrounds by default) bool true + # Enable vertex buffer objects. # This should greatly improve graphics performance. enable_vbo (VBO) bool true diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a09b98924..a9c3bcdd9 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6274,15 +6274,21 @@ object you are working with still exists. * `get_nametag_attributes()` * returns a table with the attributes of the nametag of an object * { - color = {a=0..255, r=0..255, g=0..255, b=0..255}, text = "", + color = {a=0..255, r=0..255, g=0..255, b=0..255}, + bgcolor = {a=0..255, r=0..255, g=0..255, b=0..255}, } * `set_nametag_attributes(attributes)` * sets the attributes of the nametag of an object * `attributes`: { - color = ColorSpec, text = "My Nametag", + color = ColorSpec, + -- ^ Text color + bgcolor = ColorSpec or false, + -- ^ Sets background color of nametag + -- `false` will cause the background to be set automatically based on user settings + -- Default: false } #### Lua entity only (no-op for other objects) @@ -6956,9 +6962,13 @@ Player properties need to be saved manually. -- For all other objects, a nil or empty string removes the nametag. -- To hide a nametag, set its color alpha to zero. That will disable it entirely. - nametag_color = , - -- Sets color of nametag + -- Sets text color of nametag + + nametag_bgcolor = , + -- Sets background color of nametag + -- `false` will cause the background to be set automatically based on user settings. + -- Default: false infotext = "", -- By default empty, text to be shown when pointed at object diff --git a/games/devtest/mods/testentities/visuals.lua b/games/devtest/mods/testentities/visuals.lua index e3b758329..e382ec44c 100644 --- a/games/devtest/mods/testentities/visuals.lua +++ b/games/devtest/mods/testentities/visuals.lua @@ -103,23 +103,35 @@ minetest.register_entity("testentities:nametag", { on_activate = function(self, staticdata) if staticdata ~= "" then - self.color = minetest.deserialize(staticdata).color + local data = minetest.deserialize(staticdata) + self.color = data.color + self.bgcolor = data.bgcolor else self.color = { r = math.random(0, 255), g = math.random(0, 255), b = math.random(0, 255), } + + if math.random(0, 10) > 5 then + self.bgcolor = { + r = math.random(0, 255), + g = math.random(0, 255), + b = math.random(0, 255), + a = math.random(0, 255), + } + end end assert(self.color) self.object:set_properties({ nametag = tostring(math.random(1000, 10000)), nametag_color = self.color, + nametag_bgcolor = self.bgcolor, }) end, get_staticdata = function(self) - return minetest.serialize({ color = self.color }) + return minetest.serialize({ color = self.color, bgcolor = self.bgcolor }) end, }) diff --git a/src/activeobjectmgr.h b/src/activeobjectmgr.h index 95e7d3344..aa0538e60 100644 --- a/src/activeobjectmgr.h +++ b/src/activeobjectmgr.h @@ -25,7 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., class TestClientActiveObjectMgr; class TestServerActiveObjectMgr; -template class ActiveObjectMgr +template +class ActiveObjectMgr { friend class ::TestClientActiveObjectMgr; friend class ::TestServerActiveObjectMgr; diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 9a08254b4..350b685e1 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -79,6 +79,7 @@ Camera::Camera(MapDrawControl &draw_control, Client *client): m_cache_fov = std::fmax(g_settings->getFloat("fov"), 45.0f); m_arm_inertia = g_settings->getBool("arm_inertia"); m_nametags.clear(); + m_show_nametag_backgrounds = g_settings->getBool("show_nametag_backgrounds"); } Camera::~Camera() @@ -696,18 +697,14 @@ void Camera::drawNametags() v2u32 screensize = driver->getScreenSize(); for (const Nametag *nametag : m_nametags) { - if (nametag->nametag_color.getAlpha() == 0) { - // Enforce hiding nametag, - // because if freetype is enabled, a grey - // shadow can remain. - continue; - } - v3f pos = nametag->parent_node->getAbsolutePosition() + nametag->nametag_pos * BS; + // Nametags are hidden in GenericCAO::updateNametag() + + v3f pos = nametag->parent_node->getAbsolutePosition() + nametag->pos * BS; f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f }; trans.multiplyWith1x4Matrix(transformed_pos); if (transformed_pos[3] > 0) { std::wstring nametag_colorless = - unescape_translate(utf8_to_wide(nametag->nametag_text)); + unescape_translate(utf8_to_wide(nametag->text)); core::dimension2d textsize = font->getDimension( nametag_colorless.c_str()); f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : @@ -720,26 +717,22 @@ void Camera::drawNametags() core::rect size(0, 0, textsize.Width, textsize.Height); core::rect bg_size(-2, 0, textsize.Width+2, textsize.Height); - video::SColor textColor = nametag->nametag_color; - - bool darkBackground = textColor.getLuminance() > 186; - video::SColor backgroundColor = darkBackground - ? video::SColor(50, 50, 50, 50) - : video::SColor(50, 255, 255, 255); - driver->draw2DRectangle(backgroundColor, bg_size + screen_pos); + auto bgcolor = nametag->getBgColor(m_show_nametag_backgrounds); + if (bgcolor.getAlpha() != 0) + driver->draw2DRectangle(bgcolor, bg_size + screen_pos); font->draw( - translate_string(utf8_to_wide(nametag->nametag_text)).c_str(), - size + screen_pos, textColor); + translate_string(utf8_to_wide(nametag->text)).c_str(), + size + screen_pos, nametag->textcolor); } } } Nametag *Camera::addNametag(scene::ISceneNode *parent_node, - const std::string &nametag_text, video::SColor nametag_color, - const v3f &pos) + const std::string &text, video::SColor textcolor, + Optional bgcolor, const v3f &pos) { - Nametag *nametag = new Nametag(parent_node, nametag_text, nametag_color, pos); + Nametag *nametag = new Nametag(parent_node, text, textcolor, bgcolor, pos); m_nametags.push_back(nametag); return nametag; } diff --git a/src/client/camera.h b/src/client/camera.h index 16a1961be..6fd8d9aa7 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -25,27 +25,47 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "util/Optional.h" class LocalPlayer; struct MapDrawControl; class Client; class WieldMeshSceneNode; -struct Nametag { +struct Nametag +{ + scene::ISceneNode *parent_node; + std::string text; + video::SColor textcolor; + Optional bgcolor; + v3f pos; + Nametag(scene::ISceneNode *a_parent_node, - const std::string &a_nametag_text, - const video::SColor &a_nametag_color, - const v3f &a_nametag_pos): + const std::string &text, + const video::SColor &textcolor, + const Optional &bgcolor, + const v3f &pos): parent_node(a_parent_node), - nametag_text(a_nametag_text), - nametag_color(a_nametag_color), - nametag_pos(a_nametag_pos) + text(text), + textcolor(textcolor), + bgcolor(bgcolor), + pos(pos) { } - scene::ISceneNode *parent_node; - std::string nametag_text; - video::SColor nametag_color; - v3f nametag_pos; + + video::SColor getBgColor(bool use_fallback) const + { + if (bgcolor) + return bgcolor.value(); + else if (!use_fallback) + return video::SColor(0, 0, 0, 0); + else if (textcolor.getLuminance() > 186) + // Dark background for light text + return video::SColor(50, 50, 50, 50); + else + // Light background for dark text + return video::SColor(50, 255, 255, 255); + } }; enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT}; @@ -164,8 +184,8 @@ public: } Nametag *addNametag(scene::ISceneNode *parent_node, - const std::string &nametag_text, video::SColor nametag_color, - const v3f &pos); + const std::string &text, video::SColor textcolor, + Optional bgcolor, const v3f &pos); void removeNametag(Nametag *nametag); @@ -245,4 +265,5 @@ private: bool m_arm_inertia; std::list m_nametags; + bool m_show_nametag_backgrounds; }; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index c65977b44..97ae9afc4 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -934,7 +934,7 @@ void GenericCAO::updateNametag() if (m_is_local_player) // No nametag for local player return; - if (m_prop.nametag.empty()) { + if (m_prop.nametag.empty() || m_prop.nametag_color.getAlpha() == 0) { // Delete nametag if (m_nametag) { m_client->getCamera()->removeNametag(m_nametag); @@ -952,12 +952,14 @@ void GenericCAO::updateNametag() if (!m_nametag) { // Add nametag m_nametag = m_client->getCamera()->addNametag(node, - m_prop.nametag, m_prop.nametag_color, pos); + m_prop.nametag, m_prop.nametag_color, + m_prop.nametag_bgcolor, pos); } else { // Update nametag - m_nametag->nametag_text = m_prop.nametag; - m_nametag->nametag_color = m_prop.nametag_color; - m_nametag->nametag_pos = pos; + m_nametag->text = m_prop.nametag; + m_nametag->textcolor = m_prop.nametag_color; + m_nametag->bgcolor = m_prop.nametag_bgcolor; + m_nametag->pos = pos; } } diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 41c4922a4..cda953082 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -240,6 +240,7 @@ void set_default_settings() #endif settings->setDefault("enable_particles", "true"); settings->setDefault("arm_inertia", "true"); + settings->setDefault("show_nametag_backgrounds", "true"); settings->setDefault("enable_minimap", "true"); settings->setDefault("minimap_shape_round", "true"); diff --git a/src/object_properties.cpp b/src/object_properties.cpp index f31773060..2eebc27d6 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/basic_macros.h" #include +static const video::SColor NULL_BGCOLOR{0, 1, 1, 1}; + ObjectProperties::ObjectProperties() { textures.emplace_back("unknown_object.png"); @@ -62,6 +64,13 @@ std::string ObjectProperties::dump() os << ", nametag=" << nametag; os << ", nametag_color=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed() << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" "; + + if (nametag_bgcolor) + os << ", nametag_bgcolor=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed() + << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" "; + else + os << ", nametag_bgcolor=null "; + os << ", selectionbox=" << PP(selectionbox.MinEdge) << "," << PP(selectionbox.MaxEdge); os << ", pointable=" << pointable; os << ", static_save=" << static_save; @@ -121,6 +130,13 @@ void ObjectProperties::serialize(std::ostream &os) const writeU8(os, shaded); writeU8(os, show_on_minimap); + if (!nametag_bgcolor) + writeARGB8(os, NULL_BGCOLOR); + else if (nametag_bgcolor.value().getAlpha() == 0) + writeARGB8(os, video::SColor(0, 0, 0, 0)); + else + writeARGB8(os, nametag_bgcolor.value()); + // Add stuff only at the bottom. // Never remove anything, because we don't want new versions of this } @@ -182,5 +198,11 @@ void ObjectProperties::deSerialize(std::istream &is) if (is.eof()) return; show_on_minimap = tmp; + + auto bgcolor = readARGB8(is); + if (bgcolor != NULL_BGCOLOR) + nametag_bgcolor = bgcolor; + else + nametag_bgcolor = nullopt; } catch (SerializationError &e) {} } diff --git a/src/object_properties.h b/src/object_properties.h index adb483527..db28eebfd 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "util/Optional.h" struct ObjectProperties { @@ -53,6 +54,7 @@ struct ObjectProperties s8 glow = 0; std::string nametag = ""; video::SColor nametag_color = video::SColor(255, 255, 255, 255); + Optional nametag_bgcolor = nullopt; f32 automatic_face_movement_max_rotation_per_sec = -1.0f; std::string infotext; //! For dropped items, this contains item information. diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 2f9fbd74b..6995f6b61 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -312,6 +312,17 @@ void read_object_properties(lua_State *L, int index, prop->nametag_color = color; } lua_pop(L, 1); + lua_getfield(L, -1, "nametag_bgcolor"); + if (!lua_isnil(L, -1)) { + if (lua_toboolean(L, -1)) { + video::SColor color; + if (read_color(L, -1, &color)) + prop->nametag_bgcolor = color; + } else { + prop->nametag_bgcolor = nullopt; + } + } + lua_pop(L, 1); lua_getfield(L, -1, "automatic_face_movement_max_rotation_per_sec"); if (lua_isnumber(L, -1)) { @@ -403,6 +414,13 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) lua_setfield(L, -2, "nametag"); push_ARGB8(L, prop->nametag_color); lua_setfield(L, -2, "nametag_color"); + if (prop->nametag_bgcolor) { + push_ARGB8(L, prop->nametag_bgcolor.value()); + lua_setfield(L, -2, "nametag_bgcolor"); + } else { + lua_pushboolean(L, false); + lua_setfield(L, -2, "nametag_bgcolor"); + } lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec); lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec"); lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size()); diff --git a/src/script/common/helper.cpp b/src/script/common/helper.cpp index 488144790..fbf24e1b7 100644 --- a/src/script/common/helper.cpp +++ b/src/script/common/helper.cpp @@ -50,22 +50,26 @@ bool LuaHelper::isNaN(lua_State *L, int idx) /* * Read template functions */ -template <> bool LuaHelper::readParam(lua_State *L, int index) +template <> +bool LuaHelper::readParam(lua_State *L, int index) { return lua_toboolean(L, index) != 0; } -template <> s16 LuaHelper::readParam(lua_State *L, int index) +template <> +s16 LuaHelper::readParam(lua_State *L, int index) { return lua_tonumber(L, index); } -template <> int LuaHelper::readParam(lua_State *L, int index) +template <> +int LuaHelper::readParam(lua_State *L, int index) { return luaL_checkint(L, index); } -template <> float LuaHelper::readParam(lua_State *L, int index) +template <> +float LuaHelper::readParam(lua_State *L, int index) { if (isNaN(L, index)) throw LuaError("NaN value is not allowed."); @@ -73,7 +77,8 @@ template <> float LuaHelper::readParam(lua_State *L, int index) return (float)luaL_checknumber(L, index); } -template <> v2s16 LuaHelper::readParam(lua_State *L, int index) +template <> +v2s16 LuaHelper::readParam(lua_State *L, int index) { v2s16 p; CHECK_POS_TAB(index); @@ -88,7 +93,8 @@ template <> v2s16 LuaHelper::readParam(lua_State *L, int index) return p; } -template <> v2f LuaHelper::readParam(lua_State *L, int index) +template <> +v2f LuaHelper::readParam(lua_State *L, int index) { v2f p; CHECK_POS_TAB(index); @@ -103,7 +109,8 @@ template <> v2f LuaHelper::readParam(lua_State *L, int index) return p; } -template <> v3f LuaHelper::readParam(lua_State *L, int index) +template <> +v3f LuaHelper::readParam(lua_State *L, int index) { v3f p; CHECK_POS_TAB(index); @@ -122,7 +129,8 @@ template <> v3f LuaHelper::readParam(lua_State *L, int index) return p; } -template <> std::string LuaHelper::readParam(lua_State *L, int index) +template <> +std::string LuaHelper::readParam(lua_State *L, int index) { size_t length; std::string result; diff --git a/src/script/common/helper.h b/src/script/common/helper.h index 7a794dc9b..6491e73cf 100644 --- a/src/script/common/helper.h +++ b/src/script/common/helper.h @@ -38,7 +38,8 @@ protected: * @param index Lua Index to read * @return read value from Lua */ - template static T readParam(lua_State *L, int index); + template + static T readParam(lua_State *L, int index); /** * Read a value using a template type T from Lua State L and index diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 07aa3f7c9..8ae99b929 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -737,6 +737,18 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L) } lua_pop(L, 1); + lua_getfield(L, -1, "bgcolor"); + if (!lua_isnil(L, -1)) { + if (lua_toboolean(L, -1)) { + video::SColor color; + if (read_color(L, -1, &color)) + prop->nametag_bgcolor = color; + } else { + prop->nametag_bgcolor = nullopt; + } + } + lua_pop(L, 1); + std::string nametag = getstringfield_default(L, 2, "text", ""); prop->nametag = nametag; @@ -758,13 +770,24 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L) if (!prop) return 0; - video::SColor color = prop->nametag_color; - lua_newtable(L); - push_ARGB8(L, color); + + push_ARGB8(L, prop->nametag_color); lua_setfield(L, -2, "color"); + + if (prop->nametag_bgcolor) { + push_ARGB8(L, prop->nametag_bgcolor.value()); + lua_setfield(L, -2, "bgcolor"); + } else { + lua_pushboolean(L, false); + lua_setfield(L, -2, "bgcolor"); + } + lua_pushstring(L, prop->nametag.c_str()); lua_setfield(L, -2, "text"); + + + return 1; } diff --git a/src/util/Optional.h b/src/util/Optional.h new file mode 100644 index 000000000..9c2842b43 --- /dev/null +++ b/src/util/Optional.h @@ -0,0 +1,77 @@ +/* +Minetest +Copyright (C) 2021 rubenwardy + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "debug.h" + +struct nullopt_t +{ +}; +constexpr nullopt_t nullopt{}; + +/** + * An implementation of optional for C++11, which aims to be + * compatible with a subset of std::optional features. + * + * Unfortunately, Minetest doesn't use C++17 yet. + * + * @tparam T The type to be stored + */ +template +class Optional +{ + bool m_has_value = false; + T m_value; + +public: + Optional() noexcept {} + Optional(nullopt_t) noexcept {} + Optional(const T &value) noexcept : m_has_value(true), m_value(value) {} + Optional(const Optional &other) noexcept : + m_has_value(other.m_has_value), m_value(other.m_value) + { + } + + void operator=(nullopt_t) noexcept { m_has_value = false; } + + void operator=(const Optional &other) noexcept + { + m_has_value = other.m_has_value; + m_value = other.m_value; + } + + T &value() + { + FATAL_ERROR_IF(!m_has_value, "optional doesn't have value"); + return m_value; + } + + const T &value() const + { + FATAL_ERROR_IF(!m_has_value, "optional doesn't have value"); + return m_value; + } + + const T &value_or(const T &def) const { return m_has_value ? m_value : def; } + + bool has_value() const noexcept { return m_has_value; } + + explicit operator bool() const { return m_has_value; } +}; diff --git a/src/util/serialize.h b/src/util/serialize.h index b3ec28eab..15bdd050d 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -290,7 +290,7 @@ inline void writeS8(u8 *data, s8 i) inline void writeS16(u8 *data, s16 i) { - writeU16(data, (u16)i); + writeU16(data, (u16)i); } inline void writeS32(u8 *data, s32 i) -- cgit v1.2.3 From 051e4c2b00a30c496b5545a6f0b01c9a14e937a4 Mon Sep 17 00:00:00 2001 From: Lars Müller <34514239+appgurueu@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:02:23 +0100 Subject: Fix wrong reported item counts for inventory actions using Shift-Move (#10930) --- games/devtest/mods/chest/init.lua | 16 ++++++++++++++-- src/inventorymanager.cpp | 33 +++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/chest/init.lua b/games/devtest/mods/chest/init.lua index fc92bfdd1..5798c13e7 100644 --- a/games/devtest/mods/chest/init.lua +++ b/games/devtest/mods/chest/init.lua @@ -23,6 +23,18 @@ minetest.register_node("chest:chest", { local inv = meta:get_inventory() return inv:is_empty("main") end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.chat_send_player(player:get_player_name(), "Allow put: " .. stack:to_string()) + return stack:get_count() + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.chat_send_player(player:get_player_name(), "Allow take: " .. stack:to_string()) + return stack:get_count() + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.chat_send_player(player:get_player_name(), "On put: " .. stack:to_string()) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.chat_send_player(player:get_player_name(), "On take: " .. stack:to_string()) + end, }) - - diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index 635bd2e4b..554708e8e 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -301,6 +301,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame if (!list_to->getItem(dest_i).empty()) { to_i = dest_i; apply(mgr, player, gamedef); + assert(move_count <= count); count -= move_count; } } @@ -352,10 +353,12 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame bool allow_swap = !list_to->itemFits(to_i, src_item, &restitem) && restitem.count == src_item.count && !caused_by_move_somewhere; + move_count = src_item.count - restitem.count; // Shift-click: Cannot fill this stack, proceed with next slot - if (caused_by_move_somewhere && restitem.count == src_item.count) + if (caused_by_move_somewhere && move_count == 0) { return; + } if (allow_swap) { // Swap will affect the entire stack if it can performed. @@ -384,9 +387,16 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame src_can_take_count = dst_can_put_count = 0; } else { // Take from one inventory, put into another + int src_item_count = src_item.count; + if (caused_by_move_somewhere) + // When moving somewhere: temporarily use the actual movable stack + // size to ensure correct callback execution. + src_item.count = move_count; dst_can_put_count = allowPut(src_item, player); src_can_take_count = allowTake(src_item, player); - + if (caused_by_move_somewhere) + // Reset source item count + src_item.count = src_item_count; bool swap_expected = allow_swap; allow_swap = allow_swap && (src_can_take_count == -1 || src_can_take_count >= src_item.count) @@ -416,12 +426,17 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame count = src_can_take_count; if (dst_can_put_count != -1 && count > dst_can_put_count) count = dst_can_put_count; + /* Limit according to source item count */ if (count > list_from->getItem(from_i).count) count = list_from->getItem(from_i).count; /* If no items will be moved, don't go further */ if (count == 0) { + if (caused_by_move_somewhere) + // Set move count to zero, as no items have been moved + move_count = 0; + // Undo client prediction. See 'clientApply' if (from_inv.type == InventoryLocation::PLAYER) list_from->setModified(); @@ -438,6 +453,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame <<" list=\""< &modlist) const; + /** + * Recursively gets all paths of mod folders that can contain media files. + * + * Result is ordered in descending priority, ie. files from an earlier path + * should not be replaced by files from a latter one. + * + * @param paths result vector + */ void getModsMediaPaths(std::vector &paths) const; }; -- cgit v1.2.3 From 88f514ad7a849eb4a67b5ee2c41c93856cf3808f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 15 Mar 2021 09:13:15 +0000 Subject: Devtest: Fix missing log level in minetest.log (#11068) --- games/devtest/mods/experimental/commands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/experimental/commands.lua b/games/devtest/mods/experimental/commands.lua index 132b08b0b..8bfa467e1 100644 --- a/games/devtest/mods/experimental/commands.lua +++ b/games/devtest/mods/experimental/commands.lua @@ -215,5 +215,5 @@ minetest.register_chatcommand("test_place_nodes", { }) core.register_on_chatcommand(function(name, command, params) - minetest.log("caught command '"..command.."', issued by '"..name.."'. Parameters: '"..params.."'") + minetest.log("action", "caught command '"..command.."', issued by '"..name.."'. Parameters: '"..params.."'") end) -- cgit v1.2.3 From 91135381421f646e0f6a8d9201b5cdc7e42605e1 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 16 Mar 2021 17:37:24 +0000 Subject: DevTest: Formspec tests, children getter, better lighttool (#10918) --- games/devtest/mods/testformspec/formspec.lua | 37 +++- games/devtest/mods/testtools/README.md | 21 +++ games/devtest/mods/testtools/init.lua | 196 ++++++++++++++++++--- games/devtest/mods/testtools/light.lua | 31 +++- .../textures/testtools_children_getter.png | Bin 0 -> 281 bytes .../textures/testtools_node_meta_editor.png | Bin 0 -> 135 bytes 6 files changed, 253 insertions(+), 32 deletions(-) create mode 100644 games/devtest/mods/testtools/textures/testtools_children_getter.png create mode 100644 games/devtest/mods/testtools/textures/testtools_node_meta_editor.png (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua index 2a2bdad60..501b5e354 100644 --- a/games/devtest/mods/testformspec/formspec.lua +++ b/games/devtest/mods/testformspec/formspec.lua @@ -362,20 +362,51 @@ Number] animated_image[5.5,0.5;5,2;;testformspec_animation.png;4;100] animated_image[5.5,2.75;5,2;;testformspec_animation.jpg;4;100] + ]], + + -- Model + [[ + formspec_version[3] + size[12,13] style[m1;bgcolor=black] - model[0.5,6;4,4;m1;testformspec_character.b3d;testformspec_character.png] - model[5,6;4,4;m2;testformspec_chest.obj;default_chest_top.png,default_chest_top.png,default_chest_side.png,default_chest_side.png,default_chest_front.png,default_chest_inside.png;30,1;true;true] + style[m2;bgcolor=black] + label[5,1;all defaults] + label[5,5.1;angle = 0, 180 +continuous = false +mouse control = false +frame loop range = 0,30] + label[5,9.2;continuous = true +mouse control = true] + model[0.5,0.1;4,4;m1;testformspec_character.b3d;testformspec_character.png] + model[0.5,4.2;4,4;m2;testformspec_character.b3d;testformspec_character.png;0,180;false;false;0,30] + model[0.5,8.3;4,4;m3;testformspec_chest.obj;default_chest_top.png,default_chest_top.png,default_chest_side.png,default_chest_side.png,default_chest_front.png,default_chest_inside.png;30,1;true;true] ]], -- Scroll containers "formspec_version[3]size[12,13]" .. scroll_fs, + + -- Sound + [[ + formspec_version[3] + size[12,13] + style[snd_btn;sound=soundstuff_mono] + style[snd_ibtn;sound=soundstuff_mono] + style[snd_drp;sound=soundstuff_mono] + style[snd_chk;sound=soundstuff_mono] + style[snd_tab;sound=soundstuff_mono] + button[0.5,0.5;2,1;snd_btn;Sound] + image_button[0.5,2;2,1;testformspec_item.png;snd_ibtn;Sound] + dropdown[0.5,4;4;snd_drp;Sound,Two,Three;] + checkbox[0.5,5.5.5;snd_chk;Sound;] + tabheader[0.5,7;8,0.65;snd_tab;Soundtab1,Soundtab2,Soundtab3;1;false;false] + ]], } local function show_test_formspec(pname, page_id) page_id = page_id or 2 - local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Anim,ScrollC;" .. page_id .. ";false;false]" + local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Anim,Model,ScrollC,Sound;" .. page_id .. ";false;false]" minetest.show_formspec(pname, "testformspec:formspec", fs) end diff --git a/games/devtest/mods/testtools/README.md b/games/devtest/mods/testtools/README.md index 9cfe29ea4..a1eb95ed7 100644 --- a/games/devtest/mods/testtools/README.md +++ b/games/devtest/mods/testtools/README.md @@ -33,6 +33,13 @@ Usage: * Punch node: Make it fall * Place: Try to teleport up to 2 units upwards, then make it fall +## Node Meta Editor +Edit and view metadata of nodes. + +Usage: + +* Punch: Open node metadata editor + ## Entity Rotator Changes the entity rotation (with `set_rotation`). @@ -90,6 +97,13 @@ Usage: * Place: Increase move distance * Sneak+place: Decrease move distance +## Children Getter +Shows list of objects that are attached to an object (aka "children") in chat. + +Usage: +* Punch object: Show children of punched object +* Punch air: Show your own children + ## Entity Visual Scaler Change visual size of entities @@ -97,3 +111,10 @@ Usage: * Punch entity to increase visual size * Sneak+punch entity to decrease visual size + +## Light Tool +Show light level of node. + +Usage: +* Punch: Show light info of node in front of the punched node's side +* Place: Show light info of the node that you touched diff --git a/games/devtest/mods/testtools/init.lua b/games/devtest/mods/testtools/init.lua index d578b264a..1041acdeb 100644 --- a/games/devtest/mods/testtools/init.lua +++ b/games/devtest/mods/testtools/init.lua @@ -3,8 +3,6 @@ local F = minetest.formspec_escape dofile(minetest.get_modpath("testtools") .. "/light.lua") --- TODO: Add a Node Metadata tool - minetest.register_tool("testtools:param2tool", { description = S("Param2 Tool") .."\n".. S("Modify param2 value of nodes") .."\n".. @@ -111,25 +109,6 @@ minetest.register_tool("testtools:node_setter", { end, }) -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "testtools:node_setter" then - local playername = player:get_player_name() - local witem = player:get_wielded_item() - if witem:get_name() == "testtools:node_setter" then - if fields.nodename and fields.param2 then - local param2 = tonumber(fields.param2) - if not param2 then - return - end - local meta = witem:get_meta() - meta:set_string("node", fields.nodename) - meta:set_int("node_param2", param2) - player:set_wielded_item(witem) - end - end - end -end) - minetest.register_tool("testtools:remover", { description = S("Remover") .."\n".. S("Punch: Remove pointed node or object"), @@ -634,6 +613,54 @@ minetest.register_tool("testtools:object_attacher", { end, }) +local function print_object(obj) + if obj:is_player() then + return "player '"..obj:get_player_name().."'" + elseif obj:get_luaentity() then + return "LuaEntity '"..obj:get_luaentity().name.."'" + else + return "object" + end +end + +minetest.register_tool("testtools:children_getter", { + description = S("Children Getter") .."\n".. + S("Shows list of objects attached to object") .."\n".. + S("Punch object to show its 'children'") .."\n".. + S("Punch air to show your own 'children'"), + inventory_image = "testtools_children_getter.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + if user and user:is_player() then + local name = user:get_player_name() + local selected_object + local self_name + if pointed_thing.type == "object" then + selected_object = pointed_thing.ref + elseif pointed_thing.type == "nothing" then + selected_object = user + else + return + end + self_name = print_object(selected_object) + local children = selected_object:get_children() + local ret = "" + for c=1, #children do + ret = ret .. "* " .. print_object(children[c]) + if c < #children then + ret = ret .. "\n" + end + end + if ret == "" then + ret = S("No children attached to @1.", self_name) + else + ret = S("Children of @1:", self_name) .. "\n" .. ret + end + minetest.chat_send_player(user:get_player_name(), ret) + end + end, +}) + -- Use loadstring to parse param as a Lua value local function use_loadstring(param, player) -- For security reasons, require 'server' priv, just in case @@ -666,6 +693,68 @@ local function use_loadstring(param, player) return true, errOrResult end +-- Node Meta Editor +local node_meta_posses = {} +local node_meta_latest_keylist = {} + +local function show_node_meta_formspec(user, pos, key, value, keylist) + local textlist + if keylist then + textlist = "textlist[0,0.5;2.5,6.5;keylist;"..keylist.."]" + else + textlist = "" + end + minetest.show_formspec(user:get_player_name(), + "testtools:node_meta_editor", + "size[15,9]".. + "label[0,0;"..F(S("Current keys:")).."]".. + textlist.. + "field[3,0.5;12,1;key;"..F(S("Key"))..";"..F(key).."]".. + "textarea[3,1.5;12,6;value;"..F(S("Value (use empty value to delete key)"))..";"..F(value).."]".. + "button[0,8;3,1;get;"..F(S("Get value")).."]".. + "button[4,8;3,1;set;"..F(S("Set value")).."]".. + "label[0,7.2;"..F(S("pos = @1", minetest.pos_to_string(pos))).."]") +end + +local function get_node_meta_keylist(meta, playername, escaped) + local keys = {} + local ekeys = {} + local mtable = meta:to_table() + for k,_ in pairs(mtable.fields) do + table.insert(keys, k) + if escaped then + table.insert(ekeys, F(k)) + else + table.insert(ekeys, k) + end + end + if playername then + node_meta_latest_keylist[playername] = keys + end + return table.concat(ekeys, ",") +end + +minetest.register_tool("testtools:node_meta_editor", { + description = S("Node Meta Editor") .. "\n" .. + S("Place: Edit node metadata"), + inventory_image = "testtools_node_meta_editor.png", + groups = { testtool = 1, disable_repair = 1 }, + on_place = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + if not user:is_player() then + return itemstack + end + local pos = pointed_thing.under + node_meta_posses[user:get_player_name()] = pos + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + show_node_meta_formspec(user, pos, "", "", get_node_meta_keylist(meta, user:get_player_name(), true)) + return itemstack + end, +}) + minetest.register_on_player_receive_fields(function(player, formname, fields) if not (player and player:is_player()) then return @@ -728,5 +817,70 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) editor_formspec(name, selected_objects[name], prop_to_string(props[key]), sel) return end + elseif formname == "testtools:node_setter" then + local playername = player:get_player_name() + local witem = player:get_wielded_item() + if witem:get_name() == "testtools:node_setter" then + if fields.nodename and fields.param2 then + local param2 = tonumber(fields.param2) + if not param2 then + return + end + local meta = witem:get_meta() + meta:set_string("node", fields.nodename) + meta:set_int("node_param2", param2) + player:set_wielded_item(witem) + end + end + elseif formname == "testtools:node_meta_editor" then + local name = player:get_player_name() + local pos = node_meta_posses[name] + if fields.keylist then + local evnt = minetest.explode_textlist_event(fields.keylist) + if evnt.type == "DCL" or evnt.type == "CHG" then + local keylist_table = node_meta_latest_keylist[name] + if not pos then + return + end + local meta = minetest.get_meta(pos) + if not keylist_table then + return + end + if #keylist_table == 0 then + return + end + local key = keylist_table[evnt.index] + local value = meta:get_string(key) + local keylist_escaped = {} + for k,v in pairs(keylist_table) do + keylist_escaped[k] = F(v) + end + local keylist = table.concat(keylist_escaped, ",") + show_node_meta_formspec(player, pos, key, value, keylist) + return + end + elseif fields.key and fields.key ~= "" and fields.value then + if not pos then + return + end + local meta = minetest.get_meta(pos) + if fields.get then + local value = meta:get_string(fields.key) + show_node_meta_formspec(player, pos, fields.key, value, + get_node_meta_keylist(meta, name, true)) + return + elseif fields.set then + meta:set_string(fields.key, fields.value) + show_node_meta_formspec(player, pos, fields.key, fields.value, + get_node_meta_keylist(meta, name, true)) + return + end + end end end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + node_meta_latest_keylist[name] = nil + node_meta_posses[name] = nil +end) diff --git a/games/devtest/mods/testtools/light.lua b/games/devtest/mods/testtools/light.lua index a9458ca6b..afca9a489 100644 --- a/games/devtest/mods/testtools/light.lua +++ b/games/devtest/mods/testtools/light.lua @@ -1,22 +1,37 @@ local S = minetest.get_translator("testtools") -minetest.register_tool("testtools:lighttool", { - description = S("Light tool"), - inventory_image = "testtools_lighttool.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - local pos = pointed_thing.above +local function get_func(is_place) + return function(itemstack, user, pointed_thing) + local pos + if is_place then + pos = pointed_thing.under + else + pos = pointed_thing.above + end if pointed_thing.type ~= "node" or not pos then return end local node = minetest.get_node(pos) + local pstr = minetest.pos_to_string(pos) local time = minetest.get_timeofday() local sunlight = minetest.get_natural_light(pos) local artificial = minetest.get_artificial_light(node.param1) - local message = ("param1 0x%02x | time %.5f | sunlight %d | artificial %d") - :format(node.param1, time, sunlight, artificial) + local message = ("pos=%s | param1=0x%02x | " .. + "sunlight=%d | artificial=%d | timeofday=%.5f" ) + :format(pstr, node.param1, sunlight, artificial, time) minetest.chat_send_player(user:get_player_name(), message) end +end + +minetest.register_tool("testtools:lighttool", { + description = S("Light Tool") .. "\n" .. + S("Show light values of node") .. "\n" .. + S("Punch: Light of node above touched node") .. "\n" .. + S("Place: Light of touched node itself"), + inventory_image = "testtools_lighttool.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = get_func(false), + on_place = get_func(true), }) diff --git a/games/devtest/mods/testtools/textures/testtools_children_getter.png b/games/devtest/mods/testtools/textures/testtools_children_getter.png new file mode 100644 index 000000000..b7fa34025 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_children_getter.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png b/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png new file mode 100644 index 000000000..89eafd65c Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png differ -- cgit v1.2.3 From 3b78a223717c69918a5af422e21561f47ec74ce1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 30 Mar 2021 01:25:11 +0300 Subject: Degrotate support for mesh nodes (#7840) --- builtin/game/item.lua | 6 +++- doc/lua_api.txt | 11 ++++-- games/devtest/mods/testnodes/drawtypes.lua | 56 +++++++++++++++++++++++++++++- src/client/content_mapblock.cpp | 16 ++++++--- src/client/content_mapblock.h | 2 +- src/mapnode.cpp | 21 +++++++++++ src/mapnode.h | 3 ++ src/nodedef.cpp | 3 +- src/nodedef.h | 4 ++- src/script/common/c_content.cpp | 3 +- src/script/cpp_api/s_node.cpp | 1 + 11 files changed, 113 insertions(+), 13 deletions(-) (limited to 'games/devtest/mods') diff --git a/builtin/game/item.lua b/builtin/game/item.lua index b68177c22..17746e9a8 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -157,7 +157,7 @@ end function core.is_colored_paramtype(ptype) return (ptype == "color") or (ptype == "colorfacedir") or - (ptype == "colorwallmounted") + (ptype == "colorwallmounted") or (ptype == "colordegrotate") end function core.strip_param2_color(param2, paramtype2) @@ -168,6 +168,8 @@ function core.strip_param2_color(param2, paramtype2) param2 = math.floor(param2 / 32) * 32 elseif paramtype2 == "colorwallmounted" then param2 = math.floor(param2 / 8) * 8 + elseif paramtype2 == "colordegrotate" then + param2 = math.floor(param2 / 32) * 32 end -- paramtype2 == "color" requires no modification. return param2 @@ -345,6 +347,8 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2, color_divisor = 8 elseif def.paramtype2 == "colorfacedir" then color_divisor = 32 + elseif def.paramtype2 == "colordegrotate" then + color_divisor = 32 end if color_divisor then local color = math.floor(metatable.palette_index / color_divisor) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 737a690f6..8804c9e7f 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1048,9 +1048,9 @@ The function of `param2` is determined by `paramtype2` in node definition. * The height of the 'plantlike' section is stored in `param2`. * The height is (`param2` / 16) nodes. * `paramtype2 = "degrotate"` - * Only valid for "plantlike" drawtype. The rotation of the node is stored in - `param2`. - * Values range 0 - 179. The value stored in `param2` is multiplied by two to + * Valid for `plantlike` and `mesh` drawtypes. The rotation of the node is + stored in `param2`. + * Values range 0–239. The value stored in `param2` is multiplied by 1.5 to get the actual rotation in degrees of the node. * `paramtype2 = "meshoptions"` * Only valid for "plantlike" drawtype. `param2` encodes the shape and @@ -1088,6 +1088,11 @@ The function of `param2` is determined by `paramtype2` in node definition. * `param2` values 0-63 define 64 levels of internal liquid, 0 being empty and 63 being full. * Liquid texture is defined using `special_tiles = {"modname_tilename.png"}` +* `paramtype2 = "colordegrotate"` + * Same as `degrotate`, but with colors. + * The first (most-significant) three bits of `param2` tells which color + is picked from the palette. The palette should have 8 pixels. + * Remaining 5 bits store rotation in range 0–23 (i.e. in 15° steps) * `paramtype2 = "none"` * `param2` will not be used by the engine and can be used to store an arbitrary value diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index ff970144d..02d71b50d 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -223,6 +223,30 @@ minetest.register_node("testnodes:plantlike_waving", { -- param2 will rotate +local function rotate_on_rightclick(pos, node, clicker) + local def = minetest.registered_nodes[node.name] + local aux1 = clicker:get_player_control().aux1 + + local deg, deg_max + local color, color_mult = 0, 0 + if def.paramtype2 == "degrotate" then + deg = node.param2 + deg_max = 240 + elseif def.paramtype2 == "colordegrotate" then + -- MSB [3x color, 5x rotation] LSB + deg = node.param2 % 2^5 + deg_max = 24 + color_mult = 2^5 + color = math.floor(node.param2 / color_mult) + end + + deg = (deg + (aux1 and 10 or 1)) % deg_max + node.param2 = color * color_mult + deg + minetest.swap_node(pos, node) + minetest.chat_send_player(clicker:get_player_name(), + "Rotation is now " .. deg .. " / " .. deg_max) +end + minetest.register_node("testnodes:plantlike_degrotate", { description = S("Degrotate Plantlike Drawtype Test Node"), drawtype = "plantlike", @@ -230,12 +254,42 @@ minetest.register_node("testnodes:plantlike_degrotate", { paramtype2 = "degrotate", tiles = { "testnodes_plantlike_degrotate.png" }, - + on_rightclick = rotate_on_rightclick, + place_param2 = 7, walkable = false, sunlight_propagates = true, groups = { dig_immediate = 3 }, }) +minetest.register_node("testnodes:mesh_degrotate", { + description = S("Degrotate Mesh Drawtype Test Node"), + drawtype = "mesh", + paramtype = "light", + paramtype2 = "degrotate", + mesh = "testnodes_pyramid.obj", + tiles = { "testnodes_mesh_stripes2.png" }, + + on_rightclick = rotate_on_rightclick, + place_param2 = 7, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:mesh_colordegrotate", { + description = S("Color Degrotate Mesh Drawtype Test Node"), + drawtype = "mesh", + paramtype2 = "colordegrotate", + palette = "testnodes_palette_facedir.png", + mesh = "testnodes_pyramid.obj", + tiles = { "testnodes_mesh_stripes2.png" }, + + on_rightclick = rotate_on_rightclick, + -- color index 1, 7 steps rotated + place_param2 = 1 * 2^5 + 7, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + -- param2 will change height minetest.register_node("testnodes:plantlike_leveled", { description = S("Leveled Plantlike Drawtype Test Node"), diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 90284ecce..ce7235bca 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -968,7 +968,7 @@ void MapblockMeshGenerator::drawPlantlike() draw_style = PLANT_STYLE_CROSS; scale = BS / 2 * f->visual_scale; offset = v3f(0, 0, 0); - rotate_degree = 0; + rotate_degree = 0.0f; random_offset_Y = false; face_num = 0; plant_height = 1.0; @@ -988,7 +988,8 @@ void MapblockMeshGenerator::drawPlantlike() break; case CPT2_DEGROTATE: - rotate_degree = n.param2 * 2; + case CPT2_COLORED_DEGROTATE: + rotate_degree = 1.5f * n.getDegRotate(nodedef); break; case CPT2_LEVELED: @@ -1343,6 +1344,7 @@ void MapblockMeshGenerator::drawMeshNode() u8 facedir = 0; scene::IMesh* mesh; bool private_mesh; // as a grab/drop pair is not thread-safe + int degrotate = 0; if (f->param_type_2 == CPT2_FACEDIR || f->param_type_2 == CPT2_COLORED_FACEDIR) { @@ -1354,9 +1356,12 @@ void MapblockMeshGenerator::drawMeshNode() facedir = n.getWallMounted(nodedef); if (!enable_mesh_cache) facedir = wallmounted_to_facedir[facedir]; + } else if (f->param_type_2 == CPT2_DEGROTATE || + f->param_type_2 == CPT2_COLORED_DEGROTATE) { + degrotate = n.getDegRotate(nodedef); } - if (!data->m_smooth_lighting && f->mesh_ptr[facedir]) { + if (!data->m_smooth_lighting && f->mesh_ptr[facedir] && !degrotate) { // use cached meshes private_mesh = false; mesh = f->mesh_ptr[facedir]; @@ -1364,7 +1369,10 @@ void MapblockMeshGenerator::drawMeshNode() // no cache, clone and rotate mesh private_mesh = true; mesh = cloneMesh(f->mesh_ptr[0]); - rotateMeshBy6dFacedir(mesh, facedir); + if (facedir) + rotateMeshBy6dFacedir(mesh, facedir); + else if (degrotate) + rotateMeshXZby(mesh, 1.5f * degrotate); recalculateBoundingBox(mesh); meshmanip->recalculateNormals(mesh, true, false); } else diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index 487d84a07..a6c450d1f 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -139,7 +139,7 @@ public: // plantlike-specific PlantlikeStyle draw_style; v3f offset; - int rotate_degree; + float rotate_degree; bool random_offset_Y; int face_num; float plant_height; diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 0551f3b6f..20980b238 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -177,6 +177,16 @@ v3s16 MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const } } +u8 MapNode::getDegRotate(const NodeDefManager *nodemgr) const +{ + const ContentFeatures &f = nodemgr->get(*this); + if (f.param_type_2 == CPT2_DEGROTATE) + return getParam2() % 240; + if (f.param_type_2 == CPT2_COLORED_DEGROTATE) + return 10 * ((getParam2() & 0x1F) % 24); + return 0; +} + void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot) { ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2; @@ -230,6 +240,17 @@ void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot) Rotation oldrot = wallmounted_to_rot[wmountface - 2]; param2 &= ~7; param2 |= rot_to_wallmounted[(oldrot - rot) & 3]; + } else if (cpt2 == CPT2_DEGROTATE) { + int angle = param2; // in 1.5° + angle += 60 * rot; // don’t do that on u8 + angle %= 240; + param2 = angle; + } else if (cpt2 == CPT2_COLORED_DEGROTATE) { + int angle = param2 & 0x1F; // in 15° + int color = param2 & 0xE0; + angle += 6 * rot; + angle %= 24; + param2 = color | angle; } } diff --git a/src/mapnode.h b/src/mapnode.h index a9ae63ba3..28ff9e43d 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -240,6 +240,9 @@ struct MapNode u8 getWallMounted(const NodeDefManager *nodemgr) const; v3s16 getWallMountedDir(const NodeDefManager *nodemgr) const; + /// @returns Rotation in range 0–239 (in 1.5° steps) + u8 getDegRotate(const NodeDefManager *nodemgr) const; + void rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot); /*! diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 8a1f6203b..3dcac439f 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -944,7 +944,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc if (param_type_2 == CPT2_COLOR || param_type_2 == CPT2_COLORED_FACEDIR || - param_type_2 == CPT2_COLORED_WALLMOUNTED) + param_type_2 == CPT2_COLORED_WALLMOUNTED || + param_type_2 == CPT2_COLORED_DEGROTATE) palette = tsrc->getPalette(palette_name); if (drawtype == NDT_MESH && !mesh.empty()) { diff --git a/src/nodedef.h b/src/nodedef.h index 3e77624eb..b8cf7c14d 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -67,7 +67,7 @@ enum ContentParamType2 CPT2_WALLMOUNTED, // Block level like FLOWINGLIQUID CPT2_LEVELED, - // 2D rotation for things like plants + // 2D rotation CPT2_DEGROTATE, // Mesh options for plants CPT2_MESHOPTIONS, @@ -79,6 +79,8 @@ enum ContentParamType2 CPT2_COLORED_WALLMOUNTED, // Glasslike framed drawtype internal liquid level, param2 values 0 to 63 CPT2_GLASSLIKE_LIQUID_LEVEL, + // 3 bits of palette index, then degrotate + CPT2_COLORED_DEGROTATE, }; enum LiquidType diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index eca0c89d1..52baeae9d 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -685,7 +685,8 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) if (!f.palette_name.empty() && !(f.param_type_2 == CPT2_COLOR || f.param_type_2 == CPT2_COLORED_FACEDIR || - f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) + f.param_type_2 == CPT2_COLORED_WALLMOUNTED || + f.param_type_2 == CPT2_COLORED_DEGROTATE)) warningstream << "Node " << f.name.c_str() << " has a palette, but not a suitable paramtype2." << std::endl; diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index f23fbfbde..029cb6308 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -65,6 +65,7 @@ struct EnumString ScriptApiNode::es_ContentParamType2[] = {CPT2_COLORED_FACEDIR, "colorfacedir"}, {CPT2_COLORED_WALLMOUNTED, "colorwallmounted"}, {CPT2_GLASSLIKE_LIQUID_LEVEL, "glasslikeliquidlevel"}, + {CPT2_COLORED_DEGROTATE, "colordegrotate"}, {0, NULL}, }; -- cgit v1.2.3 From 3e1904fa8c4aae3448d58b7e60545a4fdd8234f3 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 5 Apr 2021 11:37:58 +0000 Subject: Devtest: Remove testnodes_show_fallback_image --- games/devtest/mods/testnodes/drawtypes.lua | 20 -------------------- games/devtest/mods/testnodes/settingtypes.txt | 4 ---- games/devtest/settingtypes.txt | 5 ----- 3 files changed, 29 deletions(-) delete mode 100644 games/devtest/mods/testnodes/settingtypes.txt (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index 02d71b50d..f6d48b06f 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -15,22 +15,6 @@ testing this node easier and more convenient. local S = minetest.get_translator("testnodes") --- If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. --- This is due to . --- This is only added to make the items more visible to avoid confusion, but you will no longer see --- the default inventory images for these items. When you want to test the default inventory image of drawtypes, --- this should be turned off. --- TODO: Remove support for fallback inventory image as soon #9209 is fixed. -local SHOW_FALLBACK_IMAGE = minetest.settings:get_bool("testnodes_show_fallback_image", false) - -local fallback_image = function(img) - if SHOW_FALLBACK_IMAGE then - return img - else - return nil - end -end - -- A regular cube minetest.register_node("testnodes:normal", { description = S("Normal Drawtype Test Node"), @@ -158,7 +142,6 @@ minetest.register_node("testnodes:torchlike", { walkable = false, sunlight_propagates = true, groups = { dig_immediate = 3 }, - inventory_image = fallback_image("testnodes_torchlike_floor.png"), }) minetest.register_node("testnodes:torchlike_wallmounted", { @@ -176,7 +159,6 @@ minetest.register_node("testnodes:torchlike_wallmounted", { walkable = false, sunlight_propagates = true, groups = { dig_immediate = 3 }, - inventory_image = fallback_image("testnodes_torchlike_floor.png"), }) @@ -192,7 +174,6 @@ minetest.register_node("testnodes:signlike", { walkable = false, groups = { dig_immediate = 3 }, sunlight_propagates = true, - inventory_image = fallback_image("testnodes_signlike.png"), }) minetest.register_node("testnodes:plantlike", { @@ -510,7 +491,6 @@ minetest.register_node("testnodes:airlike", { walkable = false, groups = { dig_immediate = 3 }, sunlight_propagates = true, - inventory_image = fallback_image("testnodes_airlike.png"), }) -- param2 changes liquid height diff --git a/games/devtest/mods/testnodes/settingtypes.txt b/games/devtest/mods/testnodes/settingtypes.txt deleted file mode 100644 index 7f753bf3e..000000000 --- a/games/devtest/mods/testnodes/settingtypes.txt +++ /dev/null @@ -1,4 +0,0 @@ -# If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. -# This is due to . -# This is only added to make the items more visible to avoid confusion, but you will no longer see the default inventory images for these items. When you want to test the default inventory image of drawtypes, this should be turned off. -testnodes_show_fallback_image (Use fallback inventory images) bool false diff --git a/games/devtest/settingtypes.txt b/games/devtest/settingtypes.txt index 40ee5845b..c4365643e 100644 --- a/games/devtest/settingtypes.txt +++ b/games/devtest/settingtypes.txt @@ -30,8 +30,3 @@ devtest_dungeon_mossycobble (Generate mossy cobblestone) bool false # If enabled, some very basic biomes will be registered. devtest_register_biomes (Register biomes) bool true - -# If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. -# This is due to . -# This is only added to make the items more visible to avoid confusion, but you will no longer see the default inventory images for these items. When you want to test the default inventory image of drawtypes, this should be turned off. -testnodes_show_fallback_image (Use fallback inventory images) bool false -- cgit v1.2.3 From 90a7bd6a0afb6509e96bcb373f95b448ee7f3b1d Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 20 Apr 2021 17:50:03 +0000 Subject: Put torch/signlike node on floor if no paramtype2 (#11074) --- builtin/game/falling.lua | 15 ++++++--------- doc/lua_api.txt | 16 +++++++++++----- games/devtest/mods/testnodes/drawtypes.lua | 24 ++++++++++++++++-------- src/client/wieldmesh.cpp | 10 ++++++---- src/mapnode.cpp | 5 ++++- 5 files changed, 43 insertions(+), 27 deletions(-) (limited to 'games/devtest/mods') diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 5450542ff..1f0a63993 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -84,9 +84,6 @@ core.register_entity(":__builtin:falling_node", { local textures if def.tiles and def.tiles[1] then local tile = def.tiles[1] - if def.drawtype == "torchlike" and def.paramtype2 ~= "wallmounted" then - tile = def.tiles[2] or def.tiles[1] - end if type(tile) == "table" then tile = tile.name end @@ -147,11 +144,7 @@ core.register_entity(":__builtin:falling_node", { -- Rotate entity if def.drawtype == "torchlike" then - if def.paramtype2 == "wallmounted" then - self.object:set_yaw(math.pi*0.25) - else - self.object:set_yaw(-math.pi*0.25) - end + self.object:set_yaw(math.pi*0.25) elseif ((node.param2 ~= 0 or def.drawtype == "nodebox" or def.drawtype == "mesh") and (def.wield_image == "" or def.wield_image == nil)) or def.drawtype == "signlike" @@ -165,8 +158,12 @@ core.register_entity(":__builtin:falling_node", { if euler then self.object:set_rotation(euler) end - elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted") then + elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted" or def.drawtype == "signlike") then local rot = node.param2 % 8 + if (def.drawtype == "signlike" and def.paramtype2 ~= "wallmounted" and def.paramtype2 ~= "colorwallmounted") then + -- Change rotation to "floor" by default for non-wallmounted paramtype2 + rot = 1 + end local pitch, yaw, roll = 0, 0, 0 if def.drawtype == "nodebox" or def.drawtype == "mesh" then if rot == 0 then diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 4c963465a..5f72b8b2b 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1140,14 +1140,20 @@ Look for examples in `games/devtest` or `games/minetest_game`. used to compensate for how `glasslike` reduces visual thickness. * `torchlike` * A single vertical texture. - * If placed on top of a node, uses the first texture specified in `tiles`. - * If placed against the underside of a node, uses the second texture - specified in `tiles`. - * If placed on the side of a node, uses the third texture specified in - `tiles` and is perpendicular to that node. + * If `paramtype2="[color]wallmounted": + * If placed on top of a node, uses the first texture specified in `tiles`. + * If placed against the underside of a node, uses the second texture + specified in `tiles`. + * If placed on the side of a node, uses the third texture specified in + `tiles` and is perpendicular to that node. + * If `paramtype2="none"`: + * Will be rendered as if placed on top of a node (see + above) and only the first texture is used. * `signlike` * A single texture parallel to, and mounted against, the top, underside or side of a node. + * If `paramtype2="[color]wallmounted", it rotates according to `param2` + * If `paramtype2="none"`, it will always be on the floor. * `plantlike` * Two vertical and diagonal textures at right-angles to each other. * See `paramtype2 = "meshoptions"` above for other options. diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index f6d48b06f..881ba75aa 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -129,14 +129,10 @@ minetest.register_node("testnodes:fencelike", { }) minetest.register_node("testnodes:torchlike", { - description = S("Torchlike Drawtype Test Node"), + description = S("Floor Torchlike Drawtype Test Node"), drawtype = "torchlike", paramtype = "light", - tiles = { - "testnodes_torchlike_floor.png", - "testnodes_torchlike_ceiling.png", - "testnodes_torchlike_wall.png", - }, + tiles = { "testnodes_torchlike_floor.png^[colorize:#FF0000:64" }, walkable = false, @@ -161,9 +157,21 @@ minetest.register_node("testnodes:torchlike_wallmounted", { groups = { dig_immediate = 3 }, }) +minetest.register_node("testnodes:signlike", { + description = S("Floor Signlike Drawtype Test Node"), + drawtype = "signlike", + paramtype = "light", + tiles = { "testnodes_signlike.png^[colorize:#FF0000:64" }, -minetest.register_node("testnodes:signlike", { + walkable = false, + groups = { dig_immediate = 3 }, + sunlight_propagates = true, + inventory_image = fallback_image("testnodes_signlike.png"), +}) + + +minetest.register_node("testnodes:signlike_wallmounted", { description = S("Wallmounted Signlike Drawtype Test Node"), drawtype = "signlike", paramtype = "light", @@ -583,7 +591,7 @@ scale("plantlike", scale("torchlike_wallmounted", S("Double-sized Wallmounted Torchlike Drawtype Test Node"), S("Half-sized Wallmounted Torchlike Drawtype Test Node")) -scale("signlike", +scale("signlike_wallmounted", S("Double-sized Wallmounted Signlike Drawtype Test Node"), S("Half-sized Wallmounted Signlike Drawtype Test Node")) scale("firelike", diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index e76bbfa9e..d9d5e57cd 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -313,12 +313,14 @@ static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n, // keep it } else if (f.param_type_2 == CPT2_WALLMOUNTED || f.param_type_2 == CPT2_COLORED_WALLMOUNTED) { - if (f.drawtype == NDT_TORCHLIKE) - n.setParam2(1); - else if (f.drawtype == NDT_SIGNLIKE || + if (f.drawtype == NDT_TORCHLIKE || + f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_NODEBOX || - f.drawtype == NDT_MESH) + f.drawtype == NDT_MESH) { n.setParam2(4); + } + } else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE) { + n.setParam2(1); } gen.renderSingle(n.getContent(), n.getParam2()); diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 20980b238..c885bfe1d 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -159,8 +159,11 @@ u8 MapNode::getWallMounted(const NodeDefManager *nodemgr) const { const ContentFeatures &f = nodemgr->get(*this); if (f.param_type_2 == CPT2_WALLMOUNTED || - f.param_type_2 == CPT2_COLORED_WALLMOUNTED) + f.param_type_2 == CPT2_COLORED_WALLMOUNTED) { return getParam2() & 0x07; + } else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE) { + return 1; + } return 0; } -- cgit v1.2.3 From daf862a38a0df84a7e4cd387e41c55ae4467f4d2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 21 Apr 2021 16:42:34 +0200 Subject: Fix devtest Lua error fallback_image() was removed in 3e1904fa8c4aae3448d58b7e60545a4fdd8234f3, which was written after this PR but merged before it. --- games/devtest/mods/testnodes/drawtypes.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'games/devtest/mods') diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index 881ba75aa..3bf631714 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -167,7 +167,6 @@ minetest.register_node("testnodes:signlike", { walkable = false, groups = { dig_immediate = 3 }, sunlight_propagates = true, - inventory_image = fallback_image("testnodes_signlike.png"), }) -- cgit v1.2.3 From 228f1c67704ab8014d30a3301bd15a1a88324ce0 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 28 Apr 2021 06:38:47 +0000 Subject: Fix rotation for falling mesh degrotate nodes (#11159) --- builtin/game/falling.lua | 8 ++++++++ games/devtest/mods/experimental/commands.lua | 8 +++++--- games/devtest/mods/testnodes/drawtypes.lua | 13 +++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) (limited to 'games/devtest/mods') diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 1f0a63993..2cc0d8fac 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -205,6 +205,14 @@ core.register_entity(":__builtin:falling_node", { end end self.object:set_rotation({x=pitch, y=yaw, z=roll}) + elseif (def.drawtype == "mesh" and def.paramtype2 == "degrotate") then + local p2 = (node.param2 - (def.place_param2 or 0)) % 240 + local yaw = (p2 / 240) * (math.pi * 2) + self.object:set_yaw(yaw) + elseif (def.drawtype == "mesh" and def.paramtype2 == "colordegrotate") then + local p2 = (node.param2 % 32 - (def.place_param2 or 0) % 32) % 24 + local yaw = (p2 / 24) * (math.pi * 2) + self.object:set_yaw(yaw) end end end, diff --git a/games/devtest/mods/experimental/commands.lua b/games/devtest/mods/experimental/commands.lua index 8bfa467e1..e42ae954d 100644 --- a/games/devtest/mods/experimental/commands.lua +++ b/games/devtest/mods/experimental/commands.lua @@ -131,10 +131,11 @@ local function place_nodes(param) p2_max = 63 elseif def.paramtype2 == "leveled" then p2_max = 127 - elseif def.paramtype2 == "degrotate" and def.drawtype == "plantlike" then - p2_max = 179 + elseif def.paramtype2 == "degrotate" and (def.drawtype == "plantlike" or def.drawtype == "mesh") then + p2_max = 239 elseif def.paramtype2 == "colorfacedir" or def.paramtype2 == "colorwallmounted" or + def.paramtype2 == "colordegrotate" or def.paramtype2 == "color" then p2_max = 255 end @@ -143,7 +144,8 @@ local function place_nodes(param) -- Skip undefined param2 values if not ((def.paramtype2 == "meshoptions" and p2 % 8 > 4) or (def.paramtype2 == "colorwallmounted" and p2 % 8 > 5) or - (def.paramtype2 == "colorfacedir" and p2 % 32 > 23)) then + ((def.paramtype2 == "colorfacedir" or def.paramtype2 == "colordegrotate") + and p2 % 32 > 23)) then minetest.set_node(pos, { name = itemstring, param2 = p2 }) nodes_placed = nodes_placed + 1 diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua index 3bf631714..2bc7ec2e3 100644 --- a/games/devtest/mods/testnodes/drawtypes.lua +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -254,11 +254,11 @@ minetest.register_node("testnodes:mesh_degrotate", { drawtype = "mesh", paramtype = "light", paramtype2 = "degrotate", - mesh = "testnodes_pyramid.obj", + mesh = "testnodes_ocorner.obj", tiles = { "testnodes_mesh_stripes2.png" }, on_rightclick = rotate_on_rightclick, - place_param2 = 7, + place_param2 = 10, -- 15° sunlight_propagates = true, groups = { dig_immediate = 3 }, }) @@ -266,14 +266,15 @@ minetest.register_node("testnodes:mesh_degrotate", { minetest.register_node("testnodes:mesh_colordegrotate", { description = S("Color Degrotate Mesh Drawtype Test Node"), drawtype = "mesh", + paramtype = "light", paramtype2 = "colordegrotate", palette = "testnodes_palette_facedir.png", - mesh = "testnodes_pyramid.obj", - tiles = { "testnodes_mesh_stripes2.png" }, + mesh = "testnodes_ocorner.obj", + tiles = { "testnodes_mesh_stripes3.png" }, on_rightclick = rotate_on_rightclick, - -- color index 1, 7 steps rotated - place_param2 = 1 * 2^5 + 7, + -- color index 1, 1 step (=15°) rotated + place_param2 = 1 * 2^5 + 1, sunlight_propagates = true, groups = { dig_immediate = 3 }, }) -- cgit v1.2.3