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,38 +52,63 @@ function grenades.register_grenade(name, def)
minetest.register_entity("grenades:grenade_"..name, grenade_entity) minetest.register_entity("grenades:grenade_"..name, grenade_entity)
minetest.register_node("grenades:grenade_"..name, { if def.placeable == true then
description = def.description, minetest.register_node("grenades:grenade_"..name, {
stack_max = 1, description = def.description,
range = 4, stack_max = 1,
paramtype = "light", range = 4,
sunlight_propagates = true, paramtype = "light",
walkable = false, sunlight_propagates = true,
drawtype = "plantlike", walkable = false,
selection_box = { drawtype = "plantlike",
type = "fixed", selection_box = {
fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3}, type = "fixed",
}, fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3},
tiles = {def.image}, },
inventory_image = def.image, tiles = {def.image},
groups = {oddly_breakable_by_hand = 1}, inventory_image = def.image,
on_use = function(itemstack, user, pointed_thing) groups = {oddly_breakable_by_hand = 2},
local player_name = user:get_player_name() on_use = function(itemstack, user, pointed_thing)
local inv = user:get_inventory() local player_name = user:get_player_name()
local inv = user:get_inventory()
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
local grenade = throw_grenade("grenades:grenade_"..name, user) local grenade = throw_grenade("grenades:grenade_"..name, user)
grenade.timer = 0 grenade.timer = 0
grenade.thrower_name = player_name grenade.thrower_name = player_name
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack = "" itemstack = ""
end
end end
end
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