forked from nalc/homedecor_modpack
		
	Merge branch 'keys_api' into 'master'
Keys api See merge request VanessaE/homedecor_modpack!11
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
unused_args = false
 | 
			
		||||
allow_defined_top = true
 | 
			
		||||
max_comment_line_length = 999
 | 
			
		||||
 | 
			
		||||
read_globals = {
 | 
			
		||||
	"DIR_DELIM",
 | 
			
		||||
 
 | 
			
		||||
@@ -146,7 +146,11 @@ function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, no
 | 
			
		||||
	local forceright = placer:get_player_control()["sneak"]
 | 
			
		||||
	local fdir = minetest.dir_to_facedir(placer:get_look_dir())
 | 
			
		||||
 | 
			
		||||
	local is_right_wing = node1 == minetest.get_node({ x = pos.x + homedecor.fdir_to_left[fdir+1][1], y=pos.y, z = pos.z + homedecor.fdir_to_left[fdir+1][2] }).name
 | 
			
		||||
	local is_right_wing = node1 == minetest.get_node(
 | 
			
		||||
		{
 | 
			
		||||
			x = pos.x + homedecor.fdir_to_left[fdir+1][1],
 | 
			
		||||
			y = pos.y,
 | 
			
		||||
			z = pos.z + homedecor.fdir_to_left[fdir+1][2] }).name
 | 
			
		||||
	if forceright or is_right_wing then
 | 
			
		||||
		node1, node2 = node1_right, node2_right
 | 
			
		||||
	end
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,8 @@ function homedecor.handle_inventory(name, def, original_def)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	def.can_dig = def.can_dig or default_can_dig
 | 
			
		||||
	def.on_metadata_inventory_move = def.on_metadata_inventory_move or function(pos, from_list, from_index, to_list, to_index, count, player)
 | 
			
		||||
	def.on_metadata_inventory_move = def.on_metadata_inventory_move or
 | 
			
		||||
			function(pos, from_list, from_index, to_list, to_index, count, player)
 | 
			
		||||
		minetest.log("action", S("@1 moves stuff in @2 at @3",
 | 
			
		||||
			player:get_player_name(), name, minetest.pos_to_string(pos)
 | 
			
		||||
		))
 | 
			
		||||
@@ -114,57 +115,82 @@ function homedecor.handle_inventory(name, def, original_def)
 | 
			
		||||
 | 
			
		||||
		local allow_move = def.allow_metadata_inventory_move
 | 
			
		||||
		def.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
 | 
			
		||||
			local meta = minetest.get_meta(pos)
 | 
			
		||||
			local owner = meta:get_string("owner")
 | 
			
		||||
			local playername = player:get_player_name()
 | 
			
		||||
 | 
			
		||||
			if playername == owner or
 | 
			
		||||
					minetest.check_player_privs(playername, "protection_bypass") then
 | 
			
		||||
				return allow_move and
 | 
			
		||||
						allow_move(pos, from_list, from_index, to_list, to_index, count, player) or
 | 
			
		||||
						count
 | 
			
		||||
			if not default.can_interact_with_node(player, pos) then
 | 
			
		||||
				minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4",
 | 
			
		||||
					player:get_player_name(), name,
 | 
			
		||||
					minetest.get_meta(pos):get_string("owner"), minetest.pos_to_string(pos)
 | 
			
		||||
				))
 | 
			
		||||
				return 0
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4",
 | 
			
		||||
				playername, name, owner, minetest.pos_to_string(pos)
 | 
			
		||||
			))
 | 
			
		||||
			return 0
 | 
			
		||||
			return allow_move and allow_move(pos, from_list, from_index, to_list, to_index, count, player) or
 | 
			
		||||
					count
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		local allow_put = def.allow_metadata_inventory_put
 | 
			
		||||
		def.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
 | 
			
		||||
			local meta = minetest.get_meta(pos)
 | 
			
		||||
			local owner = meta:get_string("owner")
 | 
			
		||||
			local playername = player:get_player_name()
 | 
			
		||||
 | 
			
		||||
			if playername == owner or
 | 
			
		||||
					minetest.check_player_privs(playername, "protection_bypass") then
 | 
			
		||||
				return allow_put and allow_put(pos, listname, index, stack, player) or
 | 
			
		||||
						stack:get_count()
 | 
			
		||||
			if not default.can_interact_with_node(player, pos) then
 | 
			
		||||
				minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4",
 | 
			
		||||
					player:get_player_name(), name,
 | 
			
		||||
					minetest.get_meta(pos):get_string("owner"), minetest.pos_to_string(pos)
 | 
			
		||||
				))
 | 
			
		||||
				return 0
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4",
 | 
			
		||||
				playername, name, owner, minetest.pos_to_string(pos)
 | 
			
		||||
			))
 | 
			
		||||
			return 0
 | 
			
		||||
			return allow_put and allow_put(pos, listname, index, stack, player) or
 | 
			
		||||
					stack:get_count()
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		local allow_take = def.allow_metadata_inventory_take
 | 
			
		||||
		def.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
 | 
			
		||||
			if not default.can_interact_with_node(player, pos) then
 | 
			
		||||
				minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4",
 | 
			
		||||
					player:get_player_name(), name,
 | 
			
		||||
					minetest.get_meta(pos):get_string("owner"), minetest.pos_to_string(pos)
 | 
			
		||||
				))
 | 
			
		||||
				return 0
 | 
			
		||||
			end
 | 
			
		||||
			return allow_take and allow_take(pos, listname, index, stack, player) or
 | 
			
		||||
					stack:get_count()
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		local can_dig = def.can_dig
 | 
			
		||||
		def.can_dig = function(pos, player)
 | 
			
		||||
			return default.can_interact_with_node(player, pos) and (can_dig and (can_dig(pos, player) or true))
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		def.on_key_use = function(pos, player)
 | 
			
		||||
			local secret = minetest.get_meta(pos):get_string("key_lock_secret")
 | 
			
		||||
			local itemstack = player:get_wielded_item()
 | 
			
		||||
			local key_meta = itemstack:get_meta()
 | 
			
		||||
 | 
			
		||||
			if secret ~= key_meta:get_string("secret") then
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			minetest.show_formspec(
 | 
			
		||||
				player:get_player_name(),
 | 
			
		||||
				name.."_locked",
 | 
			
		||||
				minetest.get_meta(pos):get_string("formspec")
 | 
			
		||||
			)
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		def.on_skeleton_key_use = function(pos, player, newsecret)
 | 
			
		||||
			local meta = minetest.get_meta(pos)
 | 
			
		||||
			local owner = meta:get_string("owner")
 | 
			
		||||
			local playername = player:get_player_name()
 | 
			
		||||
 | 
			
		||||
			if playername == owner or
 | 
			
		||||
					minetest.check_player_privs(playername, "protection_bypass") then
 | 
			
		||||
				return allow_take and allow_take(pos, listname, index, stack, player) or
 | 
			
		||||
						stack:get_count()
 | 
			
		||||
			-- verify placer is owner
 | 
			
		||||
			if owner ~= playername then
 | 
			
		||||
				minetest.record_protection_violation(pos, playername)
 | 
			
		||||
				return nil
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4",
 | 
			
		||||
				playername, name, owner, minetest.pos_to_string(pos)
 | 
			
		||||
			))
 | 
			
		||||
			return 0
 | 
			
		||||
			local secret = meta:get_string("key_lock_secret")
 | 
			
		||||
			if secret == "" then
 | 
			
		||||
				secret = newsecret
 | 
			
		||||
				meta:set_string("key_lock_secret", secret)
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			return secret, meta:get_string("description"), owner
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								homedecor_common/mod.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								homedecor_common/mod.conf
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
name = homedecor_common
 | 
			
		||||
