mcl_chests: Fix the cracking animation; code and docs clean-up ()

* Fix the cracking animation on chests by setting `use_texture_alpha` to "blend" instead of "clip"
* De-duplicate double chests' `on_rightclick` code
* Use `ipairs(tbl)` instead of `i=1,#tbl` where applicable
* Lots of miscellaneous code formatting/styling fixes
* Minor grammar fixes in documentation files

Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4959
Reviewed-by: teknomunk <teknomunk@protonmail.com>
Co-authored-by: Mikita Wiśniewski <rudzik8@protonmail.com>
Co-committed-by: Mikita Wiśniewski <rudzik8@protonmail.com>
This commit is contained in:
Mikita Wiśniewski 2025-03-03 12:18:44 +01:00 committed by the-real-herowl
parent c40906c340
commit bd93df71fe
8 changed files with 388 additions and 445 deletions

View file

@ -7,7 +7,7 @@ animations are achieved by giving each chest node an entity, as Luanti (as of
Because of that, a lot of parameters passed through the exposed functions are
related to nodes and entities.
Please refer to the [Luanti documentation](http://api.minetest.net/) and code
Please refer to the [Luanti documentation](http://api.luanti.org/) and code
comments in `api.lua`.
@ -27,9 +27,9 @@ trapped chests.
-- Will be shown as chest's name in the inventory.
title = {
small = S("Stone Chest") -- the same as `desc` if not specified
double = S("Large Stone Chest") -- defaults to `"Large " .. desc`
}
small = S("Stone Chest"), -- the same as `desc` if not specified
double = S("Large Stone Chest"), -- defaults to `"Large " .. desc`
}
-- These will be shown when opening the chest (in formspecs).
longdesc = S(
@ -41,9 +41,9 @@ trapped chests.
-- Equivalent to `_doc_items_longdesc`, `_doc_items_usagehelp` and
-- `_tt_help` fields of Item/Node definition. Shown in the tooltip and wiki.
tiles = {
small = { "vl_stone_chests_small.png" },
double = { "vl_stone_chests_double.png" },
tiles = {
small = {"vl_stone_chests_small.png"},
double = {"vl_stone_chests_double.png"},
inv = {
"vl_stone_chests_top.png",
"vl_stone_chests_bottom.png",
@ -51,8 +51,8 @@ trapped chests.
"vl_stone_chests_left.png",
"vl_stone_chests_back.png",
"vl_stone_chests_front.png"
},
},
},
},
-- `small` and `double` fields contain the textures that will be applied to
-- chest entities.
-- `inv` field contains table of textures (6 in total, for each cube side),
@ -62,14 +62,14 @@ trapped chests.
pickaxey = 1,
stone = 1,
material_stone = 1,
},
},
-- Equivalent to `groups` field of Item/Node definition. There is some table
-- merging occuring internally, but it is purely for entity rendering.
-- merging occurring internally, but it is purely for entity rendering.
sounds = {
sounds = {
mcl_sounds.node_sound_stone_defaults(), -- defaults to `nil`
"vl_stone_chests_sound" -- defaults to `"default_chest"`
},
},
-- First value is equivalent to `sounds` field of Item/Node definition.
-- Second value is a sound prefix, from which the actual sounds will be
-- concatenated (e.g. `vl_stone_chests_sound_open.ogg`). See `api.lua`.
@ -81,12 +81,12 @@ trapped chests.
hidden = false,
-- Equivalent to `_doc_items_hidden` field of Item/Node definition.
mesecons = {
receptor = {
mesecons = {
receptor = {
state = mesecon.state.on,
rules = mesecon.rules.pplate,
},
},
}
},
-- Equivalent to `mesecons` field of Item/Node definition.
on_rightclick = function(pos, node, clicker)
@ -179,7 +179,7 @@ and is applied in `on_rotate` field of Node definition.
This table contains all currently open chests, indexed by player name.
`nil` if player is not using a chest, and `{ pos = <chest node position> }`
`nil` if player is not using a chest, and `{pos = <chest node position>}`
otherwise (where position is a vector value).
@ -227,7 +227,7 @@ This function is called when a chest is closed by `player_chest_close`.
## `mcl_chests.is_not_shulker_box(stack)`
This function checks for whether `stack` is a shulker box, and returns `false`
if it is. Used internally to disallow putting shulker boxes into shulker boxes.
This function checks whether `stack` is a shulker box, and returns `false` if
it is. Used internally to disallow putting shulker boxes into shulker boxes.
* `stack` is an ItemStack.

View file

@ -9,7 +9,7 @@ The API is documented in `API.md`.
## License of source code
Copyright (C) 2011-2012 celeron55, Perttu Ahola <celeron55@gmail.com>\
Copyright (C) 2024 rudzik8, Mikita Wiśniewski <rudzik8@protonmail.com>
Copyright (C) 2024-2025 rudzik8, Mikita Wiśniewski <rudzik8@protonmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View file

