Compare commits

...

10 Commits

Author SHA1 Message Date
tenplus1
22c81f4818 tweak & tidy code 2024-12-05 13:53:25 +00:00
tenplus1
e49346d65d add helper function 2024-08-08 15:05:57 +01:00
tenplus1
ab4b086753 add translation support 2024-08-08 14:39:20 +01:00
tenplus1
76c23bffa0 update minetest.conf 2024-05-30 10:27:13 +01:00
tenplus1
f2ea1dfaa5 code tidy and tweak 2024-05-30 10:24:43 +01:00
tenplus1
c3969b1c64 5.x only 2023-08-08 15:00:15 +01:00
tenplus1
06e2613c80 add loaded msg 2022-12-19 17:19:05 +00:00
tenplus1
b2159c9a22 update license.txt 2022-11-25 18:35:32 +00:00
tenplus1
64c57187e1 update license.txt 2022-11-25 09:44:37 +00:00
tenplus1
3d23991d01 update readme (thanks mckaygerhard) 2022-02-19 08:12:32 +00:00
8 changed files with 160 additions and 237 deletions

49
2d.lua
View File

@ -1,49 +0,0 @@
-- unlit torch
minetest.register_node("real_torch:torch", {
description = "Unlit Torch",
drawtype = "torchlike",
tiles = {
{name = "real_torch_on_floor.png"},
{name = "real_torch_ceiling.png"},
{name = "real_torch_wall.png"}
},
inventory_image = "real_torch_on_floor.png",
wield_image = "real_torch_on_floor.png",
paramtype = "light",
paramtype2 = "wallmounted",
light_source = 3,
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
selection_box = {
type = "wallmounted",
wall_top = {-0.1, 0.5 - 0.6, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5 + 0.6, 0.1},
wall_side = {-0.5, -0.3, -0.1, -0.5 + 0.3, 0.3, 0.1}
},
groups = {choppy = 2, dig_immediate = 3, attached_node = 1},
legacy_wallmounted = true,
sounds = default.node_sound_defaults()
})
-- override default torches to burn out after 8-10 minutes
minetest.override_item("default:torch", {
on_timer = function(pos, elapsed)
local p2 = minetest.get_node(pos).param2
minetest.set_node(pos, {name = "real_torch:torch", param2 = p2})
minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10})
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration))
end,
})

145
3d.lua
View File

