if basic_materials is installed

allow holding shift/sneak while "placing" a spawner
to automatically "set" the streetlight in concrete.
master
Vanessa Dannenberg 2019-05-03 01:53:42 -04:00
parent 47201c422a
commit 616f2d7777
4 changed files with 29 additions and 2 deletions

View File

@ -1,4 +1,5 @@
default
basic_materials?
creative?
ilights?
gloopblocks?

View File

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

View File

@ -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",{

View File

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