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

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

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

by bdjnk » Sun Jun 09, 2013 13:16

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 stupid crafting recipe:

  glass glass glass
  glass torch glass
  glass glass glass

Please suggest a new one!


+ The Original 'Original Post'
Last edited by bdjnk on Sun Feb 15, 2015 06:15, edited 8 times in total.
 

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

by bdjnk » Sun Jun 09, 2013 13:55

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

by bdjnk » Mon Jun 10, 2013 19:58

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: 327
Joined: Fri May 10, 2013 00:49
Location: Take your best guess
GitHub: DeepGaze
IRC: DeepGaze
In-game: DeepGaze

by DeepGaze » Thu Jun 27, 2013 16:21

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

by bdjnk » Fri Jun 28, 2013 02:25

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
 

paramat
Member
 
Posts: 1641
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat

by paramat » Fri Jun 28, 2013 05:32

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.
 

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

by Jordach » Fri Jun 28, 2013 07:00

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

( ͡° ͜ʖ ͡°)


<ecks> as a devoted christian, i cannot use an operating system that has daemons
https://www.dropbox.com/s/llwlj2ua0aozk ... I.odt?dl=0
 

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

by bdjnk » Fri Jun 28, 2013 10:22

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 » Fri Jun 28, 2013 11:06

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: 484
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Fri Jun 28, 2013 16:37

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: 3270
Joined: Sun Apr 01, 2012 12:38
Location: Waynesville, NC
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaEzekowitz

by VanessaE » Fri Jun 28, 2013 17:22

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 (16-512px)
Tips (Pandacoin/PND): P9A9ykEZnEpgFThPLsRptgQV2hrUtUJxew
 

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

by bdjnk » Fri Jun 28, 2013 21:45

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

by bdjnk » Fri Jun 28, 2013 23:40

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: 3270
Joined: Sun Apr 01, 2012 12:38
Location: Waynesville, NC
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaEzekowitz

by VanessaE » Sat Jun 29, 2013 01:34

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 (16-512px)
Tips (Pandacoin/PND): P9A9ykEZnEpgFThPLsRptgQV2hrUtUJxew
 

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

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

by dgm5555 » Sun Apr 27, 2014 12:02

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: 1923
Joined: Sun Sep 09, 2012 17:31

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

by Sokomine » Mon Apr 28, 2014 01:35

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

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

by bdjnk » Thu Jun 26, 2014 04:49

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
Member
 
Posts: 2924
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
 

Sokomine
Member
 
Posts: 1923
Joined: Sun Sep 09, 2012 17:31

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

by Sokomine » Thu Jun 26, 2014 15:02

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

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

by bdjnk » Thu Jun 26, 2014 19:35

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: 2754
Joined: Mon Aug 01, 2011 14:26
Location: France
GitHub: Calinou
IRC: Calinou
In-game: Calinou

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

by Calinou » Thu Jun 26, 2014 20:02

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).
My mods and texture packs.
Tox ID: 8DF315693CFC073999DE33B8348D5A3A4B6F676FC30708E485B2E2AD1496E20C26A94EEE79AF
Follow me on Quitter.
 

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

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

by bdjnk » Thu Jul 03, 2014 04:40

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

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

by bdjnk » Mon Aug 25, 2014 18:55

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: 67
Joined: Wed Mar 20, 2013 21:03
Location: New York
GitHub: bdjnk

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

by bdjnk » Wed Aug 27, 2014 19:28

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: 204
Joined: Mon Jul 07, 2014 01:14
IRC: Nappi
In-game: Nappi

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

by Napiophelios » Mon Sep 15, 2014 01:23

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?
 

Next

Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 1 guest