From 3197c4a6bc97860b4f5cbc09282a98d392df0e85 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 16 Feb 2019 09:56:15 +0100 Subject: [PATCH] added option to make machines public --- functions.lua | 42 ++++++++++++++++++++++++++++++++++++++ init.lua | 1 + locale/de.txt | 12 +++++++++++ locale/template.txt | 22 +++++++++++++++----- nodes_straw.lua | 49 ++++++++++++++++++++++++--------------------- 5 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 functions.lua diff --git a/functions.lua b/functions.lua new file mode 100644 index 0000000..81d88bc --- /dev/null +++ b/functions.lua @@ -0,0 +1,42 @@ + +local S = cottages.S + +--- if no owner is set, all players may use the node; else only the owner +cottages.player_can_use = function( meta, player ) + if( not( player) or not( meta )) then + return false; + end + local pname = player:get_player_name(); + local owner = meta:get_string('owner' ); + local public = meta:get_string('public') + if( not(owner) or owner=="" or owner==pname or public=="public") then + return true; + end + return false; +end + + +-- call this in on_receive_fields and add suitable buttons in order +-- to switch between public and private use +cottages.switch_public = function(pos, formname, fields, sender, name_of_the_thing) + -- switch between public and private + local meta = minetest.get_meta(pos) + local public = meta:get_string("public") + local owner = meta:get_string("owner") + if( sender and sender:get_player_name() == owner and fields.public) then + if( public ~= "public") then + meta:set_string("public", "public") + meta:set_string("infotext", + S("Public "..name_of_the_thing.." (owned by %s)"):format(owner)) + minetest.chat_send_player(owner, + S("Your "..name_of_the_thing.." can now be used by other players as well.")) + else + meta:set_string("public", "") + meta:set_string("infotext", + S("Private "..name_of_the_thing.." (owned by %s)"):format(owner)) + minetest.chat_send_player(owner, + S("Your "..name_of_the_thing.." can only be used by yourself.")) + end + return true + end +end diff --git a/init.lua b/init.lua index a2a4751..29227a9 100644 --- a/init.lua +++ b/init.lua @@ -57,6 +57,7 @@ cottages.handmill_product[ 'default:coal_lump'] = 'dye:black 6'; cottages.handmill_max_per_turn = 20; cottages.handmill_min_per_turn = 0; +dofile(minetest.get_modpath("cottages").."/functions.lua"); -- uncomment parts you do not want dofile(minetest.get_modpath("cottages").."/nodes_furniture.lua"); diff --git a/locale/de.txt b/locale/de.txt index 9677a3b..8ff2979 100644 --- a/locale/de.txt +++ b/locale/de.txt @@ -109,6 +109,8 @@ straw = Stroh threshing floor = Dreschboden Threshing floor = Dreschboden Threshing floor (owned by %s) = Dreschboden (gehoert %s) +Public threshing floor (owned by %s) = Öffentlicher Dreschboden (gehoert %s) +Private threshing floor (owned by %s) = Privater Dreschboden (gehoert %s) Harvested wheat: = Geernteter Weizen Straw: = Stroh Seeds: = Koerner @@ -120,6 +122,8 @@ You have threshed the last %s wheat. = Du hast die letzten %s Weizenaehren gedr mill, powered by punching = Muehle, durch Schlagen antreiben Mill, powered by punching = Muehle, durch Schlagen antreiben Mill, powered by punching (owned by %s) = Muehle, durch Schlagen antreiben (gehoert %s) +Public mill, powered by punching (owned by %s) = Öffentliche Muehle, durch Schlagen antreiben (gehoert %s) +Private mill, powered by punching (owned by %s) = Private Muehle, durch Schlagen antreiben (gehoert %s) Wheat seeds: = Weizenkoerner Flour: = Mehl Mill = Muehle @@ -128,3 +132,11 @@ Punch this hand-driven mill = Schlage auf diese handbetriebene Muehle to convert wheat seeds into flour. = um Weizenkoerner in Mehl umzuwandeln. You have grinded %s wheat seeds (%s are left). = Du hast %s Weizenkoerner gemahlen (%s bleiben uebrig). You have grinded the last %s wheat seeds. = Du hast die letzten %s Weizenkoerner gemahlen. + +Your threshing floor can now be used by other players as well. = Dein Dreschboden kann jetzt auch von anderen Spielern benutzt werden. +Your mill, powered by punching can now be used by other players as well. = Deine Mühle kann jetzt auch von anderen Spielern benutzt werden. + +Your threshing floor can only be used by yourself. = Dein Dreschboden kann nur noch von dir benutzt werden. +Your mill, powered by punching can only be used by yourself. = Deine Mühle kann nur noch von dir benutzt werden. + +Public? = Öffentlich? diff --git a/locale/template.txt b/locale/template.txt index cbc6990..36b3f87 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -105,9 +105,11 @@ Reet for thatching = layer of straw = straw bale = straw = -threshing floor = -Threshing floor = -Threshing floor (owned by %s) = +threshing floor = +Threshing floor = +Threshing floor (owned by %s) = +Public threshing floor (owned by %s) = +Private threshing floor (owned by %s) = Harvested wheat: = Straw: = Seeds: = @@ -117,8 +119,10 @@ to get straw and seeds from wheat. = You have threshed %s wheat (%s are left). = You have threshed the last %s wheat. = mill, powered by punching = -Mill, powered by punching = -Mill, powered by punching (owned by %s) = +Mill, powered by punching = +Mill, powered by punching (owned by %s) = +Public mill, powered by punching (owned by %s) = +Private mill, powered by punching (owned by %s) = Wheat seeds: = Flour: = Mill = @@ -127,3 +131,11 @@ Punch this hand-driven mill = to convert wheat seeds into flour. = You have grinded %s wheat seeds (%s are left). = You have grinded the last %s wheat seeds. = + +Your threshing floor can now be used by other players as well. = +Your mill, powered by punching can now be used by other players as well. = + +Your threshing floor can only be used by yourself. = +Your mill, powered by punching can only be used by yourself. = + +Public? = diff --git a/nodes_straw.lua b/nodes_straw.lua index c19b869..ff30bf8 100644 --- a/nodes_straw.lua +++ b/nodes_straw.lua @@ -6,18 +6,6 @@ local S = cottages.S -local cottages_can_use = function( meta, player ) - if( not( player) or not( meta )) then - return false; - end - local pname = player:get_player_name(); - local owner = meta:get_string('owner' ); - if( not(owner) or owner=="" or owner==pname ) then - return true; - end - return false; -end - -- an even simpler from of bed - usually for animals -- it is a nodebox and not wallmounted because that makes it easier to replace beds with straw mats @@ -91,6 +79,7 @@ local cottages_formspec_treshing_floor = "size[8,8]".. "image[1.5,0;1,1;"..cottages.texture_stick.."]".. "image[0,1;1,1;farming_wheat.png]".. + "button_exit[6.8,0.0;1.5,0.5;public;"..S("Public?").."]".. "list[current_name;harvest;1,1;2,1;]".. "list[current_name;straw;5,0;2,2;]".. "list[current_name;seeds;5,2;2,2;]".. @@ -109,7 +98,8 @@ minetest.register_node("cottages:threshing_floor", { tiles = {"cottages_junglewood.png^farming_wheat.png","cottages_junglewood.png","cottages_junglewood.png^"..cottages.texture_stick}, paramtype = "light", paramtype2 = "facedir", - groups = {cracky=2}, + -- can be digged with axe and pick + groups = {cracky=2, choppy=2}, is_ground_content = false, node_box = { type = "fixed", @@ -131,23 +121,29 @@ minetest.register_node("cottages:threshing_floor", { }, on_construct = function(pos) local meta = minetest.get_meta(pos); - meta:set_string("infotext", S("Threshing floor")); + meta:set_string("infotext", S("Public threshing floor")); local inv = meta:get_inventory(); inv:set_size("harvest", 2); inv:set_size("straw", 4); inv:set_size("seeds", 4); meta:set_string("formspec", cottages_formspec_treshing_floor ); + meta:set_string("public", "public") end, after_place_node = function(pos, placer) local meta = minetest.get_meta(pos); meta:set_string("owner", placer:get_player_name() or ""); - meta:set_string("infotext", S("Threshing floor (owned by %s)"):format(meta:get_string("owner") or "")); + meta:set_string("infotext", S("Private threshing floor (owned by %s)"):format(meta:get_string("owner") or "")); meta:set_string("formspec", cottages_formspec_treshing_floor.. "label[2.5,-0.5;"..S("Owner: %s"):format(meta:get_string("owner") or "").."]" ); + meta:set_string("public", "private") end, + on_receive_fields = function(pos, formname, fields, sender) + cottages.switch_public(pos, formname, fields, sender, 'threshing floor') + end, + can_dig = function(pos,player) local meta = minetest.get_meta(pos); @@ -167,7 +163,7 @@ minetest.register_node("cottages:threshing_floor", { allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) local meta = minetest.get_meta(pos) - if( not( cottages_can_use( meta, player ))) then + if( not( cottages.player_can_use( meta, player ))) then return 0 end return count; @@ -182,7 +178,7 @@ minetest.register_node("cottages:threshing_floor", { return 0; end - if( not( cottages_can_use( meta, player ))) then + if( not( cottages.player_can_use( meta, player ))) then return 0 end return stack:get_count() @@ -190,7 +186,7 @@ minetest.register_node("cottages:threshing_floor", { allow_metadata_inventory_take = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) - if( not( cottages_can_use( meta, player ))) then + if( not( cottages.player_can_use( meta, player ))) then return 0 end return stack:get_count() @@ -348,6 +344,7 @@ minetest.register_node("cottages:threshing_floor", { local cottages_handmill_formspec = "size[8,8]".. "image[0,1;1,1;"..cottages.texture_wheat_seed.."]".. + "button_exit[6.0,0.0;1.5,0.5;public;"..S("Public?").."]".. "list[current_name;seeds;1,1;1,1;]".. "list[current_name;flour;5,1;2,2;]".. "label[0,0.5;"..S("Wheat seeds:").."]".. @@ -380,22 +377,28 @@ minetest.register_node("cottages:handmill", { }, on_construct = function(pos) local meta = minetest.get_meta(pos); - meta:set_string("infotext", S("Mill, powered by punching")); + meta:set_string("infotext", S("Public mill, powered by punching")); local inv = meta:get_inventory(); inv:set_size("seeds", 1); inv:set_size("flour", 4); meta:set_string("formspec", cottages_handmill_formspec ); + meta:set_string("public", "public") end, after_place_node = function(pos, placer) local meta = minetest.get_meta(pos); meta:set_string("owner", placer:get_player_name() or ""); - meta:set_string("infotext", S("Mill, powered by punching (owned by %s)"):format(meta:get_string("owner") or "")); + meta:set_string("infotext", S("Private mill, powered by punching (owned by %s)"):format(meta:get_string("owner") or "")); meta:set_string("formspec", cottages_handmill_formspec.. "label[2.5,-0.5;"..S("Owner: %s"):format(meta:get_string('owner') or "").."]" ); + meta:set_string("public", "private") end, + on_receive_fields = function(pos, formname, fields, sender) + cottages.switch_public(pos, formname, fields, sender, 'mill, powered by punching') + end, + can_dig = function(pos,player) local meta = minetest.get_meta(pos); @@ -414,7 +417,7 @@ minetest.register_node("cottages:handmill", { allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) local meta = minetest.get_meta(pos) - if( not( cottages_can_use( meta, player ))) then + if( not( cottages.player_can_use( meta, player ))) then return 0 end return count; @@ -428,7 +431,7 @@ minetest.register_node("cottages:handmill", { return 0; end - if( not( cottages_can_use( meta, player ))) then + if( not( cottages.player_can_use( meta, player ))) then return 0 end return stack:get_count() @@ -436,7 +439,7 @@ minetest.register_node("cottages:handmill", { allow_metadata_inventory_take = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) - if( not( cottages_can_use( meta, player ))) then + if( not( cottages.player_can_use( meta, player ))) then return 0 end return stack:get_count()