1
0
mirror of https://github.com/Sokomine/cottages.git synced 2024-12-27 11:10:36 +01:00

added option to make machines public

This commit is contained in:
Sokomine 2019-02-16 09:56:15 +01:00
parent 739f3a7ac4
commit 3197c4a6bc
5 changed files with 98 additions and 28 deletions

42
functions.lua Normal file
View File

@ -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

View File

@ -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");

View File

@ -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?

View File

@ -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? =

View File

@ -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()