Page 1 of 2

[mod] Lighten wielded item [wielded_light]

Posted: Wed Jan 10, 2018 09:22
by bell07
Idea taken from torches_wieldlight in https://github.com/minetest-mods/torches, but written from scratch and usable for all shining items. The shining does work on player's wielded item, but in addition on dropped items (throw a torch down using Q button) and also on throwed items using minetest-mods/throwing / minetest-mods/sling.

By default the "light_source" value from node definition is used but lower by 2. This way the placing torches is not obsolete because of brighter.
Examle: Torch with placed value 13 does shine with 11 if wielded or dropped.

Image
+ Spoiler
known issues
Does work in "air" nodes only, that means shining does not work on ladders, snow, slabs and other nearly empty or airlike nodes.

For Modders:
In addition further items could get or redefined the light value by:

Code: Select all

wielded_light.register_item_light(itemname, light_level)
This does not change the item/node definition, just the shining from this mod.

As external usable API functions exists to be able to use the shining in other mods, see end of README.md file on github and throwing commit for example.

Dependencies: none
License: GPL-3

Download/Source: https://github.com/minetest-mods/wielded_light

Re: [mod] Lighten wielded item [wielded_light]

Posted: Wed Jan 10, 2018 10:13
by ChimneySwift
Yeeees
I've really wanted a mod like this, I'll have to really check it out to see how stable it is (IIRC there were some issues with the other mod?), thanks for doing this.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Wed Jan 10, 2018 10:24
by Codesound
+1

THANKS, good idea!

R

Re: [mod] Lighten wielded item [wielded_light]

Posted: Wed Jan 10, 2018 12:31
by bell07
IIRC there were some issues with the other mod?
The other mod overrides the torch definition. The main goal of the torch mod was to add a 3D torch to the minetest. Since the 3D-torches was added to minetest_game/mods/default, this mod is less maintained as the "default" and seems to be redundant/obsolete. But I still used the separate torch mod without any issues because of optional lightning feature.
With this new mod i is possible to get the lightning feature on all items without any item redefinition.

Note: I did developed it using more newer features like node-timer so maybe my version is less stable as torch mod because of it's a new mod.
The main idea is the same: The wielded item of all players is checked each globalstep and a invisible air-like lightning node is placed at player position if lightning should happen. After some time the node is replaced back to "air". Because of pulling and often node updates around the player maybe performance issues appears. Same risk as in the torches mod.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Wed Jan 10, 2018 16:45
by azekill_DIABLO
thanks!! so useful!!!

Re: [mod] Lighten wielded item [wielded_light]

Posted: Thu Jan 11, 2018 15:18
by texmex
How does this mod compare to https://github.com/krondor-game/wield_light ?

Re: [mod] Lighten wielded item [wielded_light]

Posted: Thu Jan 11, 2018 17:17
by burli
texmex wrote:How does this mod compare to https://github.com/krondor-game/wield_light ?
This version should be better than the version from krondor-game because it use swap_node instead of set_node

Re: [mod] Lighten wielded item [wielded_light]

Posted: Thu Jan 11, 2018 19:52
by bell07
oh, I did not seen the krondor mod. If I look to the code I see the next differences:

1. krondor mod is 2 years old, should be stable.
2. krondor registers only 1 helper node with light level 14. So krondors light is brighter, but with static brightness at maximum 14. My mod registers nodes 1-11. It is more dim but according the brightness of the wielded item.
3. krondor mod uses register_source() method for compatible items and hardcodes torch, flame and lava source and bucked for light. My mod looks to the item definition for light level and supports all bright items.
4. The case to avoid the light flickers if the player stay on the same position is solved in different way. krondor save position in lua table "positions" to track them, I just reset the timer back to initial value.
5. The already mentioned swap_node vs. set_node/remove_node unsure if it makes a difference for air.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Thu Jan 11, 2018 21:14
by burli
swap_node is faster

Re: [mod] Lighten wielded item [wielded_light]

Posted: Fri Jan 12, 2018 14:01
by texmex
Excellent answers, thanks. Two ideas for further development comes to mind:

Make sure it works on tools as well (perhaps it already does. I'm unsure if light_source can be applied to other things than just nodes definitions). If tool definitions can't have light_source, perhaps offer a small API for registering an item's light level. (This API could also be useful for when you don't want specific lit nodes to emit wield light). Like so:

Code: Select all

wield_light.register_source('default:superpick')
wield_light.unregister_source('default:torch')
Also, could the mod be extended to support light emitting entities as well? So that torches lights up the environment even as dropped items. That would be awesome. Code related to detecting throwing here.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Fri Jan 12, 2018 15:24
by bell07
Thank you for suggestions. I added to my todo list:

