Grenades are no longer placable. API feature allows to register grenades as placable

This commit is contained in:
LoneWolfHT 2018-11-23 20:47:54 -08:00
parent 7861c00e30
commit 0494e8088e

@ -52,6 +52,7 @@ function grenades.register_grenade(name, def)
minetest.register_entity("grenades:grenade_"..name, grenade_entity) minetest.register_entity("grenades:grenade_"..name, grenade_entity)
if def.placeable == true then
minetest.register_node("grenades:grenade_"..name, { minetest.register_node("grenades:grenade_"..name, {
description = def.description, description = def.description,
stack_max = 1, stack_max = 1,
@ -66,7 +67,7 @@ function grenades.register_grenade(name, def)
}, },
tiles = {def.image}, tiles = {def.image},
inventory_image = def.image, inventory_image = def.image,
groups = {oddly_breakable_by_hand = 1}, groups = {oddly_breakable_by_hand = 2},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
local player_name = user:get_player_name() local player_name = user:get_player_name()
local inv = user:get_inventory() local inv = user:get_inventory()
@ -84,6 +85,30 @@ function grenades.register_grenade(name, def)
return itemstack return itemstack
end end
}) })
else
minetest.register_craftitem("grenades:grenade_"..name, {
description = def.description,
stack_max = 1,
range = 4,
inventory_image = def.image,
on_use = function(itemstack, user, pointed_thing)
local player_name = user:get_player_name()
local inv = user:get_inventory()
if pointed_thing.type ~= "node" then
local grenade = throw_grenade("grenades:grenade_"..name, user)
grenade.timer = 0
grenade.thrower_name = player_name
if not minetest.setting_getbool("creative_mode") then
itemstack = ""
end
end
return itemstack
end
})
end
if def.recipe and (not settings:get_bool("enable_grenade_recipes") or if def.recipe and (not settings:get_bool("enable_grenade_recipes") or
settings:get_bool("enable_grenade_recipes") == true) then settings:get_bool("enable_grenade_recipes") == true) then