forked from VoxeLibre/VoxeLibre
Hopper minecarts pull from containers above rail
This commit is contained in:
parent
0951acd06c
commit
af9409c69f
|
@ -345,6 +345,33 @@ function mcl_util.hopper_push(pos, dst_pos)
|
|||
return ok
|
||||
end
|
||||
|
||||
function mcl_util.hopper_pull_to_inventory(hop_inv, hop_list, src_pos)
|
||||
-- TODO: merge together with hopper_pull after https://git.minetest.land/MineClone2/MineClone2/pulls/4190 is merged
|
||||
-- Get node pos' for item transfer
|
||||
local src = minetest.get_node(src_pos)
|
||||
if not minetest.registered_nodes[src.name] then return end
|
||||
local src_type = minetest.get_item_group(src.name, "container")
|
||||
if src_type ~= 2 then return end
|
||||
local src_def = minetest.registered_nodes[src.name]
|
||||
|
||||
local src_list = 'main'
|
||||
local src_inv, stack_id
|
||||
|
||||
if src_def._mcl_hoppers_on_try_pull then
|
||||
src_inv, src_list, stack_id = src_def._mcl_hoppers_on_try_pull(src_pos, pos, hop_inv, hop_list)
|
||||
else
|
||||
local src_meta = minetest.get_meta(src_pos)
|
||||
src_inv = src_meta:get_inventory()
|
||||
stack_id = mcl_util.select_stack(src_inv, src_list, hop_inv, hop_list)
|
||||
end
|
||||
|
||||
if stack_id ~= nil then
|
||||
local ok = mcl_util.move_item(src_inv, src_list, stack_id, hop_inv, hop_list)
|
||||
if src_def._mcl_hoppers_on_after_pull then
|
||||
src_def._mcl_hoppers_on_after_pull(src_pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Try pulling from source inventory to hopper inventory
|
||||
---@param pos Vector
|
||||
---@param src_pos Vector
|
||||
|
|
|
@ -31,10 +31,10 @@ local function handle_cart_enter(self,pos)
|
|||
end
|
||||
|
||||
-- Handle above-track behaviors (to ensure hoppers can transfer at least one item)
|
||||
pos = pos + vector.new(0,1,0)
|
||||
local node = minetest.get_node(pos)
|
||||
local above_pos = pos + vector.new(0,1,0)
|
||||
local node = minetest.get_node(above_pos)
|
||||
if node_def._mcl_minecarts_on_enter_below then
|
||||
node_def._mcl_minecarts_on_enter_below(pos, cart)
|
||||
node_def._mcl_minecarts_on_enter_below(above_pos, cart)
|
||||
end
|
||||
|
||||
-- Handle cart-specific behaviors
|
||||
|
@ -639,6 +639,9 @@ local function register_entity(entity_id, def)
|
|||
staticdata = make_staticdata()
|
||||
self._staticdata = staticdata
|
||||
end
|
||||
if (staticdata.hopper_delay or 0) > 0 then
|
||||
staticdata.hopper_delay = staticdata.hopper_delay - dtime
|
||||
end
|
||||
|
||||
local pos, rou_pos, node = self.object:get_pos()
|
||||
--local update = {}
|
||||
|
@ -835,7 +838,7 @@ function mcl_minecarts.place_minecart(itemstack, pointed_thing, placer)
|
|||
le._staticdata = make_staticdata( railtype, railpos, cart_dir )
|
||||
end
|
||||
|
||||
handle_cart_enter( railpos )
|
||||
handle_cart_enter(le, railpos)
|
||||
|
||||
local pname = ""
|
||||
if placer then
|
||||
|
@ -1083,7 +1086,17 @@ register_minecart({
|
|||
on_rightclick = nil,
|
||||
on_activate_by_rail = nil,
|
||||
_mcl_minecarts_on_enter = function(self,pos)
|
||||
-- TODO: try to pull from containers into our inventory
|
||||
local staticdata = self._staticdata
|
||||
if (staticdata.hopper_delay or 0) > 0 then
|
||||
return
|
||||
end
|
||||
|
||||
-- try to pull from containers into our inventory
|
||||
local inv = mcl_entity_invs.load_inv(self,5)
|
||||
local above_pos = pos + vector.new(0,1,0)
|
||||
mcl_util.hopper_pull_to_inventory(inv, 'main', above_pos)
|
||||
|
||||
staticdata.hopper_delay = (staticdata.hopper_delay or 0) + (1/20)
|
||||
end,
|
||||
creative = true
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue