2017-05-28 11:40:50 +02:00
|
|
|
local function mesechest_get_output_rules(node)
|
|
|
|
local rules = {{x=-1, y=0, z=0},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=0, z=1}}
|
2021-03-07 19:19:00 +01:00
|
|
|
for _ = 0, node.param2 do
|
2017-05-28 11:40:50 +02:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local open_chests = {}
|
|
|
|
|
2017-06-09 19:44:25 +02:00
|
|
|
-- Override minetest.register_node so it adds a prefix ":"
|
|
|
|
local old_minetest_register_node = minetest.register_node
|
2017-05-28 11:40:50 +02:00
|
|
|
minetest.register_node = function(name, def)
|
2017-06-09 19:44:25 +02:00
|
|
|
local old_on_metadata_inventory_put = def.on_metadata_inventory_put
|
|
|
|
local old_on_metadata_inventory_take = def.on_metadata_inventory_take
|
|
|
|
local old_on_rightclick = def.on_rightclick
|
2017-05-28 11:40:50 +02:00
|
|
|
|
|
|
|
def.on_metadata_inventory_put = function(pos, ...)
|
2017-06-09 19:44:25 +02:00
|
|
|
old_on_metadata_inventory_put(pos, ...)
|
2017-05-28 11:40:50 +02:00
|
|
|
mesecon.receptor_on(pos, {mesechest_get_output_rules(minetest.get_node(pos))[2]})
|
|
|
|
minetest.after(1, function(pos)
|
|
|
|
mesecon.receptor_off(pos, {mesechest_get_output_rules(minetest.get_node(pos))[2]})
|
|
|
|
end, pos)
|
|
|
|
end
|
|
|
|
def.on_metadata_inventory_take = function(pos, ...)
|
|
|
|
old_on_metadata_inventory_take(pos, ...)
|
|
|
|
mesecon.receptor_on(pos, {mesechest_get_output_rules(minetest.get_node(pos))[3]})
|
|
|
|
minetest.after(1, function(pos)
|
|
|
|
mesecon.receptor_off(pos, {mesechest_get_output_rules(minetest.get_node(pos))[3]})
|
|
|
|
end, pos)
|
|
|
|
end
|
|
|
|
def.on_rightclick = function(pos, node, clicker, ...)
|
|
|
|
if old_on_rightclick(pos, node, clicker, ...) == nil then
|
|
|
|
mesecon.receptor_on(pos, {mesechest_get_output_rules(node)[1]})
|
|
|
|
open_chests[clicker:get_player_name()] = pos
|
|
|
|
end
|
|
|
|
end
|
2017-06-09 19:55:12 +02:00
|
|
|
|
|
|
|
old_minetest_register_node(":"..name, def)
|
2017-05-28 11:40:50 +02:00
|
|
|
end
|
2017-06-09 19:44:25 +02:00
|
|
|
local old_minetest_register_lbm = minetest.register_lbm
|
|
|
|
minetest.register_lbm = function() end
|
2017-05-28 11:40:50 +02:00
|
|
|
|
|
|
|
-- Get the on_player_receive_fields function. That's a huge hack
|
|
|
|
for i, f in ipairs(minetest.registered_on_player_receive_fields) do
|
|
|
|
local serialized = minetest.serialize(f)
|
|
|
|
if string.find(serialized, "default:chest") then
|
|
|
|
minetest.registered_on_player_receive_fields[i] = function(player, formname, fields)
|
|
|
|
if f(player, formname, fields) == true then
|
|
|
|
local pn = player:get_player_name()
|
2017-06-09 19:44:25 +02:00
|
|
|
if open_chests[pn] then
|
|
|
|
mesecon.receptor_off(open_chests[pn], {mesechest_get_output_rules(minetest.get_node(open_chests[pn]))[1]})
|
|
|
|
open_chests[pn] = nil
|
|
|
|
end
|
2017-05-28 11:40:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-09 19:44:25 +02:00
|
|
|
default.register_chest("mesechest", {
|
2017-05-28 11:40:50 +02:00
|
|
|
description = "Mese Chest",
|
2017-06-09 19:55:12 +02:00
|
|
|
tiles = {
|
2017-06-09 20:09:37 +02:00
|
|
|
"default_chest_top.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_top.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_side.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_side.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_front.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_inside.png^[colorize:#d8e002:70"
|
2017-06-09 19:55:12 +02:00
|
|
|
},
|
2017-05-28 11:40:50 +02:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
sound_open = "default_chest_open",
|
|
|
|
sound_close = "default_chest_close",
|
|
|
|
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
|
|
|
mesecons = {
|
|
|
|
receptor = {
|
|
|
|
rules = mesechest_get_output_rules
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-06-09 19:44:25 +02:00
|
|
|
default.register_chest("mesechest_locked", {
|
2017-05-28 11:40:50 +02:00
|
|
|
description = "Locked Mese Chest",
|
2017-06-09 19:55:12 +02:00
|
|
|
tiles = {
|
2017-06-09 20:09:37 +02:00
|
|
|
"default_chest_top.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_top.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_side.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_side.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_lock.png^[colorize:#d8e002:70",
|
|
|
|
"default_chest_inside.png^[colorize:#d8e002:70"
|
2017-06-09 19:55:12 +02:00
|
|
|
},
|
2017-05-28 11:40:50 +02:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
sound_open = "default_chest_open",
|
|
|
|
sound_close = "default_chest_close",
|
|
|
|
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
|
|
|
protected = true,
|
|
|
|
mesecons = {
|
|
|
|
receptor = {
|
|
|
|
rules = mesechest_get_output_rules
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-06-09 19:44:25 +02:00
|
|
|
minetest.register_node = old_minetest_register_node
|
|
|
|
minetest.register_lbm = old_minetest_register_lbm
|
2017-06-10 10:11:05 +02:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "default:mesechest",
|
|
|
|
recipe = {{"group:mesecon_conductor_craftable", "default:chest", "group:mesecon_conductor_craftable"}}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "default:mesechest_locked",
|
|
|
|
recipe = {{"group:mesecon_conductor_craftable", "default:chest_locked", "group:mesecon_conductor_craftable"}}
|
|
|
|
})
|
2018-12-31 17:26:41 +01:00
|
|
|
|
|
|
|
minetest.log("action", "[moremesecons_mesechest] loaded.")
|