Code: Select all

wielded_light.register_item_light(itemname, light_level)
Allow to add wielded light to items without light_source, or redefine existing light.

Code: Select all

wielded_light.update_light(pos, light_level)
Check/set/update light helper node at position. This method allow to enable light on any position. The function can be used for any entity from on_step function without any conditions.

Unfortunately the '__builtin:item' does not have any callbacks in on_step so I cannot enhance the dropped items without any hacks or builtin-modifications :-(

Re: [mod] Lighten wielded item [wielded_light]

Posted: Fri Jan 12, 2018 15:47
by texmex
Great additions, thanks. Now I'll be able to switch over from wield_light to wielded_light.

Do you think pursuing a Github issue for __builtin:item on_step callback is viable?

Re: [mod] Lighten wielded item [wielded_light]

Posted: Fri Jan 12, 2018 21:01
by bell07
texmex wrote:Now I'll be able to switch over from wield_light to wielded_light.
I see the name difference comes from my bad english. Maybe I should change the name? Any proposal? wielded_bright? shining?
texmex wrote:Do you think pursuing a Github issue for __builtin:item on_step callback is viable?
I just did it ;-) https://github.com/minetest/minetest/issues/6909

Re: [mod] Lighten wielded item [wielded_light]

Posted: Fri Jan 12, 2018 22:03
by bell07
Shining API:
`function wielded_light.update_light(pos, light_level)`
Enable or update the shining at pos with light_level for 0.6 seconds. Can be used in any on_step call to get other entitys shining for example

`wielded_light.register_item_light(itemname, light_level)`
Override or set custom light level to an item. This does not change the item/node definition, just the lighting in this mod.
done

Beter mod name proposals still welcome

Re: [mod] Lighten wielded item [wielded_light]

Posted: Sat Jan 13, 2018 09:55
by texmex
Very good!

As for name, I thing wield_light is good. Simple and descriptive. Neoascetic probably wouldn't mind as this is a drop-in replacement.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Sat Jan 13, 2018 12:42
by bell07
I looked trough different translators and "wielded item" should be ok too. What native speaker means?
I do not like to take over the name from an other existing mod.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Sat Jan 13, 2018 14:21
by bell07
Just noticed I did not pushed the latest version to github. Now done, the shining-API can be tested now.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Mon Jan 22, 2018 14:05
by hajo
texmex wrote:ideas for further development ..
Make sure it works on tools as well (perhaps it already does..)
Like some well-known swords, that glow in the dark ?
Is such a feature in the LotR-subgame already ?

Re: [mod] Lighten wielded item [wielded_light]

Posted: Mon Jan 22, 2018 14:15
by bell07
Already possible. Just add an

Code: Select all

wielded_light.register_item_light('swordmod:wellknown', 14)
to the corresponding mod or to a small own compatibility mod that depends on both, sword and wielded_light.

swordmod:wellknown: placeholder for your item, the 14 is the light level.

But note: not the sword shines but the player position. And only if environment light is lower then the item light.

Re: [mod] Lighten wielded item [wielded_light]

Posted: Tue May 08, 2018 14:59
by bell07
Added support for dropped items shining
https://github.com/bell07/wielded_light ... ms_shining

Image

And also new API method

Code: Select all

function wielded_light.update_light_by_item(stack, pos)
that is used internally for both, wielded and dropped items..

Re: [mod] Lighten wielded item [wielded_light]

Posted: Tue May 08, 2018 15:46
by azekill_DIABLO
Wow! does it light stronger if the stack is full?

Re: [mod] Lighten wielded item [wielded_light]

Posted: Tue May 08, 2018 16:10
by bell07
azekill_DIABLO wrote:Wow! does it light stronger if the stack is full?
And idea about formula how the stack size should be used to calculate light value? At the time it is just light_source - 2

Re: [mod] Lighten wielded item [wielded_light]

Posted: Tue May 08, 2018 16:11
by Phoenixflo44
Maybe you can do it that way if you throw a torch that it will continue to shine

Re: [mod] Lighten wielded item [wielded_light]

Posted: Tue May 08, 2018 16:16
by bell07
Phoenixflo44 wrote:Maybe you can do it that way if you throw a torch that it will continue to shine
Already in discussion on github: https://github.com/minetest-mods/wielded_light/issues/1
Working Prototype exists

Re: [mod] Lighten wielded item [wielded_light]

Posted: Tue May 08, 2018 16:19
by Phoenixflo44
oh, OK