Refactor mcl_throwing throw function

Wuzzy 2017-02-14 23:18:23 +01:00
parent b057a20b2a
commit 53409bfbec
2 changed files with 19 additions and 10 deletions

@ -1,8 +1,8 @@
mcl_throwing = {}
dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua") dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua")
dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua") dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
mcl_throwing = {}
local arrows = { local arrows = {
["mcl_throwing:arrow"] = "mcl_throwing:arrow_entity", ["mcl_throwing:arrow"] = "mcl_throwing:arrow_entity",
} }

@ -3,12 +3,21 @@
-- --
local GRAVITY = tonumber(minetest.setting_get("movement_gravity")) local GRAVITY = tonumber(minetest.setting_get("movement_gravity"))
local snowball_VELOCITY=22
local egg_VELOCITY=22
local pearl_VELOCITY=22
--Shoot item local velocities = {
local throw_function = function (entity_name, velocity) ["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 func = function(item, player, pointed_thing)
local playerpos=player:getpos() local playerpos=player:getpos()
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, entity_name) 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", description = "Snowball",
inventory_image = "mcl_throwing_snowball.png", inventory_image = "mcl_throwing_snowball.png",
stack_max = 16, 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) on_construct = function(pos)
pos.y = pos.y - 1 pos.y = pos.y - 1
if minetest.get_node(pos).name == "default:dirt_with_grass" then if minetest.get_node(pos).name == "default:dirt_with_grass" then
@ -145,7 +154,7 @@ minetest.register_craftitem("mcl_throwing:egg", {
description = "Egg", description = "Egg",
inventory_image = "mcl_throwing_egg.png", inventory_image = "mcl_throwing_egg.png",
stack_max = 16, stack_max = 16,
on_use = throw_function("mcl_throwing:egg_entity", egg_VELOCITY), on_use = throw_function("mcl_throwing:egg_entity"),
groups = { craftitem = 1 }, groups = { craftitem = 1 },
}) })
@ -155,6 +164,6 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", {
wield_image = "mcl_throwing_ender_pearl.png", wield_image = "mcl_throwing_ender_pearl.png",
inventory_image = "mcl_throwing_ender_pearl.png", inventory_image = "mcl_throwing_ender_pearl.png",
stack_max = 16, stack_max = 16,
on_use = throw_function("mcl_throwing:ender_pearl_entity", pearl_VELOCITY), on_use = throw_function("mcl_throwing:ender_pearl_entity"),
}) })