summaryrefslogtreecommitdiff
path: root/simple_streetlights
diff options
context:
space:
mode:
Diffstat (limited to 'simple_streetlights')
-rw-r--r--simple_streetlights/COPYING.minedot24
-rw-r--r--simple_streetlights/depends.txt1
-rw-r--r--simple_streetlights/init.lua121
-rw-r--r--simple_streetlights/minedot.lua84
-rw-r--r--simple_streetlights/schems/streetlight-double.mtsbin0 -> 159 bytes
-rw-r--r--simple_streetlights/schems/streetlight-single.mtsbin0 -> 125 bytes
-rw-r--r--simple_streetlights/simple.lua129
-rw-r--r--simple_streetlights/textures/minedot_streetlights_double.pngbin0 -> 210 bytes
-rw-r--r--simple_streetlights/textures/minedot_streetlights_single.pngbin0 -> 199 bytes
9 files changed, 243 insertions, 116 deletions
diff --git a/simple_streetlights/COPYING.minedot b/simple_streetlights/COPYING.minedot
new file mode 100644
index 0000000..68a49da
--- /dev/null
+++ b/simple_streetlights/COPYING.minedot
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/simple_streetlights/depends.txt b/simple_streetlights/depends.txt
index e1cc6bc..191f064 100644
--- a/simple_streetlights/depends.txt
+++ b/simple_streetlights/depends.txt
@@ -3,3 +3,4 @@ creative?
ilights?
gloopblocks?
homedecor?
+streetspoles?
diff --git a/simple_streetlights/init.lua b/simple_streetlights/init.lua
index c4fca68..50310b6 100644
--- a/simple_streetlights/init.lua
+++ b/simple_streetlights/init.lua
@@ -1,119 +1,8 @@
-local fdir_to_right = {
- { 1, 0 },
- { 0, -1 },
- { -1, 0 },
- { 0, 1 }
-}
+-- simple streetlight spawner mod
-local function check_and_place(itemstack, placer, pointed_thing, pole, light)
- if not placer then return end
- local player_name = placer:get_player_name()
- local fdir = minetest.dir_to_facedir(placer:get_look_dir())
+local modpath = minetest.get_modpath("simple_streetlights")
- local pos1 = minetest.get_pointed_thing_position(pointed_thing)
- local node1 = minetest.get_node(pos1)
- if not node1 or node1.name == "ignore" then return end
- local def1 = minetest.registered_items[node1.name]
-
- print(dump(pos1))
- print(node1.name)
- print(dump(def1))
-
-
- if (def1 and def1.buildable_to) then
- pos1.y = pos1.y-1
- end
- local node1 = minetest.get_node(pos1)
-
- local node2, node3, node4
- local def1 = minetest.registered_items[node1.name]
- local def2, def3, def4
-
- local pos2, pos3, pos4
- for i = 1, 5 do
- pos2 = { x=pos1.x, y = pos1.y+i, z=pos1.z }
- node2 = minetest.get_node(pos2)
- def2 = minetest.registered_items[node2.name]
- if minetest.is_protected(pos2, player_name) or not (def2 and def2.buildable_to) then return end
- end
-
- pos3 = { x = pos1.x+fdir_to_right[fdir+1][1], y = pos1.y+5, z = pos1.z+fdir_to_right[fdir+1][2] }
- node3 = minetest.get_node(pos3)
- def3 = minetest.registered_items[node3.name]
- if minetest.is_protected(pos3, player_name) or not (def3 and def3.buildable_to) then return end
-
- pos4 = { x = pos1.x+fdir_to_right[fdir+1][1], y = pos1.y+4, z = pos1.z+fdir_to_right[fdir+1][2] }
- node4 = minetest.get_node(pos4)
- def4 = minetest.registered_items[node4.name]
- if minetest.is_protected(pos4, player_name) or not (def3 and def4.buildable_to) 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
- inv:remove_item("main", pole.." 5")
- inv:remove_item("main", light)
- end
-
- for i = 1, 5 do
- pos2 = {x=pos1.x, y = pos1.y+i, z=pos1.z}
- minetest.set_node(pos2, {name = pole })
- end
- minetest.set_node(pos3, { name = pole })
- minetest.set_node(pos4, { name = light, param2 = 0 })
-end
-
-minetest.register_tool("simple_streetlights:spawner_wood_meselamp", {
- description = "Streetlight spawner (wooden pole, Mese lamp cube)",
- inventory_image = "simple_streetlights_spawner_wood_meselamp.png",
- use_texture_alpha = true,
- tool_capabilities = { full_punch_interval=0.1 },
- on_place = function(itemstack, placer, pointed_thing)
- check_and_place(itemstack, placer, pointed_thing, "default:fence_wood", "default:meselamp")
- end
-})
-
-if minetest.get_modpath("ilights") then
- minetest.register_tool("simple_streetlights:spawner_wood_white", {
- description = "Streetlight spawner (wooden pole, white light)",
- inventory_image = "simple_streetlights_spawner_wood_white.png",
- use_texture_alpha = true,
- tool_capabilities = { full_punch_interval=0.1 },
- on_place = function(itemstack, placer, pointed_thing)
- check_and_place(itemstack, placer, pointed_thing, "default:fence_wood", "ilights:light")
- end
- })
-
- if minetest.get_modpath("gloopblocks") then
- minetest.register_tool("simple_streetlights:spawner_steel_white", {
- description = "Streetlight spawner (steel pole, white light)",
- inventory_image = "simple_streetlights_spawner_steel_white.png",
- use_texture_alpha = true,
- tool_capabilities = { full_punch_interval=0.1 },
- on_place = function(itemstack, placer, pointed_thing)
- check_and_place(itemstack, placer, pointed_thing, "gloopblocks:fence_steel", "ilights:light")
- end
- })
- end
-
- if minetest.get_modpath("homedecor") then
- minetest.register_tool("simple_streetlights:spawner_wrought_iron_white", {
- description = "Streetlight spawner (wrought iron pole, white light)",
- inventory_image = "simple_streetlights_spawner_wrought_iron_white.png",
- use_texture_alpha = true,
- tool_capabilities = { full_punch_interval=0.1 },
- on_place = function(itemstack, placer, pointed_thing)
- check_and_place(itemstack, placer, pointed_thing, "homedecor:fence_wrought_iron", "ilights:light")
- end
- })
-
- minetest.register_tool("simple_streetlights:spawner_brass_white", {
- description = "Streetlight spawner (brass pole, white light)",
- inventory_image = "simple_streetlights_spawner_brass_white.png",
- use_texture_alpha = true,
- tool_capabilities = { full_punch_interval=0.1 },
- on_place = function(itemstack, placer, pointed_thing)
- check_and_place(itemstack, placer, pointed_thing, "homedecor:fence_brass", "ilights:light")
- end
- })
- end
+dofile(modpath.."/simple.lua")
+if minetest.get_modpath("homedecor") and minetest.get_modpath("streetspoles") then
+ dofile(modpath.."/minedot.lua")
end
diff --git a/simple_streetlights/minedot.lua b/simple_streetlights/minedot.lua
new file mode 100644
index 0000000..7521deb
--- /dev/null
+++ b/simple_streetlights/minedot.lua
@@ -0,0 +1,84 @@
+local schems = {
+ single = minetest.register_schematic(string.format("schems%sstreetlight-single.mts",DIR_DELIM)),
+ double = minetest.register_schematic(string.format("schems%sstreetlight-double.mts",DIR_DELIM)),
+}
+
+local singleMaterials = {
+ ItemStack("streets:bigpole 6"),
+ ItemStack("streets:bigpole_edge 2"),
+ ItemStack("homedecor:glowlight_quarter 1"),
+}
+
+local doubleMaterials = {
+ ItemStack("streets:bigpole 7"),
+ ItemStack("streets:bigpole_edge 2"),
+ ItemStack("streets:bigpole_tjunction 1"),
+ ItemStack("homedecor:glowlight_quarter 2"),
+}
+
+local offsets = {
+ single = {
+ [0] = {x = 0,y = 0,z = 0},
+ [90] = {x = 0,y = 0,z = 0},
+ [180] = {x = 0,y = 0,z = -2},
+ [270] = {x = -2,y = 0,z = 0},
+ },
+ double = {
+ [0] = {x = 0,y = 0,z = -2},
+ [90] = {x = -2,y = 0,z = 0},
+ [180] = {x = 0,y = 0,z = -2},
+ [270] = {x = -2,y = 0,z = 0},
+ },
+}
+
+local function takeMaterials(player,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})
+ local hasMaterials = true
+ for _,i in ipairs(materials) do
+ if not inv:contains_item("main",i) then hasMaterials = false end
+ end
+ if hasMaterials then
+ for _,i in ipairs(materials) do inv:remove_item("main",i) end
+ return true
+ else
+ minetest.chat_send_player(name,"You don't have the necessary materials to do that!")
+ return false
+ end
+end
+
+local function place(itemstack,player,pointed)
+ if not player then return end
+ 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.")
+ return
+ end
+ local pos = pointed.above
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass = true}) then
+ 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
+ local facedir = minetest.facedir_to_dir(minetest.dir_to_facedir(player:get_look_dir()))
+ local schemDir = 0
+ if facedir.x == 1 then schemDir = 180
+ elseif facedir.z == 1 then schemDir = 90
+ elseif facedir.z == -1 then schemDir = 270 end
+ 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)
+end
+
+minetest.register_tool(":minedot_streetlights:spawner_single",{
+ description = "MineDOT-style Street Light Spawner (single-sided)",
+ inventory_image = "minedot_streetlights_single.png",
+ on_place = place,
+})
+
+minetest.register_tool(":minedot_streetlights:spawner_double",{
+ description = "MineDOT-style Street Light Spawner (double-sided)",
+ inventory_image = "minedot_streetlights_double.png",
+ on_place = place,
+})
diff --git a/simple_streetlights/schems/streetlight-double.mts b/simple_streetlights/schems/streetlight-double.mts
new file mode 100644
index 0000000..80ba16f
--- /dev/null
+++ b/simple_streetlights/schems/streetlight-double.mts
Binary files differ
diff --git a/simple_streetlights/schems/streetlight-single.mts b/simple_streetlights/schems/streetlight-single.mts
new file mode 100644
index 0000000..73439f3
--- /dev/null
+++ b/simple_streetlights/schems/streetlight-single.mts
Binary files differ
diff --git a/simple_streetlights/simple.lua b/simple_streetlights/simple.lua
new file mode 100644
index 0000000..5d2518e
--- /dev/null
+++ b/simple_streetlights/simple.lua
@@ -0,0 +1,129 @@
+
+local fdir_to_right = {
+ { 1, 0 },
+ { 0, -1 },
+ { -1, 0 },
+ { 0, 1 }
+}
+
+minetest.register_privilege("streetlight", {
+ description = "Allows using streetlight spawners",
+ give_to_singleplayer = true
+})
+
+local function check_and_place(itemstack, placer, pointed_thing, pole, light)
+ 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.")
+ return
+ end
+ local player_name = placer:get_player_name()
+ local fdir = minetest.dir_to_facedir(placer:get_look_dir())
+
+ local pos1 = minetest.get_pointed_thing_position(pointed_thing)
+ local node1 = minetest.get_node(pos1)
+ if not node1 or node1.name == "ignore" then return end
+ local def1 = minetest.registered_items[node1.name]
+
+ print(dump(pos1))
+ print(node1.name)
+ print(dump(def1))
+
+
+ if (def1 and def1.buildable_to) then
+ pos1.y = pos1.y-1
+ end
+ local node1 = minetest.get_node(pos1)
+
+ local node2, node3, node4
+ local def1 = minetest.registered_items[node1.name]
+ local def2, def3, def4
+
+ local pos2, pos3, pos4
+ for i = 1, 5 do
+ pos2 = { x=pos1.x, y = pos1.y+i, z=pos1.z }
+ node2 = minetest.get_node(pos2)
+ def2 = minetest.registered_items[node2.name]
+ if minetest.is_protected(pos2, player_name) or not (def2 and def2.buildable_to) then return end
+ end
+
+ pos3 = { x = pos1.x+fdir_to_right[fdir+1][1], y = pos1.y+5, z = pos1.z+fdir_to_right[fdir+1][2] }
+ node3 = minetest.get_node(pos3)
+ def3 = minetest.registered_items[node3.name]
+ if minetest.is_protected(pos3, player_name) or not (def3 and def3.buildable_to) then return end
+
+ pos4 = { x = pos1.x+fdir_to_right[fdir+1][1], y = pos1.y+4, z = pos1.z+fdir_to_right[fdir+1][2] }
+ node4 = minetest.get_node(pos4)
+ def4 = minetest.registered_items[node4.name]
+ if minetest.is_protected(pos4, player_name) or not (def3 and def4.buildable_to) 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
+ inv:remove_item("main", pole.." 5")
+ inv:remove_item("main", light)
+ end
+
+ for i = 1, 5 do
+ pos2 = {x=pos1.x, y = pos1.y+i, z=pos1.z}
+ minetest.set_node(pos2, {name = pole })
+ end
+ minetest.set_node(pos3, { name = pole })
+ minetest.set_node(pos4, { name = light, param2 = 0 })
+end
+
+minetest.register_tool("simple_streetlights:spawner_wood_meselamp", {
+ description = "Streetlight spawner (wooden pole, Mese lamp cube)",
+ inventory_image = "simple_streetlights_spawner_wood_meselamp.png",
+ use_texture_alpha = true,
+ tool_capabilities = { full_punch_interval=0.1 },
+ on_place = function(itemstack, placer, pointed_thing)
+ check_and_place(itemstack, placer, pointed_thing, "default:fence_wood", "default:meselamp")
+ end
+})
+
+if minetest.get_modpath("ilights") then
+ minetest.register_tool("simple_streetlights:spawner_wood_white", {
+ description = "Streetlight spawner (wooden pole, white light)",
+ inventory_image = "simple_streetlights_spawner_wood_white.png",
+ use_texture_alpha = true,
+ tool_capabilities = { full_punch_interval=0.1 },
+ on_place = function(itemstack, placer, pointed_thing)
+ check_and_place(itemstack, placer, pointed_thing, "default:fence_wood", "ilights:light")
+ end
+ })
+
+ if minetest.get_modpath("gloopblocks") then
+ minetest.register_tool("simple_streetlights:spawner_steel_white", {
+ description = "Streetlight spawner (steel pole, white light)",
+ inventory_image = "simple_streetlights_spawner_steel_white.png",
+ use_texture_alpha = true,
+ tool_capabilities = { full_punch_interval=0.1 },
+ on_place = function(itemstack, placer, pointed_thing)
+ check_and_place(itemstack, placer, pointed_thing, "gloopblocks:fence_steel", "ilights:light")
+ end
+ })
+ end
+
+ if minetest.get_modpath("homedecor") then
+ minetest.register_tool("simple_streetlights:spawner_wrought_iron_white", {
+ description = "Streetlight spawner (wrought iron pole, white light)",
+ inventory_image = "simple_streetlights_spawner_wrought_iron_white.png",
+ use_texture_alpha = true,
+ tool_capabilities = { full_punch_interval=0.1 },
+ on_place = function(itemstack, placer, pointed_thing)
+ check_and_place(itemstack, placer, pointed_thing, "homedecor:fence_wrought_iron", "ilights:light")
+ end
+ })
+
+ minetest.register_tool("simple_streetlights:spawner_brass_white", {
+ description = "Streetlight spawner (brass pole, white light)",
+ inventory_image = "simple_streetlights_spawner_brass_white.png",
+ use_texture_alpha = true,
+ tool_capabilities = { full_punch_interval=0.1 },
+ on_place = function(itemstack, placer, pointed_thing)
+ check_and_place(itemstack, placer, pointed_thing, "homedecor:fence_brass", "ilights:light")
+ end
+ })
+ end
+end
diff --git a/simple_streetlights/textures/minedot_streetlights_double.png b/simple_streetlights/textures/minedot_streetlights_double.png
new file mode 100644
index 0000000..0a6f3fc
--- /dev/null
+++ b/simple_streetlights/textures/minedot_streetlights_double.png
Binary files differ
diff --git a/simple_streetlights/textures/minedot_streetlights_single.png b/simple_streetlights/textures/minedot_streetlights_single.png
new file mode 100644
index 0000000..be0556c
--- /dev/null
+++ b/simple_streetlights/textures/minedot_streetlights_single.png
Binary files differ