forked from mtcontrib/connected_chests
Add hopper mod support
This commit is contained in:
parent
0e4ef74b52
commit
12b8325896
56
init.lua
56
init.lua
|
@ -649,3 +649,59 @@ minetest.register_alias("connected_chests:chest_left_locked", "default:chest_loc
|
|||
minetest.register_alias("connected_chests:chest_right_locked", "default:chest_locked_connected_right")
|
||||
minetest.register_alias("connected_chests:chest_locked_left", "default:chest_locked_connected_left")
|
||||
minetest.register_alias("connected_chests:chest_locked_right", "default:chest_locked_connected_right")
|
||||
|
||||
if minetest.get_modpath("hopper") then
|
||||
local function get_inventory(chest_right_pos)
|
||||
local node_right = minetest.get_node(chest_right_pos)
|
||||
if node_right.param2 > 3 then
|
||||
-- The right connected chest node has an invalid param2 value
|
||||
-- Cannot determine the inventory
|
||||
return
|
||||
end
|
||||
local x, z = unpack(param_tab2[node_right.param2])
|
||||
local chest_left_pos = {x=chest_right_pos.x+x, y=chest_right_pos.y, z=chest_right_pos.z+z}
|
||||
local node_left = minetest.get_node(chest_left_pos)
|
||||
if node_left.name ~= "default:chest_connected_left" and node_left.name ~= "default:chest_connected_left_open" then
|
||||
minetest.log("error","The left chest is not a chest: " .. node_left.name .. " at " .. vector.to_string(chest_left_pos))
|
||||
return
|
||||
end
|
||||
if node_left.param2 ~= node_right.param2 then
|
||||
minetest.log("error","The chests are pointing in different directions: node_left.param2:"
|
||||
.. node_left.param2 .. ", node_right.param2:" .. node_right.param2)
|
||||
return
|
||||
end
|
||||
return minetest.get_meta(chest_left_pos):get_inventory()
|
||||
end
|
||||
hopper:add_container({
|
||||
{"top", "default:chest_connected_left", "main"},
|
||||
{"bottom", "default:chest_connected_left", "main"},
|
||||
{"side", "default:chest_connected_left", "main"},
|
||||
{"top", "default:chest_connected_right", "main", get_inventory = get_inventory},
|
||||
{"bottom", "default:chest_connected_right", "main", get_inventory = get_inventory},
|
||||
{"side", "default:chest_connected_right", "main", get_inventory = get_inventory},
|
||||
{"top", "default:chest_connected_left_open", "main"},
|
||||
{"bottom", "default:chest_connected_left_open", "main"},
|
||||
{"side", "default:chest_connected_left_open", "main"},
|
||||
{"top", "default:chest_connected_right_open", "main", get_inventory = get_inventory},
|
||||
{"bottom", "default:chest_connected_right_open", "main", get_inventory = get_inventory},
|
||||
{"side", "default:chest_connected_right_open", "main", get_inventory = get_inventory},
|
||||
})
|
||||
local function set_hopper_param2(hopper_pos, chest_left_pos)
|
||||
local param2_by_offset = {
|
||||
[vector.new(-1, 0, 0):to_string()] = 0,
|
||||
[vector.new( 0, 0, 1):to_string()] = 1,
|
||||
[vector.new( 1, 0, 0):to_string()] = 2,
|
||||
[vector.new( 0, 0,-1):to_string()] = 3,
|
||||
}
|
||||
local hopper_param2 = param2_by_offset[(chest_left_pos - hopper_pos):to_string()]
|
||||
if hopper_param2 then
|
||||
return hopper_param2
|
||||
end
|
||||
local x, z = unpack(param_tab2[minetest.get_node(chest_left_pos).param2])
|
||||
local chest_right_pos = {x=chest_left_pos.x-x, y=chest_left_pos.y, z=chest_left_pos.z-z}
|
||||
return param2_by_offset[(chest_right_pos - hopper_pos):to_string()]
|
||||
end
|
||||
hopper:set_extra_container_info({
|
||||
{"default:chest_connected_left", set_hopper_param2 = set_hopper_param2},
|
||||
})
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user