From 206a730e89ec7db09f4570a4cfbd26671f8b6ddc Mon Sep 17 00:00:00 2001 From: cheapie Date: Fri, 2 Nov 2018 16:42:41 -0500 Subject: Initial commit --- COPYING | 24 +++++++++ depends.txt | 2 + init.lua | 90 +++++++++++++++++++++++++++++++ schems/streetlight-double.mts | Bin 0 -> 159 bytes schems/streetlight-single.mts | Bin 0 -> 125 bytes textures/minedot_streetlights_double.png | Bin 0 -> 210 bytes textures/minedot_streetlights_single.png | Bin 0 -> 199 bytes 7 files changed, 116 insertions(+) create mode 100644 COPYING create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 schems/streetlight-double.mts create mode 100644 schems/streetlight-single.mts create mode 100644 textures/minedot_streetlights_double.png create mode 100644 textures/minedot_streetlights_single.png diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/COPYING @@ -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 diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..52273b7 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +streetspoles +homedecor diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..a1f8f82 --- /dev/null +++ b/init.lua @@ -0,0 +1,90 @@ +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, +}) + +if not minetest.get_modpath("simple_streetlights") then + minetest.register_privilege("streetlight",{ + description = "Can use streetlight spawners", + }) +end diff --git a/schems/streetlight-double.mts b/schems/streetlight-double.mts new file mode 100644 index 0000000..80ba16f Binary files /dev/null and b/schems/streetlight-double.mts differ diff --git a/schems/streetlight-single.mts b/schems/streetlight-single.mts new file mode 100644 index 0000000..73439f3 Binary files /dev/null and b/schems/streetlight-single.mts differ diff --git a/textures/minedot_streetlights_double.png b/textures/minedot_streetlights_double.png new file mode 100644 index 0000000..0a6f3fc Binary files /dev/null and b/textures/minedot_streetlights_double.png differ diff --git a/textures/minedot_streetlights_single.png b/textures/minedot_streetlights_single.png new file mode 100644 index 0000000..be0556c Binary files /dev/null and b/textures/minedot_streetlights_single.png differ -- cgit v1.2.3