description = Homedecor mod: common
 | 
			
		||||
depends = default, creative
 | 
			
		||||
optional_depends = intllib
 | 
			
		||||
@@ -22,7 +22,8 @@ homedecor.box = {
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
	bar_y = function(radius) return {-radius, -0.5, -radius, radius, 0.5, radius} end,
 | 
			
		||||
	cuboid = function(radius_x, radius_y, radius_z) return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end,
 | 
			
		||||
	cuboid = function(radius_x, radius_y, radius_z)
 | 
			
		||||
		return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
homedecor.nodebox = {
 | 
			
		||||
 
 | 
			
		||||
@@ -70,7 +70,11 @@ function homedecor.register(name, original_def)
 | 
			
		||||
			if not fdir or fdir > 3 then return end
 | 
			
		||||
 | 
			
		||||
			if expand.right and expand.forward ~= "air" then
 | 
			
		||||
				local right_pos = { x=pos.x+homedecor.fdir_to_right[fdir+1][1], y=pos.y, z=pos.z+homedecor.fdir_to_right[fdir+1][2] }
 | 
			
		||||
				local right_pos = {
 | 
			
		||||
					x = pos.x + homedecor.fdir_to_right[fdir+1][1],
 | 
			
		||||
					y = pos.y,
 | 
			
		||||
					z = pos.z + homedecor.fdir_to_right[fdir+1][2]
 | 
			
		||||
				}
 | 
			
		||||
				local node = minetest.get_node(right_pos).name
 | 
			
		||||
				if node == expand.right or node == placeholder_node then
 | 
			
		||||
					minetest.remove_node(right_pos)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user