@ -1,6 +1,6 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local S = core.get_translator(core.get_current_modname())
local F = core.formspec_escape
local C = core.colorize
local get_double_container_neighbor_pos = mcl_util.get_double_container_neighbor_pos
@ -9,12 +9,12 @@ local table = table
local sf = string.format
-- Recursively merge tables with eachother
-- Recursively merge tables with each other
local function table_merge(tbl, ...)
local t = table.copy(tbl)
for k,v in pairs(...) do
if type(t[k]) == "table" and type(v) == "table" then
table_merge(t[k], v)
t[k] = table_merge(t[k], v)
else
t[k] = v
end
@ -27,21 +27,21 @@ end
-- This is necessary to show the chest as an animated mesh, as Luanti doesn't support assigning animated meshes to
-- nodes directly. We're bypassing this limitation by giving each chest its own entity, and making the chest node
-- itself fully transparent.
local animated_chests = (minetest.settings:get_bool("animated_chests") ~= false)
local animated_chests = (core.settings:get_bool("animated_chests") ~= false)
local entity_animations = {
shulker = {
speed = 50,
open = { x = 45, y = 95 },
close = { x = 95, y = 145 },
open = {x = 45, y = 95},
close = {x = 95, y = 145},
},
chest = {
speed = 25,
open = { x = 0, y = 7 },
close = { x = 13, y = 20 },
open = {x = 0, y = 7},
close = {x = 13, y = 20},
},
}
minetest.register_entity("mcl_chests:chest", {
core.register_entity("mcl_chests:chest", {
initial_properties = {
visual = "mesh",
pointable = false,
@ -60,8 +60,9 @@ minetest.register_entity("mcl_chests:chest", {
self.players[playername] = true
if not self.is_open then
self:set_animation("open")
minetest.sound_play(self.sound_prefix .. "_open", { pos = self.node_pos, gain = 0.5, max_hear_distance = 16 },
true)
core.sound_play(self.sound_prefix .. "_open", {
pos = self.node_pos, gain = 0.5, max_hear_distance = 16
}, true)
self.is_open = true
end
end,
@ -74,9 +75,9 @@ minetest.register_entity("mcl_chests:chest", {
return
end
self:set_animation("close")
minetest.sound_play(self.sound_prefix .. "_close",
{ pos = self.node_pos, gain = 0.3, max_hear_distance = 16 },
true)
core.sound_play(self.sound_prefix .. "_close", {
pos = self.node_pos, gain = 0.3, max_hear_distance = 16
}, true)
self.is_open = false
end
end,
@ -87,7 +88,7 @@ minetest.register_entity("mcl_chests:chest", {
self.sound_prefix = sound_prefix
self.animation_type = animation_type
local obj = self.object
obj:set_armor_groups({ immortal = 1 })
obj:set_armor_groups({immortal = 1})
obj:set_properties({
textures = textures,
mesh = mesh_prefix .. (double and "_double" or "") .. ".b3d",
@ -101,7 +102,7 @@ minetest.register_entity("mcl_chests:chest", {
end,
set_yaw = function(self, dir)
self.object:set_yaw(minetest.dir_to_yaw(dir))
self.object:set_yaw(core.dir_to_yaw(dir))
end,
check = function(self)
@ -109,7 +110,7 @@ minetest.register_entity("mcl_chests:chest", {
if not node_pos or not node_name then
return false
end
local node = minetest.get_node(node_pos)
local node = core.get_node(node_pos)
if node.name ~= node_name then
return false
end
@ -118,10 +119,9 @@ minetest.register_entity("mcl_chests:chest", {
on_activate = function(self, initialization_data)
if initialization_data and initialization_data:find("\"###mcl_chests:chest###\"") then
self:initialize(unpack(minetest.deserialize(initialization_data)))
self:initialize(unpack(core.deserialize(initialization_data)))
else
minetest.log("warning",
"[mcl_chests] on_activate called without proper initialization_data ... removing entity")
core.log("warning", "[mcl_chests] on_activate called without proper initialization_data ... removing entity")
self.object:remove()
end
end,
@ -133,17 +133,17 @@ minetest.register_entity("mcl_chests:chest", {
end
})
local add, mul, vec, cross = vector.add, vector.multiply, vector.new, vector.cross
local function get_entity_pos(pos, dir, double)
pos = vector.copy(pos)
if double then
local add, mul, vec, cross = vector.add, vector.multiply, vector.new, vector.cross
pos = add(pos, mul(cross(dir, vec(0, 1, 0)), -0.5))
end
return pos
end
local function find_entity(pos)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0)) do
for _, obj in pairs(core.get_objects_inside_radius(pos, 0)) do
local luaentity = obj:get_luaentity()
if luaentity and luaentity.name == "mcl_chests:chest" then
return luaentity
@ -152,40 +152,41 @@ local function find_entity(pos)
end
local function get_entity_info(pos, param2, double, dir, entity_pos)
dir = dir or minetest.facedir_to_dir(param2)
dir = dir or core.facedir_to_dir(param2)
return dir, get_entity_pos(pos, dir, double)
end
local function create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir,
entity_pos)
local function create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, entity_pos)
dir, entity_pos = get_entity_info(pos, param2, double, dir, entity_pos)
local initialization_data = minetest.serialize({pos, node_name, textures, dir, double, sound_prefix,
mesh_prefix, animation_type, "###mcl_chests:chest###"})
local obj = minetest.add_entity(entity_pos, "mcl_chests:chest", initialization_data)
local initialization_data = core.serialize({
pos, node_name, textures, dir, double, sound_prefix,
mesh_prefix, animation_type, "###mcl_chests:chest###"
})
local obj = core.add_entity(entity_pos, "mcl_chests:chest", initialization_data)
if obj and obj:get_pos() then
return obj:get_luaentity()
else
minetest.log("warning", "[mcl_chests] Failed to create entity at " ..
(entity_pos and minetest.pos_to_string(entity_pos, 1) or "nil"))
core.log("warning", "[mcl_chests] Failed to create entity at " ..
(entity_pos and core.pos_to_string(entity_pos, 1) or "nil"))
end
end
mcl_chests.create_entity = create_entity
local function find_or_create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix,
animation_type, dir, entity_pos)
local function find_or_create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, entity_pos)
dir, entity_pos = get_entity_info(pos, param2, double, dir, entity_pos)
return find_entity(entity_pos) or
create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir,
entity_pos)
create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir, entity_pos)
end
mcl_chests.find_or_create_entity = find_or_create_entity
local function select_and_spawn_entity(pos, node)
local node_name = node.name
local node_def = minetest.registered_nodes[node_name]
local double_chest = minetest.get_item_group(node_name, "double_chest") > 0
find_or_create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest,
node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type)
local node_def = core.registered_nodes[node_name]
local double_chest = core.get_item_group(node_name, "double_chest") > 0
return find_or_create_entity(
pos, node_name, node_def._chest_entity_textures, node.param2, double_chest,
node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type
)
end
mcl_chests.select_and_spawn_entity = select_and_spawn_entity
@ -195,11 +196,13 @@ if screwdriver then
simple_rotate = function(pos, node, user, mode, new_param2)
if screwdriver.rotate_simple(pos, node, user, mode, new_param2) ~= false then
local nodename = node.name
local nodedef = minetest.registered_nodes[nodename]
local dir = minetest.facedir_to_dir(new_param2)
find_or_create_entity(pos, nodename, nodedef._chest_entity_textures, new_param2, false,
nodedef._chest_entity_sound,
nodedef._chest_entity_mesh, nodedef._chest_entity_animation_type, dir):set_yaw(dir)
local nodedef = core.registered_nodes[nodename]
local dir = core.facedir_to_dir(new_param2)
find_or_create_entity(
pos, nodename, nodedef._chest_entity_textures, new_param2, false,
nodedef._chest_entity_sound, nodedef._chest_entity_mesh,
nodedef._chest_entity_animation_type, dir
):set_yaw(dir)
else
return false
end
@ -211,7 +214,7 @@ mcl_chests.no_rotate, mcl_chests.simple_rotate = no_rotate, simple_rotate
-- -------------------
-- Key: Player name
-- Value:
-- If player is using a chest: { pos = <chest node position> }
-- If player is using a chest: {pos = <chest node position>}
-- Otherwise: nil
local open_chests = {}
mcl_chests.open_chests = open_chests
@ -230,9 +233,11 @@ local function player_chest_open(player, pos, node_name, textures, param2, doubl
shulker = shulker
}
if animated_chests then
local dir = minetest.facedir_to_dir(param2)
find_or_create_entity(pos, node_name, textures, param2, double, sound, mesh,
shulker and "shulker" or "chest", dir):open(name)
local dir = core.facedir_to_dir(param2)
find_or_create_entity(
pos, node_name, textures, param2, double, sound,
mesh, shulker and "shulker" or "chest", dir
):open(name)
end
end
mcl_chests.player_chest_open = player_chest_open
@ -240,8 +245,8 @@ mcl_chests.player_chest_open = player_chest_open
-- Simple protection checking functions
local function protection_check_move(pos, from_list, from_index, to_list, to_index, count, player)
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
if core.is_protected(pos, name) then
core.record_protection_violation(pos, name)
return 0
else
return count
@ -251,8 +256,8 @@ mcl_chests.protection_check_move = protection_check_move
local function protection_check_take(pos, listname, index, stack, player)
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
if core.is_protected(pos, name) then
core.record_protection_violation(pos, name)
return 0
else
return stack:get_count()
@ -262,53 +267,55 @@ mcl_chests.protection_check_put_take = protection_check_take
-- Logging functions
local function log_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name() ..
" moves stuff to chest at " .. minetest.pos_to_string(pos))
core.log("action", player:get_player_name() .. " moves stuff to chest at " .. core.pos_to_string(pos))
end
local function log_inventory_put(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" moves stuff to chest at " .. minetest.pos_to_string(pos))
core.log("action", player:get_player_name() .. " moves stuff to chest at " .. core.pos_to_string(pos))
-- BEGIN OF LISTRING WORKAROUND
if listname == "input" then
local inv = minetest.get_inventory({ type = "node", pos = pos })
local inv = core.get_inventory({type = "node", pos = pos})
inv:add_item("main", stack)
end
-- END OF LISTRING WORKAROUND
end
local function log_inventory_take(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" takes stuff from chest at " .. minetest.pos_to_string(pos))
core.log("action", player:get_player_name() .. " takes stuff from chest at " .. core.pos_to_string(pos))
end
-- To be called when a chest is closed (only relevant for trapped chest atm)
local function chest_update_after_close(pos)
local node = minetest.get_node(pos)
local node = core.get_node(pos)
if node.name == "mcl_chests:trapped_chest_on_small" then
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_small", param2 = node.param2 })
find_or_create_entity(pos, "mcl_chests:trapped_chest_small", { "mcl_chests_trapped.png" }, node.param2, false,
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_small")
core.swap_node(pos, {name = "mcl_chests:trapped_chest_small", param2 = node.param2})
find_or_create_entity(
pos, "mcl_chests:trapped_chest_small", mcl_chests.tiles.chest_trapped_small,
node.param2, false, "default_chest", "mcl_chests_chest", "chest"
):reinitialize("mcl_chests:trapped_chest_small")
mesecon.receptor_off(pos, mesecon.rules.pplate)
elseif node.name == "mcl_chests:trapped_chest_on_left" then
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_left", param2 = node.param2 })
find_or_create_entity(pos, "mcl_chests:trapped_chest_left", mcl_chests.tiles.chest_trapped_double, node.param2, true,
"default_chest", "mcl_chests_chest", "chest"):reinitialize("mcl_chests:trapped_chest_left")
core.swap_node(pos, {name = "mcl_chests:trapped_chest_left", param2 = node.param2})
find_or_create_entity(
pos, "mcl_chests:trapped_chest_left", mcl_chests.tiles.chest_trapped_double,
node.param2, true, "default_chest", "mcl_chests_chest", "chest"
):reinitialize("mcl_chests:trapped_chest_left")
mesecon.receptor_off(pos, mesecon.rules.pplate)
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 })
core.swap_node(pos_other, {name = "mcl_chests:trapped_chest_right", param2 = node.param2})
mesecon.receptor_off(pos_other, mesecon.rules.pplate)
elseif node.name == "mcl_chests:trapped_chest_on_right" then
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_right", param2 = node.param2 })
core.swap_node(pos, {name = "mcl_chests:trapped_chest_right", param2 = node.param2})
mesecon.receptor_off(pos, mesecon.rules.pplate)
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 })
find_or_create_entity(pos_other, "mcl_chests:trapped_chest_left", mcl_chests.tiles.chest_trapped_double,
node.param2, true, "default_chest", "mcl_chests_chest", "chest")
:reinitialize("mcl_chests:trapped_chest_left")
core.swap_node(pos_other, {name = "mcl_chests:trapped_chest_left", param2 = node.param2})
find_or_create_entity(
pos_other, "mcl_chests:trapped_chest_left", mcl_chests.tiles.chest_trapped_double,
node.param2, true, "default_chest", "mcl_chests_chest", "chest"
):reinitialize("mcl_chests:trapped_chest_left")
mesecon.receptor_off(pos_other, mesecon.rules.pplate)
end
end
@ -322,9 +329,11 @@ local function player_chest_close(player)
return
end
if animated_chests then
find_or_create_entity(open_chest.pos, open_chest.node_name, open_chest.textures, open_chest.param2,
open_chest.double, open_chest.sound, open_chest.mesh, open_chest.shulker and "shulker" or "chest")
:close(name)
find_or_create_entity(
open_chest.pos, open_chest.node_name, open_chest.textures,
open_chest.param2, open_chest.double, open_chest.sound,
open_chest.mesh, open_chest.shulker and "shulker" or "chest"
):close(name)
end
chest_update_after_close(open_chest.pos)
@ -364,10 +373,10 @@ local function double_chest_add_item(top_inv, bottom_inv, listname, stack)
end
local function on_chest_blast(pos)
local node = minetest.get_node(pos)
local node = core.get_node(pos)
local drop_items_chest = mcl_util.drop_items_from_meta_container("main")
drop_items_chest(pos, node)
minetest.remove_node(pos)
core.remove_node(pos)
end
local function limit_put_list(stack, list)
@ -388,21 +397,20 @@ local function limit_put(stack, top_inv, bottom_inv)
end
local function close_forms(canonical_basename, pos)
local players = minetest.get_connected_players()
for p = 1, #players do
if vector.distance(players[p]:get_pos(), pos) <= 30 then
minetest.close_formspec(players[p]:get_player_name(),
for _, player in ipairs(core.get_connected_players()) do
if vector.distance(player:get_pos(), pos) <= 30 then
core.close_formspec(player:get_player_name(),
"mcl_chests:" .. canonical_basename .. "_" .. pos.x .. "_" .. pos.y .. "_" .. pos.z)
end
end
end
local function get_chest_inventories(pos, side)
local inv = minetest.get_inventory({ type = "node", pos = pos })
local inv = core.get_inventory({type = "node", pos = pos})
local node = minetest.get_node(pos)
local node = core.get_node(pos)
local pos_other = get_double_container_neighbor_pos(pos, node.param2, side)
local inv_other = minetest.get_inventory({ type = "node", pos = pos_other })
local inv_other = core.get_inventory({type = "node", pos = pos_other})
local top_inv, bottom_inv
if side == "left" then
@ -415,6 +423,10 @@ local function get_chest_inventories(pos, side)
return top_inv, bottom_inv
end
local function after_place_chest(pos, placer, itemstack, pointed_thing)
core.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
end
-- Functions used in double chest registration code
-- ------------------------------------------------
-- The `return function` wrapping is necessary to avoid stacking up parameters.
@ -444,40 +456,98 @@ local function hopper_push_double(side) return function(pos, hop_pos, hop_inv, h
end end
local function construct_double_chest(side, names) return function(pos)
local n = minetest.get_node(pos)
local param2 = n.param2
local p = get_double_container_neighbor_pos(pos, param2, side)
local node = core.get_node(pos)
local param2 = node.param2
local pos_other = get_double_container_neighbor_pos(pos, param2, side)
-- Turn into a small chest if the neighbor is gone
if not p or minetest.get_node(p).name ~= names[side].cr then
n.name = names.small.a
minetest.swap_node(pos, n)
if not pos_other or core.get_node(pos_other).name ~= names[side].r then
node.name = names.small.a
core.swap_node(pos, node)
end
end end
local function destruct_double_chest(side, names, canonical_basename, small_textures, sound_prefix) return function(pos)
local n = minetest.get_node(pos)
if n.name == names.small.a then
local node = core.get_node(pos)
if node.name == names.small.a then
return
end
close_forms(canonical_basename, pos)
local param2 = n.param2
local p = get_double_container_neighbor_pos(pos, param2, side)
if not p or minetest.get_node(p).name ~= names[side].r then
local param2 = node.param2
local pos_other = get_double_container_neighbor_pos(pos, param2, side)
if not pos_other or core.get_node(pos_other).name ~= names[side].r then
return
end
close_forms(canonical_basename, p)
close_forms(canonical_basename, pos_other)
minetest.swap_node(p, { name = names.small.a, param2 = param2 })
create_entity(p, names.small.a, small_textures, param2, false, sound_prefix, "mcl_chests_chest", "chest")
core.swap_node(pos_other, {name = names.small.a, param2 = param2})
create_entity(pos_other, names.small.a, small_textures, param2, false, sound_prefix, "mcl_chests_chest", "chest")
end end
local function on_rightclick_double(side, names, d, double_textures) return function(pos, node, clicker)
local pos_left = side == "left" and pos or get_double_container_neighbor_pos(pos, node.param2, side)
local pos_right = side == "right" and pos or get_double_container_neighbor_pos(pos, node.param2, side)
do -- Don't open if there's no space from the top
local above_def_left = core.registered_nodes[core.get_node(vector.offset(pos_left, 0, 1, 0)).name]
local above_def_right = core.registered_nodes[core.get_node(vector.offset(pos_right, 0, 1, 0)).name]
if (not above_def_left or above_def_left.groups.opaque == 1) or
(not above_def_right or above_def_right.groups.opaque == 1) then
return false
end
end
local name = core.get_meta(pos_left):get_string("name")
if name == "" then -- if empty after that ^
name = core.get_meta(pos_right):get_string("name")
if name == "" then -- if STILL empty after that ^
name = d.title.double
end
end
core.show_formspec(clicker:get_player_name(),
sf("mcl_chests:%s_%s_%s_%s", d.canonical_basename, pos.x, pos.y, pos.z),
table.concat({
"formspec_version[4]",
"size[11.75,14.15]",
"label[0.375,0.375;", F(C(mcl_formspec.label_color, name)), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos_left.x, pos_left.y, pos_left.z),
mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos_right.x, pos_right.y, pos_right.z),
"label[0.375,8.45;", F(C(mcl_formspec.label_color, S("Inventory"))), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3),
"list[current_player;main;0.375,8.825;9,3;9]",
mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1),
"list[current_player;main;0.375,12.775;9,1;]",
--BEGIN OF LISTRING WORKAROUND
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
--END OF LISTRING WORKAROUND
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;main]", pos_left.x, pos_left.y, pos_left.z),
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;main]", pos_right.x, pos_right.y, pos_right.z),
})
)
if d["on_rightclick_"..side] then
d["on_rightclick_"..side](pos, node, clicker)
end
player_chest_open(clicker, pos_left, names.left.a, double_textures, node.param2, true, d.sounds[2], "mcl_chests_chest")
end end
-- Small chests use `protection_check_take` for both put and take actions.
local function protection_check_put(side) return function(pos, listname, index, stack, player)
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
if core.is_protected(pos, name) then
core.record_protection_violation(pos, name)
return 0
-- BEGIN OF LISTRING WORKAROUND
elseif listname == "input" then
@ -490,8 +560,8 @@ local function protection_check_put(side) return function(pos, listname, index,
end end
local function log_inventory_put_double(side) return function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" moves stuff to chest at " .. minetest.pos_to_string(pos))
core.log("action", player:get_player_name() ..
" moves stuff to chest at " .. core.pos_to_string(pos))
-- BEGIN OF LISTRING WORKAROUND
if listname == "input" then
local top_inv, bottom_inv = get_chest_inventories(pos, side)
@ -508,7 +578,7 @@ end end
-- Some parameters here are only utilized by trapped chests.
function mcl_chests.register_chest(basename, d)
-- If this passes without crash, we know for a fact that d = {...}
assert((d and type(d) == "table"), "Second argument to mcl_chests.register_chest must be a table")
assert(d and type(d) == "table", "Second argument to mcl_chests.register_chest must be a table")
-- Fallback for when there is no `title` field
if not d.title then d.title = {} end
@ -531,13 +601,9 @@ function mcl_chests.register_chest(basename, d)
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" }
d.sounds = {nil, "default_chest"}
end
if not d.sounds[2] then
@ -580,7 +646,7 @@ function mcl_chests.register_chest(basename, d)
local double_textures = d.tiles.double
-- Construct groups
local groups_inv = table_merge({ deco_block = 1 }, d.groups)
local groups_inv = table_merge({deco_block = 1}, d.groups)
local groups_small = table_merge(groups_inv, {
container = 2,
deco_block = 1,
@ -600,7 +666,7 @@ function mcl_chests.register_chest(basename, d)
-- Dummy inventory node
-- Will turn into names.small.a when placed down
minetest.register_node("mcl_chests:" .. basename, {
core.register_node("mcl_chests:" .. basename, {
description = d.desc,
_tt_help = d.tt_help,
_doc_items_longdesc = d.longdesc,
@ -614,17 +680,15 @@ function mcl_chests.register_chest(basename, d)
paramtype2 = "facedir",
sounds = d.sounds[1],
groups = groups_inv,
on_construct = function(pos, node)
local node = minetest.get_node(pos)
on_construct = function(pos)
local node = core.get_node(pos)
node.name = names.small.a
minetest.set_node(pos, node)
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
core.set_node(pos, node)
end,
after_place_node = after_place_chest,
})
minetest.register_node(names.small.a, {
core.register_node(names.small.a, {
description = d.desc,
_tt_help = d.tt_help,
_doc_items_longdesc = d.longdesc,
@ -633,10 +697,10 @@ function mcl_chests.register_chest(basename, d)
drawtype = "nodebox",
node_box = {
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},
},
tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip",
tiles = {"blank.png^[resize:16x16"},
use_texture_alpha = "blend",
_chest_entity_textures = small_textures,
_chest_entity_sound = d.sounds[2],
_chest_entity_mesh = "mcl_chests_chest",
@ -648,8 +712,8 @@ function mcl_chests.register_chest(basename, d)
is_ground_content = false,
sounds = d.sounds[1],
on_construct = function(pos)
local param2 = minetest.get_node(pos).param2
local meta = minetest.get_meta(pos)
local param2 = core.get_node(pos).param2
local meta = core.get_meta(pos)
--[[ This is a workaround for Luanti issue 5894
<https://github.com/minetest/minetest/issues/5894>.
@ -677,29 +741,27 @@ function mcl_chests.register_chest(basename, d)
-- END OF LISTRING WORKAROUND
-- Combine into a double chest if neighbouring another small chest
if minetest.get_node(get_double_container_neighbor_pos(pos, param2, "right")).name ==
names.small.a then
minetest.swap_node(pos, { name = names.right.a, param2 = param2 })
if core.get_node(get_double_container_neighbor_pos(pos, param2, "right")).name ==
names.small.c then
core.swap_node(pos, {name = names.right.c, param2 = param2})
local p = get_double_container_neighbor_pos(pos, param2, "right")
minetest.swap_node(p, { name = names.left.a, param2 = param2 })
create_entity(p, names.left.a, double_textures, param2, true, d.sounds[2],
core.swap_node(p, {name = names.left.c, param2 = param2})
create_entity(p, names.left.c, double_textures, param2, true, d.sounds[2],
"mcl_chests_chest", "chest")
elseif minetest.get_node(get_double_container_neighbor_pos(pos, param2, "left")).name ==
names.small.a then
minetest.swap_node(pos, { name = names.left.a, param2 = param2 })
create_entity(pos, names.left.a, double_textures, param2, true, d.sounds[2],
elseif core.get_node(get_double_container_neighbor_pos(pos, param2, "left")).name ==
names.small.c then
core.swap_node(pos, {name = names.left.c, param2 = param2})
create_entity(pos, names.left.c, double_textures, param2, true, d.sounds[2],
"mcl_chests_chest", "chest")
local p = get_double_container_neighbor_pos(pos, param2, "left")
minetest.swap_node(p, { name = names.right.a, param2 = param2 })
core.swap_node(p, {name = names.right.a, param2 = param2})
else
minetest.swap_node(pos, { name = names.small.a, param2 = param2 })
create_entity(pos, names.small.a, small_textures, param2, false, d.sounds[2],
core.swap_node(pos, {name = names.small.c, param2 = param2})
create_entity(pos, names.small.c, small_textures, param2, false, d.sounds[2],
"mcl_chests_chest", "chest")
end
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
end,
after_place_node = after_place_chest,
after_dig_node = drop_items_chest,
on_blast = on_chest_blast,
allow_metadata_inventory_move = protection_check_move,
@ -712,28 +774,27 @@ function mcl_chests.register_chest(basename, d)
_mcl_hardness = d.hardness,
on_rightclick = function(pos, node, clicker)
local topnode = minetest.get_node({ x = pos.x, y = pos.y + 1, z = pos.z })
if topnode and topnode.name and minetest.registered_nodes[topnode.name] then
if minetest.registered_nodes[topnode.name].groups.opaque == 1 then
-- won't open if there is no space from the top
return false
end
local topnode = core.get_node(vector.offset(pos, 0, 1, 0))
if topnode and topnode.name and core.registered_nodes[topnode.name]
and core.registered_nodes[topnode.name].groups.opaque == 1 then
-- won't open if there is no space from the top
return false
end
local name = minetest.get_meta(pos):get_string("name")
local name = core.get_meta(pos):get_string("name")
if name == "" then
name = d.title.small
end
minetest.show_formspec(clicker:get_player_name(),
core.show_formspec(clicker:get_player_name(),
sf("mcl_chests:%s_%s_%s_%s", d.canonical_basename, pos.x, pos.y, pos.z),
table.concat({
"formspec_version[4]",
"size[11.75,10.425]",
"label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]",
"label[0.375,0.375;", F(C(mcl_formspec.label_color, name)), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z),
"label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]",
"label[0.375,4.7;", F(C(mcl_formspec.label_color, S("Inventory"))), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3),
"list[current_player;main;0.375,5.1;9,3;9]",
@ -759,14 +820,14 @@ function mcl_chests.register_chest(basename, d)
on_rotate = simple_rotate,
})
minetest.register_node(names.left.a, {
core.register_node(names.left.a, {
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = { -0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375 },
fixed = {-0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375},
},
tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip",
tiles = {"blank.png^[resize:16x16"},
use_texture_alpha = "blend",
_chest_entity_textures = double_textures,
_chest_entity_sound = d.sounds[2],
_chest_entity_mesh = "mcl_chests_chest",
@ -778,10 +839,8 @@ function mcl_chests.register_chest(basename, d)
is_ground_content = false,
sounds = d.sounds[1],
on_construct = construct_double_chest("left", names),
after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
end,
on_destruct = destruct_double_chest("left", names, d.canonical_basename, small_textures, d.sounds[2]),
after_place_node = after_place_chest,
after_dig_node = drop_items_chest,
on_blast = on_chest_blast,
allow_metadata_inventory_move = protection_check_move,
@ -792,91 +851,30 @@ function mcl_chests.register_chest(basename, d)
on_metadata_inventory_take = log_inventory_take,
_mcl_blast_resistance = d.hardness,
_mcl_hardness = d.hardness,
on_rightclick = function(pos, node, clicker)
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_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
return false
end
local name = minetest.get_meta(pos):get_string("name")
if name == "" then -- if empty after that ^
name = minetest.get_meta(pos_other):get_string("name")
end if name == "" then -- if STILL empty after that ^
name = d.title.double
end
minetest.show_formspec(clicker:get_player_name(),
sf("mcl_chests:%s_%s_%s_%s", d.canonical_basename, pos.x, pos.y, pos.z),
table.concat({
"formspec_version[4]",
"size[11.75,14.15]",
"label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos.x, pos.y, pos.z),
mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos_other.x, pos_other.y, pos_other.z),
"label[0.375,8.45;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3),
"list[current_player;main;0.375,8.825;9,3;9]",
mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1),
"list[current_player;main;0.375,12.775;9,1;]",
--BEGIN OF LISTRING WORKAROUND
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
--END OF LISTRING WORKAROUND
"listring[current_player;main]" ..
sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z),
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z),
})
)
if d.on_rightclick_left then
d.on_rightclick_left(pos, node, clicker)
end
player_chest_open(clicker, pos, names.left.a, double_textures, node.param2, true, d.sounds[2],
"mcl_chests_chest")
end,
on_rightclick = on_rightclick_double("left", names, d, double_textures),
mesecons = d.mesecons,
on_rotate = no_rotate,
_mcl_hoppers_on_try_pull = hopper_pull_double("left"),
_mcl_hoppers_on_try_push = hopper_push_double("left"),
})
minetest.register_node(names.right.a, {
core.register_node(names.right.a, {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375 },
fixed = {-0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375},
},
tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip",
tiles = {"blank.png^[resize:16x16"},
use_texture_alpha = "blend",
groups = groups_right,
drop = d.drop,
is_ground_content = false,
sounds = d.sounds[1],
on_construct = construct_double_chest("right", names),
after_place_node = function(pos, placer, itemstack, pointed_thing)
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
end,
on_destruct = destruct_double_chest("right", names, d.canonical_basename, small_textures, d.sounds[2]),
after_place_node = after_place_chest,
after_dig_node = drop_items_chest,
on_blast = on_chest_blast,
allow_metadata_inventory_move = protection_check_move,
@ -887,66 +885,7 @@ function mcl_chests.register_chest(basename, d)
on_metadata_inventory_take = log_inventory_take,
_mcl_blast_resistance = d.hardness,
_mcl_hardness = d.hardness,
on_rightclick = function(pos, node, clicker)
local pos_other = get_double_container_neighbor_pos(pos, node.param2, "right")
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[
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
return false
end
local name = minetest.get_meta(pos):get_string("name")
if name == "" then -- if empty after that ^
name = minetest.get_meta(pos_other):get_string("name")
end if name == "" then -- if STILL empty after that ^
name = d.title.double
end
minetest.show_formspec(clicker:get_player_name(),
sf("mcl_chests:%s_%s_%s_%s", d.canonical_basename, pos.x, pos.y, pos.z),
table.concat({
"formspec_version[4]",
"size[11.75,14.15]",
"label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,0.75;9,3;]", pos_other.x, pos_other.y, pos_other.z),
mcl_formspec.get_itemslot_bg_v4(0.375, 4.5, 9, 3),
sf("list[nodemeta:%s,%s,%s;main;0.375,4.5;9,3;]", pos.x, pos.y, pos.z),
"label[0.375,8.45;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 8.825, 9, 3),
"list[current_player;main;0.375,8.825;9,3;9]",
mcl_formspec.get_itemslot_bg_v4(0.375, 12.775, 9, 1),
"list[current_player;main;0.375,12.775;9,1;]",
--BEGIN OF LISTRING WORKAROUND
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;input]", pos.x, pos.y, pos.z),
--END OF LISTRING WORKAROUND
"listring[current_player;main]" ..
sf("listring[nodemeta:%s,%s,%s;main]", pos_other.x, pos_other.y, pos_other.z),
"listring[current_player;main]",
sf("listring[nodemeta:%s,%s,%s;main]", pos.x, pos.y, pos.z),
})
)
if d.on_rightclick_right then
d.on_rightclick_right(pos, node, clicker)
end
player_chest_open(clicker, pos_other, names.left.a, double_textures, node.param2, true, d.sounds[2],
"mcl_chests_chest")
end,
on_rightclick = on_rightclick_double("right", names, d, double_textures),
mesecons = d.mesecons,
on_rotate = no_rotate,
_mcl_hoppers_on_try_pull = hopper_pull_double("right"),
@ -961,6 +900,6 @@ end
-- Returns false if itemstack is a shulker box
function mcl_chests.is_not_shulker_box(stack)
local g = minetest.get_item_group(stack:get_name(), "shulker_box")
local g = core.get_item_group(stack:get_name(), "shulker_box")
return g == 0 or g == nil
end

View file

@ -1,4 +1,4 @@
local S = minetest.get_translator(minetest.get_current_modname())
local S = core.get_translator(core.get_current_modname())
local get_double_container_neighbor_pos = mcl_util.get_double_container_neighbor_pos
local chestusage = S("To access its inventory, rightclick it. When broken, the items will drop out.")
@ -14,9 +14,11 @@ mcl_chests.register_chest("chest", {
tiles = {
small = mcl_chests.tiles.chest_normal_small,
double = mcl_chests.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_back.png", "default_chest_front.png" },
"mcl_chests_chest_back.png", "default_chest_front.png"
},
},
groups = {
handy = 1,
@ -24,7 +26,7 @@ mcl_chests.register_chest("chest", {
material_wood = 1,
flammable = -1,
},
sounds = { mcl_sounds.node_sound_wood_defaults() },
sounds = {mcl_sounds.node_sound_wood_defaults()},
hardness = 2.5,
hidden = false,
})
@ -46,8 +48,8 @@ mcl_chests.register_chest("trapped_chest", {
"chests with double the capacity by placing two trapped chests next to each other."
),
usagehelp = chestusage,
tt_help = S("27 inventory slots") ..
"\n" .. S("Can be combined to a large chest") .. "\n" .. S("Emits a redstone signal when opened"),
tt_help = S("27 inventory slots") .. "\n" ..
S("Can be combined to a large chest") .. "\n" .. S("Emits a redstone signal when opened"),
tiles = traptiles,
groups = {
handy = 1,
@ -56,7 +58,7 @@ mcl_chests.register_chest("trapped_chest", {
flammable = -1,
mesecon = 2,
},
sounds = { mcl_sounds.node_sound_wood_defaults() },
sounds = {mcl_sounds.node_sound_wood_defaults()},
hardness = 2.5,
hidden = false,
mesecons = {
@ -66,36 +68,39 @@ mcl_chests.register_chest("trapped_chest", {
},
},
on_rightclick = function(pos, node, clicker)
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_small", param2 = node.param2 })
mcl_chests.find_or_create_entity(pos, "mcl_chests:trapped_chest_on_small", { "mcl_chests_trapped.png" },
node.param2, false, "default_chest", "mcl_chests_chest", "chest")
:reinitialize("mcl_chests:trapped_chest_on_small")
core.swap_node(pos, {name = "mcl_chests:trapped_chest_on_small", param2 = node.param2})
mcl_chests.find_or_create_entity(
pos, "mcl_chests:trapped_chest_on_small", mcl_chests.tiles.chest_trapped_small,
node.param2, false, "default_chest", "mcl_chests_chest", "chest"
):reinitialize("mcl_chests:trapped_chest_on_small")
mesecon.receptor_on(pos, mesecon.rules.pplate)
end,
on_rightclick_left = function(pos, node, clicker)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
meta:set_int("players", 1)
minetest.swap_node(pos, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 })
mcl_chests.find_or_create_entity(pos, "mcl_chests:trapped_chest_on_left",
mcl_chests.tiles.chest_trapped_double, node.param2, true, "default_chest", "mcl_chests_chest",
"chest"):reinitialize("mcl_chests:trapped_chest_on_left")
core.swap_node(pos, {name = "mcl_chests:trapped_chest_on_left", param2 = node.param2})
mcl_chests.find_or_create_entity(
pos, "mcl_chests:trapped_chest_on_left", mcl_chests.tiles.chest_trapped_double,
node.param2, true, "default_chest", "mcl_chests_chest", "chest"
):reinitialize("mcl_chests:trapped_chest_on_left")
mesecon.receptor_on(pos, mesecon.rules.pplate)
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 })
core.swap_node(pos_other, {name = "mcl_chests:trapped_chest_on_right", param2 = node.param2})
mesecon.receptor_on(pos_other, mesecon.rules.pplate)
end,
on_rightclick_right = function(pos, node, clicker)
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 })
core.swap_node(pos, {name = "mcl_chests:trapped_chest_on_right", param2 = node.param2})
mesecon.receptor_on(pos, mesecon.rules.pplate)
minetest.swap_node(pos_other, { name = "mcl_chests:trapped_chest_on_left", param2 = node.param2 })
mcl_chests.find_or_create_entity(pos_other, "mcl_chests:trapped_chest_on_left",
mcl_chests.tiles.chest_trapped_double, node.param2, true, "default_chest", "mcl_chests_chest",
"chest"):reinitialize("mcl_chests:trapped_chest_on_left")
core.swap_node(pos_other, {name = "mcl_chests:trapped_chest_on_left", param2 = node.param2})
mcl_chests.find_or_create_entity(
pos_other, "mcl_chests:trapped_chest_on_left", mcl_chests.tiles.chest_trapped_double,
node.param2, true, "default_chest", "mcl_chests_chest", "chest"
):reinitialize("mcl_chests:trapped_chest_on_left")
mesecon.receptor_on(pos_other, mesecon.rules.pplate)
end
})
@ -113,7 +118,7 @@ mcl_chests.register_chest("trapped_chest_on", {
flammable = -1,
mesecon = 2,
},
sounds = { mcl_sounds.node_sound_wood_defaults() },
sounds = {mcl_sounds.node_sound_wood_defaults()},
hardness = 2.5,
hidden = true,
mesecons = {
@ -126,22 +131,22 @@ mcl_chests.register_chest("trapped_chest_on", {
canonical_basename = "trapped_chest"
})
minetest.register_craft({
core.register_craft({
output = "mcl_chests:chest",
recipe = {
{ "group:wood", "group:wood", "group:wood" },
{ "group:wood", "", "group:wood" },
{ "group:wood", "group:wood", "group:wood" },
{"group:wood", "group:wood", "group:wood"},
{"group:wood", "", "group:wood"},
{"group:wood", "group:wood", "group:wood"},
},
})
minetest.register_craft({
core.register_craft({
type = "fuel",
recipe = "mcl_chests:chest",
burntime = 15,
})
minetest.register_craft({
core.register_craft({
type = "fuel",
recipe = "mcl_chests:trapped_chest",
burntime = 15,
@ -149,7 +154,7 @@ minetest.register_craft({
-- Disable active/open trapped chests when loaded because nobody could have them open at loading time.
-- Fixes redstone weirdness.
minetest.register_lbm({
core.register_lbm({
label = "Disable active trapped chests",
name = "mcl_chests:reset_trapped_chests",
nodenames = {
@ -159,7 +164,7 @@ minetest.register_lbm({
},
run_at_every_load = true,
action = function(pos, node)
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
core.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. core.pos_to_string(pos))
mcl_chests.chest_update_after_close(pos)
end,
})

View file

@ -1,6 +1,6 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local S = core.get_translator(core.get_current_modname())
local F = core.formspec_escape
local C = core.colorize
local longdesc = S(
"Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This " ..
@ -9,10 +9,10 @@ local longdesc = S(
"not the items of other players."
)
minetest.register_node("mcl_chests:ender_chest", {
core.register_node("mcl_chests:ender_chest", {
description = S("Ender Chest"),
_tt_help = S("27 interdimensional inventory slots") ..
"\n" .. S("Put items inside, retrieve them from any ender chest"),
_tt_help = S("27 interdimensional inventory slots") .. "\n" ..
S("Put items inside, retrieve them from any ender chest"),
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."),
drawtype = "mesh",
@ -21,12 +21,12 @@ minetest.register_node("mcl_chests:ender_chest", {
use_texture_alpha = "opaque",
paramtype = "light",
paramtype2 = "facedir",
groups = { deco_block = 1 },
groups = {deco_block = 1},
sounds = mcl_sounds.node_sound_stone_defaults(),
on_construct = function(pos)
local node = minetest.get_node(pos)
local node = core.get_node(pos)
node.name = "mcl_chests:ender_chest_small"
minetest.set_node(pos, node)
core.set_node(pos, node)
end,
})
@ -34,10 +34,10 @@ mcl_chests.formspec_ender_chest = table.concat({
"formspec_version[4]",
"size[11.75,10.425]",
"label[0.375,0.375;" .. F(C(mcl_formspec.label_color, S("Ender Chest"))) .. "]",
"label[0.375,0.375;", F(C(mcl_formspec.label_color, S("Ender Chest"))), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3),
"list[current_player;enderchest;0.375,0.75;9,3;]",
"label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]",
"label[0.375,4.7;", F(C(mcl_formspec.label_color, S("Inventory"))), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3),
"list[current_player;main;0.375,5.1;9,3;9]",
@ -48,26 +48,26 @@ mcl_chests.formspec_ender_chest = table.concat({
"listring[current_player;main]",
})
minetest.register_node("mcl_chests:ender_chest_small", {
core.register_node("mcl_chests:ender_chest_small", {
description = S("Ender Chest"),
_tt_help = S("27 interdimensional inventory slots") ..
"\n" .. S("Put items inside, retrieve them from any ender chest"),
_tt_help = S("27 interdimensional inventory slots") .. "\n" ..
S("Put items inside, retrieve them from any ender chest"),
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = S("Rightclick the ender chest to access your personal interdimensional inventory."),
drawtype = "nodebox",
node_box = {
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 = mcl_chests.tiles.ender_chest_texture,
_chest_entity_sound = "mcl_chests_enderchest",
_chest_entity_mesh = "mcl_chests_chest",
_chest_entity_animation_type = "chest",
tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip",
tiles = {"blank.png^[resize:16x16"},
use_texture_alpha = "blend",
-- Note: The “container” group is missing here because the ender chest does not
-- have an inventory on its own
groups = { pickaxey = 1, deco_block = 1, material_stone = 1, chest_entity = 1, not_in_creative_inventory = 1 },
groups = {pickaxey = 1, deco_block = 1, material_stone = 1, chest_entity = 1, not_in_creative_inventory = 1},
is_ground_content = false,
paramtype = "light",
light_source = 7,
@ -76,14 +76,14 @@ minetest.register_node("mcl_chests:ender_chest_small", {
drop = "mcl_core:obsidian 8",
on_construct = function(pos)
mcl_chests.create_entity(pos, "mcl_chests:ender_chest_small", mcl_chests.tiles.ender_chest_texture,
minetest.get_node(pos).param2, false, "mcl_chests_enderchest", "mcl_chests_chest", "chest")
core.get_node(pos).param2, false, "mcl_chests_enderchest", "mcl_chests_chest", "chest")
end,
on_rightclick = function(pos, node, clicker)
if minetest.registered_nodes[minetest.get_node(vector.offset(pos, 0, 1, 0)).name].groups.opaque == 1 then
if core.registered_nodes[core.get_node(vector.offset(pos, 0, 1, 0)).name].groups.opaque == 1 then
-- won't open if there is no space from the top
return false
end
minetest.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_" .. clicker:get_player_name(),
core.show_formspec(clicker:get_player_name(), "mcl_chests:ender_chest_" .. clicker:get_player_name(),
mcl_chests.formspec_ender_chest)
mcl_chests.player_chest_open(clicker, pos, "mcl_chests:ender_chest_small",
mcl_chests.tiles.ender_chest_texture, node.param2, false, "mcl_chests_enderchest",
@ -96,43 +96,43 @@ minetest.register_node("mcl_chests:ender_chest_small", {
end,
_mcl_blast_resistance = 600,
_mcl_hardness = 22.5,
_mcl_silk_touch_drop = { "mcl_chests:ender_chest" },
_mcl_silk_touch_drop = {"mcl_chests:ender_chest"},
on_rotate = mcl_chests.simple_rotate,
})
minetest.register_on_joinplayer(function(player)
core.register_on_joinplayer(function(player)
local inv = player:get_inventory()
inv:set_size("enderchest", 9 * 3)
end)
minetest.register_allow_player_inventory_action(function(player, action, inv, info)
core.register_allow_player_inventory_action(function(player, action, inv, info)
if inv:get_location().type == "player" and (
action == "move" and (info.from_list == "enderchest" or info.to_list == "enderchest")
or action == "put" and info.listname == "enderchest"
or action == "take" and info.listname == "enderchest") then
local def = player:get_wielded_item():get_definition()
local range = (def and def.range or player:get_inventory():get_stack("hand", 1):get_definition().range) + 1
if not minetest.find_node_near(player:get_pos(), range, "mcl_chests:ender_chest_small", true) then
if not core.find_node_near(player:get_pos(), range, "mcl_chests:ender_chest_small", true) then
return 0
end
end
end)
minetest.register_craft({
core.register_craft({
output = "mcl_chests:ender_chest",
recipe = {
{ "mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian" },
{ "mcl_core:obsidian", "mcl_end:ender_eye", "mcl_core:obsidian" },
{ "mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian" },
{"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"},
{"mcl_core:obsidian", "mcl_end:ender_eye", "mcl_core:obsidian"},
{"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"},
},
})
minetest.register_lbm({
core.register_lbm({
label = "Upgrade old ender chest formspec",
name = "mcl_chests:replace_old_ender_form",
nodenames = { "mcl_chests:ender_chest_small" },
nodenames = {"mcl_chests:ender_chest_small"},
run_at_every_load = false,
action = function(pos, node)
minetest.get_meta(pos):set_string("formspec", "")
core.get_meta(pos):set_string("formspec", "")
end,
})

View file

@ -1,4 +1,4 @@
local S = minetest.get_translator(minetest.get_current_modname())
local S = core.get_translator(core.get_current_modname())
mcl_chests.register_chest("stone_chest", {
desc = S("Stone Chest"),
@ -13,9 +13,10 @@ mcl_chests.register_chest("stone_chest", {
usagehelp = S("To access its inventory, rightclick it. When broken, the items will drop out."),
tt_help = S("27 inventory slots") .. "\n" .. S("Can be combined to a large stone chest"),
tiles = {
small = { mcl_chests.tiles.chest_normal_small[1] .. "^[hsl:-15:-80:-20" },
double = { mcl_chests.tiles.chest_normal_double[1] .. "^[hsl:-15:-80:-20" },
inv = { "default_chest_top.png^[hsl:-15:-80:-20",
small = {mcl_chests.tiles.chest_normal_small[1] .. "^[hsl:-15:-80:-20"},
double = {mcl_chests.tiles.chest_normal_double[1] .. "^[hsl:-15:-80:-20"},
inv = {
"default_chest_top.png^[hsl:-15:-80:-20",
"mcl_chests_chest_bottom.png^[hsl:-15:-80:-20",
"mcl_chests_chest_right.png^[hsl:-15:-80:-20",
"mcl_chests_chest_left.png^[hsl:-15:-80:-20",
@ -40,11 +41,11 @@ mcl_chests.register_chest("stone_chest", {
end,
})
minetest.register_craft({
core.register_craft({
output = "mcl_chests:stone_chest",
recipe = {
{ "mcl_core:stone", "mcl_core:stone", "mcl_core:stone" },
{ "mcl_core:stone", "", "mcl_core:stone" },
{ "mcl_core:stone", "mcl_core:stone", "mcl_core:stone" },
{"mcl_core:stone", "mcl_core:stone", "mcl_core:stone"},
{"mcl_core:stone", "", "mcl_core:stone"},
{"mcl_core:stone", "mcl_core:stone", "mcl_core:stone"},
},
})

View file

@ -7,13 +7,13 @@ mcl_chests = {}
-- Christmas chest setup
local it_is_christmas = mcl_util.is_it_christmas()
local tiles = { -- extensions will be added later
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 = {-- extensions will be added later
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"
@ -34,7 +34,7 @@ end
mcl_chests.tiles = tiles
local modpath = minetest.get_modpath("mcl_chests")
local modpath = core.get_modpath("mcl_chests")
dofile(modpath .. "/api.lua")
dofile(modpath .. "/chests.lua")
dofile(modpath .. "/ender.lua")
@ -44,7 +44,7 @@ dofile(modpath .. "/shulkers.lua")
-- Disable chest when it has been closed
minetest.register_on_player_receive_fields(function(player, formname, fields)
core.register_on_player_receive_fields(function(player, formname, fields)
if formname:find("mcl_chests:") == 1 then
if fields.quit then
mcl_chests.player_chest_close(player)
@ -52,19 +52,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end)
minetest.register_on_leaveplayer(function(player)
mcl_chests.player_chest_close(player)
end)
core.register_on_leaveplayer(mcl_chests.player_chest_close)
minetest.register_lbm({
core.register_lbm({
label = "Spawn Chest entities",
name = "mcl_chests:spawn_chest_entities",
nodenames = { "group:chest_entity" },
nodenames = {"group:chest_entity"},
run_at_every_load = true,
action = mcl_chests.select_and_spawn_entity,
})
minetest.register_lbm({
core.register_lbm({
label = "Replace old chest nodes",
name = "mcl_chests:replace_old",
nodenames = {
@ -78,13 +76,13 @@ minetest.register_lbm({
action = function(pos, node)
local node_name = node.name
node.name = node_name .. "_small"
minetest.swap_node(pos, node)
core.swap_node(pos, node)
mcl_chests.select_and_spawn_entity(pos, node)
if node_name == "mcl_chests:trapped_chest_on" then
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
core.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. core.pos_to_string(pos))
mcl_chests.chest_update_after_close(pos)
elseif node_name == "mcl_chests:ender_chest" then
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
meta:set_string("formspec", mcl_chests.formspec_ender_chest)
end
end

View file

@ -1,6 +1,6 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local S = core.get_translator(core.get_current_modname())
local F = core.formspec_escape
local C = core.colorize
-- Shulker boxes
local boxtypes = {
@ -55,10 +55,10 @@ local function formspec_shulker_box(name)
"formspec_version[4]",
"size[11.75,10.425]",
"label[0.375,0.375;" .. F(C(mcl_formspec.label_color, name)) .. "]",
"label[0.375,0.375;", F(C(mcl_formspec.label_color, name)), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 0.75, 9, 3),
"list[context;main;0.375,0.75;9,3;]",
"label[0.375,4.7;" .. F(C(mcl_formspec.label_color, S("Inventory"))) .. "]",
"label[0.375,4.7;", F(C(mcl_formspec.label_color, S("Inventory"))), "]",
mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3),
"list[current_player;main;0.375,5.1;9,3;9]",
@ -103,14 +103,14 @@ for color, desc in pairs(boxtypes) do
local normal_name = "mcl_chests:" .. color .. "_shulker_box"
local small_name = normal_name .. "_small"
minetest.register_node(normal_name, {
core.register_node(normal_name, {
description = desc,
_tt_help = S("27 inventory slots") .. "\n" .. S("Can be carried around with its contents"),
_doc_items_create_entry = create_entry,
_doc_items_entry_name = entry_name,
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usagehelp,
tiles = { mob_texture },
tiles = {mob_texture},
use_texture_alpha = "opaque",
drawtype = "mesh",
mesh = "mcl_chests_shulker.b3d",
@ -130,12 +130,12 @@ for color, desc in pairs(boxtypes) do
paramtype = "light",
paramtype2 = "facedir",
on_construct = function(pos)
local node = minetest.get_node(pos)
local node = core.get_node(pos)
node.name = small_name
minetest.set_node(pos, node)
core.set_node(pos, node)
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local nmeta = minetest.get_meta(pos)
local nmeta = core.get_meta(pos)
local imeta = itemstack:get_meta()
-- Convert old itemstacks to not use get_metadata()
@ -145,13 +145,13 @@ for color, desc in pairs(boxtypes) do
itemstack:set_metadata("") -- clear
end
local iinv_main = minetest.deserialize(imeta:get_string("inv"))
local iinv_main = core.deserialize(imeta:get_string("inv"))
local ninv = nmeta:get_inventory()
ninv:set_list("main", iinv_main)
ninv:set_size("main", 9 * 3)
set_shulkerbox_meta(nmeta, imeta)
if minetest.is_creative_enabled(placer:get_player_name()) then
if core.is_creative_enabled(placer:get_player_name()) then
if not ninv:is_empty("main") then
return nil
else
@ -163,21 +163,21 @@ for color, desc in pairs(boxtypes) do
end,
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
-- Place shulker box as node
if minetest.registered_nodes[dropnode.name].buildable_to then
minetest.set_node(droppos, { name = small_name, param2 = minetest.dir_to_facedir(dropdir) })
local ninv = minetest.get_inventory({ type = "node", pos = droppos })
if core.registered_nodes[dropnode.name].buildable_to then
core.set_node(droppos, {name = small_name, param2 = core.dir_to_facedir(dropdir)})
local ninv = core.get_inventory({type = "node", pos = droppos})
local imeta = stack:get_meta()
local iinv_main = minetest.deserialize(imeta:get_string("inv"))
local iinv_main = core.deserialize(imeta:get_string("inv"))
ninv:set_list("main", iinv_main)
ninv:set_size("main", 9 * 3)
set_shulkerbox_meta(minetest.get_meta(droppos), imeta)
set_shulkerbox_meta(core.get_meta(droppos), imeta)
stack:take_item()
end
return stack
end,
})
minetest.register_node(small_name, {
core.register_node(small_name, {
description = desc,
_tt_help = S("27 inventory slots") .. "\n" .. S("Can be carried around with its contents"),
_doc_items_create_entry = create_entry,
@ -187,11 +187,11 @@ for color, desc in pairs(boxtypes) do
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = { -0.48, -0.5, -0.48, 0.48, 0.489, 0.48 },
fixed = {-0.48, -0.5, -0.48, 0.48, 0.489, 0.48},
},
tiles = { "blank.png^[resize:16x16" },
use_texture_alpha = "clip",
_chest_entity_textures = { mob_texture },
tiles = {"blank.png^[resize:16x16"},
use_texture_alpha = "blend",
_chest_entity_textures = {mob_texture},
_chest_entity_sound = "mcl_chests_shulker",
_chest_entity_mesh = "mcl_chests_shulker",
_chest_entity_animation_type = "shulker",
@ -212,15 +212,15 @@ for color, desc in pairs(boxtypes) do
paramtype = "light",
paramtype2 = "facedir",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
meta:set_string("formspec", formspec_shulker_box(nil))
local inv = meta:get_inventory()
inv:set_size("main", 9 * 3)
mcl_chests.create_entity(pos, small_name, { mob_texture }, minetest.get_node(pos).param2, false,
mcl_chests.create_entity(pos, small_name, {mob_texture}, core.get_node(pos).param2, false,
"mcl_chests_shulker", "mcl_chests_shulker", "shulker")
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local nmeta = minetest.get_meta(pos)
local nmeta = core.get_meta(pos)
local imeta = itemstack:get_meta()
-- Convert old itemstacks to not use get_metadata()
@ -230,13 +230,13 @@ for color, desc in pairs(boxtypes) do
itemstack:set_metadata("") -- clear
end
local iinv_main = minetest.deserialize(imeta:get_string("inv"))
local iinv_main = core.deserialize(imeta:get_string("inv"))
local ninv = nmeta:get_inventory()
ninv:set_list("main", iinv_main)
ninv:set_size("main", 9 * 3)
set_shulkerbox_meta(nmeta, imeta)
if minetest.is_creative_enabled(placer:get_player_name()) then
if core.is_creative_enabled(placer:get_player_name()) then
if not ninv:is_empty("main") then
return nil
else
@ -247,7 +247,7 @@ for color, desc in pairs(boxtypes) do
end
end,
on_rightclick = function(pos, node, clicker)
mcl_chests.player_chest_open(clicker, pos, small_name, { mob_texture }, node.param2, false,
mcl_chests.player_chest_open(clicker, pos, small_name, {mob_texture}, node.param2, false,
"mcl_chests_shulker", "mcl_chests_shulker", true)
end,
on_receive_fields = function(pos, formname, fields, sender)
@ -256,38 +256,38 @@ for color, desc in pairs(boxtypes) do
end
end,
on_destruct = function(pos)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local items = {}
for i = 1, inv:get_size("main") do
local stack = inv:get_stack("main", i)
items[i] = stack:to_string()
end
local data = minetest.serialize(items)
local data = core.serialize(items)
local boxitem = ItemStack("mcl_chests:" .. color .. "_shulker_box")
local boxitem_meta = boxitem:get_meta()
boxitem_meta:set_string("description", meta:get_string("description"))
boxitem_meta:set_string("name", meta:get_string("name"))
boxitem_meta:set_string("inv", data)
if minetest.is_creative_enabled("") then
if core.is_creative_enabled("") then
if not inv:is_empty("main") then
minetest.add_item(pos, boxitem)
core.add_item(pos, boxitem)
end
else
minetest.add_item(pos, boxitem)
core.add_item(pos, boxitem)
end
end,
allow_metadata_inventory_move = mcl_chests.protection_check_move,
allow_metadata_inventory_take = mcl_chests.protection_check_put_take,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
if core.is_protected(pos, name) then
core.record_protection_violation(pos, name)
return 0
end
-- Do not allow to place shulker boxes into shulker boxes
local group = minetest.get_item_group(stack:get_name(), "shulker_box")
local group = core.get_item_group(stack:get_name(), "shulker_box")
if group == 0 or group == nil then
return stack:get_count()
else
@ -298,7 +298,7 @@ for color, desc in pairs(boxtypes) do
_mcl_blast_resistance = 2,
_mcl_hardness = 2,
_mcl_hoppers_on_try_push = function(pos, hop_pos, hop_inv, hop_list)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
return inv, "main",
mcl_util.select_stack(hop_inv, hop_list, inv, "main", mcl_chests.is_not_shulker_box, 1)
@ -310,31 +310,31 @@ for color, desc in pairs(boxtypes) do
doc.add_entry_alias("nodes", small_canonical_name, "nodes", small_name)
end
minetest.register_craft({
core.register_craft({
type = "shapeless",
output = normal_name,
recipe = { "group:shulker_box", "mcl_dye:" .. color },
recipe = {"group:shulker_box", "mcl_dye:" .. color},
})
end
minetest.register_craft({
core.register_craft({
output = "mcl_chests:violet_shulker_box",
recipe = {
{ "mcl_mobitems:shulker_shell" },
{ "mcl_chests:chest" },
{ "mcl_mobitems:shulker_shell" },
{"mcl_mobitems:shulker_shell"},
{"mcl_chests:chest"},
{"mcl_mobitems:shulker_shell"},
},
})
-- Save metadata of shulker box when used in crafting
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
if minetest.get_item_group(itemstack:get_name(), "shulker_box") ~= 1 then return end
core.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
if core.get_item_group(itemstack:get_name(), "shulker_box") ~= 1 then return end
local original
for i = 1, #old_craft_grid do
local item = old_craft_grid[i]:get_name()
if minetest.get_item_group(item, "shulker_box") == 1 then
original = old_craft_grid[i]
for _, stack in ipairs(old_craft_grid) do
local item = stack:get_name()
if core.get_item_group(item, "shulker_box") == 1 then
original = stack
break
end
end
@ -346,13 +346,13 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
end
end)
minetest.register_lbm({
core.register_lbm({
label = "Update shulker box formspecs (0.72.0)",
name = "mcl_chests:update_shulker_box_formspecs_0_72_0",
nodenames = { "group:shulker_box" },
nodenames = {"group:shulker_box"},
run_at_every_load = false,
action = function(pos, node)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
meta:set_string("formspec", formspec_shulker_box(meta:get_string("name")))
end,
})