Add _on_dispense callback for dispenser; refactor

This commit is contained in:
Wuzzy 2018-02-01 22:45:19 +01:00
parent 8774e7674d
commit fa10dc93ae
11 changed files with 196 additions and 211 deletions

View file

@ -7,6 +7,12 @@ minetest.register_craftitem("mcl_throwing:arrow", {
_doc_items_usagehelp = "To use arrows as ammunition for a bow, just put them anywhere in your inventory, they will be used up automatically. To use arrows as ammunition for a dispenser, place them in the dispenser's inventory.",
inventory_image = "mcl_throwing_arrow_inv.png",
groups = { ammo=1, ammo_bow=1 },
_on_dispense = function(itemstack, dispenserpos, droppos, dropnode, dropdir)
-- Shoot arrow
local shootpos = vector.add(dispenserpos, vector.multiply(dropdir, 0.51))
local yaw = math.atan2(dropdir.z, dropdir.x) - math.pi/2
mcl_throwing.shoot_arrow(itemstack:get_name(), shootpos, dropdir, yaw, nil, 19, 3)
end,
})
minetest.register_node("mcl_throwing:arrow_box", {

View file

@ -34,7 +34,7 @@ end
-- Throw item
local throw_function = function(entity_name, velocity)
local func = function(item, player, pointed_thing)
local playerpos = player:getpos()
local playerpos = player:get_pos()
local dir = player:get_look_dir()
local obj = mcl_throwing.throw(item, {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, velocity)
obj:get_luaentity()._thrower = player:get_player_name()
@ -46,6 +46,12 @@ local throw_function = function(entity_name, velocity)
return func
end
local dispense_function = function(stack, dispenserpos, droppos, dropnode, dropdir)
-- Launch throwable item
local shootpos = vector.add(dispenserpos, vector.multiply(dropdir, 0.51))
mcl_throwing.throw(stack:get_name(), shootpos, dropdir)
end
-- Staticdata handling because objects may want to be reloaded
local get_staticdata = function(self)
local data = {
@ -288,6 +294,7 @@ minetest.register_craftitem("mcl_throwing:snowball", {
inventory_image = "mcl_throwing_snowball.png",
stack_max = 16,
on_use = throw_function("mcl_throwing:snowball_entity"),
_on_dispense = dispense_function,
})
-- Egg
@ -298,6 +305,7 @@ minetest.register_craftitem("mcl_throwing:egg", {
inventory_image = "mcl_throwing_egg.png",
stack_max = 16,
on_use = throw_function("mcl_throwing:egg_entity"),
_on_dispense = dispense_function,
groups = { craftitem = 1 },
})