From 0494e8088e3ce8086faa59592c5292dade1da3ff Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Fri, 23 Nov 2018 20:47:54 -0800 Subject: [PATCH] Grenades are no longer placable. API feature allows to register grenades as placable --- init.lua | 81 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/init.lua b/init.lua index f2fedf3..b336eee 100644 --- a/init.lua +++ b/init.lua @@ -52,38 +52,63 @@ function grenades.register_grenade(name, def) minetest.register_entity("grenades:grenade_"..name, grenade_entity) - minetest.register_node("grenades:grenade_"..name, { - description = def.description, - stack_max = 1, - range = 4, - paramtype = "light", - sunlight_propagates = true, - walkable = false, - drawtype = "plantlike", - selection_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3}, - }, - tiles = {def.image}, - inventory_image = def.image, - groups = {oddly_breakable_by_hand = 1}, - on_use = function(itemstack, user, pointed_thing) - local player_name = user:get_player_name() - local inv = user:get_inventory() + if def.placeable == true then + minetest.register_node("grenades:grenade_"..name, { + description = def.description, + stack_max = 1, + range = 4, + paramtype = "light", + sunlight_propagates = true, + walkable = false, + drawtype = "plantlike", + selection_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.3, 0.3, 0.4, 0.3}, + }, + tiles = {def.image}, + inventory_image = def.image, + groups = {oddly_breakable_by_hand = 2}, + 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 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 = "" + if not minetest.setting_getbool("creative_mode") then + itemstack = "" + end end - end - return itemstack - end - }) + return itemstack + 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 settings:get_bool("enable_grenade_recipes") == true) then