forked from Mineclonia/Mineclonia
Inventory + Screwdriver support
This commit is contained in:
parent
54f7d76298
commit
ae59f9fd3c
|
@ -1,12 +1,6 @@
|
||||||
local S = minetest.get_translator("mcl_chests")
|
local S = minetest.get_translator("mcl_chests")
|
||||||
local mod_doc = minetest.get_modpath("doc")
|
local mod_doc = minetest.get_modpath("doc")
|
||||||
|
|
||||||
local no_rotate, simple_rotate
|
|
||||||
if minetest.get_modpath("screwdriver") then
|
|
||||||
no_rotate = screwdriver.disallow
|
|
||||||
simple_rotate = screwdriver.rotate_simple
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Chest Entity
|
-- Chest Entity
|
||||||
local entity_animations = {}
|
local entity_animations = {}
|
||||||
local entity_animation_speed = 25
|
local entity_animation_speed = 25
|
||||||
|
@ -76,8 +70,16 @@ minetest.register_entity("mcl_chests:chest", {
|
||||||
self.node_name = node_name
|
self.node_name = node_name
|
||||||
local obj = self.object
|
local obj = self.object
|
||||||
obj:set_properties({textures = textures})
|
obj:set_properties({textures = textures})
|
||||||
obj:set_yaw(minetest.dir_to_yaw(dir))
|
|
||||||
obj:set_properties({mesh = double and "mcl_chests_double_chest.b3d" or "mcl_chests_chest.b3d"})
|
obj:set_properties({mesh = double and "mcl_chests_double_chest.b3d" or "mcl_chests_chest.b3d"})
|
||||||
|
self:set_yaw(dir)
|
||||||
|
end,
|
||||||
|
|
||||||
|
reinitialize = function(self, node_name)
|
||||||
|
self.node_name = node_name
|
||||||
|
end,
|
||||||
|
|
||||||
|
set_yaw = function(self, dir)
|
||||||
|
self.object:set_yaw(minetest.dir_to_yaw(dir))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
check = function(self)
|
check = function(self)
|
||||||
|
@ -149,6 +151,20 @@ local function find_or_create_entity(pos, node_name, textures, param2, double)
|
||||||
return find_entity(entity_pos) or create_entity(pos, node_name, textures, param2, double, dir, entity_pos)
|
return find_entity(entity_pos) or create_entity(pos, node_name, textures, param2, double, dir, entity_pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local no_rotate, simple_rotate
|
||||||
|
if minetest.get_modpath("screwdriver") then
|
||||||
|
no_rotate = screwdriver.disallow
|
||||||
|
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]
|
||||||
|
find_or_create_entity(pos, nodename, nodedef._chest_entity_textures, new_param2, false):set_yaw(minetest.facedir_to_dir(new_param2))
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[ List of open chests.
|
--[[ List of open chests.
|
||||||
Key: Player name
|
Key: Player name
|
||||||
Value:
|
Value:
|
||||||
|
@ -291,11 +307,34 @@ local on_chest_blast = function(pos)
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local small_name = "mcl_chests:"..basename
|
local small_name = "mcl_chests:"..basename.."_small"
|
||||||
local small_textures = tiles_table.small
|
local small_textures = tiles_table.small
|
||||||
local left_name = "mcl_chests:"..basename.."_left"
|
local left_name = "mcl_chests:"..basename.."_left"
|
||||||
local left_textures = tiles_table.double
|
local left_textures = tiles_table.double
|
||||||
|
|
||||||
|
minetest.register_node("mcl_chests:"..basename, {
|
||||||
|
description = desc,
|
||||||
|
_tt_help = tt_help,
|
||||||
|
_doc_items_longdesc = longdesc,
|
||||||
|
_doc_items_usagehelp = usagehelp,
|
||||||
|
_doc_items_hidden = hidden,
|
||||||
|
drawtype = "mesh",
|
||||||
|
mesh = "mcl_chests_chest.obj",
|
||||||
|
tiles = small_textures,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
stack_max = 64,
|
||||||
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
||||||
|
on_construct = function(pos, node)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
node.name = small_name
|
||||||
|
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"))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_node(small_name, {
|
minetest.register_node(small_name, {
|
||||||
description = desc,
|
description = desc,
|
||||||
_tt_help = tt_help,
|
_tt_help = tt_help,
|
||||||
|
@ -311,7 +350,6 @@ minetest.register_node(small_name, {
|
||||||
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},
|
||||||
},
|
},
|
||||||
inventory_image = "mcl_chests_normal.png",
|
|
||||||
tiles = {"blank.png"},
|
tiles = {"blank.png"},
|
||||||
_chest_entity_textures = small_textures,
|
_chest_entity_textures = small_textures,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
|
@ -346,18 +384,18 @@ minetest.register_node(small_name, {
|
||||||
-- BEGIN OF LISTRING WORKAROUND
|
-- BEGIN OF LISTRING WORKAROUND
|
||||||
inv:set_size("input", 1)
|
inv:set_size("input", 1)
|
||||||
-- END OF LISTRING WORKAROUND
|
-- END OF LISTRING WORKAROUND
|
||||||
if minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "right")).name == "mcl_chests:"..canonical_basename then
|
if minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "right")).name == "mcl_chests:"..canonical_basename.."_small" then
|
||||||
minetest.swap_node(pos, {name="mcl_chests:"..canonical_basename.."_right",param2=param2})
|
minetest.swap_node(pos, {name="mcl_chests:"..canonical_basename.."_right",param2=param2})
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
||||||
minetest.swap_node(p, { name = "mcl_chests:"..canonical_basename.."_left", param2 = param2 })
|
minetest.swap_node(p, { name = "mcl_chests:"..canonical_basename.."_left", param2 = param2 })
|
||||||
create_entity(p, "mcl_chests:"..canonical_basename.."_left", left_textures, param2, true)
|
create_entity(p, "mcl_chests:"..canonical_basename.."_left", left_textures, param2, true)
|
||||||
elseif minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "left")).name == "mcl_chests:"..canonical_basename then
|
elseif minetest.get_node(mcl_util.get_double_container_neighbor_pos(pos, param2, "left")).name == "mcl_chests:"..canonical_basename.."_small" then
|
||||||
minetest.swap_node(pos, {name="mcl_chests:"..canonical_basename.."_left",param2=param2})
|
minetest.swap_node(pos, {name="mcl_chests:"..canonical_basename.."_left",param2=param2})
|
||||||
create_entity(pos, "mcl_chests:"..canonical_basename.."_left", left_textures, param2, true)
|
create_entity(pos, "mcl_chests:"..canonical_basename.."_left", left_textures, param2, true)
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left")
|
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left")
|
||||||
minetest.swap_node(p, { name = "mcl_chests:"..canonical_basename.."_right", param2 = param2 })
|
minetest.swap_node(p, { name = "mcl_chests:"..canonical_basename.."_right", param2 = param2 })
|
||||||
else
|
else
|
||||||
minetest.swap_node(pos, { name = "mcl_chests:"..canonical_basename, param2 = param2 })
|
minetest.swap_node(pos, { name = "mcl_chests:"..canonical_basename.."_small", param2 = param2 })
|
||||||
create_entity(pos, small_name, small_textures, param2, false)
|
create_entity(pos, small_name, small_textures, param2, false)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -435,11 +473,11 @@ minetest.register_node(left_name, {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.4375, -0.5, -0.4375, 1.4375, 0.375, 0.4375},
|
fixed = {-0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375},
|
||||||
},
|
},
|
||||||
collision_box = {
|
collision_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.4375, -0.5, -0.4375, 1.4375, 0.375, 0.4375},
|
fixed = {-0.4375, -0.5, -0.4375, 0.5, 0.375, 0.4375},
|
||||||
},
|
},
|
||||||
tiles = {"blank.png"},
|
tiles = {"blank.png"},
|
||||||
_chest_entity_textures = left_textures,
|
_chest_entity_textures = left_textures,
|
||||||
|
@ -454,7 +492,7 @@ minetest.register_node(left_name, {
|
||||||
local param2 = n.param2
|
local param2 = n.param2
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left")
|
local p = mcl_util.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
|
n.name = "mcl_chests:"..canonical_basename.."_small"
|
||||||
minetest.swap_node(pos, n)
|
minetest.swap_node(pos, n)
|
||||||
end
|
end
|
||||||
create_entity(pos, left_name, left_textures, param2, true)
|
create_entity(pos, left_name, left_textures, param2, true)
|
||||||
|
@ -464,7 +502,7 @@ minetest.register_node(left_name, {
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local n = minetest.get_node(pos)
|
local n = minetest.get_node(pos)
|
||||||
if n.name == "mcl_chests:"..basename then
|
if n.name == small_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -481,8 +519,8 @@ minetest.register_node(left_name, {
|
||||||
for pl=1, #players do
|
for pl=1, #players do
|
||||||
minetest.close_formspec(players[pl]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..p.x.."_"..p.y.."_"..p.z)
|
minetest.close_formspec(players[pl]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..p.x.."_"..p.y.."_"..p.z)
|
||||||
end
|
end
|
||||||
minetest.swap_node(p, { name = "mcl_chests:"..basename, param2 = param2 })
|
minetest.swap_node(p, { name = small_name, param2 = param2 })
|
||||||
create_entity(p, "mcl_chests:"..basename, small_textures, param2, false)
|
create_entity(p, small_name, small_textures, param2, false)
|
||||||
end,
|
end,
|
||||||
after_dig_node = drop_items_chest,
|
after_dig_node = drop_items_chest,
|
||||||
on_blast = on_chest_blast,
|
on_blast = on_chest_blast,
|
||||||
|
@ -590,11 +628,11 @@ minetest.register_node("mcl_chests:"..basename.."_right", {
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {0, 0, 0, 0, 0, 0},
|
fixed = {-0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375},
|
||||||
},
|
},
|
||||||
collision_box = {
|
collision_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {0, 0, 0, 0, 0, 0},
|
fixed = {-0.5, -0.5, -0.4375, 0.4375, 0.375, 0.4375},
|
||||||
},
|
},
|
||||||
groups = {handy=1,axey=1, container=6,not_in_creative_inventory=1, material_wood=1,flammable=-1,double_chest=2},
|
groups = {handy=1,axey=1, container=6,not_in_creative_inventory=1, material_wood=1,flammable=-1,double_chest=2},
|
||||||
drop = drop,
|
drop = drop,
|
||||||
|
@ -605,7 +643,7 @@ minetest.register_node("mcl_chests:"..basename.."_right", {
|
||||||
local param2 = n.param2
|
local param2 = n.param2
|
||||||
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right")
|
||||||
if not p or minetest.get_node(p).name ~= "mcl_chests:"..canonical_basename.."_left" then
|
if not p or minetest.get_node(p).name ~= "mcl_chests:"..canonical_basename.."_left" then
|
||||||
n.name = "mcl_chests:"..canonical_basename
|
n.name = "mcl_chests:"..canonical_basename.."_small"
|
||||||
minetest.swap_node(pos, n)
|
minetest.swap_node(pos, n)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -614,7 +652,7 @@ minetest.register_node("mcl_chests:"..basename.."_right", {
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local n = minetest.get_node(pos)
|
local n = minetest.get_node(pos)
|
||||||
if n.name == "mcl_chests:"..basename then
|
if n.name == small_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -631,7 +669,8 @@ minetest.register_node("mcl_chests:"..basename.."_right", {
|
||||||
for pl=1, #players do
|
for pl=1, #players do
|
||||||
minetest.close_formspec(players[pl]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..p.x.."_"..p.y.."_"..p.z)
|
minetest.close_formspec(players[pl]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..p.x.."_"..p.y.."_"..p.z)
|
||||||
end
|
end
|
||||||
minetest.swap_node(p, { name = "mcl_chests:"..basename, param2 = param2 })
|
minetest.swap_node(p, { name = small_name, param2 = param2 })
|
||||||
|
create_entity(p, small_name, small_textures, param2, false)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
end,
|
end,
|
||||||
after_dig_node = drop_items_chest,
|
after_dig_node = drop_items_chest,
|
||||||
|
@ -736,8 +775,8 @@ minetest.register_node("mcl_chests:"..basename.."_right", {
|
||||||
})
|
})
|
||||||
|
|
||||||
if mod_doc then
|
if mod_doc then
|
||||||
doc.add_entry_alias("nodes", "mcl_chests:"..basename, "nodes", "mcl_chests:"..basename.."_left")
|
doc.add_entry_alias("nodes", small_name, "nodes", "mcl_chests:"..basename.."_left")
|
||||||
doc.add_entry_alias("nodes", "mcl_chests:"..basename, "nodes", "mcl_chests:"..basename.."_right")
|
doc.add_entry_alias("nodes", small_name, "nodes", "mcl_chests:"..basename.."_right")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- END OF register_chest FUNCTION BODY
|
-- END OF register_chest FUNCTION BODY
|
||||||
|
@ -1182,16 +1221,30 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
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
|
||||||
|
create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest)
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_lbm({
|
minetest.register_lbm({
|
||||||
label = "Spawn Chest entities",
|
label = "Spawn Chest entities",
|
||||||
name = "mcl_chests:spawn_chest_entities",
|
name = "mcl_chests:spawn_chest_entities",
|
||||||
nodenames = {"group:chest_entity"},
|
nodenames = {"group:chest_entity"},
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
|
action = select_and_spawn_entity,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Replace old chest nodes",
|
||||||
|
name = "mcl_chests:replace_old",
|
||||||
|
nodenames = {"mcl_chests:chest", "mcl_chests:trapped_chest", "mcl_chests:trapped_chest_on"},
|
||||||
|
run_at_every_load = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local node_name = node.name
|
node.name = node.name .. "_small"
|
||||||
local node_def = minetest.registered_nodes[node_name]
|
minetest.set_node(pos, node)
|
||||||
local double_chest = minetest.get_item_group(node_name, "double_chest") > 0
|
select_and_spawn_entity(pos, node)
|
||||||
create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest)
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1201,7 +1254,7 @@ minetest.register_lbm({
|
||||||
-- Fixes redstone weirdness.
|
-- Fixes redstone weirdness.
|
||||||
label = "Disable active trapped chests",
|
label = "Disable active trapped chests",
|
||||||
name = "mcl_chests:reset_trapped_chests",
|
name = "mcl_chests:reset_trapped_chests",
|
||||||
nodenames = { "mcl_chests:trapped_chest_on", "mcl_chests:trapped_chest_on_left", "mcl_chests:trapped_chest_on_right" },
|
nodenames = { "mcl_chests:trapped_chest_on_small", "mcl_chests:trapped_chest_on_left", "mcl_chests:trapped_chest_on_right" },
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " ..minetest.pos_to_string(pos))
|
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " ..minetest.pos_to_string(pos))
|
||||||
|
|
Loading…
Reference in New Issue