Make the chest opening/closing sound customizable + fix double chests

This commit is contained in:
Mikita Wiśniewski 2024-06-23 21:50:03 +07:00 committed by the-real-herowl
parent 6bbb6b8dec
commit a28e55160f
3 changed files with 51 additions and 24 deletions

View file

@ -463,10 +463,14 @@ local function protection_check_put(side) return function(pos, listname, index,
return 0 return 0
-- BEGIN OF LISTRING WORKAROUND -- BEGIN OF LISTRING WORKAROUND
elseif listname == "input" then elseif listname == "input" then
local inv = minetest.get_inventory({ type = "node", pos = pos })
local other_pos = get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, side) local other_pos = get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, side)
local other_inv = minetest.get_inventory({ type = "node", pos = other_pos }) local other_inv = minetest.get_inventory({ type = "node", pos = other_pos })
local inv = minetest.get_inventory({ type = "node", pos = pos }) if side == "left" then
return limit_put(stack, other_inv, inv) return limit_put(stack, inv, other_inv)
else
return limit_put(stack, other_inv, inv)
end
-- END OF LISTRING WORKAROUND -- END OF LISTRING WORKAROUND
else else
return stack:get_count() return stack:get_count()
@ -484,7 +488,11 @@ local function log_inventory_put_double(side) return function(pos, listname, ind
inv:set_stack("input", 1, nil) inv:set_stack("input", 1, nil)
double_chest_add_item(inv, other_inv, "main", stack) if side == "left" then
double_chest_add_item(inv, other_inv, "main", stack)
else
double_chest_add_item(other_inv, inv, "main", stack)
end
end end
-- END OF LISTRING WORKAROUND -- END OF LISTRING WORKAROUND
end end end end
@ -510,10 +518,24 @@ function mcl_chests.register_chest(basename, d)
if not d.groups then d.groups = {} end if not d.groups then d.groups = {} end
local on_rightclick_side = { if not d.on_rightclick_left then
left = d.on_rightclick_left, d.on_rightclick_left = d.on_rightclick
right = d.on_rightclick_right end
} if not d.on_rightclick_right then
d.on_rightclick_right = d.on_rightclick
end
--[[local on_rightclick_side = {
left = d.on_rightclick_left or d.on_rightclick,
right = d.on_rightclick_right or d.on_rightclick,
}]]
if not d.sounds or type(d.sounds) ~= "table" then
d.sounds = { nil, "default_chest" }
end
if not d.sounds[2] then
d.sounds[2] = "default_chest"
end
-- The basename of the "canonical" version of the node, if set (e.g.: trapped_chest_on → trapped_chest). -- The basename of the "canonical" version of the node, if set (e.g.: trapped_chest_on → trapped_chest).
-- Used to get a shared formspec ID and to swap the node back to the canonical version in on_construct. -- Used to get a shared formspec ID and to swap the node back to the canonical version in on_construct.
@ -569,7 +591,8 @@ function mcl_chests.register_chest(basename, d)
-- Register -- Dummy inventory node
-- Will turn into names.small.a when placed down
minetest.register_node("mcl_chests:" .. basename, { minetest.register_node("mcl_chests:" .. basename, {
description = d.desc, description = d.desc,
_tt_help = d.tt_help, _tt_help = d.tt_help,
@ -582,7 +605,7 @@ function mcl_chests.register_chest(basename, d)
use_texture_alpha = "opaque", use_texture_alpha = "opaque",
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
sounds = d.sounds, sounds = d.sounds[1],
groups = groups_inv, groups = groups_inv,
on_construct = function(pos, node) on_construct = function(pos, node)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -608,7 +631,7 @@ function mcl_chests.register_chest(basename, d)
tiles = { "blank.png^[resize:16x16" }, tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip", use_texture_alpha = "clip",
_chest_entity_textures = small_textures, _chest_entity_textures = small_textures,
_chest_entity_sound = "default_chest", _chest_entity_sound = d.sounds[2],
_chest_entity_mesh = "mcl_chests_chest", _chest_entity_mesh = "mcl_chests_chest",
_chest_entity_animation_type = "chest", _chest_entity_animation_type = "chest",
paramtype = "light", paramtype = "light",
@ -616,7 +639,7 @@ function mcl_chests.register_chest(basename, d)
drop = d.drop, drop = d.drop,
groups = groups_small, groups = groups_small,
is_ground_content = false, is_ground_content = false,
sounds = d.sounds, sounds = d.sounds[1],
on_construct = function(pos) on_construct = function(pos)
local param2 = minetest.get_node(pos).param2 local param2 = minetest.get_node(pos).param2
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -652,18 +675,18 @@ function mcl_chests.register_chest(basename, d)
minetest.swap_node(pos, { name = names.right.a, param2 = param2 }) minetest.swap_node(pos, { name = names.right.a, param2 = param2 })
local p = get_double_container_neighbor_pos(pos, param2, "right") local p = get_double_container_neighbor_pos(pos, param2, "right")
minetest.swap_node(p, { name = names.left.a, param2 = param2 }) minetest.swap_node(p, { name = names.left.a, param2 = param2 })
create_entity(p, names.left.a, double_textures, param2, true, "default_chest", create_entity(p, names.left.a, double_textures, param2, true, d.sounds[2],
"mcl_chests_chest", "chest") "mcl_chests_chest", "chest")
elseif minetest.get_node(get_double_container_neighbor_pos(pos, param2, "left")).name == elseif minetest.get_node(get_double_container_neighbor_pos(pos, param2, "left")).name ==
names.small.a then names.small.a then
minetest.swap_node(pos, { name = names.left.a, param2 = param2 }) minetest.swap_node(pos, { name = names.left.a, param2 = param2 })
create_entity(pos, names.left.a, double_textures, param2, true, "default_chest", create_entity(pos, names.left.a, double_textures, param2, true, d.sounds[2],
"mcl_chests_chest", "chest") "mcl_chests_chest", "chest")
local p = get_double_container_neighbor_pos(pos, param2, "left") local p = get_double_container_neighbor_pos(pos, param2, "left")
minetest.swap_node(p, { name = names.right.a, param2 = param2 }) minetest.swap_node(p, { name = names.right.a, param2 = param2 })
else else
minetest.swap_node(pos, { name = names.small.a, param2 = param2 }) minetest.swap_node(pos, { name = names.small.a, param2 = param2 })
create_entity(pos, names.small.a, small_textures, param2, false, "default_chest", create_entity(pos, names.small.a, small_textures, param2, false, d.sounds[2],
"mcl_chests_chest", "chest") "mcl_chests_chest", "chest")
end end
end, end,
@ -718,7 +741,7 @@ function mcl_chests.register_chest(basename, d)
d.on_rightclick(pos, node, clicker) d.on_rightclick(pos, node, clicker)
end end
player_chest_open(clicker, pos, names.small.a, small_textures, node.param2, false, "default_chest", player_chest_open(clicker, pos, names.small.a, small_textures, node.param2, false, d.sounds[2],
"mcl_chests_chest") "mcl_chests_chest")
end, end,
@ -738,7 +761,7 @@ function mcl_chests.register_chest(basename, d)
tiles = { "blank.png^[resize:16x16" }, tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip", use_texture_alpha = "clip",
_chest_entity_textures = double_textures, _chest_entity_textures = double_textures,
_chest_entity_sound = "default_chest", _chest_entity_sound = d.sounds[2],
_chest_entity_mesh = "mcl_chests_chest", _chest_entity_mesh = "mcl_chests_chest",
_chest_entity_animation_type = "chest", _chest_entity_animation_type = "chest",
paramtype = "light", paramtype = "light",
@ -746,7 +769,7 @@ function mcl_chests.register_chest(basename, d)
groups = groups_left, groups = groups_left,
drop = d.drop, drop = d.drop,
is_ground_content = false, is_ground_content = false,
sounds = d.sounds, sounds = d.sounds[1],
on_construct = construct_double_chest("left", names), on_construct = construct_double_chest("left", names),
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name")) minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
@ -819,7 +842,7 @@ function mcl_chests.register_chest(basename, d)
d.on_rightclick_left(pos, node, clicker) d.on_rightclick_left(pos, node, clicker)
end end
player_chest_open(clicker, pos, names.left.a, double_textures, node.param2, true, "default_chest", player_chest_open(clicker, pos, names.left.a, double_textures, node.param2, true, d.sounds[2],
"mcl_chests_chest") "mcl_chests_chest")
end, end,
mesecons = d.mesecons, mesecons = d.mesecons,
@ -841,7 +864,7 @@ function mcl_chests.register_chest(basename, d)
groups = groups_right, groups = groups_right,
drop = d.drop, drop = d.drop,
is_ground_content = false, is_ground_content = false,
sounds = d.sounds, sounds = d.sounds[1],
on_construct = construct_double_chest("right", names), on_construct = construct_double_chest("right", names),
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name")) minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
@ -914,7 +937,7 @@ function mcl_chests.register_chest(basename, d)
d.on_rightclick_right(pos, node, clicker) d.on_rightclick_right(pos, node, clicker)
end end
player_chest_open(clicker, pos_other, left_name, double_textures, node.param2, true, "default_chest", player_chest_open(clicker, pos_other, names.left.a, double_textures, node.param2, true, d.sounds[2],
"mcl_chests_chest") "mcl_chests_chest")
end, end,
mesecons = d.mesecons, mesecons = d.mesecons,

View file

@ -27,7 +27,7 @@ mcl_chests.register_chest("chest", {
material_wood = 1, material_wood = 1,
flammable = -1, flammable = -1,
}, },
sounds = mcl_sounds.node_sound_wood_defaults(), sounds = { mcl_sounds.node_sound_wood_defaults() },
hardness = 2.5, hardness = 2.5,
hidden = false, hidden = false,
}) })
@ -59,7 +59,7 @@ mcl_chests.register_chest("trapped_chest", {
flammable = -1, flammable = -1,
mesecon = 2, mesecon = 2,
}, },
sounds = mcl_sounds.node_sound_wood_defaults(), sounds = { mcl_sounds.node_sound_wood_defaults() },
hardness = 2.5, hardness = 2.5,
hidden = false, hidden = false,
mesecons = { mesecons = {
@ -120,7 +120,7 @@ mcl_chests.register_chest("trapped_chest_on", {
flammable = -1, flammable = -1,
mesecon = 2, mesecon = 2,
}, },
sounds = mcl_sounds.node_sound_wood_defaults(), sounds = { mcl_sounds.node_sound_wood_defaults() },
hardness = 2.5, hardness = 2.5,
hidden = true, hidden = true,
mesecons = { mesecons = {

View file

@ -29,9 +29,13 @@ mcl_chests.register_chest("stone_chest", {
stone = 1, stone = 1,
material_stone = 1, material_stone = 1,
}, },
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = { mcl_sounds.node_sound_stone_defaults() },
hardness = 4.0, hardness = 4.0,
hidden = false, hidden = false,
-- It bites!
on_rightclick = function(pos, node, clicker)
mcl_util.deal_damage(clicker, 2)
end,
}) })
minetest.register_craft({ minetest.register_craft({