mirror of
https://github.com/D00Med/scifi_nodes.git
synced 2024-12-22 16:10:18 +01:00
A little code tidying
This commit is contained in:
parent
643e3c40db
commit
5f2b22cd55
218
doors.lua
218
doors.lua
@ -14,32 +14,37 @@
|
|||||||
-- will the authors be held liable for any damages arising from the use of this content.
|
-- will the authors be held liable for any damages arising from the use of this content.
|
||||||
|
|
||||||
|
|
||||||
|
-- This table now uses named parameters and more convenient variables names
|
||||||
local doors = {
|
local doors = {
|
||||||
|
-- DOOM door {closed, closed top, opened, opened top, texture number, main ingredient, sound}
|
||||||
|
{base_name = "Doom", tex_number = "1", base_ingredient = "doors:door_obsidian_glass", sound = "scifi_nodes_door_mechanic"},
|
||||||
-- Black door
|
-- Black door
|
||||||
{"scifi_nodes:door2a","scifi_nodes:door2b","scifi_nodes:door2c","scifi_nodes:door2d","2","black", "doors:door_steel", "scifi_nodes_door_mechanic"},
|
{base_name = "black", tex_number = "2", base_ingredient = "doors:door_steel", sound = "scifi_nodes_door_mechanic"},
|
||||||
-- White door
|
-- White door
|
||||||
{"scifi_nodes:door3a","scifi_nodes:door3b","scifi_nodes:door3c","scifi_nodes:door3d","3","white", "doors:door_glass", "scifi_nodes_door_normal"},
|
{base_name = "white", tex_number = "3", base_ingredient = "doors:door_glass", sound = "scifi_nodes_door_normal"},
|
||||||
-- Green door
|
-- Green door
|
||||||
{"scifi_nodes:door4a","scifi_nodes:door4b","scifi_nodes:door4c","scifi_nodes:door4d","4","green", "doors:door_wood", "scifi_nodes_door_mechanic"},
|
{base_name = "green", tex_number = "4", base_ingredient = "doors:door_wood", sound = "scifi_nodes_door_mechanic"},
|
||||||
-- DOOM door
|
|
||||||
{"scifi_nodes:door1a","scifi_nodes:door1b","scifi_nodes:door1c","scifi_nodes:door1d","1","Doom", "doors:door_obsidian_glass", "scifi_nodes_door_mechanic"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- Maybe useful later with mesecons_doors.meseconify_door()
|
||||||
|
function get_doors_list()
|
||||||
|
return doors
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
for i in ipairs (doors) do
|
for i in ipairs (doors) do
|
||||||
|
|
||||||
-- TODO: make a map with entries: {a="", b="", desc="", etc}
|
local closed = "scifi_nodes:"..doors[i].base_name.."_door_closed"
|
||||||
local doora = doors[i][1]
|
local closed_top = "scifi_nodes:"..doors[i].base_name.."_door_closed_top"
|
||||||
local doorb = doors[i][2]
|
local opened = "scifi_nodes:"..doors[i].base_name.."_door_opened"
|
||||||
local doorc = doors[i][3]
|
local opened_top = "scifi_nodes:"..doors[i].base_name.."_door_opened_top"
|
||||||
local doord = doors[i][4]
|
local tex_number = doors[i].tex_number
|
||||||
local num = doors[i][5]
|
local base_ingredient = doors[i].base_ingredient
|
||||||
local des = doors[i][6]
|
local sound = doors[i].sound
|
||||||
local base_ingredient = doors[i][7]
|
|
||||||
local sound = doors[i][8]
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = doora .. " 2",
|
output = closed .. " 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"scifi_nodes:white2", base_ingredient, "scifi_nodes:white2"},
|
{"scifi_nodes:white2", base_ingredient, "scifi_nodes:white2"},
|
||||||
{"scifi_nodes:black", base_ingredient, "scifi_nodes:black"}
|
{"scifi_nodes:black", base_ingredient, "scifi_nodes:black"}
|
||||||
@ -80,12 +85,12 @@ function onplace(itemstack, placer, pointed_thing)
|
|||||||
pt3.z = pt3.z-1
|
pt3.z = pt3.z-1
|
||||||
p4 = 1
|
p4 = 1
|
||||||
end
|
end
|
||||||
if minetest.get_node(pt3).name == doora then
|
if minetest.get_node(pt3).name == closed then
|
||||||
minetest.set_node(pt, {name=doora, param2=p4})
|
minetest.set_node(pt, {name=closed, param2=p4})
|
||||||
minetest.set_node(pt2, {name=doorb, param2=p4})
|
minetest.set_node(pt2, {name=closed_top, param2=p4})
|
||||||
else
|
else
|
||||||
minetest.set_node(pt, {name=doora, param2=p2})
|
minetest.set_node(pt, {name=closed, param2=p2})
|
||||||
minetest.set_node(pt2, {name=doorb, param2=p2})
|
minetest.set_node(pt2, {name=closed_top, param2=p2})
|
||||||
end
|
end
|
||||||
itemstack:take_item(1)
|
itemstack:take_item(1)
|
||||||
|
|
||||||
@ -115,40 +120,40 @@ function rightclick(pos, node, player, itemstack, pointed_thing)
|
|||||||
local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
|
local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
|
||||||
|
|
||||||
|
|
||||||
minetest.set_node(pos, {name=doorc, param2=node.param2})
|
minetest.set_node(pos, {name=opened, param2=node.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=doord, param2=node.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=opened_top, param2=node.param2})
|
||||||
|
|
||||||
if a.name == doora then
|
if a.name == closed then
|
||||||
minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=doorc, param2=a.param2})
|
minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=opened, param2=a.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=doord, param2=a.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=opened_top, param2=a.param2})
|
||||||
end
|
end
|
||||||
if b.name == doora then
|
if b.name == closed then
|
||||||
minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=doorc, param2=b.param2})
|
minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=opened, param2=b.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=doord, param2=b.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=opened_top, param2=b.param2})
|
||||||
end
|
end
|
||||||
if c.name == doora then
|
if c.name == closed then
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=doorc, param2=c.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=opened, param2=c.param2})
|
||||||
minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=doord, param2=c.param2})
|
minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=opened_top, param2=c.param2})
|
||||||
end
|
end
|
||||||
if d.name == doora then
|
if d.name == closed then
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=doorc, param2=d.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=opened, param2=d.param2})
|
||||||
minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=doord, param2=d.param2})
|
minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=opened_top, param2=d.param2})
|
||||||
end
|
end
|
||||||
if e.name == doora then
|
if e.name == closed then
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=doorc, param2=e.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=opened, param2=e.param2})
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=doord, param2=e.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=opened_top, param2=e.param2})
|
||||||
end
|
end
|
||||||
if f.name == doora then
|
if f.name == closed then
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=doorc, param2=f.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=opened, param2=f.param2})
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=doord, param2=f.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=opened_top, param2=f.param2})
|
||||||
end
|
end
|
||||||
if g.name == doora then
|
if g.name == closed then
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=doorc, param2=g.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=opened, param2=g.param2})
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=doord, param2=g.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=opened_top, param2=g.param2})
|
||||||
end
|
end
|
||||||
if h.name == doora then
|
if h.name == closed then
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=doorc, param2=h.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=opened, param2=h.param2})
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=doord, param2=h.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=opened_top, param2=h.param2})
|
||||||
end
|
end
|
||||||
|
|
||||||
timer:start(3)
|
timer:start(3)
|
||||||
@ -156,7 +161,7 @@ function rightclick(pos, node, player, itemstack, pointed_thing)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function afterplace(pos, placer, itemstack, pointed_thing)
|
function afterplace(pos, placer, itemstack, pointed_thing)
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=doord,param2=nodeu.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=nodeu.param2})
|
||||||
end
|
end
|
||||||
|
|
||||||
function ontimer(pos, elapsed)
|
function ontimer(pos, elapsed)
|
||||||
@ -178,55 +183,55 @@ function ontimer(pos, elapsed)
|
|||||||
local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
|
local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1})
|
||||||
|
|
||||||
|
|
||||||
minetest.set_node(pos, {name=doora, param2=node.param2})
|
minetest.set_node(pos, {name=closed, param2=node.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=doorb, param2=node.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=closed_top, param2=node.param2})
|
||||||
|
|
||||||
if a.name == doorc then
|
if a.name == opened then
|
||||||
minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=doora, param2=a.param2})
|
minetest.set_node({x=pos.x, y=pos.y, z=pos.z-1}, {name=closed, param2=a.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=doorb, param2=a.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z-1}, {name=closed_top, param2=a.param2})
|
||||||
end
|
end
|
||||||
if b.name == doorc then
|
if b.name == opened then
|
||||||
minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=doora, param2=b.param2})
|
minetest.set_node({x=pos.x, y=pos.y, z=pos.z+1}, {name=closed, param2=b.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=doorb, param2=b.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z+1}, {name=closed_top, param2=b.param2})
|
||||||
end
|
end
|
||||||
if c.name == doorc then
|
if c.name == opened then
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=doora, param2=c.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z}, {name=closed, param2=c.param2})
|
||||||
minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=doorb, param2=c.param2})
|
minetest.set_node({x=pos.x+1,y=pos.y+1,z=pos.z}, {name=closed_top, param2=c.param2})
|
||||||
end
|
end
|
||||||
if d.name == doorc then
|
if d.name == opened then
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=doora, param2=d.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=closed, param2=d.param2})
|
||||||
minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=doorb, param2=d.param2})
|
minetest.set_node({x=pos.x-1,y=pos.y+1,z=pos.z}, {name=closed_top, param2=d.param2})
|
||||||
end
|
end
|
||||||
if e.name == doorc then
|
if e.name == opened then
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=doora, param2=e.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z-1}, {name=closed, param2=e.param2})
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=doorb, param2=e.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z-1}, {name=closed_top, param2=e.param2})
|
||||||
end
|
end
|
||||||
if f.name == doorc then
|
if f.name == opened then
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=doora, param2=f.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z-1}, {name=closed, param2=f.param2})
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=doorb, param2=f.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z-1}, {name=closed_top, param2=f.param2})
|
||||||
end
|
end
|
||||||
if g.name == doorc then
|
if g.name == opened then
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=doora, param2=g.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=closed, param2=g.param2})
|
||||||
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=doorb, param2=g.param2})
|
minetest.set_node({x=pos.x+1, y=pos.y+1, z=pos.z+1}, {name=closed_top, param2=g.param2})
|
||||||
end
|
end
|
||||||
if h.name == doorc then
|
if h.name == opened then
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=doora, param2=h.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y, z=pos.z+1}, {name=closed, param2=h.param2})
|
||||||
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=doorb, param2=h.param2})
|
minetest.set_node({x=pos.x-1, y=pos.y+1, z=pos.z+1}, {name=closed_top, param2=h.param2})
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node(doora, {
|
minetest.register_node(closed, {
|
||||||
description = des.." Sliding Door",
|
description = doors[i].base_name.." sliding door",
|
||||||
inventory_image = "scifi_nodes_door"..num.."a_inv.png",
|
inventory_image = "scifi_nodes_door"..tex_number.."a_inv.png",
|
||||||
wield_image = "scifi_nodes_door"..num.."a_inv.png",
|
wield_image = "scifi_nodes_door"..tex_number.."a_inv.png",
|
||||||
tiles = {
|
tiles = {
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_rbottom.png",
|
"scifi_nodes_door"..tex_number.."a_rbottom.png",
|
||||||
"scifi_nodes_door"..num.."a_bottom.png"
|
"scifi_nodes_door"..tex_number.."a_bottom.png"
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -251,14 +256,15 @@ after_destruct = afterdestruct,
|
|||||||
|
|
||||||
on_rightclick = rightclick,
|
on_rightclick = rightclick,
|
||||||
})
|
})
|
||||||
minetest.register_node(doorb, {
|
|
||||||
|
minetest.register_node(closed_top, {
|
||||||
tiles = {
|
tiles = {
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_rtop.png",
|
"scifi_nodes_door"..tex_number.."a_rtop.png",
|
||||||
"scifi_nodes_door"..num.."a_top.png"
|
"scifi_nodes_door"..tex_number.."a_top.png"
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -277,19 +283,20 @@ minetest.register_node(doorb, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
minetest.register_node(doorc, {
|
|
||||||
|
minetest.register_node(opened, {
|
||||||
tiles = {
|
tiles = {
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_rbottom0.png",
|
"scifi_nodes_door"..tex_number.."a_rbottom0.png",
|
||||||
"scifi_nodes_door"..num.."a_bottom0.png"
|
"scifi_nodes_door"..tex_number.."a_bottom0.png"
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
drop = doora,
|
drop = closed,
|
||||||
groups = {cracky = 1},
|
groups = {cracky = 1},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -307,14 +314,15 @@ after_place_node = afterplace,
|
|||||||
after_destruct = afterdestruct,
|
after_destruct = afterdestruct,
|
||||||
on_timer = ontimer,
|
on_timer = ontimer,
|
||||||
})
|
})
|
||||||
minetest.register_node(doord, {
|
|
||||||
|
minetest.register_node(opened_top, {
|
||||||
tiles = {
|
tiles = {
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_edge.png",
|
"scifi_nodes_door"..tex_number.."a_edge.png",
|
||||||
"scifi_nodes_door"..num.."a_rtopo.png",
|
"scifi_nodes_door"..tex_number.."a_rtopo.png",
|
||||||
"scifi_nodes_door"..num.."a_topo.png"
|
"scifi_nodes_door"..tex_number.."a_topo.png"
|
||||||
},
|
},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
|
Loading…
Reference in New Issue
Block a user