[Mod] Mini Sun, Pesudo Brighter Light Source [mini_sun]

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

[Mod] Mini Sun, Pesudo Brighter Light Source [mini_sun]

by bdjnk » Post

Placed mini sun nodes generate square areas of powerful light against nearby terrain. It looks like this:

Image

Code license : GPLv2/later

Mod dependencies: default

The code can be found on GitHub, right here

Code: Select all

Current crafting recipe:

    copper_ingot  glass         copper_ingot
    glass         mese_crystal  glass
    copper_ingot  glass         copper_ingot

I'm open to suggestions
Spoiler
I, like many people, want brighter lights, and got sick of all the people answering "well, 14 is the max". Here's what I came up with so far:

Code: Select all

minetest.register_node("mini_sun:glow", {
    drawtype = "airlike",
    walkable = false,
    pointable = false,
    diggable = false,
    climbable = false,
    buildable_to = true,
    light_source = 14,
    paramtype = light
})

minetest.register_craft({
    output = '"mini_sun:source" 2',
    recipe = {
        {'default:glass', 'default:glass', 'default:glass'},
        {'default:glass', 'default:torch', 'default:glass'},
        {'default:glass', 'default:glass', 'default:glass'},
    }
})

minetest.register_node("mini_sun:source", {
    tiles = { "mini_sun.png" },
    drawtype = "glasslike",
    groups = { cracky=3, oddly_breakable_by_hand=3 },
    --sounds = default.node_sound_glass_defaults(),
    drop = "mini_sun:source",
    light_source = 14,
    paramtype = light,
    on_construct = function(pos)
        for nx = pos.x-3, pos.x+3 do
            for ny = pos.y-3, pos.y+3 do
                for nz = pos.z-3, pos.z+3 do
                    local npos = {x=nx, y=ny, z=nz}
                    if minetest.get_node(npos).name == "air" then
                        minetest.add_node(npos, {name = "mini_sun:glow"})
                    end
                end
            end
        end
    end,
    on_destruct = function(pos)
        for nx = pos.x-3, pos.x+3 do
            for ny = pos.y-3, pos.y+3 do
                for nz = pos.z-3, pos.z+3 do
                    local npos = {x=nx, y=ny, z=nz}
                    if minetest.get_node(npos).name == "mini_sun:glow" then
                        minetest.remove_node(npos)
                    end
                end
            end
        end
    end
})
This has two interesting problems (so far).

The more important issue is that it's noticeably slow, even on my overpowered machine. By noticeably, I mean the lights don't all come on a once. Now you might say, "well, you add them sequentially, so what do you expect?" My question is twofold. Is there a way to have all the light generating nodes go on at once (as much as possible)? Is there a reason this loop of 27 add_node calls is so slow (with version 4.7) that I can watch it stagger through them?

The less critical issue has to do with removing the nodes. If two mini sun source nodes are placed near each other, they remove each other's glow nodes when destructed. I know, I know, "that's what you told them to do" you say. Okay, well how do I avoid that? Is there a way of implementing node hierarchies perhaps? Or maybe some other tactic to handle this scenario?
Last edited by bdjnk on Wed Mar 11, 2015 02:36, edited 9 times in total.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

I fixed the easier and less critical issue using node metadata. I also managed to make the more serious issue less serious by only placing a glow node every other block. Here is the relevant section of code:

Code: Select all

    on_construct = function(pos)
        local dist = 6
        for nx = pos.x-dist, pos.x+dist, 2 do
            for ny = pos.y-dist, pos.y+dist, 2 do
                for nz = pos.z-dist, pos.z+dist, 2 do
                    local npos = {x=nx, y=ny, z=nz}
                    if minetest.get_node(npos).name == "air" then
                        minetest.add_node(npos, {name = "mini_sun:glow"})
                        minetest.env:get_meta(npos):set_string("pos", minetest.pos_to_string(pos))
                    end
                end
            end
        end
    end,
    on_destruct = function(pos)
        local dist = 6
        for nx = pos.x-dist, pos.x+dist, 2 do
            for ny = pos.y-dist, pos.y+dist, 2 do
                for nz = pos.z-dist, pos.z+dist, 2 do
                    local npos = {x=nx, y=ny, z=nz}
                    if minetest.get_node(npos).name == "mini_sun:glow"
                    and minetest.pos_to_string(pos) == minetest.env:get_meta(npos):get_string("pos")
                    then
                        minetest.remove_node(npos)
                    end
                end
            end
        end
    end