@ -1,34 +1,37 @@
-- translation support
local S = minetest.get_translator("real_torch")
-- flood helper function
local function on_flood(pos, oldnode, newnode) local function on_flood(pos, oldnode, newnode)
-- drop as unlit torch
minetest.add_item(pos, ItemStack("real_torch:torch 1")) minetest.add_item(pos, ItemStack("real_torch:torch 1"))
-- Play flame-extinguish sound if liquid is not an 'igniter'
local nodedef = minetest.registered_items[newnode.name]
-- return if torch is unlit already -- return if torch is unlit already
if oldnode.name == "real_torch:torch" if oldnode.name:find("real_torch:") then
or oldnode.name == "real_torch:torch_wall"
or oldnode.name == "real_torch:torch_ceiling" then
return false return false
end end
-- play sound if torch is lit local def = minetest.registered_items[newnode.name]
if not (nodedef and nodedef.groups and nodedef.groups.igniter
and nodedef.groups.igniter > 0) then -- play extinquish sound if lit torch put out by water
if def and def.groups and def.groups.water and def.groups.water > 0 then
minetest.sound_play("default_cool_lava", minetest.sound_play("default_cool_lava",
{pos = pos, max_hear_distance = 16, gain = 0.1}, true) {pos = pos, max_hear_distance = 10, gain = 0.1}, true)
end end
-- Remove the torch node -- Remove the torch node
return false return false
end end
-- unlit floor torch -- unlit floor torch
minetest.register_node("real_torch:torch", { minetest.register_node("real_torch:torch", {
description = "Torch", description = S("Unlit Torch"),
drawtype = "mesh", drawtype = "mesh",
mesh = "torch_floor.obj", mesh = "torch_floor.obj",
inventory_image = "real_torch_on_floor.png", inventory_image = "real_torch_on_floor.png",
@ -37,10 +40,7 @@ minetest.register_node("real_torch:torch", {
{ {
name = "real_torch_on_floor.png", name = "real_torch_on_floor.png",
animation = { animation = {
type = "vertical_frames", type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3
aspect_w = 16,
aspect_h = 16,
length = 3.3
} }
} }
}, },
@ -54,8 +54,7 @@ minetest.register_node("real_torch:torch", {
groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1}, groups = {choppy = 2, dig_immediate = 3, flammable = 1, attached_node = 1},
drop = "real_torch:torch", drop = "real_torch:torch",
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted", wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8}
wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8}
}, },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -65,10 +64,12 @@ minetest.register_node("real_torch:torch", {
local node = minetest.get_node(under) local node = minetest.get_node(under)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if def and def.on_rightclick and if def and def.on_rightclick
((not placer) or (placer and not placer:get_player_control().sneak)) then and not (placer and placer:is_player()
and placer:get_player_control().sneak) then
return def.on_rightclick(under, node, placer, itemstack, return def.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack pointed_thing) or itemstack
end end
local above = pointed_thing.above local above = pointed_thing.above
@ -96,12 +97,11 @@ minetest.register_node("real_torch:torch", {
minetest.set_node(pos, {name = "default:torch", param2 = nod.param2}) minetest.set_node(pos, {name = "default:torch", param2 = nod.param2})
end, end,
floodable = true, floodable = true, on_rotate = false, on_flood = on_flood
on_flood = on_flood
}) })
-- unlit wall torch -- unlit wall torch
minetest.register_node("real_torch:torch_wall", { minetest.register_node("real_torch:torch_wall", {
drawtype = "mesh", drawtype = "mesh",
mesh = "torch_wall.obj", mesh = "torch_wall.obj",
@ -109,10 +109,7 @@ minetest.register_node("real_torch:torch_wall", {
{ {
name = "real_torch_on_floor.png", name = "real_torch_on_floor.png",
animation = { animation = {
type = "vertical_frames", type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3
aspect_w = 16,
aspect_h = 16,
length = 3.3
} }
} }
}, },
@ -128,8 +125,7 @@ minetest.register_node("real_torch:torch_wall", {
}, },
drop = "real_torch:torch", drop = "real_torch:torch",
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted", wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8}
wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8}
}, },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -140,12 +136,11 @@ minetest.register_node("real_torch:torch_wall", {
minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2}) minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2})
end, end,
floodable = true, floodable = true, on_rotate = false, on_flood = on_flood
on_flood = on_flood
}) })
-- unlit ceiling torch -- unlit ceiling torch
minetest.register_node("real_torch:torch_ceiling", { minetest.register_node("real_torch:torch_ceiling", {
drawtype = "mesh", drawtype = "mesh",
mesh = "torch_ceiling.obj", mesh = "torch_ceiling.obj",
@ -153,10 +148,7 @@ minetest.register_node("real_torch:torch_ceiling", {
{ {
name = "real_torch_on_floor.png", name = "real_torch_on_floor.png",
animation = { animation = {
type = "vertical_frames", type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3
aspect_w = 16,
aspect_h = 16,
length = 3.3
} }
} }
}, },
@ -172,8 +164,7 @@ minetest.register_node("real_torch:torch_ceiling", {
}, },
drop = "real_torch:torch", drop = "real_torch:torch",
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted", wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8}
wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8}
}, },
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -184,70 +175,36 @@ minetest.register_node("real_torch:torch_ceiling", {
minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2}) minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2})
end, end,
floodable = true, floodable = true, on_rotate = false, on_flood = on_flood
on_flood = on_flood
}) })
-- burnout helper function
-- override default torches to burn out after 8-10 minutes local function torch_override(name)
minetest.override_item("default:torch", {
on_timer = function(pos, elapsed) -- override default torch to burn out after 8-10 minutes and drop in water
minetest.override_item("default:" .. name, {
local p2 = minetest.get_node(pos).param2 on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "real_torch:torch", param2 = p2}) local p2 = minetest.get_node(pos).param2
minetest.sound_play("real_torch_burnout", minetest.set_node(pos, {name = "real_torch:" .. name, param2 = p2})
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end,
on_construct = function(pos) minetest.sound_play("real_torch_burnout",
minetest.get_node_timer(pos):start( {pos = pos, gain = 0.1, max_hear_distance = 10}, true)
math.random(real_torch.min_duration, real_torch.max_duration)) end,
end,
on_flood = on_flood on_construct = function(pos)
})
minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration))
end,
minetest.override_item("default:torch_wall", { on_flood = on_flood
})
end
on_timer = function(pos, elapsed) torch_override("torch")
torch_override("torch_wall")
local p2 = minetest.get_node(pos).param2 torch_override("torch_ceiling")
minetest.set_node(pos, {name = "real_torch:torch_wall", param2 = p2})
minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration))
end,
on_flood = on_flood
})
minetest.override_item("default:torch_ceiling", {
on_timer = function(pos, elapsed)
local p2 = minetest.get_node(pos).param2
minetest.set_node(pos, {name = "real_torch:torch_ceiling", param2 = p2})
minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration))
end,
on_flood = on_flood
})

