1
0
Fork 0
MineClone2/mods/mcl_throwing/init.lua

143 lines
4.2 KiB
Lua
Raw Normal View History

2015-06-29 19:55:56 +02:00
2017-01-16 23:11:04 +01:00
dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua")
dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
2015-06-29 19:55:56 +02:00
2017-01-24 02:31:49 +01:00
local arrows = {
2017-01-16 23:11:04 +01:00
{"mcl_throwing:arrow", "mcl_throwing:arrow_entity"},
2015-06-29 19:55:56 +02:00
}
2017-01-16 23:11:04 +01:00
local GRAVITY = 9.81
local mcl_throwing_shoot_arrow = function(itemstack, player)
2015-06-29 19:55:56 +02:00
for _,arrow in ipairs(arrows) do
if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then
2017-01-26 18:50:06 +01:00
if not minetest.setting_getbool("creative_mode") then
2015-06-29 19:55:56 +02:00
player:get_inventory():remove_item("main", arrow[1])
2017-01-26 18:50:06 +01:00
end
2015-06-29 19:55:56 +02:00
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2])
2015-06-29 19:55:56 +02:00
local dir = player:get_look_dir()
obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19})
2017-01-16 23:11:04 +01:00
obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
2015-06-29 19:55:56 +02:00
obj:setyaw(player:get_look_yaw()+math.pi)
2017-01-16 23:11:04 +01:00
minetest.sound_play("mcl_throwing_bow_shoot", {pos=playerpos})
2015-06-29 19:55:56 +02:00
if obj:get_luaentity().player == "" then
obj:get_luaentity().player = player
end
obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
return true
end
end
return false
end
2017-01-16 23:11:04 +01:00
minetest.register_tool("mcl_throwing:bow", {
2015-06-29 19:55:56 +02:00
description = "Bow",
2017-01-16 23:11:04 +01:00
inventory_image = "mcl_throwing_bow.png",
2015-06-29 19:55:56 +02:00
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
2017-01-24 02:31:49 +01:00
local wear = itemstack:get_wear()
2017-01-16 23:11:04 +01:00
itemstack:replace("mcl_throwing:bow_0")
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
return itemstack
end,
groups = {weapon=1,weapon_ranged=1},
2015-06-29 19:55:56 +02:00
on_use = function(itemstack, user, pointed_thing)
2017-01-16 13:24:38 +01:00
local wear = itemstack:get_wear()
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
2017-01-16 23:11:04 +01:00
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
2015-06-29 19:55:56 +02:00
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
2017-01-16 23:11:04 +01:00
minetest.register_tool("mcl_throwing:bow_0", {
2015-06-29 19:55:56 +02:00
description = "Bow",
2017-01-16 23:11:04 +01:00
inventory_image = "mcl_throwing_bow_0.png",
2015-06-29 19:55:56 +02:00
stack_max = 1,
2017-02-14 16:35:25 +01:00
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
2015-06-29 19:55:56 +02:00
on_place = function(itemstack, placer, pointed_thing)
2017-01-24 02:31:49 +01:00
local wear = itemstack:get_wear()
2017-01-16 23:11:04 +01:00
itemstack:replace("mcl_throwing:bow_1")
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
2017-01-24 02:31:49 +01:00
local wear = itemstack:get_wear()
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
2017-01-16 23:11:04 +01:00
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
2015-06-29 19:55:56 +02:00
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
2017-01-16 23:11:04 +01:00
minetest.register_tool("mcl_throwing:bow_1", {
2015-06-29 19:55:56 +02:00
description = "Bow",
2017-01-16 23:11:04 +01:00
inventory_image = "mcl_throwing_bow_1.png",
2015-06-29 19:55:56 +02:00
stack_max = 1,
2017-02-14 16:35:25 +01:00
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
2015-06-29 19:55:56 +02:00
on_place = function(itemstack, placer, pointed_thing)
2017-01-24 02:31:49 +01:00
local wear = itemstack:get_wear()
2017-01-16 23:11:04 +01:00
itemstack:replace("mcl_throwing:bow_2")
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
2017-01-24 02:31:49 +01:00
local wear = itemstack:get_wear()
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
2017-01-16 23:11:04 +01:00
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
2015-06-29 19:55:56 +02:00
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
2017-01-16 23:11:04 +01:00
minetest.register_tool("mcl_throwing:bow_2", {
2015-06-29 19:55:56 +02:00
description = "Bow",
2017-01-16 23:11:04 +01:00
inventory_image = "mcl_throwing_bow_2.png",
2015-06-29 19:55:56 +02:00
stack_max = 1,
2017-02-14 16:35:25 +01:00
groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
2015-06-29 19:55:56 +02:00
on_use = function(itemstack, user, pointed_thing)
2017-01-24 02:31:49 +01:00
local wear = itemstack:get_wear()
2017-01-16 23:11:04 +01:00
itemstack:replace("mcl_throwing:bow")
2015-06-29 19:55:56 +02:00
itemstack:add_wear(wear)
2017-01-16 23:11:04 +01:00
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
2015-06-29 19:55:56 +02:00
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
minetest.register_craft({
2017-01-16 23:11:04 +01:00
output = 'mcl_throwing:bow',
2015-06-29 19:55:56 +02:00
recipe = {
2017-02-01 17:59:15 +01:00
{'', 'mcl_core:stick', 'mcl_mobitems:string'},
{'mcl_core:stick', '', 'mcl_mobitems:string'},
{'', 'mcl_core:stick', 'mcl_mobitems:string'},
2015-06-29 19:55:56 +02:00
}
})
2017-01-10 01:59:21 +01:00
minetest.register_craft({
2017-01-16 23:11:04 +01:00
output = 'mcl_throwing:bow',
2017-01-10 01:59:21 +01:00
recipe = {
2017-02-01 17:59:15 +01:00
{'mcl_mobitems:string', 'mcl_core:stick', ''},
{'mcl_mobitems:string', '', 'mcl_core:stick'},
{'mcl_mobitems:string', 'mcl_core:stick', ''},
2017-01-10 01:59:21 +01:00
}
})
2015-06-29 19:55:56 +02:00
2017-01-10 06:43:07 +01:00
minetest.register_craft({
type = "fuel",
2017-01-16 23:11:04 +01:00
recipe = "mcl_throwing:bow",
2017-01-10 06:43:07 +01:00
burntime = 15,
})