Last edited by bdjnk on Sun Jun 09, 2013 14:20, edited 1 time in total.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

I've changes pretty much everything about the way Mini Sun works. Here is the latest version:

Code: Select all

minetest.register_node("mini_sun:glow", {
    drawtype = "airlike",
    walkable = false,
    pointable = false,
    diggable = true,
    climbable = false,
    buildable_to = true,
    light_source = 14,
    paramtype = light
})

minetest.register_craft({
    output = '"mini_sun:source" 2',
    recipe = {
        {'default:glass', 'default:glass', 'default:glass'},
        {'default:glass', 'default:torch', 'default:glass'},
        {'default:glass', 'default:glass', 'default:glass'},
    }
})

minetest.register_node("mini_sun:source", {
  tiles = { "mini_sun.png" },
    drawtype = "glasslike",
    groups = { cracky=3, oddly_breakable_by_hand=3 },
    sounds = default.node_sound_glass_defaults(),
    drop = "mini_sun:source",
    light_source = 14,
    paramtype = light,
    after_place_node = function(pos, placer)
        minetest.get_node_timer(pos):start(1.1)
    end,
    on_destruct = function(pos)
        minetest.get_node_timer(pos):stop()
    end,
    after_destruct = function(pos, oldnode)
        local dist = 6
        local minp = { x=pos.x-dist, y=pos.y-dist, z=pos.z-dist }
        local maxp = { x=pos.x+dist, y=pos.y+dist, z=pos.z+dist }
        local glow_nodes = minetest.find_nodes_in_area(minp, maxp, "mini_sun:glow")
        for key, npos in pairs(glow_nodes) do
            minetest.remove_node(npos)
            end
    end,
    on_timer = function(pos, elapsed)
        local dist = 6
        local pmod = (pos.x + pos.y + pos.z) %2 
        local minp = { x=pos.x-dist, y=pos.y-dist, z=pos.z-dist }
        local maxp = { x=pos.x+dist, y=pos.y+dist, z=pos.z+dist }
        local air_nodes = minetest.find_nodes_in_area(minp, maxp, "air")
        for key, npos in pairs(air_nodes) do
            if (npos.x + npos.y + npos.z) %2 == pmod then -- 3d checkerboard pattern
                if grounded(npos) then                    -- against lightable surfaces
                    minetest.add_node(npos, {name = "mini_sun:glow"})
                end
            end
        end
        return true
    end
})

grounded = function(pos)
    -- checks all nodes touching the edges and corners (but not faces) of the given pos
    for nx = -1, 1, 2 do
        for ny = -1, 1, 2 do
            for nz = -1, 1, 2 do
                local npos = { x=pos.x+nx, y=pos.y+ny, z=pos.z+nz }
                local name = minetest.get_node(npos).name
                if minetest.registered_nodes[name].walkable and name ~= "mini_sun:source" then
                    return true
                end
            end
        end
  end
    return false
end
As you can see, I'm trying to minimize the number of glow nodes created without compromising the brightness. Turns out, reams of really inefficient code is way faster than adding even a single glowing node. Every second, all that math gets chewed through with zero stutter. Add a couple extra glow nodes, and the whole machine seizes up and convulses wildly.

Anyway, I'm not a fan of the recipe I'm currently using, so feel free to drop some suggestions.

Oh, and here is the current source node (mini_sun.png) texture: [img=mini sun source texture]http://img580.imageshack.us/img580/1368/minisun.png[/img] (it matches the default theme)

User avatar
DeepGaze
Member
Posts: 332
Joined: Fri May 10, 2013 00:49
GitHub: DeepGaze
IRC: DeepGaze
In-game: DeepGaze
Location: Take your best guess

by DeepGaze » Post

will there be link soon? for linux plz!!
there's no place like 127.0.0.1
The deep life Minetest text page
minetest cards

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

DeepGaze wrote:will there be link soon? for linux plz!!
Even though it's in a decent state right now, I never got it working 100%. Honestly, certain things need to change in the game code and lua API (rather than a hacky solution like this one).

Aside from that, being as I was the only one commenting, I didn't realize anyone else was interested :)

Anyway, here's a link to the current version: mini_sun.zip

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

by paramat » Post

Yep i'm interested in this and have been experimenting with something similar. Perhaps to light the surface of a realm so it can be bright at night, for example a moon without atmosphere.
Last edited by paramat on Fri Jun 28, 2013 05:33, edited 1 time in total.

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

If you wanted a proper sudo sun, just give the air node light_level = 14

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

Jordach wrote:If you wanted a proper sudo sun, just give the air node light_level = 14
Um, wait, I though "air nodes" were not actually nodes at all. Can they be given a light_level? If so, how? I haven't seen anything like that in any of the documentation...
Last edited by bdjnk on Fri Jun 28, 2013 10:24, edited 1 time in total.

User avatar
Zeg9
Member
Posts: 608
Joined: Fri Sep 21, 2012 11:02
Location: France

by Zeg9 » Post

bdjnk wrote:
Jordach wrote:If you wanted a proper sudo sun, just give the air node light_level = 14
Um, wait, I though "air nodes" were not actually nodes at all. Can they be given a light_level? If so, how? I haven't seen anything like that in any of the documentation...
I think you can override the air node like you would do with any other node.

Code: Select all

minetest.register_node(":air", {
    drawtype = "airlike",
    walkable = false,
    light_source = 14,
})
I made a few (a lot of?) mods for minetest: here is a list.
See also the MT-Faithful texture pack (work in progress).

User avatar
LionsDen
Member
Posts: 530
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Post

Zeg9 wrote:I think you can override the air node like you would do with any other node.

Code: Select all

minetest.register_node(":air", {
    drawtype = "airlike",
    walkable = false,
    light_source = 14,
})
Hi, I just tried this code in a test using the Minetest development from 6/22 and I didn't see any brightness in the sky but the ground, trees, grass and everything else turned black. There were no mods running except the little test I created that had only the code up above in it. I just thought I would let you know that it doesn't seem to work like you expected. Unless maybe you then have to place these nodes in the world to get them to work.

EDIT: It got to night and suddenly there were a few sparse patches on the ground and in the trees that were lit up. There were only a few though.
Last edited by LionsDen on Fri Jun 28, 2013 16:43, edited 1 time in total.

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

You also need: paramtype="light",

(not paramtype2... whether the above is enough or the idea will work at all, I dunno, but it's needed either way)
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

This does very bad things. The entire system starts seizing up and visual glitches abound.

Code: Select all

minetest.register_node(":air", {
    drawtype = "airlike",
    walkable = false,
    paramtype = light,
    light_source = 14,
})
I'm not sure the reason, but I do know that glowing nodes are no joke for the system to process. That's why I reduced them as much as possible in my code.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

by bdjnk » Post

I just pushed a fix for the issue where dirt_with_grass becomes just plain dirt beneath glow nodes. Oh, here's the github link.

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

Make that paramtype="light", with the quotes around "light". Not that this will fix the performance issue, however. (I don't think that's fixable, because basically you're spamming the engine's lighting code)
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

dgm5555
Member
Posts: 245
Joined: Tue Apr 08, 2014 19:45

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by dgm5555 » Post

Awesome mod! Any chance you could put the git link in the first post, it took me a while to notice it.

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by Sokomine » Post

Regarding performance of the add_node calls: Why not use a schematic for that? place_schematic has a nice parameter that takes care that existing nodes are not replaced. place_schematic is very fast. What it will do to light sources I don't know. Might be worth a try?

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by bdjnk » Post

Sokomine wrote:Regarding performance of the add_node calls: Why not use a schematic for that? place_schematic has a nice parameter that takes care that existing nodes are not replaced. place_schematic is very fast. What it will do to light sources I don't know. Might be worth a try?
I would try schematics, but the documentation is very spotty. The best info I've found is the minetest.register decoration page on the dev wiki, and the lua_api.txt doc from the github repo. This might be enough for me to tinker and figure out how to use schematics, basically rediscovering fire (this is actually one of the reason I'm not messing with minetest anymore). If there are better docs, or code by others I can look at, or anything but disjointed and incomplete information that must be hunted up from all over hell, please redirect me to it.

