mirror of
https://github.com/minetest/minetest_game.git
synced 2025-07-07 08:40:23 +02:00
Add sound to doors, add glass door and trapdoor
This commit is contained in:
@ -15,6 +15,17 @@ doors = {}
|
||||
-- selection_box_top
|
||||
-- only_placer_can_open: if true only the player who placed the door can
|
||||
-- open it
|
||||
|
||||
local function is_right(pos, clicker)
|
||||
local r1 = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z})
|
||||
local r2 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1})
|
||||
if string.find(r1.name, "door_") or string.find(r2.name, "door_") then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function doors:register_door(name, def)
|
||||
def.groups.not_in_creative_inventory = 1
|
||||
|
||||
@ -156,6 +167,11 @@ function doors:register_door(name, def)
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if check_player_priv(pos, clicker) then
|
||||
on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
|
||||
if is_right(pos, clicker) then
|
||||
minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
|
||||
else
|
||||
minetest.sound_play("door_open", {gain = 0.3, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
@ -186,6 +202,11 @@ function doors:register_door(name, def)
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if check_player_priv(pos, clicker) then
|
||||
on_rightclick(pos, -1, name.."_b_1", name.."_t_2", name.."_b_2", {1,2,3,0})
|
||||
if is_right(pos, clicker) then
|
||||
minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
|
||||
else
|
||||
minetest.sound_play("door_open", {gain = 0.3, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
@ -216,6 +237,11 @@ function doors:register_door(name, def)
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if check_player_priv(pos, clicker) then
|
||||
on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
|
||||
if is_right(pos, clicker) then
|
||||
minetest.sound_play("door_open", {gain = 0.3, max_hear_distance = 10})
|
||||
else
|
||||
minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
@ -246,6 +272,11 @@ function doors:register_door(name, def)
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if check_player_priv(pos, clicker) then
|
||||
on_rightclick(pos, -1, name.."_b_2", name.."_t_1", name.."_b_1", {3,0,1,2})
|
||||
if is_right(pos, clicker) then
|
||||
minetest.sound_play("door_open", {gain = 0.3, max_hear_distance = 10})
|
||||
else
|
||||
minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
@ -289,7 +320,118 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
doors:register_door("doors:door_glass", {
|
||||
description = "Glass Door",
|
||||
inventory_image = "door_glass.png",
|
||||
groups = {snappy=1,cracky=1,oddly_breakable_by_hand=2,door=1},
|
||||
tiles_bottom = {"default_glass.png", "door_grey.png"},
|
||||
tiles_top = {"default_glass.png", "door_grey.png"},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "doors:door_glass",
|
||||
recipe = {
|
||||
{"default:glass", "default:glass"},
|
||||
{"default:glass", "default:glass"},
|
||||
{"default:glass", "default:glass"}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_alias("doors:door_wood_a_c", "doors:door_wood_t_1")
|
||||
minetest.register_alias("doors:door_wood_a_o", "doors:door_wood_t_1")
|
||||
minetest.register_alias("doors:door_wood_b_c", "doors:door_wood_b_1")
|
||||
minetest.register_alias("doors:door_wood_b_o", "doors:door_wood_b_1")
|
||||
|
||||
|
||||
----trapdoor----
|
||||
|
||||
local me
|
||||
local meta
|
||||
local state = 0
|
||||
|
||||
local function update_door(pos, node)
|
||||
minetest.env:set_node(pos, node)
|
||||
end
|
||||
|
||||
local function punch(pos)
|
||||
meta = minetest.env:get_meta(pos)
|
||||
state = meta:get_int("state")
|
||||
me = minetest.env:get_node(pos)
|
||||
local tmp_node
|
||||
local tmp_node2
|
||||
oben = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
if state == 1 then
|
||||
state = 0
|
||||
minetest.sound_play("door_close", {to_player = puncher, gain = 0.3, max_hear_distance = 10})
|
||||
tmp_node = {name="doors:trapdoor", param1=me.param1, param2=me.param2}
|
||||
else
|
||||
state = 1
|
||||
minetest.sound_play("door_open", {to_player = puncher, gain = 0.3, max_hear_distance = 10})
|
||||
tmp_node = {name="doors:trapdoor_open", param1=me.param1, param2=me.param2}
|
||||
end
|
||||
update_door(pos, tmp_node)
|
||||
meta:set_int("state", state)
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("doors:trapdoor", {
|
||||
description = "Trapdoor",
|
||||
inventory_image = "door_trapdoor.png",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"door_trapdoor.png", "door_trapdoor.png", "default_wood.png", "default_wood.png", "default_wood.png", "default_wood.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "doors:trapdoor",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}
|
||||
},
|
||||
on_creation = function(pos)
|
||||
state = 0
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
punch(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("doors:trapdoor_open", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"default_wood.png", "default_wood.png", "default_wood.png", "default_wood.png", "door_trapdoor.png", "door_trapdoor.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
pointable = true,
|
||||
stack_max = 0,
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "doors:trapdoor",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0.4, 0.5, 0.5, 0.5}
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, 0.4, 0.5, 0.5, 0.5}
|
||||
},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
punch(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'doors:trapdoor 2',
|
||||
recipe = {
|
||||
{'group:wood', 'group:wood', 'group:wood'},
|
||||
{'group:wood', 'group:wood', 'group:wood'},
|
||||
{'', '', ''},
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user