diff --git a/3d.lua b/3d.lua index 26ca2b2..dc5953e 100644 --- a/3d.lua +++ b/3d.lua @@ -1,8 +1,10 @@ -- translation support + local S = minetest.get_translator("real_torch") -- flood helper function + local function on_flood(pos, oldnode, newnode) -- drop as unlit torch @@ -26,8 +28,8 @@ local function on_flood(pos, oldnode, newnode) return false end - -- unlit floor torch + minetest.register_node("real_torch:torch", { description = S("Unlit Torch"), drawtype = "mesh", @@ -52,8 +54,7 @@ minetest.register_node("real_torch:torch", { groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1}, drop = "real_torch:torch", selection_box = { - type = "wallmounted", - wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8} + type = "wallmounted", wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8} }, sounds = default.node_sound_wood_defaults(), @@ -68,7 +69,7 @@ minetest.register_node("real_torch:torch", { and placer:get_player_control().sneak) then return def.on_rightclick(under, node, placer, itemstack, - pointed_thing) or itemstack + pointed_thing) or itemstack end local above = pointed_thing.above @@ -99,8 +100,8 @@ minetest.register_node("real_torch:torch", { floodable = true, on_rotate = false, on_flood = on_flood }) - -- unlit wall torch + minetest.register_node("real_torch:torch_wall", { drawtype = "mesh", mesh = "torch_wall.obj", @@ -124,8 +125,7 @@ minetest.register_node("real_torch:torch_wall", { }, drop = "real_torch:torch", selection_box = { - type = "wallmounted", - wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8} + type = "wallmounted", wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8} }, sounds = default.node_sound_wood_defaults(), @@ -139,8 +139,8 @@ minetest.register_node("real_torch:torch_wall", { floodable = true, on_rotate = false, on_flood = on_flood }) - -- unlit ceiling torch + minetest.register_node("real_torch:torch_ceiling", { drawtype = "mesh", mesh = "torch_ceiling.obj", @@ -164,8 +164,7 @@ minetest.register_node("real_torch:torch_ceiling", { }, drop = "real_torch:torch", selection_box = { - type = "wallmounted", - wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8} + type = "wallmounted", wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8} }, sounds = default.node_sound_wood_defaults(), @@ -179,11 +178,11 @@ minetest.register_node("real_torch:torch_ceiling", { floodable = true, on_rotate = false, on_flood = on_flood }) - -- burnout helper function + local function torch_override(name) - -- override default torch to burn out after 8-10 minutes + -- override default torch to burn out after 8-10 minutes and drop in water minetest.override_item("default:" .. name, { on_timer = function(pos, elapsed) diff --git a/init.lua b/init.lua index a91b52a..2559c48 100644 --- a/init.lua +++ b/init.lua @@ -3,18 +3,19 @@ real_torch = {} --- check for timer settings or use defaults +-- translation and torch duration settings + +local S = minetest.get_translator("real_torch") + real_torch.min_duration = tonumber(minetest.settings:get("torch_min_duration")) or 1200 real_torch.max_duration = tonumber(minetest.settings:get("torch_max_duration")) or 1800 --- translation support -local S = minetest.get_translator("real_torch") +-- add unlit torches & override current --- add unlit torches dofile(minetest.get_modpath("real_torch") .. "/3d.lua") - -- start timer on any already placed torches + minetest.register_lbm({ name = "real_torch:convert_torch_to_node_timer", nodenames = {"default:torch", "default:torch_wall", "default:torch_ceiling"}, @@ -29,15 +30,15 @@ minetest.register_lbm({ end }) - -- creative check + local creative_mode_cache = minetest.settings:get_bool("creative_mode") local function is_creative(name) return creative_mode_cache or minetest.check_player_privs(name, {creative = true}) end - -- coal powder + minetest.register_craftitem("real_torch:coal_powder", { description = S("Coal Powder"), inventory_image = "real_torch_coal_powder.png", @@ -51,22 +52,16 @@ minetest.register_craftitem("real_torch:coal_powder", { local pos = pointed_thing.under local nod = minetest.get_node(pos) - local rep = false if nod.name == "real_torch:torch" then nod.name = "default:torch" - rep = true - elseif nod.name == "real_torch:torch_wall" then nod.name = "default:torch_wall" - rep = true - elseif nod.name == "real_torch:torch_ceiling" then nod.name = "default:torch_ceiling" - rep = true - end + else nod.name = "" end - if rep then + if nod.name ~= "" then minetest.set_node(pos, {name = nod.name, param2 = nod.param2}) @@ -114,8 +109,8 @@ minetest.register_craft({ } }) +-- explosion effect --- particle effects local function add_effects(pos, radius) minetest.add_particle({ @@ -155,67 +150,59 @@ end -- will also re-light torches and cause player damage when used on lit torch. if minetest.get_modpath("tnt") then -minetest.override_item("tnt:gunpowder", { + minetest.override_item("tnt:gunpowder", { - on_use = function(itemstack, user, pointed_thing) + on_use = function(itemstack, user, pointed_thing) - if not pointed_thing or pointed_thing.type ~= "node" then - return - end + if not pointed_thing or pointed_thing.type ~= "node" then + return + end - local pos = pointed_thing.under - local nod = minetest.get_node(pos) + local pos = pointed_thing.under + local nod = minetest.get_node(pos) - local rep = false + -- torch already lit, boom! + if nod.name == "default:torch" + or nod.name == "default:torch_wall" + or nod.name == "default:torch_ceiling" then - if nod.name == "real_torch:torch" then - nod.name = "default:torch" - rep = true + -- small delay to fix dupe bug + minetest.after(0.1, function(user) - elseif nod.name == "real_torch:torch_wall" then - nod.name = "default:torch_wall" - rep = true + if user and user:get_pos() then + user:set_hp(user:get_hp() - 2) + end + end, user) - elseif nod.name == "real_torch:torch_ceiling" then - nod.name = "default:torch_ceiling" - rep = true - end + add_effects(pos, 1) - if rep then + if not is_creative(user:get_player_name()) then + itemstack:take_item() + end + end - minetest.set_node(pos, {name = nod.name, param2 = nod.param2}) + if nod.name == "real_torch:torch" then + nod.name = "default:torch" + elseif nod.name == "real_torch:torch_wall" then + nod.name = "default:torch_wall" + elseif nod.name == "real_torch:torch_ceiling" then + nod.name = "default:torch_ceiling" + else nod.name = "" end - add_effects(pos, 1) + if nod.name ~= "" then - if not is_creative(user:get_player_name()) then - itemstack:take_item() + minetest.set_node(pos, {name = nod.name, param2 = nod.param2}) + + add_effects(pos, 1) + + if not is_creative(user:get_player_name()) then + itemstack:take_item() + end end return itemstack end - - if nod.name == "default:torch" - or nod.name == "default:torch_wall" - or nod.name == "default:torch_ceiling" then - - -- small delay to fix dupe bug - minetest.after(0.1, function(user) - - if user and user:get_pos() then - user:set_hp(user:get_hp() - 2) - end - end, user) - - add_effects(pos, 1) - - if not is_creative(user:get_player_name()) then - itemstack:take_item() - end - end - - return itemstack - end -}) + }) end