[mod] Lighten wielded item [wielded_light]

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

[mod] Lighten wielded item [wielded_light]

by bell07 » Post

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
Image
Image
Image
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
Attachments
screenshot.png
screenshot.png (329.14 KiB) Viewed 2168 times
Last edited by bell07 on Thu May 10, 2018 09:11, edited 5 times in total.

User avatar
ChimneySwift
Member
Posts: 320
Joined: Fri Sep 22, 2017 06:46
GitHub: ChimneySwift
IRC: ChimneySwift
In-game: ChimneySwift
Location: 127.0.0.1

Re: [mod] Lighten wielded item [wielded_light]

by ChimneySwift » Post

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.
A spoon is basically a tiny bowl with a stick on it

User avatar
Codesound
Member
Posts: 365
Joined: Thu Jun 09, 2016 14:56

Re: [mod] Lighten wielded item [wielded_light]

by Codesound » Post

+1

THANKS, good idea!

R

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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.

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [mod] Lighten wielded item [wielded_light]

by azekill_DIABLO » Post

thanks!! so useful!!!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [mod] Lighten wielded item [wielded_light]

by texmex » Post

How does this mod compare to https://github.com/krondor-game/wield_light ?

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: [mod] Lighten wielded item [wielded_light]

by burli » Post

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

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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.

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: [mod] Lighten wielded item [wielded_light]

by burli » Post

swap_node is faster

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [mod] Lighten wielded item [wielded_light]

by texmex » Post

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.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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 :-(

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [mod] Lighten wielded item [wielded_light]

by texmex » Post

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?

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [mod] Lighten wielded item [wielded_light]

by texmex » Post

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.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

Just noticed I did not pushed the latest version to github. Now done, the shining-API can be tested now.

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: [mod] Lighten wielded item [wielded_light]

by hajo » Post

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 ?

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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..
Attachments
screenshot_20180508_163521.png
screenshot_20180508_163521.png (261.69 KiB) Viewed 2168 times

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [mod] Lighten wielded item [wielded_light]

by azekill_DIABLO » Post

Wow! does it light stronger if the stack is full?
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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

User avatar
Phoenixflo44
Member
Posts: 639
Joined: Fri Jul 28, 2017 15:01
In-game: EvilPhoenix
Location: Behind my PC, in Germany

Re: [mod] Lighten wielded item [wielded_light]

by Phoenixflo44 » Post

Maybe you can do it that way if you throw a torch that it will continue to shine
Spoiler
I hate my life

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: [mod] Lighten wielded item [wielded_light]

by bell07 » Post

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

User avatar
Phoenixflo44
Member
Posts: 639
Joined: Fri Jul 28, 2017 15:01
In-game: EvilPhoenix
Location: Behind my PC, in Germany

Re: [mod] Lighten wielded item [wielded_light]

by Phoenixflo44 » Post

oh, OK
Spoiler
I hate my life

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests