mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-05 07:13:51 +01:00
Merge pull request 'Make hoppers push items to minecarts' (#3490) from anarquimico/MineClone2:hoppers_to_minecarts into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3490 Reviewed-by: 𝕵𝖔𝖍𝖆𝖓𝖓𝖊𝖘 𝕱𝖗𝖎𝖙𝖟 <mrrar@noreply.git.minetest.land>
This commit is contained in:
commit
4c7c1fe176
@ -405,6 +405,47 @@ local function hopper_pull_from_mc(mc_ent, dest_pos, inv_size)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function hopper_push_to_mc(mc_ent, dest_pos, inv_size)
|
||||||
|
local dest_inv = mcl_entity_invs.load_inv(mc_ent, inv_size)
|
||||||
|
if not dest_inv then
|
||||||
|
mcl_log("No inv")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local meta = minetest.get_meta(dest_pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
if not inv then
|
||||||
|
mcl_log("No dest inv")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mcl_log("inv. size: " .. mc_ent._inv_size)
|
||||||
|
for i = 1, mc_ent._inv_size, 1 do
|
||||||
|
local stack = inv:get_stack("main", i)
|
||||||
|
|
||||||
|
mcl_log("i: " .. tostring(i))
|
||||||
|
mcl_log("Name: [" .. tostring(stack:get_name()) .. "]")
|
||||||
|
mcl_log("Count: " .. tostring(stack:get_count()))
|
||||||
|
mcl_log("stack max: " .. tostring(stack:get_stack_max()))
|
||||||
|
|
||||||
|
if not stack:get_name() or stack:get_name() ~= "" then
|
||||||
|
if dest_inv:room_for_item("main", stack:peek_item()) then
|
||||||
|
mcl_log("Room so unload")
|
||||||
|
dest_inv:add_item("main", stack:take_item())
|
||||||
|
inv:set_stack("main", i, stack)
|
||||||
|
|
||||||
|
-- Take one item and stop until next time
|
||||||
|
return
|
||||||
|
else
|
||||||
|
mcl_log("no Room")
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
mcl_log("nothing there")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[ BEGIN OF ABM DEFINITONS ]]
|
--[[ BEGIN OF ABM DEFINITONS ]]
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
@ -440,6 +481,15 @@ minetest.register_abm({
|
|||||||
elseif entity.name == "mcl_minecarts:chest_minecart" then
|
elseif entity.name == "mcl_minecarts:chest_minecart" then
|
||||||
hopper_pull_from_mc(entity, pos, 27)
|
hopper_pull_from_mc(entity, pos, 27)
|
||||||
end
|
end
|
||||||
|
elseif (hm_pos.y == pos.y - 1)
|
||||||
|
and (hm_pos.x >= pos.x - DIST_FROM_MC and hm_pos.x <= pos.x + DIST_FROM_MC)
|
||||||
|
and (hm_pos.z >= pos.z - DIST_FROM_MC and hm_pos.z <= pos.z + DIST_FROM_MC) then
|
||||||
|
mcl_log("Minecart close enough")
|
||||||
|
if entity.name == "mcl_minecarts:hopper_minecart" then
|
||||||
|
hopper_push_to_mc(entity, pos, 5)
|
||||||
|
elseif entity.name == "mcl_minecarts:chest_minecart" then
|
||||||
|
hopper_push_to_mc(entity, pos, 27)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user