diff --git a/depends.txt b/depends.txt index d3f8774..26a770c 100644 --- a/depends.txt +++ b/depends.txt @@ -1,4 +1,5 @@ default +basic_materials? creative? ilights? gloopblocks? diff --git a/init.lua b/init.lua index 53495f2..e18ba8a 100644 --- a/init.lua +++ b/init.lua @@ -2,6 +2,10 @@ local modpath = minetest.get_modpath("simple_streetlights") +streetlights = {} +streetlights.basic_materials = minetest.get_modpath("basic_materials") +streetlights.concrete = "basic_materials:concrete_block" + dofile(modpath.."/simple.lua") if minetest.get_modpath("homedecor_lighting") and minetest.get_modpath("streetspoles") then dofile(modpath.."/minedot.lua") diff --git a/minedot.lua b/minedot.lua index 7521deb..5c4b41d 100644 --- a/minedot.lua +++ b/minedot.lua @@ -31,7 +31,7 @@ local offsets = { }, } -local function takeMaterials(player,materials) +local function takeMaterials(player, sneak, materials) local name = player:get_player_name() if creative and creative.is_enabled_for(name) then return true end local inv = minetest.get_inventory({type = "player",name = name}) @@ -39,8 +39,14 @@ local function takeMaterials(player,materials) for _,i in ipairs(materials) do if not inv:contains_item("main",i) then hasMaterials = false end end + if sneak and streetlights.basic_materials and not inv:contains_item("main", streetlights.concrete) then + hasMaterials = false + end if hasMaterials then for _,i in ipairs(materials) do inv:remove_item("main",i) end + if sneak then + inv:remove_item("main", streetlights.concrete) + end return true else minetest.chat_send_player(name,"You don't have the necessary materials to do that!") @@ -50,6 +56,7 @@ end local function place(itemstack,player,pointed) if not player then return end + local sneak = player:get_player_control().sneak local name = player:get_player_name() if not minetest.check_player_privs(name,{streetlight = true}) then minetest.chat_send_player(name,"*** You don't have permission to use a streetlight spawner.") @@ -60,7 +67,7 @@ local function place(itemstack,player,pointed) minetest.record_protection_violation(pos,name) end local isDouble = string.sub(itemstack:get_name(),-6,-1) == "double" - if not takeMaterials(player,isDouble and doubleMaterials or singleMaterials) then return end + if not takeMaterials(player, sneak, isDouble and doubleMaterials or singleMaterials) then return end local facedir = minetest.facedir_to_dir(minetest.dir_to_facedir(player:get_look_dir())) local schemDir = 0 if facedir.x == 1 then schemDir = 180 @@ -69,6 +76,9 @@ local function place(itemstack,player,pointed) local offset = offsets[isDouble and "double" or "single"][schemDir] local pos = vector.add(pos,offset) minetest.place_schematic(pos,isDouble and schems.double or schems.single,schemDir,nil,false) + if sneak and streetlights.basic_materials then + minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name = streetlights.concrete}) + end end minetest.register_tool(":minedot_streetlights:spawner_single",{ diff --git a/simple.lua b/simple.lua index ab195b8..aaf5575 100644 --- a/simple.lua +++ b/simple.lua @@ -12,6 +12,7 @@ minetest.register_privilege("streetlight", { }) local function check_and_place(itemstack, placer, pointed_thing, pole, light, param2) + local sneak = placer:get_player_control().sneak if not placer then return end if not minetest.check_player_privs(placer, "streetlight") then minetest.chat_send_player(placer:get_player_name(), "*** You don't have permission to use a streetlight spawner.") @@ -57,9 +58,17 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa def4 = minetest.registered_items[node4.name] if minetest.is_protected(pos4, player_name) or not (def3 and def4.buildable_to) then return end + if sneak and minetest.is_protected(pos1, player_name) then return end + if not creative or not creative.is_enabled_for(player_name) then local inv = placer:get_inventory() if not inv:contains_item("main", pole.." 5") or not inv:contains_item("main", light) then return end + if sneak and inv:contains_item("main", streetlights.concrete) then + inv:remove_item("main", streetlights.concrete) + else + return + end + inv:remove_item("main", pole.." 5") inv:remove_item("main", light) end @@ -70,6 +79,9 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa end minetest.set_node(pos3, { name = pole }) minetest.set_node(pos4, { name = light, param2 = param2 }) + if sneak then + minetest.set_node(pos1, { name = streetlights.concrete }) + end end local poles_tab = {