User avatar
rubenwardy
Moderator
Posts: 6969
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by rubenwardy » Post

Or voxel manipulators.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by Sokomine » Post

bdjnk wrote: If there are better docs, or code by others I can look at, or anything but disjointed and incomplete information that must be hunted up from all over hell, please redirect me to it.
It's pretty easy and especially useful if you want your suns to be large. First off, build the thing you want to use in your local world. Install WorldEdit. Type "//p set" and punch two opposite corners of the building (or, in this case, the sun). Type "//mtschemcreate filename". You'll now find the schematic as a file in worlds/YourWorldName/schems/filename.mts Copy that to a new folder in the directory that contains your mod and which you name "schems".

In order to place it, use

Code: Select all

minetest.place_schematic( pos, minetest.get_modpath("yourmodname")..'/schems/' , "random", {}, false );
And that's it already.
A list of my mods can be found here.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by bdjnk » Post

Thanks. Sorry for being snippy before. I'll play around with schematics and look into voxel manipulators when I have some time.

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by Calinou » Post

If you want light everywhere, edit the shader files (you only need to restart the game, shaders need to be enabled) or light.cpp (recompilation required, works with and without shaders).

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by bdjnk » Post

Okay, so after looking into both, it seems like voxel manipulators is probably the better bet. I did some messing around, and got lights to show up. It works instantly! The trouble is, sometimes the light doesn't entirely disappear, even though all the light generating nodes are gone.

If you want to try and help solve this issue, check out the voxel_manipulator branch at github.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

Re: Mini Sun, Pesudo Brighter Light Source... Questions

by bdjnk » Post

bdjnk wrote:The trouble is, sometimes the light doesn't entirely disappear, even though all the light generating nodes are gone.
Okay, so it turns out my voxel_manip needed to read an area from the map which included all glow. This allows update_map() to correct all applicable light levels. Fixed.

With that out of the way, I've made some other progress in that mini suns now only remove glow they alone generate.

There's still one bug and one feature to go, as well some optimizations, before this is ready to be declared a mod. Oh, and a different recipe! Suggestions?

p.s. I'm back in master. The voxel_manipulator branch is gone.

User avatar
bdjnk
Member
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk
Location: New York
Contact:

Re: Mini Sun, Pesudo Brighter Light Source. Updated.

by bdjnk » Post

Glow now expands into dug areas and against newly placed nodes as necessary.

Also, as you may have noticed, the original post has been updated.

These are the only items remaining in my mind as possible additions:
  • Line of slight only glow node placement, which I'm not even sure is a good idea.
  • Glow working properly under water.

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: Mini Sun, Pesudo Brighter Light Source. Updated.

by Napiophelios » Post

Basically you have had 3 three versions here;
The second was a pretty good improvement over the first,
but could still slow down the game at times,

the third [latest] works the best as far as gameplay goes
but unlike with the previous 2 releases,where the area is filled with light

Image

Now you can actually see the "glow" textures and its pretty annoying.
Image

Is there anyway to have it display as with previous versions?

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 11 guests