1
0
mirror of https://github.com/Sokomine/cottages.git synced 2026-01-12 12:05:49 +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

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