View File

@ -1,2 +0,0 @@
default
tnt?

View File

@ -1 +0,0 @@
Have torches go out after a while and drop when in water.

125
init.lua
View File

@ -3,24 +3,23 @@
real_torch = {} 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.min_duration = tonumber(minetest.settings:get("torch_min_duration")) or 1200
real_torch.max_duration = tonumber(minetest.settings:get("torch_max_duration")) or 1800 real_torch.max_duration = tonumber(minetest.settings:get("torch_max_duration")) or 1800
-- add unlit torches & override current
-- check which torch(es) are available in minetest version dofile(minetest.get_modpath("real_torch") .. "/3d.lua")
if minetest.registered_nodes["default:torch_ceiling"] then
dofile(minetest.get_modpath("real_torch") .. "/3d.lua")
else
dofile(minetest.get_modpath("real_torch") .. "/2d.lua")
end
-- start timer on any already placed torches -- start timer on any already placed torches
minetest.register_lbm({ minetest.register_lbm({
name = "real_torch:convert_torch_to_node_timer", name = "real_torch:convert_torch_to_node_timer",
nodenames = {"default:torch", "default:torch_wall", "default:torch_ceiling"}, nodenames = {"default:torch", "default:torch_wall", "default:torch_ceiling"},
action = function(pos) action = function(pos)
if not minetest.get_node_timer(pos):is_started() then if not minetest.get_node_timer(pos):is_started() then
@ -31,18 +30,17 @@ minetest.register_lbm({
end end
}) })
-- creative check -- creative check
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
function is_creative(name) 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}) return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
end end
-- coal powder -- coal powder
minetest.register_craftitem("real_torch:coal_powder", { minetest.register_craftitem("real_torch:coal_powder", {
description = "Coal Powder", description = S("Coal Powder"),
inventory_image = "real_torch_coal_powder.png", inventory_image = "real_torch_coal_powder.png",
-- punching unlit torch with coal powder relights -- punching unlit torch with coal powder relights
@ -54,22 +52,17 @@ minetest.register_craftitem("real_torch:coal_powder", {
local pos = pointed_thing.under local pos = pointed_thing.under
local nod = minetest.get_node(pos) local nod = minetest.get_node(pos)
local rep = false
if nod.name == "real_torch:torch" then if nod.name == "real_torch:torch" then
nod.name = "default:torch" nod.name = "default:torch"
rep = true
elseif nod.name == "real_torch:torch_wall" then elseif nod.name == "real_torch:torch_wall" then
nod.name = "default:torch_wall" nod.name = "default:torch_wall"
rep = true
elseif nod.name == "real_torch:torch_ceiling" then elseif nod.name == "real_torch:torch_ceiling" then
nod.name = "default:torch_ceiling" nod.name = "default:torch_ceiling"
rep = true else nod.name = "" end
end
if nod.name ~= "" then
if rep then
minetest.set_node(pos, {name = nod.name, param2 = nod.param2}) minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
if not is_creative(user:get_player_name()) then if not is_creative(user:get_player_name()) then
@ -116,8 +109,8 @@ minetest.register_craft({
} }
}) })
-- explosion effect
-- particle effects
local function add_effects(pos, radius) local function add_effects(pos, radius)
minetest.add_particle({ minetest.add_particle({
@ -149,7 +142,7 @@ local function add_effects(pos, radius)
}) })
minetest.sound_play("tnt_explode", minetest.sound_play("tnt_explode",
{pos = pos, gain = 0.1, max_hear_distance = 5}, true) {pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end end
@ -157,62 +150,60 @@ end
-- will also re-light torches and cause player damage when used on lit torch. -- will also re-light torches and cause player damage when used on lit torch.
if minetest.get_modpath("tnt") then 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 if not pointed_thing or pointed_thing.type ~= "node" then
return return
end end
local pos = pointed_thing.under local pos = pointed_thing.under
local nod = minetest.get_node(pos) 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 -- small delay to fix dupe bug
nod.name = "default:torch" minetest.after(0.1, function(user)
rep = true
elseif nod.name == "real_torch:torch_wall" then if user and user:get_pos() then
nod.name = "default:torch_wall" user:set_hp(user:get_hp() - 2)
rep = true end
end, user)
elseif nod.name == "real_torch:torch_ceiling" then add_effects(pos, 1)
nod.name = "default:torch_ceiling"
rep = true
end
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 minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
itemstack:take_item()
add_effects(pos, 1)
if not is_creative(user:get_player_name()) then
itemstack:take_item()
end
end end
return itemstack return itemstack
end 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)
user:set_hp(user:get_hp() - 2)
end, user)
add_effects(pos, 1)
if not is_creative(user:get_player_name()) then
itemstack:take_item()
end
end
return itemstack
end
})
end end
print("[MOD] Real Torch loaded")

