From b1bc35f68a9a19bb23363d51b79822894881a484 Mon Sep 17 00:00:00 2001 From: BadToad Date: Fri, 23 Sep 2016 23:33:24 -0500 Subject: [PATCH] Use register_lbm to update existing formspecs so that SHIFT-CLICK works for nodes which existed prior to that formspec change. Also, fix errors (crashed) when using affect and removeaffect chat commands. --- mods/affects/chatcommands.lua | 12 ++++++---- mods/cottages/nodes_anvil.lua | 17 ++++++++++++- mods/cottages/nodes_barrel.lua | 40 +++++++++++++++++++++---------- mods/cottages/nodes_chests.lua | 13 ++++++++++ mods/cottages/nodes_furniture.lua | 25 +++++++++++++++---- mods/cottages/nodes_straw.lua | 30 ++++++++++++++++++++++- mods/default/nodes.lua | 13 ++++++++++ 7 files changed, 126 insertions(+), 24 deletions(-) diff --git a/mods/affects/chatcommands.lua b/mods/affects/chatcommands.lua index 474ead1..7c4e240 100644 --- a/mods/affects/chatcommands.lua +++ b/mods/affects/chatcommands.lua @@ -5,7 +5,9 @@ minetest.register_chatcommand("affect",{ privs = {affects=true}, func = function (name, param) local aname, affectid = string.match(param, "([^ ]+) (.+)") - if ( affects.affectPlayer(aname,affectid) ) then + if ( aname == nil or aname == "" or affectid == nil or affectid == '' ) then + minetest.chat_send_player(name, "Syntax: affect ") + elseif ( affects.affectPlayer(aname,affectid) ) then minetest.chat_send_player(name,aname.." has been affected by "..affects._affects[affectid].name) else minetest.chat_send_player(name,"Unable to affect "..aname.." with "..affectid) @@ -15,14 +17,16 @@ minetest.register_chatcommand("affect",{ minetest.register_chatcommand("removeaffect",{ params = " [affectid]", - description = "Removes and affect or all affects from a player", + description = "Remove an affect or all affects from a player", privs = {affects=true}, func = function (name, param) local aname, affectid = string.match(param, "([^ ]+) (.+)") - if ( affects.removeAffect(aname,affectid) ) then + if ( aname == nil or aname == "" ) then + minetest.chat_send_player(name, "Syntax: removeaffect [affectid]") + elseif ( affects.removeAffect(aname,affectid) ) then minetest.chat_send_player(name,"Affect removed from "..aname) else minetest.chat_send_player(name,"Unable to remove affects") end end -}) \ No newline at end of file +}) diff --git a/mods/cottages/nodes_anvil.lua b/mods/cottages/nodes_anvil.lua index 2bf4596..cbbb497 100644 --- a/mods/cottages/nodes_anvil.lua +++ b/mods/cottages/nodes_anvil.lua @@ -46,8 +46,8 @@ local cottages_anvil_formspec = "label[0,3.0;"..S("Punch anvil with hammer to").."]".. "label[0,3.3;"..S("repair tool in workpiece-slot.").."]".. "list[current_player;main;0,4;8,4;]" - .."listring[current_player;main]".."listring[current_name;hammer]" .."listring[current_player;main]".."listring[current_name;input]" + .."listring[current_player;main]".."listring[current_name;hammer]" minetest.register_node("cottages:anvil", { @@ -303,3 +303,18 @@ minetest.register_craft({ {'', cottages.craftitem_stick, '' } } }) +-------------------------------------------------------------------------------- +-- Update existing nodes to use SHIFT-CLICK +-------------------------------------------------------------------------------- +minetest.register_lbm({ + name = "cottages:anvil_lbm", + nodenames = {"cottages:anvil"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + cottages_anvil_formspec.. + "label[2.5,-0.5;"..S("Owner: %s"):format(meta:get_string('owner') or "").."]"); + end, +}) + diff --git a/mods/cottages/nodes_barrel.lua b/mods/cottages/nodes_barrel.lua index 03ce6aa..1c0c930 100644 --- a/mods/cottages/nodes_barrel.lua +++ b/mods/cottages/nodes_barrel.lua @@ -25,25 +25,25 @@ local S = cottages.S barrel = {}; +local barrel_formspec = "size[8,9]".. + "image[2.6,2;2,3;default_sandstone.png^[lowpart:".. + -- (100-percent)..":default_desert_stone.png]".. -- TODO: better images + "50:default_desert_stone.png]".. -- TODO: better images + "label[2.2,0;"..S("Pour:").."]".. + "list[current_name;input;3,0.5;1,1;]".. + "label[5,3.3;"..S("Fill:").."]".. + "list[current_name;output;5,3.8;1,1;]".. + "list[current_player;main;0,5;8,4;]" + .."listring[current_name;output]".."listring[current_player;main]" + .."listring[current_name;input]".."listring[current_player;main]" + -- prepare formspec barrel.on_construct = function( pos ) local meta = minetest.get_meta(pos); local percent = math.random( 1, 100 ); -- TODO: show real filling - meta:set_string( 'formspec', - "size[8,9]".. - "image[2.6,2;2,3;default_sandstone.png^[lowpart:".. - (100-percent)..":default_desert_stone.png]".. -- TODO: better images - "label[2.2,0;"..S("Pour:").."]".. - "list[current_name;input;3,0.5;1,1;]".. - "label[5,3.3;"..S("Fill:").."]".. - "list[current_name;output;5,3.8;1,1;]".. - "list[current_player;main;0,5;8,4;]" - .."listring[current_name;output]".."listring[current_player;main]" - .."listring[current_name;input]".."listring[current_player;main]" - ) - + meta:set_string( 'formspec', barrel_formspec) meta:set_string( 'liquid_type', '' ); -- which liquid is in the barrel? meta:set_int( 'liquid_level', 0 ); -- how much of the liquid is in there? @@ -223,3 +223,17 @@ minetest.register_craft({ {"cottages:tub"}, }, }) + +-------------------------------------------------------------------------------- +-- Update existing nodes to use SHIFT-CLICK +-------------------------------------------------------------------------------- +minetest.register_lbm({ + name = "cottages:barrel_lbm", + nodenames = {"cottages:barrel"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", barrel_formspec) + end, +}) + diff --git a/mods/cottages/nodes_chests.lua b/mods/cottages/nodes_chests.lua index c099749..41b69b5 100644 --- a/mods/cottages/nodes_chests.lua +++ b/mods/cottages/nodes_chests.lua @@ -59,3 +59,16 @@ minetest.register_node("cottages:chest_storage", { is_ground_content = false, }) +-------------------------------------------------------------------------------- +-- Update existing nodes to use SHIFT-CLICK +-------------------------------------------------------------------------------- +minetest.register_lbm({ + name = "cottages:chests_lbm", + nodenames = {"cottages:chest_private", "cottages:chest_work", "cottages:chest_storage"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", default.chest_formspec) + end, +}) + diff --git a/mods/cottages/nodes_furniture.lua b/mods/cottages/nodes_furniture.lua index b56b038..9d7251a 100644 --- a/mods/cottages/nodes_furniture.lua +++ b/mods/cottages/nodes_furniture.lua @@ -189,6 +189,12 @@ end minetest.register_node("cottages:table", cottages_table_def ); +local cottage_shelf_formspec = + "size[8,8]".. + "list[current_name;main;0,0;8,3;]".. + "list[current_player;main;0,4;8,4;]".. + "listring[]" + -- looks better than two slabs impersonating a shelf; also more 3d than a bookshelf -- the infotext shows if it's empty or not minetest.register_node("cottages:shelf", { @@ -221,11 +227,7 @@ minetest.register_node("cottages:shelf", { local meta = minetest.get_meta(pos); - meta:set_string("formspec", - "size[8,8]".. - "list[current_name;main;0,0;8,3;]".. - "list[current_player;main;0,4;8,4;]".. - "listring[current_name;main]".."listring[current_player;main]") + meta:set_string("formspec", cottage_shelf_formspec) meta:set_string("infotext", S("open storage shelf")) local inv = meta:get_inventory(); inv:set_size("main", 24); @@ -390,3 +392,16 @@ minetest.register_craft({ } }) +-------------------------------------------------------------------------------- +-- Update existing nodes to use SHIFT-CLICK +-------------------------------------------------------------------------------- +minetest.register_lbm({ + name = "cottages:shelf_lbm", + nodenames = {"cottages:shelf"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", cottage_shelf_formspec) + end, +}) + diff --git a/mods/cottages/nodes_straw.lua b/mods/cottages/nodes_straw.lua index 3940eca..361903f 100644 --- a/mods/cottages/nodes_straw.lua +++ b/mods/cottages/nodes_straw.lua @@ -99,8 +99,8 @@ local cottages_formspec_treshing_floor = "label[0,3.0;"..S("to get straw and seeds from wheat.").."]".. "list[current_player;main;0,4;8,4;]" .."listring[current_name;straw]".."listring[current_player;main]" - .."listring[current_name;seeds]".."listring[current_player;main]" .."listring[current_name;harvest]".."listring[current_player;main]" + .."listring[current_name;seeds]".."listring[current_player;main]" minetest.register_node("cottages:threshing_floor", { drawtype = "nodebox", @@ -576,3 +576,31 @@ minetest.register_craft({ {"cottages:straw","cottages:straw","cottages:straw"}, }, }) + +-------------------------------------------------------------------------------- +-- Update existing nodes to use SHIFT-CLICK +-------------------------------------------------------------------------------- +minetest.register_lbm({ + name = "cottages:threshing_floor_lbm", + nodenames = {"cottages:threshing_floor"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + cottages_formspec_treshing_floor.. + "label[2.5,-0.5;"..S("Owner: %s"):format(meta:get_string('owner') or "").."]" ); + end, +}) + +minetest.register_lbm({ + name = "cottages:handmill_lbm", + nodenames = {"cottages:handmill"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + cottages_handmill_formspec.. + "label[2.5,-0.5;"..S("Owner: %s"):format(meta:get_string('owner') or "").."]" ); + end, +}) + diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 28fb31a..7567b47 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -925,6 +925,19 @@ minetest.register_abm({ end, }) +-------------------------------------------------------------------------------- +-- Update existing nodes to use SHIFT-CLICK +-------------------------------------------------------------------------------- +minetest.register_lbm({ + name = "default:chest_lbm", + nodenames = {"default:chest", "default:npc_chest"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + meta:set_string("formspec",default.chest_formspec) + end, +}) + local function has_locked_chest_privilege(meta, player) if meta ~= nil then