scifi_nodes/doors.lua

387 lines
11 KiB
Lua
Raw Normal View History

2016-07-11 06:26:57 +02:00
-- mydoors mod by don
-- DO WHAT YOU WANT TO PUBLIC LICENSE
-- or abbreviated DWYWPL
-- December 2nd 2015
-- License Copyright (C) 2015 Michael Tomaino (PlatinumArts@gmail.com)
-- www.sandboxgamemaker.com/DWYWPL/
-- DO WHAT YOU WANT TO PUBLIC LICENSE
-- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-- 1. You are allowed to do whatever you want to with what content is using this license.
2019-09-05 09:00:39 +02:00
-- 2. This content is provided 'as-is', without any express or implied warranty. In no event
2016-07-11 06:26:57 +02:00
-- will the authors be held liable for any damages arising from the use of this content.
2019-05-09 16:08:43 +02:00
-- Retrieving mod settings
2019-08-13 06:25:38 +02:00
scifi_nodes.doors_open_with_mesecon_only = minetest.settings:get_bool("scifi_nodes.doors_open_with_mesecon_only", false)
2019-05-09 16:08:43 +02:00
2019-05-01 18:53:13 +02:00
-- Some aliases to deal with old namming policy --
2019-08-14 19:13:38 +02:00
minetest.register_alias("scifi_nodes:door1a","scifi_nodes:Doom_door_closed")
minetest.register_alias("scifi_nodes:door1b","scifi_nodes:Doom_door_closed_top")
minetest.register_alias("scifi_nodes:door1c","scifi_nodes:Doom_door_opened")
minetest.register_alias("scifi_nodes:door1d","scifi_nodes:Doom_door_opened_top")
minetest.register_alias("scifi_nodes:door2a","scifi_nodes:black_door_closed")
minetest.register_alias("scifi_nodes:door2b","scifi_nodes:black_door_closed_top")
minetest.register_alias("scifi_nodes:door2c","scifi_nodes:black_door_opened")
minetest.register_alias("scifi_nodes:door2d","scifi_nodes:black_door_opened_top")
minetest.register_alias("scifi_nodes:door3a","scifi_nodes:white_door_closed")
minetest.register_alias("scifi_nodes:door3b","scifi_nodes:white_door_closed_top")
minetest.register_alias("scifi_nodes:door3c","scifi_nodes:white_door_opened")
minetest.register_alias("scifi_nodes:door3d","scifi_nodes:white_door_opened_top")
minetest.register_alias("scifi_nodes:door4a","scifi_nodes:green_door_closed")
minetest.register_alias("scifi_nodes:door4b","scifi_nodes:green_door_closed_top")
minetest.register_alias("scifi_nodes:door4c","scifi_nodes:green_door_opened")
minetest.register_alias("scifi_nodes:door4d","scifi_nodes:green_door_opened_top")
2019-05-01 18:53:13 +02:00
2019-04-23 14:59:51 +02:00
-- This table now uses named parameters and more convenient variables names
2016-07-11 06:26:57 +02:00
local doors = {
{base_name = "Doom", base_ingredient = "doors:door_obsidian_glass", sound = "scifi_nodes_door_normal"},
{base_name = "black", base_ingredient = "doors:door_steel", sound = "scifi_nodes_door_normal"},
{base_name = "white", base_ingredient = "doors:door_glass", sound = "scifi_nodes_door_normal"},
{base_name = "green", base_ingredient = "doors:door_wood", sound = "scifi_nodes_door_normal"},
{base_name = "blue", base_ingredient = "default:steelblock", sound = "scifi_nodes_door_normal"}
2018-11-02 11:15:06 +01:00
}
for _, current_door in ipairs(doors) do
2018-11-02 11:15:06 +01:00
2019-04-27 10:22:38 +02:00
local closed = "scifi_nodes:"..current_door.base_name.."_door_closed"
local closed_top = "scifi_nodes:"..current_door.base_name.."_door_closed_top"
local opened = "scifi_nodes:"..current_door.base_name.."_door_opened"
local opened_top = "scifi_nodes:"..current_door.base_name.."_door_opened_top"
local base_name = current_door.base_name
local base_ingredient = current_door.base_ingredient
local sound = current_door.sound
minetest.register_craft({
output = closed .. " 2",
recipe = {
{"scifi_nodes:white2", base_ingredient, "scifi_nodes:white2"},
{"scifi_nodes:black", base_ingredient, "scifi_nodes:black"}
}
})
2018-08-20 07:43:00 +02:00
2016-07-11 06:26:57 +02:00
local function onplace(itemstack, placer, pointed_thing)
2019-05-01 18:53:13 +02:00
-- Is there room enough ?
2019-04-27 10:22:38 +02:00
local pos1 = pointed_thing.above
local pos2 = {x=pos1.x, y=pos1.y, z=pos1.z}
2019-05-01 18:53:13 +02:00
pos2.y = pos2.y+1 -- 2 nodes above
2019-05-01 18:53:13 +02:00
if
2019-04-27 10:22:38 +02:00
not minetest.registered_nodes[minetest.get_node(pos1).name].buildable_to or
not minetest.registered_nodes[minetest.get_node(pos2).name].buildable_to or
not placer or
not placer:is_player() or
minetest.is_protected(pos1, placer:get_player_name()) or
minetest.is_protected(pos2, placer:get_player_name()) then
return
end
2019-05-01 18:53:13 +02:00
local pt = pointed_thing.above
local pt2 = {x=pt.x, y=pt.y, z=pt.z}
pt2.y = pt2.y+1
-- Player look dir is converted to node rotation ?
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
-- Where to look for another door ?
local pt3 = {x=pt.x, y=pt.y, z=pt.z}
-- Door param2 depends of placer's look dir
local p4 = 0
if p2 == 0 then
pt3.x = pt3.x-1
p4 = 2
elseif p2 == 1 then
pt3.z = pt3.z+1
p4 = 3
elseif p2 == 2 then
pt3.x = pt3.x+1
p4 = 0
elseif p2 == 3 then
pt3.z = pt3.z-1
p4 = 1
end
-- First door of a pair is already there
if minetest.get_node(pt3).name == closed then
minetest.set_node(pt, {name=closed, param2=p4,})
minetest.set_node(pt2, {name=closed_top, param2=p4})
-- Placed door is the first of a pair
else
minetest.set_node(pt, {name=closed, param2=p2,})
minetest.set_node(pt2, {name=closed_top, param2=p2})
end
itemstack:take_item(1)
2019-04-27 10:22:38 +02:00
return itemstack;
2016-07-11 06:26:57 +02:00
end
local function afterdestruct(pos, oldnode)
2019-05-01 18:53:13 +02:00
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name="air"})
2019-04-27 10:22:38 +02:00
end
2018-11-02 11:15:06 +01:00
local function change_adjacent(target, pos, node)
local target_opposite, target_top
if target == opened then
target_top = opened_top
target_opposite = closed
else
target_top = closed_top
target_opposite = opened
end
for offset = -1,1,2 do
local x = pos.x
local y = pos.y
local z = pos.z
-- match param2=0 or param2=2
if node.param2 % 2 == 0 then
x = x + offset
else
z = z + offset
end
local adjacent = minetest.get_node({x=x, y=y, z=z})
if adjacent.name == target_opposite then
minetest.set_node({x=x, y=y, z=z}, {name=target, param2 = adjacent.param2})
minetest.set_node({x=x, y=y+1, z=z}, {name=target_top, param2 = adjacent.param2})
end
end
end
local function open_door(pos, node)
2019-04-27 10:22:38 +02:00
-- play sound
minetest.sound_play(sound,{
max_hear_distance = 16,
pos = pos,
gain = 1.0
})
local timer = minetest.get_node_timer(pos)
minetest.set_node(pos, {name=opened, param2=node.param2})
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=opened_top, param2=node.param2})
change_adjacent(opened, pos, node)
timer:start(3)
2019-04-27 10:22:38 +02:00
end
2016-07-11 06:26:57 +02:00
local function afterplace(pos, placer, itemstack, pointed_thing)
2019-09-05 09:00:39 +02:00
local node = minetest.get_node(pos)
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=node.param2})
2019-04-27 10:22:38 +02:00
end
2018-11-02 11:15:06 +01:00
local function ontimer(pos, elapsed)
2019-04-27 10:22:38 +02:00
-- play sound
minetest.sound_play(sound,{
max_hear_distance = 16,
pos = pos,
gain = 1.0
})
local node = minetest.get_node(pos)
2016-07-11 06:26:57 +02:00
2019-05-01 18:53:13 +02:00
minetest.set_node(pos, {name=closed, param2=node.param2})
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=closed_top, param2=node.param2})
change_adjacent(closed, pos, node)
2019-04-27 10:22:38 +02:00
end
2016-07-11 06:26:57 +02:00
2019-05-01 18:53:13 +02:00
local mesecons_doors_rules = {
2019-04-27 10:22:38 +02:00
-- get signal from pressure plate
{x=-1, y=0, z=0},
2019-05-01 18:53:13 +02:00
{x=0, y=0, z=1},
{x=0, y=0, z=-1},
{x=1, y=0, z=0},
2019-04-27 10:22:38 +02:00
-- get signal from wall mounted button
2019-05-01 18:53:13 +02:00
{x=-1, y=1, z=-1},
2019-04-27 10:22:38 +02:00
{x=-1, y=1, z=1},
2019-05-01 18:53:13 +02:00
{x=0, y=1, z=-1},
{x=0, y=1, z=1},
2019-04-27 10:22:38 +02:00
{x=1, y=1, z=-1},
2019-05-01 18:53:13 +02:00
{x=1, y=1, z=1},
{x=-1, y=1, z=0},
{x=1, y=1, z=0},
2019-04-27 10:22:38 +02:00
}
2019-05-01 18:53:13 +02:00
local mesecons_doors_def = {
effector = {
2019-05-09 16:08:43 +02:00
action_on = open_door,
2019-05-01 18:53:13 +02:00
rules = mesecons_doors_rules
},
2019-04-27 10:22:38 +02:00
}
2019-08-15 09:25:03 +02:00
2019-12-11 10:58:25 +01:00
local function nodig(pos, digger)
return false
end
2019-08-13 06:25:38 +02:00
local doors_rightclick = nil -- Crashes serv if empty table !
2019-08-15 09:25:03 +02:00
if not scifi_nodes.doors_open_with_mesecon_only then doors_rightclick = open_door end
2016-07-11 06:26:57 +02:00
2019-04-27 10:22:38 +02:00
minetest.register_node(closed, {
description = current_door.base_name.." sliding door",
inventory_image = "scifi_nodes_door_"..base_name.."_inv.png",
wield_image = "scifi_nodes_door_"..base_name.."_inv.png",
tiles = {
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_rbottom.png",
"scifi_nodes_door_"..base_name.."_bottom.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
groups = {
cracky = 3,
oddly_breakable_by_hand = 1,
2024-02-29 20:41:04 +01:00
scifi_nodes_door = 1,
door = 1
},
is_ground_content = false,
2019-04-27 10:22:38 +02:00
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625}
}
},
_open = open_door,
2019-05-01 18:53:13 +02:00
mesecons = mesecons_doors_def,
2019-04-27 10:22:38 +02:00
on_place = onplace,
after_destruct = afterdestruct,
2019-08-13 06:25:38 +02:00
on_rightclick = doors_rightclick,
2022-12-03 18:30:28 +01:00
sounds = scifi_nodes.node_sound_metal_defaults(),
2019-04-27 10:22:38 +02:00
})
2019-04-23 14:59:51 +02:00
2019-04-27 10:22:38 +02:00
minetest.register_node(closed_top, {
tiles = {
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_rtop.png",
"scifi_nodes_door_"..base_name.."_top.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
2024-02-29 20:41:04 +01:00
groups = {cracky = 1, dig_generic = 3, door = 1},
is_ground_content = false,
2019-04-27 10:22:38 +02:00
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.0625, 0.5, 0.5, 0.0625}
}
},
selection_box = {
type = "fixed",
fixed = {
{0, 0, 0, 0, 0, 0},
}
},
2019-12-11 10:58:25 +01:00
can_dig = nodig,
2022-12-03 18:30:28 +01:00
sounds = scifi_nodes.node_sound_metal_defaults(),
2019-04-27 10:22:38 +02:00
})
2019-04-23 14:59:51 +02:00
2019-04-27 10:22:38 +02:00
minetest.register_node(opened, {
tiles = {
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_rbottom0.png",
"scifi_nodes_door_"..base_name.."_bottom0.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
drop = closed,
2024-02-29 20:41:04 +01:00
groups = {cracky = 1, dig_generic = 3, door = 2},
is_ground_content = false,
2019-04-27 10:22:38 +02:00
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.0625, -0.25, 1.5, 0.0625},
}
},
2019-12-11 10:58:25 +01:00
after_place_node = afterplace,
after_destruct = afterdestruct,
on_timer = ontimer,
2022-12-03 18:30:28 +01:00
sounds = scifi_nodes.node_sound_metal_defaults(),
2019-04-27 10:22:38 +02:00
})
minetest.register_node(opened_top, {
tiles = {
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_edge.png",
"scifi_nodes_door_"..base_name.."_rtopo.png",
"scifi_nodes_door_"..base_name.."_topo.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
2024-02-29 20:41:04 +01:00
groups = {cracky = 1, dig_generic = 3, door = 2},
is_ground_content = false,
2019-04-27 10:22:38 +02:00
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.0625, -0.25, 0.5, 0.0625},
}
},
selection_box = {
type = "fixed",
fixed = {
2019-09-05 09:00:39 +02:00
{0, 0, 0, 0, 0, 0},
2019-04-27 10:22:38 +02:00
}
},
2019-12-11 10:58:25 +01:00
can_dig = nodig,
2022-12-03 18:30:28 +01:00
sounds = scifi_nodes.node_sound_metal_defaults(),
2019-04-27 10:22:38 +02:00
})
end -- end of doors table browsing
-- opens the scifi-door at the given position
function scifi_nodes.open_door(pos)
local node = minetest.get_node_or_nil(pos)
if not node then
-- area not loaded
return false
end
local def = minetest.registered_nodes[node.name]
if type(def._open) ~= "function" then
-- open function not found
return false
end
if not def.groups or not def.groups.scifi_nodes_door then
-- not a scifi_nodes door
return false
end
-- call open function
def._open(pos, node)
return true
end