View File

@ -1,21 +1,7 @@
The MIT License (MIT) Textures by VanessaE (CC BY-SA 3.0):
default_torch_animated.png
default_torch_on_ceiling_animated.png
default_torch_on_floor_animated.png
default_torch_on_floor.png
Copyright (c) 2016 TenPlus1 The torch code was derived by sofar from the 'torches' mod by BlockMen (LGPLv2.1+)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,4 +1,5 @@
name = real_torch name = real_torch
description = Have torches go out after a while and drop when in water.
depends = default depends = default
optional_depends = tnt optional_depends = tnt
description = Have torches go out after a while and drop when in water. min_minetest_version = 5.0

View File

@ -1,7 +1,16 @@
Real Torch by TenPlus1 minetest mod Real Torch
=======================
This mod changes minetest torches so that they have a life of 20-30 minutes which Made torchs more realistic way behaviour.
is configurable using the torch_min_duration and torch_max_duration settings.
Information
-----------
This mod is named `real_torch`, changes torches so that they have a life
of 20-30 minutes which is configurable using the `torch_min_duration`
and `torch_max_duration` settings. It also can be relight using coals, flint or steel, and can be affected by water.
![screenshot.png](screenshot.png)
- 2x coal lumps can be crafted into 12x coal powder - 2x coal lumps can be crafted into 12x coal powder
- coal powder and an unlit torch can be crafted into a lit torch again - coal powder and an unlit torch can be crafted into a lit torch again
@ -14,7 +23,22 @@ is configurable using the torch_min_duration and torch_max_duration settings.
https://forum.minetest.net/viewtopic.php?f=11&t=15721 https://forum.minetest.net/viewtopic.php?f=11&t=15721
Technical information
---------------------
This mod does not override the normal torch, so once you put a torch if
you removed the mod those will remains as normal ones if relights/lights it!
### New Craft items
It added new coal, rest of torch related are just overrides for features.
| name | node |
| ---- | ---- |
| Coal Powder | real_torch:coal_powder |
Changelog: Changelog:
----------
- 0.1 - Initial upload - 0.1 - Initial upload
- 0.2 - Punching unlit torch with coal powder relights torch - 0.2 - Punching unlit torch with coal powder relights torch
@ -26,3 +50,19 @@ Changelog:
- 0.8 - Updated to newer functions, requires Minetest 0.4.16 to run - 0.8 - Updated to newer functions, requires Minetest 0.4.16 to run
- 0.9 - Use on_flood from newer 5.x functions to drop torches - 0.9 - Use on_flood from newer 5.x functions to drop torches
- 1.0 - Tweak code and use use_texture_alpha = "clip" to stop warnings - 1.0 - Tweak code and use use_texture_alpha = "clip" to stop warnings
License
-------
**Code**
The MIT License (MIT), Copyright (c) 2016 TenPlus1
Check [license.txt](license.txt)
**Sizzle sound **
CC0 1.0 Universal (CC0 1.0)
Check [sounds/license.txt](sounds/license.txt)
**Extinguish sound**
Attribution 3.0 Unported (CC BY 3.0)
Vlatko Blažek
Check [sounds/license.txt](sounds/license.txt)