mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-25 04:13:44 +01:00
Refactor throwable code even more, add mini API
This commit is contained in:
parent
53409bfbec
commit
eca6cd30b6
@ -4,26 +4,39 @@
|
|||||||
|
|
||||||
local GRAVITY = tonumber(minetest.setting_get("movement_gravity"))
|
local GRAVITY = tonumber(minetest.setting_get("movement_gravity"))
|
||||||
|
|
||||||
|
local entity_mapping = {
|
||||||
|
["mcl_throwing:snowball"] = "mcl_throwing:snowball_entity",
|
||||||
|
["mcl_throwing:egg"] = "mcl_throwing:egg_entity",
|
||||||
|
["mcl_throwing:ender_pearl"] = "mcl_throwing:ender_pearl_entity",
|
||||||
|
}
|
||||||
|
|
||||||
local velocities = {
|
local velocities = {
|
||||||
["mcl_throwing:snowball_entity"] = 22,
|
["mcl_throwing:snowball_entity"] = 22,
|
||||||
["mcl_throwing:egg_entity"] = 22,
|
["mcl_throwing:egg_entity"] = 22,
|
||||||
["mcl_throwing:ender_pearl_entity"] = 22,
|
["mcl_throwing:ender_pearl_entity"] = 22,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Throw item
|
mcl_throwing.throw = function(throw_item, pos, dir, velocity)
|
||||||
local throw_function = function(entity_name, velocity)
|
|
||||||
if velocity == nil then
|
if velocity == nil then
|
||||||
velocity = velocities[entity_name]
|
velocity = velocities[entity_name]
|
||||||
end
|
end
|
||||||
if velocity == nil then
|
if velocity == nil then
|
||||||
velocity = 22
|
velocity = 22
|
||||||
end
|
end
|
||||||
local func = function(item, player, pointed_thing)
|
|
||||||
local playerpos=player:getpos()
|
local itemstring = throw_item:get_name()
|
||||||
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, entity_name)
|
local obj = minetest.add_entity(pos, entity_mapping[itemstring])
|
||||||
local dir=player:get_look_dir()
|
|
||||||
obj:setvelocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity})
|
obj:setvelocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity})
|
||||||
obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
|
obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
|
||||||
|
return obj
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Throw item
|
||||||
|
local throw_function = function(entity_name, velocity)
|
||||||
|
local func = function(item, player, pointed_thing)
|
||||||
|
local playerpos = player:getpos()
|
||||||
|
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()
|
obj:get_luaentity()._thrower = player:get_player_name()
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
item:take_item()
|
item:take_item()
|
||||||
|
Loading…
Reference in New Issue
Block a user