diff --git a/mods/mcl_throwing/init.lua b/mods/mcl_throwing/init.lua index 0d060b75f0..dae327b47b 100644 --- a/mods/mcl_throwing/init.lua +++ b/mods/mcl_throwing/init.lua @@ -1,8 +1,8 @@ +mcl_throwing = {} + dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua") dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua") -mcl_throwing = {} - local arrows = { ["mcl_throwing:arrow"] = "mcl_throwing:arrow_entity", } diff --git a/mods/mcl_throwing/throwable.lua b/mods/mcl_throwing/throwable.lua index 8c32c17c2d..baeb7d7b69 100644 --- a/mods/mcl_throwing/throwable.lua +++ b/mods/mcl_throwing/throwable.lua @@ -3,12 +3,21 @@ -- local GRAVITY = tonumber(minetest.setting_get("movement_gravity")) -local snowball_VELOCITY=22 -local egg_VELOCITY=22 -local pearl_VELOCITY=22 ---Shoot item -local throw_function = function (entity_name, velocity) +local velocities = { + ["mcl_throwing:snowball_entity"] = 22, + ["mcl_throwing:egg_entity"] = 22, + ["mcl_throwing:ender_pearl_entity"] = 22, +} + +-- Throw item +local throw_function = function(entity_name, velocity) + if velocity == nil then + velocity = velocities[entity_name] + end + if velocity == nil then + velocity = 22 + end local func = function(item, player, pointed_thing) local playerpos=player:getpos() local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, entity_name) @@ -131,7 +140,7 @@ minetest.register_craftitem("mcl_throwing:snowball", { description = "Snowball", inventory_image = "mcl_throwing_snowball.png", stack_max = 16, - on_use = throw_function("mcl_throwing:snowball_entity", snowball_VELOCITY), + on_use = throw_function("mcl_throwing:snowball_entity"), on_construct = function(pos) pos.y = pos.y - 1 if minetest.get_node(pos).name == "default:dirt_with_grass" then @@ -145,7 +154,7 @@ minetest.register_craftitem("mcl_throwing:egg", { description = "Egg", inventory_image = "mcl_throwing_egg.png", stack_max = 16, - on_use = throw_function("mcl_throwing:egg_entity", egg_VELOCITY), + on_use = throw_function("mcl_throwing:egg_entity"), groups = { craftitem = 1 }, }) @@ -155,6 +164,6 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", { wield_image = "mcl_throwing_ender_pearl.png", inventory_image = "mcl_throwing_ender_pearl.png", stack_max = 16, - on_use = throw_function("mcl_throwing:ender_pearl_entity", pearl_VELOCITY), + on_use = throw_function("mcl_throwing:ender_pearl_entity"), })