From 2879a08bd002dfd3c8e067bbbf354cbcd303bccb Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Wed, 9 Aug 2017 11:09:18 +0100 Subject: [PATCH] unlit torches can be relit with flint&steel or gunpowder, timer settings added --- 2d.lua | 3 +- 3d.lua | 23 +++++++++-- depends.txt | 1 + init.lua | 116 ++++++++++++++++++++++++++++++++++++++++++++++++---- readme.md | 9 +++- 5 files changed, 137 insertions(+), 15 deletions(-) diff --git a/2d.lua b/2d.lua index 7ef8456..e28c6c6 100644 --- a/2d.lua +++ b/2d.lua @@ -39,6 +39,7 @@ minetest.override_item("default:torch", { end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(480, 600)) + minetest.get_node_timer(pos):start( + math.random(real_torch.min_duration, real_torch.max_duration)) end, }) diff --git a/3d.lua b/3d.lua index 71b8e6e..9b738a4 100644 --- a/3d.lua +++ b/3d.lua @@ -47,7 +47,11 @@ minetest.register_node("real_torch:torch", { itemstack:set_name("real_torch:torch") return itemstack - end + end, + on_ignite = function(pos, igniter) + local nod = minetest.get_node(pos) + minetest.set_node(pos, {name = "default:torch", param2 = nod.param2}) + end, }) @@ -70,6 +74,10 @@ minetest.register_node("real_torch:torch_wall", { wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8}, }, sounds = default.node_sound_wood_defaults(), + on_ignite = function(pos, igniter) + local nod = minetest.get_node(pos) + minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2}) + end, }) @@ -92,6 +100,10 @@ minetest.register_node("real_torch:torch_ceiling", { wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8}, }, sounds = default.node_sound_wood_defaults(), + on_ignite = function(pos, igniter) + local nod = minetest.get_node(pos) + minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2}) + end, }) @@ -106,7 +118,8 @@ minetest.override_item("default:torch", { end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(480, 600)) + minetest.get_node_timer(pos):start( + math.random(real_torch.min_duration, real_torch.max_duration)) end, }) @@ -121,7 +134,8 @@ minetest.override_item("default:torch_wall", { end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(480, 600)) + minetest.get_node_timer(pos):start( + math.random(real_torch.min_duration, real_torch.max_duration)) end, }) @@ -136,6 +150,7 @@ minetest.override_item("default:torch_ceiling", { end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(480, 600)) + minetest.get_node_timer(pos):start( + math.random(real_torch.min_duration, real_torch.max_duration)) end, }) diff --git a/depends.txt b/depends.txt index 4ad96d5..ecb02a0 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,2 @@ default +tnt? diff --git a/init.lua b/init.lua index a83d3c6..23a3542 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,12 @@ -- Realistic Torch mod by TenPlus1 +real_torch = {} + +-- check for timer settings or use defaults +real_torch.min_duration = tonumber(minetest.setting_get("torch_min_duration")) or 480 +real_torch.max_duration = tonumber(minetest.setting_get("torch_min_duration")) or 600 + -- check which torch(es) are available in minetest version if minetest.registered_nodes["default:torch_ceiling"] then @@ -17,7 +23,8 @@ minetest.register_lbm({ nodenames = {"default:torch", "default:torch_wall", "default:torch_ceiling"}, action = function(pos) if not minetest.get_node_timer(pos):is_started() then - minetest.get_node_timer(pos):start(math.random(480, 600)) + minetest.get_node_timer(pos):start( + math.random(real_torch.min_duration, real_torch.max_duration)) end end }) @@ -37,20 +44,23 @@ 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 - - minetest.set_node(pos, {name = "default:torch", param2 = nod.param2}) - itemstack:take_item() + nod.name = "default:torch" + rep = true elseif nod.name == "real_torch:torch_wall" then - - minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2}) - itemstack:take_item() + nod.name = "default:torch_wall" + rep = true elseif nod.name == "real_torch:torch_ceiling" then + nod.name = "default:torch_ceiling" + rep = true + end - minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2}) + if rep then + minetest.set_node(pos, {name = nod.name, param2 = nod.param2}) itemstack:take_item() end @@ -86,6 +96,7 @@ minetest.register_craft({ recipe = {"real_torch:torch", "real_torch:coal_powder"}, }) + -- Make sure Ethereal mod isn't running as this Abm already exists there if not minetest.get_modpath("ethereal") then @@ -134,3 +145,92 @@ minetest.register_abm({ }) end + + +-- particle effects +local function add_effects(pos, radius) + + minetest.add_particle({ + pos = pos, + velocity = vector.new(), + acceleration = vector.new(), + expirationtime = 0.4, + size = radius * 10, + collisiondetection = false, + vertical = false, + texture = "tnt_boom.png", + glow = 15, + }) + + minetest.add_particlespawner({ + amount = 16, + time = 0.5, + minpos = vector.subtract(pos, radius / 2), + maxpos = vector.add(pos, radius / 2), + minvel = {x = -2, y = -2, z = -2}, + maxvel = {x = 2, y = 2, z = 2}, + minacc = vector.new(), + maxacc = vector.new(), + minexptime = 1, + maxexptime = 2.5, + minsize = radius * 3, + maxsize = radius * 5, + texture = "tnt_smoke.png", + }) + + minetest.sound_play("tnt_explode", {pos = pos, gain = 0.1, max_hear_distance = 5}) +end + + +-- override tnt:gunpowder to explode when used on torch, +-- 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", { + + on_use = function(itemstack, user, pointed_thing) + + if not pointed_thing or pointed_thing.type ~= "node" then + return + end + + 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 + + if rep then + minetest.set_node(pos, {name = nod.name, param2 = nod.param2}) + add_effects(pos, 1) + itemstack:take_item() + return itemstack + end + + if nod.name == "default:torch" + or nod.name == "default:torch_wall" + or nod.name == "default:torch_ceiling" then + + user:set_hp(user:get_hp() - 2) + + add_effects(pos, 1) + + itemstack:take_item() + end + + return itemstack + end, +}) +end diff --git a/readme.md b/readme.md index 678e799..c443c60 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,14 @@ Real Torch by TenPlus1 -This mod changes minetest torches so that they have a life of 8-10 minutes. +This mod changes minetest torches so that they have a life of 8-10 minutes which +is configurable using the torch_min_duration and torch_max_duration settings. -- coal lumps can be crafted into coal powder +- 2x coal lumps can be crafted into 10x coal powder - coal powder and an unlit torch can be crafted into a lit torch again - punching an unlit torch with coal powder relights it +- punching an unlit torch with flint & steel relights it +- punching an unlit torch with gunpowder explodes and relights it +- never punch a lit torch with gunpowder, ow! - water near torches make them drop as unlit torches - coal powder can also be used for fuel or crafted into black dye @@ -18,3 +22,4 @@ Changelog: - 0.4 - Changed my mind, now detects old 2D or new 3D torches and works accordingly - 0.5 - 2x coal lumps give 10x coal dust, also fixed check for ethereal mod - 0.6 - Burnout and extinguish sounds added by tacotexmex :) +- 0.7 - Torches can be re-lit using flint & steel and gunpowder, settings added