Add _on_dispense callback for dispenser; refactor
This commit is contained in:
parent
8774e7674d
commit
fa10dc93ae
11 changed files with 196 additions and 211 deletions
|
@ -307,6 +307,16 @@ for b=1, #boat_ids do
|
|||
end
|
||||
return itemstack
|
||||
end,
|
||||
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
|
||||
local below = {x=droppos.x, y=droppos.y-1, z=droppos.z}
|
||||
local belownode = minetest.get_node(below)
|
||||
-- Place boat as entity on or in water
|
||||
if minetest.get_item_group(dropnode.name, "water") ~= 0 or (dropnode.name == "air" and minetest.get_item_group(belownode.name, "water") ~= 0) then
|
||||
minetest.add_entity(droppos, "mcl_boats:boat")
|
||||
else
|
||||
minetest.add_item(droppos, stack)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local c = craftstuffs[b]
|
||||
|
|
|
@ -332,6 +332,7 @@ mcl_minecarts.place_minecart = function(itemstack, pointed_thing)
|
|||
return itemstack
|
||||
end
|
||||
|
||||
|
||||
local register_craftitem = function(itemstring, entity_id, description, longdesc, usagehelp, icon, creative)
|
||||
entity_mapping[itemstring] = entity_id
|
||||
|
||||
|
@ -356,6 +357,19 @@ local register_craftitem = function(itemstring, entity_id, description, longdesc
|
|||
|
||||
return mcl_minecarts.place_minecart(itemstack, pointed_thing)
|
||||
end,
|
||||
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
|
||||
-- Place minecart as entity on rail. If there's no rail, just drop it.
|
||||
local placed
|
||||
if minetest.get_item_group(dropnode.name, "rail") ~= 0 then
|
||||
-- FIXME: This places minecarts even if the spot is already occupied
|
||||
local pointed_thing = { under = droppos, above = { x=droppos.x, y=droppos.y+1, z=droppos.z } }
|
||||
placed = mcl_minecarts.place_minecart(stack, pointed_thing)
|
||||
end
|
||||
if placed == nil then
|
||||
-- Drop item
|
||||
minetest.add_item(droppos, stack)
|
||||
end
|
||||
end,
|
||||
groups = groups,
|
||||
}
|
||||
def.description = description
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue