mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-08-21 09:27:25 +02:00
Clean-up ITEMS/mcl_chests code, part 2
Chest tile management has been reorganized to use postfixes, some slight formatting fixes applied here and there, and roughly marked down where the new files should (ideally) begin and end.
This commit is contained in:
parent
0a5b1af69f
commit
4a4a8b5d81
@ -1,6 +1,6 @@
|
|||||||
-- TODO
|
-- TODO
|
||||||
-- ====
|
-- ====
|
||||||
-- [ ] Take another full look at this code and clean-up even more.
|
-- [x] Take another full look at this code and clean-up even more.
|
||||||
-- [ ] Expose more functions that are currently local.
|
-- [ ] Expose more functions that are currently local.
|
||||||
-- [ ] Split this giant 1.6k-line file into:
|
-- [ ] Split this giant 1.6k-line file into:
|
||||||
-- - init.lua (dofiles and LBMs)
|
-- - init.lua (dofiles and LBMs)
|
||||||
@ -21,35 +21,47 @@ local table = table
|
|||||||
local math = math
|
local math = math
|
||||||
|
|
||||||
local sf = string.format
|
local sf = string.format
|
||||||
|
local sm = string.match
|
||||||
|
|
||||||
mcl_chests = {}
|
mcl_chests = {}
|
||||||
|
|
||||||
|
local get_double_container_neighbor_pos = mcl_util.get_double_container_neighbor_pos
|
||||||
|
|
||||||
-- Christmas chest setup
|
-- Christmas chest setup
|
||||||
local it_is_christmas = mcl_util.is_it_christmas()
|
local it_is_christmas = mcl_util.is_it_christmas()
|
||||||
|
|
||||||
local tiles_chest_normal_small = { "mcl_chests_normal.png" }
|
local tiles = { -- extensions will be added later
|
||||||
local tiles_chest_normal_double = { "mcl_chests_normal_double.png" }
|
chest_normal_small = { "mcl_chests_normal" },
|
||||||
|
chest_normal_double = { "mcl_chests_normal_double" },
|
||||||
|
chest_trapped_small = { "mcl_chests_trapped" },
|
||||||
|
chest_trapped_double = { "mcl_chests_trapped_double" },
|
||||||
|
chest_ender_small = { "mcl_chests_ender" },
|
||||||
|
ender_chest_texture = { "mcl_chests_ender" },
|
||||||
|
}
|
||||||
|
|
||||||
|
local tiles_postfix = ".png"
|
||||||
|
local tiles_postfix_double = ".png"
|
||||||
if it_is_christmas then
|
if it_is_christmas then
|
||||||
tiles_chest_normal_small = { "mcl_chests_normal_present.png^mcl_chests_noise.png" }
|
tiles_postfix = "_present.png^mcl_chests_noise.png"
|
||||||
tiles_chest_normal_double = { "mcl_chests_normal_double_present.png^mcl_chests_noise_double.png" }
|
tiles_postfix_double = "_present.png^mcl_chests_noise_double.png"
|
||||||
end
|
end
|
||||||
|
|
||||||
local tiles_chest_trapped_small = { "mcl_chests_trapped.png" }
|
-- Append the postfixes for each entry
|
||||||
local tiles_chest_trapped_double = { "mcl_chests_trapped_double.png" }
|
for k,v in pairs(tiles) do
|
||||||
|
if not sm(k, "double") then
|
||||||
if it_is_christmas then
|
tiles[k] = {v[1] .. tiles_postfix}
|
||||||
tiles_chest_trapped_small = { "mcl_chests_trapped_present.png^mcl_chests_noise.png" }
|
else
|
||||||
tiles_chest_trapped_double = { "mcl_chests_trapped_double_present.png^mcl_chests_noise_double.png" }
|
tiles[k] = {v[1] .. tiles_postfix_double}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tiles_chest_ender_small = { "mcl_chests_ender.png" }
|
|
||||||
local ender_chest_texture = { "mcl_chests_ender.png" }
|
|
||||||
|
|
||||||
if it_is_christmas then
|
|
||||||
tiles_chest_ender_small = { "mcl_chests_ender_present.png^mcl_chests_noise.png" }
|
-- ======= --
|
||||||
ender_chest_texture = { "mcl_chests_ender_present.png" }
|
-- api.lua --
|
||||||
end
|
-- ======= --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Chest Entity
|
-- Chest Entity
|
||||||
-- ============
|
-- ============
|
||||||
@ -196,7 +208,7 @@ local function find_or_create_entity(pos, node_name, textures, param2, double, s
|
|||||||
end
|
end
|
||||||
|
|
||||||
local no_rotate, simple_rotate
|
local no_rotate, simple_rotate
|
||||||
if minetest.get_modpath("screwdriver") then
|
if screwdriver then
|
||||||
no_rotate = screwdriver.disallow
|
no_rotate = screwdriver.disallow
|
||||||
simple_rotate = function(pos, node, user, mode, new_param2)
|
simple_rotate = function(pos, node, user, mode, new_param2)
|
||||||
if screwdriver.rotate_simple(pos, node, user, mode, new_param2) ~= false then
|
if screwdriver.rotate_simple(pos, node, user, mode, new_param2) ~= false then
|
||||||
@ -274,20 +286,20 @@ local function chest_update_after_close(pos)
|
|||||||
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
|
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
|
||||||
elseif node.name == "mcl_chests:trapped_chest_on_left" then
|
elseif node.name == "mcl_chests:trapped_chest_on_left" then
|
||||||
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 })
|
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 })
|
||||||
find_or_create_entity(pos, "mcl_chests:trapped_chest_left", tiles_chest_trapped_double, node.param2, true,
|
find_or_create_entity(pos, "mcl_chests:trapped_chest_left", tiles.chest_trapped_double, node.param2, true,
|
||||||
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
|
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
|
||||||
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
|
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
|
||||||
|
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "left")
|
||||||
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 })
|
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 })
|
||||||
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
|
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
|
||||||
elseif node.name == "mcl_chests:trapped_chest_on_right" then
|
elseif node.name == "mcl_chests:trapped_chest_on_right" then
|
||||||
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 })
|
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 })
|
||||||
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
|
mesecon.receptor_off(pos, trapped_chest_mesecons_rules)
|
||||||
|
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "right")
|
||||||
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 })
|
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 })
|
||||||
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", tiles_chest_trapped_double, node.param2, true,
|
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", tiles.chest_trapped_double, node.param2, true,
|
||||||
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
|
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
|
||||||
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
|
mesecon.receptor_off(pos_other, trapped_chest_mesecons_rules)
|
||||||
end
|
end
|
||||||
@ -456,6 +468,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
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)
|
||||||
|
|
||||||
--[[ This is a workaround for Minetest issue 5894
|
--[[ This is a workaround for Minetest issue 5894
|
||||||
<https://github.com/minetest/minetest/issues/5894>.
|
<https://github.com/minetest/minetest/issues/5894>.
|
||||||
Apparently if we don't do this, large chests initially don't work when
|
Apparently if we don't do this, large chests initially don't work when
|
||||||
@ -466,8 +479,10 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
meta:set_string("workaround", "ignore_me")
|
meta:set_string("workaround", "ignore_me")
|
||||||
meta:set_string("workaround", nil) -- Done to keep metadata clean
|
meta:set_string("workaround", nil) -- Done to keep metadata clean
|
||||||
-- END OF WORKAROUND --
|
-- END OF WORKAROUND --
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 9 * 3)
|
inv:set_size("main", 9 * 3)
|
||||||
|
|
||||||
--[[ The "input" list is *another* workaround (hahahaha!) around the fact that Minetest
|
--[[ The "input" list is *another* workaround (hahahaha!) around the fact that Minetest
|
||||||
does not support listrings to put items into an alternative list if the first one
|
does not support listrings to put items into an alternative list if the first one
|
||||||
happens to be full. See <https://github.com/minetest/minetest/issues/5343>.
|
happens to be full. See <https://github.com/minetest/minetest/issues/5343>.
|
||||||
@ -480,19 +495,19 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
-- END OF LISTRING WORKAROUND
|
-- END OF LISTRING WORKAROUND
|
||||||
|
|
||||||
-- Combine into a double chest if neighbouring another small chest
|
-- Combine into a double chest if neighbouring another small chest
|
||||||
if minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "right")).name ==
|
if minetest.get_node(get_double_container_neighbor_pos(pos, param2, "right")).name ==
|
||||||
small_name then
|
small_name then
|
||||||
minetest.swap_node(pos, { name = right_name, param2 = param2 })
|
minetest.swap_node(pos, { name = right_name, param2 = param2 })
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
local p = get_double_container_neighbor_pos(pos, param2, "right")
|
||||||
minetest.swap_node(p, { name = left_name, param2 = param2 })
|
minetest.swap_node(p, { name = left_name, param2 = param2 })
|
||||||
create_entity(p, left_name, double_textures, param2, true, "default_chest",
|
create_entity(p, left_name, double_textures, param2, true, "default_chest",
|
||||||
"mcl_chests_chest", "chest")
|
"mcl_chests_chest", "chest")
|
||||||
elseif minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "left")).name ==
|
elseif minetest.get_node(get_double_container_neighbor_pos(pos, param2, "left")).name ==
|
||||||
small_name then
|
small_name then
|
||||||
minetest.swap_node(pos, { name = left_name, param2 = param2 })
|
minetest.swap_node(pos, { name = left_name, param2 = param2 })
|
||||||
create_entity(pos, left_name, double_textures, param2, true, "default_chest",
|
create_entity(pos, left_name, double_textures, param2, true, "default_chest",
|
||||||
"mcl_chests_chest", "chest")
|
"mcl_chests_chest", "chest")
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left")
|
local p = get_double_container_neighbor_pos(pos, param2, "left")
|
||||||
minetest.swap_node(p, { name = right_name, param2 = param2 })
|
minetest.swap_node(p, { name = right_name, param2 = param2 })
|
||||||
else
|
else
|
||||||
minetest.swap_node(pos, { name = small_name, param2 = param2 })
|
minetest.swap_node(pos, { name = small_name, param2 = param2 })
|
||||||
@ -607,7 +622,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local n = minetest.get_node(pos)
|
local n = minetest.get_node(pos)
|
||||||
local param2 = n.param2
|
local param2 = n.param2
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left")
|
local p = get_double_container_neighbor_pos(pos, param2, "left")
|
||||||
if not p or minetest.get_node(p).name ~= "mcl_chests:" .. canonical_basename .. "_right" then
|
if not p or minetest.get_node(p).name ~= "mcl_chests:" .. canonical_basename .. "_right" then
|
||||||
n.name = "mcl_chests:" .. canonical_basename .. "_small"
|
n.name = "mcl_chests:" .. canonical_basename .. "_small"
|
||||||
minetest.swap_node(pos, n)
|
minetest.swap_node(pos, n)
|
||||||
@ -626,7 +641,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
close_forms(canonical_basename, pos)
|
close_forms(canonical_basename, pos)
|
||||||
|
|
||||||
local param2 = n.param2
|
local param2 = n.param2
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left")
|
local p = get_double_container_neighbor_pos(pos, param2, "left")
|
||||||
if not p or minetest.get_node(p).name ~= "mcl_chests:" .. basename .. "_right" then
|
if not p or minetest.get_node(p).name ~= "mcl_chests:" .. basename .. "_right" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -647,7 +662,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
-- 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 inv = minetest.get_inventory({ type = "node", pos = pos })
|
||||||
local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "left")
|
local other_pos = get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "left")
|
||||||
local other_inv = minetest.get_inventory({ type = "node", pos = other_pos })
|
local other_inv = minetest.get_inventory({ type = "node", pos = other_pos })
|
||||||
return limit_put(stack, inv, other_inv)
|
return limit_put(stack, inv, other_inv)
|
||||||
-- END OF LISTRING WORKAROUND
|
-- END OF LISTRING WORKAROUND
|
||||||
@ -665,7 +680,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
-- BEGIN OF LISTRING WORKAROUND
|
-- BEGIN OF LISTRING WORKAROUND
|
||||||
if listname == "input" then
|
if listname == "input" then
|
||||||
local inv = minetest.get_inventory({ type = "node", pos = pos })
|
local inv = minetest.get_inventory({ type = "node", pos = pos })
|
||||||
local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "left")
|
local other_pos = get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "left")
|
||||||
local other_inv = minetest.get_inventory({ type = "node", pos = other_pos })
|
local other_inv = minetest.get_inventory({ type = "node", pos = other_pos })
|
||||||
|
|
||||||
inv:set_stack("input", 1, nil)
|
inv:set_stack("input", 1, nil)
|
||||||
@ -682,21 +697,24 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
_mcl_hardness = 2.5,
|
_mcl_hardness = 2.5,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "left")
|
||||||
local above_def = minetest.registered_nodes[minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name]
|
local above_def = minetest.registered_nodes[
|
||||||
|
minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name
|
||||||
|
]
|
||||||
local above_def_other = minetest.registered_nodes[
|
local above_def_other = minetest.registered_nodes[
|
||||||
minetest.get_node({ x = pos_other.x, y = pos_other.y + 1, z = pos_other.z }).name]
|
minetest.get_node({ x = pos_other.x, y = pos_other.y + 1, z = pos_other.z }).name
|
||||||
|
]
|
||||||
|
|
||||||
if not above_def or above_def.groups.opaque == 1 or not above_def_other or above_def_other.groups.opaque == 1 then
|
if (not above_def or above_def.groups.opaque == 1 or not above_def_other
|
||||||
|
or above_def_other.groups.opaque == 1) then
|
||||||
-- won't open if there is no space from the top
|
-- won't open if there is no space from the top
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = minetest.get_meta(pos):get_string("name")
|
local name = minetest.get_meta(pos):get_string("name")
|
||||||
if name == "" then
|
if name == "" then -- if empty after that ^
|
||||||
name = minetest.get_meta(pos_other):get_string("name")
|
name = minetest.get_meta(pos_other):get_string("name")
|
||||||
end
|
end if name == "" then -- if STILL empty after that ^
|
||||||
if name == "" then
|
|
||||||
name = S("Large Chest")
|
name = S("Large Chest")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -722,6 +740,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
"listring[current_player;main]",
|
"listring[current_player;main]",
|
||||||
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
|
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
|
||||||
--END OF LISTRING WORKAROUND
|
--END OF LISTRING WORKAROUND
|
||||||
|
|
||||||
"listring[current_player;main]" ..
|
"listring[current_player;main]" ..
|
||||||
sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z),
|
sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z),
|
||||||
"listring[current_player;main]",
|
"listring[current_player;main]",
|
||||||
@ -741,12 +760,14 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
_mcl_hoppers_on_try_pull = function(pos, hop_pos, hop_inv, hop_list)
|
_mcl_hoppers_on_try_pull = function(pos, hop_pos, hop_inv, hop_list)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
local stack_id = mcl_util.select_stack(inv, "main", hop_inv, hop_list)
|
local stack_id = mcl_util.select_stack(inv, "main", hop_inv, hop_list)
|
||||||
if stack_id ~= nil then
|
if stack_id ~= nil then
|
||||||
return inv, "main", stack_id
|
return inv, "main", stack_id
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "left")
|
||||||
local meta_other = minetest.get_meta(pos_other)
|
local meta_other = minetest.get_meta(pos_other)
|
||||||
local inv_other = meta_other:get_inventory()
|
local inv_other = meta_other:get_inventory()
|
||||||
stack_id = mcl_util.select_stack(inv_other, "main", hop_inv, hop_list)
|
stack_id = mcl_util.select_stack(inv_other, "main", hop_inv, hop_list)
|
||||||
@ -755,12 +776,14 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
_mcl_hoppers_on_try_push = function(pos, hop_pos, hop_inv, hop_list)
|
_mcl_hoppers_on_try_push = function(pos, hop_pos, hop_inv, hop_list)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
local stack_id = mcl_util.select_stack(hop_inv, hop_list, inv, "main", nil, 1)
|
local stack_id = mcl_util.select_stack(hop_inv, hop_list, inv, "main", nil, 1)
|
||||||
if stack_id ~= nil then
|
if stack_id ~= nil then
|
||||||
return inv, "main", stack_id
|
return inv, "main", stack_id
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "left")
|
||||||
local meta_other = minetest.get_meta(pos_other)
|
local meta_other = minetest.get_meta(pos_other)
|
||||||
local inv_other = meta_other:get_inventory()
|
local inv_other = meta_other:get_inventory()
|
||||||
stack_id = mcl_util.select_stack(hop_inv, hop_list, inv_other, "main", nil, 1)
|
stack_id = mcl_util.select_stack(hop_inv, hop_list, inv_other, "main", nil, 1)
|
||||||
@ -793,7 +816,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local n = minetest.get_node(pos)
|
local n = minetest.get_node(pos)
|
||||||
local param2 = n.param2
|
local param2 = n.param2
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
local p = get_double_container_neighbor_pos(pos, param2, "right")
|
||||||
if not p or minetest.get_node(p).name ~= left_name then
|
if not p or minetest.get_node(p).name ~= left_name then
|
||||||
n.name = small_name
|
n.name = small_name
|
||||||
minetest.swap_node(pos, n)
|
minetest.swap_node(pos, n)
|
||||||
@ -811,7 +834,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
close_forms(canonical_basename, pos)
|
close_forms(canonical_basename, pos)
|
||||||
|
|
||||||
local param2 = n.param2
|
local param2 = n.param2
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
local p = get_double_container_neighbor_pos(pos, param2, "right")
|
||||||
if not p or minetest.get_node(p).name ~= left_name then
|
if not p or minetest.get_node(p).name ~= left_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -831,7 +854,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
return 0
|
return 0
|
||||||
-- BEGIN OF LISTRING WORKAROUND
|
-- BEGIN OF LISTRING WORKAROUND
|
||||||
elseif listname == "input" then
|
elseif listname == "input" then
|
||||||
local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "right")
|
local other_pos = get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "right")
|
||||||
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 })
|
local inv = minetest.get_inventory({ type = "node", pos = pos })
|
||||||
return limit_put(stack, other_inv, inv)
|
return limit_put(stack, other_inv, inv)
|
||||||
@ -849,7 +872,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
" moves stuff to chest at " .. minetest.pos_to_string(pos))
|
" moves stuff to chest at " .. minetest.pos_to_string(pos))
|
||||||
-- BEGIN OF LISTRING WORKAROUND
|
-- BEGIN OF LISTRING WORKAROUND
|
||||||
if listname == "input" then
|
if listname == "input" then
|
||||||
local other_pos = mcl_util.get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "right")
|
local other_pos = get_double_container_neighbor_pos(pos, minetest.get_node(pos).param2, "right")
|
||||||
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 })
|
local inv = minetest.get_inventory({ type = "node", pos = pos })
|
||||||
|
|
||||||
@ -867,20 +890,24 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
_mcl_hardness = 2.5,
|
_mcl_hardness = 2.5,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "right")
|
||||||
if minetest.registered_nodes[minetest.get_node(vector.offset(pos, 0, 1, 0)).name].groups.opaque == 1
|
local above_def = minetest.registered_nodes[
|
||||||
or
|
minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z }).name
|
||||||
minetest.registered_nodes[minetest.get_node(vector.offset(pos_other, 0, 1, 0)).name].groups.opaque
|
]
|
||||||
== 1 then
|
local above_def_other = minetest.registered_nodes[
|
||||||
|
minetest.get_node({ x = pos_other.x, y = pos_other.y + 1, z = pos_other.z }).name
|
||||||
|
]
|
||||||
|
|
||||||
|
if (not above_def or above_def.groups.opaque == 1 or not above_def_other
|
||||||
|
or above_def_other.groups.opaque == 1) then
|
||||||
-- won't open if there is no space from the top
|
-- won't open if there is no space from the top
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = minetest.get_meta(pos_other):get_string("name")
|
local name = minetest.get_meta(pos):get_string("name")
|
||||||
if name == "" then
|
if name == "" then -- if empty after that ^
|
||||||
name = minetest.get_meta(pos):get_string("name")
|
name = minetest.get_meta(pos_other):get_string("name")
|
||||||
end
|
end if name == "" then -- if STILL empty after that ^
|
||||||
if name == "" then
|
|
||||||
name = S("Large Chest")
|
name = S("Large Chest")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -906,6 +933,7 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
"listring[current_player;main]",
|
"listring[current_player;main]",
|
||||||
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
|
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
|
||||||
--END OF LISTRING WORKAROUND
|
--END OF LISTRING WORKAROUND
|
||||||
|
|
||||||
"listring[current_player;main]" ..
|
"listring[current_player;main]" ..
|
||||||
sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z),
|
sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z),
|
||||||
"listring[current_player;main]",
|
"listring[current_player;main]",
|
||||||
@ -924,13 +952,15 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
on_rotate = no_rotate,
|
on_rotate = no_rotate,
|
||||||
_mcl_hoppers_on_try_pull = function(pos, hop_pos, hop_inv, hop_list)
|
_mcl_hoppers_on_try_pull = function(pos, hop_pos, hop_inv, hop_list)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "right")
|
||||||
local meta_other = minetest.get_meta(pos_other)
|
local meta_other = minetest.get_meta(pos_other)
|
||||||
local inv_other = meta_other:get_inventory()
|
local inv_other = meta_other:get_inventory()
|
||||||
|
|
||||||
local stack_id = mcl_util.select_stack(inv_other, "main", hop_inv, hop_list)
|
local stack_id = mcl_util.select_stack(inv_other, "main", hop_inv, hop_list)
|
||||||
if stack_id ~= nil then
|
if stack_id ~= nil then
|
||||||
return inv_other, "main", stack_id
|
return inv_other, "main", stack_id
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
stack_id = mcl_util.select_stack(inv, "main", hop_inv, hop_list)
|
stack_id = mcl_util.select_stack(inv, "main", hop_inv, hop_list)
|
||||||
@ -938,13 +968,15 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
end,
|
end,
|
||||||
_mcl_hoppers_on_try_push = function(pos, hop_pos, hop_inv, hop_list)
|
_mcl_hoppers_on_try_push = function(pos, hop_pos, hop_inv, hop_list)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "right")
|
||||||
local meta_other = minetest.get_meta(pos_other)
|
local meta_other = minetest.get_meta(pos_other)
|
||||||
local inv_other = meta_other:get_inventory()
|
local inv_other = meta_other:get_inventory()
|
||||||
|
|
||||||
local stack_id = mcl_util.select_stack(hop_inv, hop_list, inv_other, "main", nil, 1)
|
local stack_id = mcl_util.select_stack(hop_inv, hop_list, inv_other, "main", nil, 1)
|
||||||
if stack_id ~= nil then
|
if stack_id ~= nil then
|
||||||
return inv_other, "main", stack_id
|
return inv_other, "main", stack_id
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
stack_id = mcl_util.select_stack(hop_inv, hop_list, inv, "main", nil, 1)
|
stack_id = mcl_util.select_stack(hop_inv, hop_list, inv, "main", nil, 1)
|
||||||
@ -958,6 +990,14 @@ function mcl_chests.register_chest(basename, desc, longdesc, usagehelp, tt_help,
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ========== --
|
||||||
|
-- chests.lua --
|
||||||
|
-- ========== --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local chestusage = S("To access its inventory, rightclick it. When broken, the items will drop out.")
|
local chestusage = S("To access its inventory, rightclick it. When broken, the items will drop out.")
|
||||||
|
|
||||||
mcl_chests.register_chest("chest",
|
mcl_chests.register_chest("chest",
|
||||||
@ -966,8 +1006,8 @@ mcl_chests.register_chest("chest",
|
|||||||
chestusage,
|
chestusage,
|
||||||
S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest"),
|
S("27 inventory slots") .. "\n" .. S("Can be combined to a large chest"),
|
||||||
{
|
{
|
||||||
small = tiles_chest_normal_small,
|
small = tiles.chest_normal_small,
|
||||||
double = tiles_chest_normal_double,
|
double = tiles.chest_normal_double,
|
||||||
inv = { "default_chest_top.png", "mcl_chests_chest_bottom.png",
|
inv = { "default_chest_top.png", "mcl_chests_chest_bottom.png",
|
||||||
"mcl_chests_chest_right.png", "mcl_chests_chest_left.png",
|
"mcl_chests_chest_right.png", "mcl_chests_chest_left.png",
|
||||||
"mcl_chests_chest_back.png", "default_chest_front.png" },
|
"mcl_chests_chest_back.png", "default_chest_front.png" },
|
||||||
@ -976,8 +1016,8 @@ mcl_chests.register_chest("chest",
|
|||||||
)
|
)
|
||||||
|
|
||||||
local traptiles = {
|
local traptiles = {
|
||||||
small = tiles_chest_trapped_small,
|
small = tiles.chest_trapped_small,
|
||||||
double = tiles_chest_trapped_double,
|
double = tiles.chest_trapped_double,
|
||||||
}
|
}
|
||||||
|
|
||||||
mcl_chests.register_chest("trapped_chest",
|
mcl_chests.register_chest("trapped_chest",
|
||||||
@ -1005,22 +1045,22 @@ mcl_chests.register_chest("trapped_chest",
|
|||||||
meta:set_int("players", 1)
|
meta:set_int("players", 1)
|
||||||
|
|
||||||
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 })
|
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 })
|
||||||
find_or_create_entity(pos, "mcl_chests:trapped_chest_on_left", tiles_chest_trapped_double, node.param2, true,
|
find_or_create_entity(pos, "mcl_chests:trapped_chest_on_left", tiles.chest_trapped_double, node.param2, true,
|
||||||
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left")
|
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left")
|
||||||
mesecon.receptor_on(pos, trapped_chest_mesecons_rules)
|
mesecon.receptor_on(pos, trapped_chest_mesecons_rules)
|
||||||
|
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "left")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "left")
|
||||||
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_right", param2 = node.param2 })
|
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_right", param2 = node.param2 })
|
||||||
mesecon.receptor_on(pos_other, trapped_chest_mesecons_rules)
|
mesecon.receptor_on(pos_other, trapped_chest_mesecons_rules)
|
||||||
end,
|
end,
|
||||||
function(pos, node, clicker)
|
function(pos, node, clicker)
|
||||||
local pos_other = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
|
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "right")
|
||||||
|
|
||||||
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_right", param2 = node.param2 })
|
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_right", param2 = node.param2 })
|
||||||
mesecon.receptor_on(pos, trapped_chest_mesecons_rules)
|
mesecon.receptor_on(pos, trapped_chest_mesecons_rules)
|
||||||
|
|
||||||
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 })
|
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 })
|
||||||
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_on_left", tiles_chest_trapped_double, node.param2,
|
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_on_left", tiles.chest_trapped_double, node.param2,
|
||||||
true,
|
true,
|
||||||
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left")
|
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_on_left")
|
||||||
mesecon.receptor_on(pos_other, trapped_chest_mesecons_rules)
|
mesecon.receptor_on(pos_other, trapped_chest_mesecons_rules)
|
||||||
@ -1040,6 +1080,14 @@ mcl_chests.register_chest("trapped_chest_on",
|
|||||||
"trapped_chest"
|
"trapped_chest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ================= --
|
||||||
|
-- CONTINUE init.lua --
|
||||||
|
-- ================= --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Disable chest when it has been closed
|
-- Disable chest when it has been closed
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname:find("mcl_chests:") == 1 then
|
if formname:find("mcl_chests:") == 1 then
|
||||||
@ -1053,6 +1101,14 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
player_chest_close(player)
|
player_chest_close(player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- =================== --
|
||||||
|
-- CONTINUE chests.lua --
|
||||||
|
-- =================== --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "mcl_chests:chest",
|
output = "mcl_chests:chest",
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -1074,6 +1130,14 @@ minetest.register_craft({
|
|||||||
burntime = 15,
|
burntime = 15,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ========= --
|
||||||
|
-- ender.lua --
|
||||||
|
-- ========= --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("mcl_chests:ender_chest", {
|
minetest.register_node("mcl_chests:ender_chest", {
|
||||||
description = S("Ender Chest"),
|
description = S("Ender Chest"),
|
||||||
_tt_help = S("27 interdimensional inventory slots") ..
|
_tt_help = S("27 interdimensional inventory slots") ..
|
||||||
@ -1083,7 +1147,7 @@ minetest.register_node("mcl_chests:ender_chest", {
|
|||||||
_doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."),
|
_doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."),
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = "mcl_chests_chest.b3d",
|
mesh = "mcl_chests_chest.b3d",
|
||||||
tiles = tiles_chest_ender_small,
|
tiles = tiles.chest_ender_small,
|
||||||
use_texture_alpha = "opaque",
|
use_texture_alpha = "opaque",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -1127,7 +1191,7 @@ minetest.register_node("mcl_chests:ender_chest_small", {
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = { -0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375 },
|
fixed = { -0.4375, -0.5, -0.4375, 0.4375, 0.375, 0.4375 },
|
||||||
},
|
},
|
||||||
_chest_entity_textures = ender_chest_texture,
|
_chest_entity_textures = tiles.ender_chest_texture,
|
||||||
_chest_entity_sound = "mcl_chests_enderchest",
|
_chest_entity_sound = "mcl_chests_enderchest",
|
||||||
_chest_entity_mesh = "mcl_chests_chest",
|
_chest_entity_mesh = "mcl_chests_chest",
|
||||||
_chest_entity_animation_type = "chest",
|
_chest_entity_animation_type = "chest",
|
||||||
@ -1143,7 +1207,7 @@ minetest.register_node("mcl_chests:ender_chest_small", {
|
|||||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||||
drop = "mcl_core:obsidian 8",
|
drop = "mcl_core:obsidian 8",
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
create_entity(pos, "mcl_chests:ender_chest_small", ender_chest_texture, minetest.get_node(pos).param2, false,
|
create_entity(pos, "mcl_chests:ender_chest_small", tiles.ender_chest_texture, minetest.get_node(pos).param2, false,
|
||||||
"mcl_chests_enderchest", "mcl_chests_chest", "chest")
|
"mcl_chests_enderchest", "mcl_chests_chest", "chest")
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
@ -1153,7 +1217,7 @@ minetest.register_node("mcl_chests:ender_chest_small", {
|
|||||||
end
|
end
|
||||||
minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_" .. clicker:get_player_name(),
|
minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_" .. clicker:get_player_name(),
|
||||||
formspec_ender_chest)
|
formspec_ender_chest)
|
||||||
player_chest_open(clicker, pos, "mcl_chests:ender_chest_small", ender_chest_texture, node.param2, false,
|
player_chest_open(clicker, pos, "mcl_chests:ender_chest_small", tiles.ender_chest_texture, node.param2, false,
|
||||||
"mcl_chests_enderchest", "mcl_chests_chest")
|
"mcl_chests_enderchest", "mcl_chests_chest")
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
@ -1195,6 +1259,14 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ============ --
|
||||||
|
-- shulkers.lua --
|
||||||
|
-- ============ --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Shulker boxes
|
-- Shulker boxes
|
||||||
local boxtypes = {
|
local boxtypes = {
|
||||||
white = S("White Shulker Box"),
|
white = S("White Shulker Box"),
|
||||||
@ -1487,12 +1559,28 @@ for color, desc in pairs(boxtypes) do
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ================ --
|
||||||
|
-- CONTINUE api.lua --
|
||||||
|
-- ================ --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Returns false if itemstack is a shulker box
|
-- Returns false if itemstack is a shulker box
|
||||||
function mcl_chests.is_not_shulker_box(stack)
|
function mcl_chests.is_not_shulker_box(stack)
|
||||||
local g = minetest.get_item_group(stack:get_name(), "shulker_box")
|
local g = minetest.get_item_group(stack:get_name(), "shulker_box")
|
||||||
return g == 0 or g == nil
|
return g == 0 or g == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ===================== --
|
||||||
|
-- CONTINUE shulkers.lua --
|
||||||
|
-- ===================== --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "mcl_chests:violet_shulker_box",
|
output = "mcl_chests:violet_shulker_box",
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -1523,6 +1611,14 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ================= --
|
||||||
|
-- CONTINUE init.lua --
|
||||||
|
-- ================= --
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function select_and_spawn_entity(pos, node)
|
local function select_and_spawn_entity(pos, node)
|
||||||
local node_name = node.name
|
local node_name = node.name
|
||||||
local node_def = minetest.registered_nodes[node_name]
|
local node_def = minetest.registered_nodes[node_name]
|
||||||
|
Loading…
Reference in New Issue
Block a user