add MineDOT-style streetlights
parent
28be26e020
commit
53eb541543
|
@ -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/>
|
|
@ -3,3 +3,4 @@ creative?
|
|||
ilights?
|
||||
gloopblocks?
|
||||
homedecor?
|
||||
streetspoles?
|
||||
|
|
130
init.lua
130
init.lua
|
@ -1,128 +1,8 @@
|
|||
local fdir_to_right = {
|
||||
{ 1, 0 },
|
||||
{ 0, -1 },
|
||||
{ -1, 0 },
|
||||
{ 0, 1 }
|
||||
}
|
||||
-- simple streetlight spawner mod
|
||||
|
||||
minetest.register_privilege("streetlight", {
|
||||
description = "Allows using streetlight spawners",
|
||||
give_to_singleplayer = true
|
||||
})
|
||||
local modpath = minetest.get_modpath("simple_streetlights")
|
||||
|
||||
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
|
||||
dofile(modpath.."/simple.lua")
|
||||
if minetest.get_modpath("homedecor") and minetest.get_modpath("streetspoles") then
|
||||
dofile(modpath.."/minedot.lua")
|
||||
end
|
||||
|
|
|
@ -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,
|
||||
})
|
Binary file not shown.
Binary file not shown.
|
@ -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
|
Binary file not shown.
After Width: | Height: | Size: 210 B |
Binary file not shown.
After Width: | Height: | Size: 199 B |
Loading…
Reference in New Issue