forked from VoxeLibre/VoxeLibre
Hopper minecarts pull from containers above rail
This commit is contained in:
parent
0b5e742a9f
commit
2e3de195b2
|
@ -335,6 +335,33 @@ function mcl_util.hopper_push(pos, dst_pos)
|
||||||
return false
|
return false
|
||||||
end
|
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
|
-- Try pulling from source inventory to hopper inventory
|
||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
---@param src_pos Vector
|
---@param src_pos Vector
|
||||||
|
|
|
@ -31,10 +31,10 @@ local function handle_cart_enter(self,pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle above-track behaviors (to ensure hoppers can transfer at least one item)
|
-- Handle above-track behaviors (to ensure hoppers can transfer at least one item)
|
||||||
pos = pos + vector.new(0,1,0)
|
local above_pos = pos + vector.new(0,1,0)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(above_pos)
|
||||||
if node_def._mcl_minecarts_on_enter_below then
|
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
|
end
|
||||||
|
|
||||||
-- Handle cart-specific behaviors
|
-- Handle cart-specific behaviors
|
||||||
|
@ -116,7 +116,7 @@ local function do_movement_step(self, remaining_distance)
|
||||||
staticdata.connected_at = pos
|
staticdata.connected_at = pos
|
||||||
|
|
||||||
-- Enter the new node
|
-- Enter the new node
|
||||||
handle_cart_enter(self,pos)
|
handle_cart_enter(self, pos)
|
||||||
|
|
||||||
-- check for hopper under the rail
|
-- check for hopper under the rail
|
||||||
local under_pos = pos - vector.new(0,1,0)
|
local under_pos = pos - vector.new(0,1,0)
|
||||||
|
@ -639,6 +639,9 @@ local function register_entity(entity_id, def)
|
||||||
staticdata = make_staticdata()
|
staticdata = make_staticdata()
|
||||||
self._staticdata = staticdata
|
self._staticdata = staticdata
|
||||||
end
|
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 pos, rou_pos, node = self.object:get_pos()
|
||||||
--local update = {}
|
--local update = {}
|
||||||
|
@ -835,7 +838,7 @@ function mcl_minecarts.place_minecart(itemstack, pointed_thing, placer)
|
||||||
le._staticdata = make_staticdata( railtype, railpos, cart_dir )
|
le._staticdata = make_staticdata( railtype, railpos, cart_dir )
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_cart_enter( railpos )
|
handle_cart_enter(le, railpos)
|
||||||
|
|
||||||
local pname = ""
|
local pname = ""
|
||||||
if placer then
|
if placer then
|
||||||
|
@ -1083,7 +1086,17 @@ register_minecart({
|
||||||
on_rightclick = nil,
|
on_rightclick = nil,
|
||||||
on_activate_by_rail = nil,
|
on_activate_by_rail = nil,
|
||||||
_mcl_minecarts_on_enter = function(self,pos)
|
_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,
|
end,
|
||||||
creative = true
|
creative = true
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue