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)
-- drop as unlit torch
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
if oldnode.name == "real_torch:torch"
or oldnode.name == "real_torch:torch_wall"
or oldnode.name == "real_torch:torch_ceiling" then
if oldnode.name:find("real_torch:") then
return false
end
-- play sound if torch is lit
if not (nodedef and nodedef.groups and nodedef.groups.igniter
and nodedef.groups.igniter > 0) then
local def = minetest.registered_items[newnode.name]
-- 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",
{pos = pos, max_hear_distance = 16, gain = 0.1}, true)
{pos = pos, max_hear_distance = 10, gain = 0.1}, true)
end
-- Remove the torch node
return false
end
-- unlit floor torch
minetest.register_node("real_torch:torch", {
description = "Torch",
description = S("Unlit Torch"),
drawtype = "mesh",
mesh = "torch_floor.obj",
inventory_image = "real_torch_on_floor.png",
@ -37,10 +40,7 @@ minetest.register_node("real_torch:torch", {
{
name = "real_torch_on_floor.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 3.3
type = "vertical_frames", 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},
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(),
@ -65,10 +64,12 @@ minetest.register_node("real_torch:torch", {
local node = minetest.get_node(under)
local def = minetest.registered_nodes[node.name]
if def and def.on_rightclick and
((not placer) or (placer and not placer:get_player_control().sneak)) then
if def and def.on_rightclick
and not (placer and placer:is_player()
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
@ -96,12 +97,11 @@ minetest.register_node("real_torch:torch", {
minetest.set_node(pos, {name = "default:torch", param2 = nod.param2})
end,
floodable = true,
on_flood = on_flood
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",
@ -109,10 +109,7 @@ minetest.register_node("real_torch:torch_wall", {
{
name = "real_torch_on_floor.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 3.3
type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3
}
}
},
@ -128,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(),
@ -140,12 +136,11 @@ minetest.register_node("real_torch:torch_wall", {
minetest.set_node(pos, {name = "default:torch_wall", param2 = nod.param2})
end,
floodable = true,
on_flood = on_flood
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",
@ -153,10 +148,7 @@ minetest.register_node("real_torch:torch_ceiling", {
{
name = "real_torch_on_floor.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 3.3
type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3
}
}
},
@ -172,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(),
@ -184,70 +175,36 @@ minetest.register_node("real_torch:torch_ceiling", {
minetest.set_node(pos, {name = "default:torch_ceiling", param2 = nod.param2})
end,
floodable = true,
on_flood = on_flood
floodable = true, on_rotate = false, on_flood = on_flood
})
-- burnout helper function
-- override default torches to burn out after 8-10 minutes
minetest.override_item("default:torch", {
local function torch_override(name)
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",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
end,
minetest.set_node(pos, {name = "real_torch:" .. name, param2 = p2})
on_construct = function(pos)
minetest.get_node_timer(pos):start(
math.random(real_torch.min_duration, real_torch.max_duration))
end,
minetest.sound_play("real_torch_burnout",
{pos = pos, gain = 0.1, max_hear_distance = 10}, true)
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)
local p2 = minetest.get_node(pos).param2
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
})
torch_override("torch")
torch_override("torch_wall")
torch_override("torch_ceiling")

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 = {}
-- 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
-- add unlit torches & override current
-- check which torch(es) are available in minetest version
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
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"},
action = function(pos)
if not minetest.get_node_timer(pos):is_started() then
@ -31,18 +30,17 @@ minetest.register_lbm({
end
})
-- 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})
end
-- coal powder
minetest.register_craftitem("real_torch:coal_powder", {
description = "Coal Powder",
description = S("Coal Powder"),
inventory_image = "real_torch_coal_powder.png",
-- punching unlit torch with coal powder relights
@ -54,22 +52,17 @@ 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 nod.name ~= "" then
if rep then
minetest.set_node(pos, {name = nod.name, param2 = nod.param2})
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)
minetest.add_particle({
@ -149,7 +142,7 @@ local function add_effects(pos, radius)
})
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
@ -157,62 +150,60 @@ 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)
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
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
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.
The torch code was derived by sofar from the 'torches' mod by BlockMen (LGPLv2.1+)

View File

@ -1,4 +1,5 @@
name = real_torch
description = Have torches go out after a while and drop when in water.
depends = default
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
is configurable using the torch_min_duration and torch_max_duration settings.
Made torchs more realistic way behaviour.
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
- 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
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:
----------
- 0.1 - Initial upload
- 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.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
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)