[Mod] Magic Lantern [magic_latern]

ironzorg
Member
 
Posts: 46
Joined: Tue Aug 23, 2011 06:34

[Mod] Magic Lantern [magic_latern]

by ironzorg » Sun Dec 04, 2011 21:11

Hello everybody,

Here's a mod that allows you to make lights that will glow accordingly to the average level of light surrounding the lamp.
It's very useful as a decorative item: the darker it gets the brighter the lamp will be, and when the sun comes up the lamp stops glowing.

The recipe: one torch surrounded by glass.

Dependencies: default

Since I'm not an artist, I don't provide textures (sorry for that) but I had interesting ideas if you feel like creating the textures yourself:
- The block wears successively 14 textures (there are 14 levels of enlightment), so you can make them so they show a specific hour (like a clock).
- You can make the textures more and more bright as their id (the number of the file name) increases to add realism.

The threshold variables are just a trick I used so that the block emits the same amount of light during more then one cycle.

Code: Select all
local LANTERN_NODES = {}
local LIGHT_THRESHOLD_NIGHT = 4
local LIGHT_THRESHOLD_DAY = 10

for i = 0, LIGHT_MAX do
    table.insert(LANTERN_NODES, 'magic_lantern:magic_lantern_' .. i)
end

-- Functions
minetest.register_abm({
    nodenames = LANTERN_NODES,
    interval = 6,
    chance = 1,
    action = function(pos, node, _, __)
        local aname = node.name

        minetest.env:remove_node(pos)
        local l = minetest.env:get_node_light(pos, nil) - 1

        if l == nil then
            l = 0
        end

        if l < LIGHT_THRESHOLD_NIGHT then
            l = 0
        elseif l > LIGHT_THRESHOLD_DAY then
            l = LIGHT_MAX
        end

         local nname = 'magic_lantern:magic_lantern_' .. (LIGHT_MAX - l)

        minetest.env:add_node(pos, { name = nname })
    end
})

-- Nodes
for i, ml in ipairs(LANTERN_NODES) do
    minetest.register_node(ml, {
        tile_images = { 'magic_lantern_' .. (i - 1) .. '.png' },
        inventory_image = 'magic_lantern_' .. (i - 1) .. '.png',
        drawtype = 'glasslike',
        paramtype = "light",
        walkable = true,
        sunlight_propagates = true,
        light_source = i - 1,
        material = minetest.digprop_glasslike(2.0),
        furnace_burntime = 4,
    })
end

-- Crafts
minetest.register_craft({
    output = 'NodeItem "magic_lantern:magic_lantern_0" 1',
    recipe = {
        {'node "default:glass" 1', 'node "default:glass" 1', 'node "default:glass" 1'},
        {'node "default:glass" 1', 'node "default:torch" 1', 'node "default:glass" 1'},
        {'node "default:glass" 1', 'node "default:glass" 1', 'node "default:glass" 1'},
    },
})


Image

Image

Image

The screenshots are not really convincing because I used the same texture for all the sprites, but like I said you will probably get a better effect if you can draw good looking textures (don't hesitate to post your textures in this thread !).

Do-whatever-you-want-with-my-code license.

Download on mediafire

Feedback appreciated.
Last edited by ironzorg on Sun Dec 11, 2011 19:41, edited 1 time in total.
 

User avatar
Miklosher
New member
 
Posts: 5
Joined: Sun Nov 27, 2011 17:04

by Miklosher » Sun Dec 04, 2011 22:34

This is fu***ng amazing.
 

ironzorg
Member
 
Posts: 46
Joined: Tue Aug 23, 2011 06:34

by ironzorg » Mon Dec 05, 2011 15:00

Miklosher wrote:This is fu***ng amazing.


Thank you, I will try and make a screenshot of the block ingame with proper textures ;)
 

User avatar
Hackeridze
Member
 
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Sun Dec 11, 2011 15:02

Where the textures?
My game: RTMG
GENTOO USER
 

User avatar
sfan5
Moderator
 
Posts: 3817
Joined: Wed Aug 24, 2011 09:44
Location: Germany
GitHub: sfan5
IRC: sfan5

by sfan5 » Sun Dec 11, 2011 15:31

You must make the textures yourself
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)
 

ironzorg
Member
 
Posts: 46
Joined: Tue Aug 23, 2011 06:34

by ironzorg » Sun Dec 11, 2011 15:47

Hackeridze wrote:Where the textures?


You unfortunately have to draw them yourself, since I don't provide any.
 

bwog
Member
 
Posts: 283
Joined: Wed Nov 30, 2011 14:09
Location: United States

by bwog » Sun Dec 11, 2011 16:05

Could you package everything into a .zip file? That would make it easier for everyone else.
 

MarkTraceur
Member
 
Posts: 103
Joined: Sat Dec 03, 2011 05:41
Location: San Francisco, CA

by MarkTraceur » Sun Dec 11, 2011 18:04

More simpler, let gitorious do it for you:

https://gitorious.org

They automatically generate tarballs for your project, and we already have a modders group on there:

https://gitorious.org/+minetest-modders

Join today! :)
Mods: https://gitorious.org/marktraceur-minetest-mods
IRC: marktraceur on freenode
 

ironzorg
Member
 
Posts: 46
Joined: Tue Aug 23, 2011 06:34

by ironzorg » Sun Dec 11, 2011 19:41

bwog wrote:Could you package everything into a .zip file? That would make it easier for everyone else.


Since it's only a couple functions in a init file, I thought it would be overkill to upload a whole archive for the mod…
But since you're the second one to ask, here you go !
The textures I used for the screenshots are in it.
 

User avatar
RabbiBob
Member
 
Posts: 335
Joined: Sat Jan 28, 2012 22:40
Location: /teleport 54,47,28
 

User avatar
MirceaKitsune
Member
 
Posts: 856
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Mon Feb 13, 2012 16:25

+1. This looks like a very nice mod... will try it out.
 

User avatar
Mineing Master
Member
 
Posts: 26
Joined: Mon Jun 25, 2012 18:04
Location: Wisconsin

by Mineing Master » Wed Jun 27, 2012 18:26

How do you get the magic lanturn in the game I can't figure that out.
 

minenato
New member
 
Posts: 1
Joined: Wed Jun 27, 2012 18:51

by minenato » Wed Jun 27, 2012 22:59

i tried install this but no works

/home/myusername/.minetest/mods/minetest/magic_lantern ?
 

User avatar
prof-turbo
Member
 
Posts: 518
Joined: Mon May 07, 2012 17:02
Location: MinetestForFun or Teeworlds master server list

by prof-turbo » Sun Nov 11, 2012 10:44

No,now it's
home/your_username/minetest~/games/minetest_game (or minimal)/mods/magic_lantern
Last edited by prof-turbo on Sun Nov 11, 2012 10:44, edited 1 time in total.
You should take a look at http://www.xorhub.com
 

User avatar
luk3yx
Member
 
Posts: 57
Joined: Sun Oct 21, 2012 18:14
Location: Earth
GitHub: luk3yx
IRC: luk3yx
In-game: luk3yx

by luk3yx » Fri Dec 21, 2012 00:36

I like the idea of this mod, I'll try and download it.
Last edited by luk3yx on Tue Dec 27, 2016 04:46, edited 1 time in total.
git_undo() { [ -e .git ] || return 1; local r; r=$(git remote get-url origin); cd ..; rm -rf "$OLDPWD"; git clone "$r" "$OLDPWD"; cd "$OLDPWD"; }
 

User avatar
luk3yx
Member
 
Posts: 57
Joined: Sun Oct 21, 2012 18:14
Location: Earth
GitHub: luk3yx
IRC: luk3yx
In-game: luk3yx

by luk3yx » Fri Dec 21, 2012 00:44

I didn't seem to be able to run it properly. It may be just me, however if it isn't, it's worth investigating.
Last edited by luk3yx on Tue Dec 27, 2016 04:45, edited 2 times in total.
git_undo() { [ -e .git ] || return 1; local r; r=$(git remote get-url origin); cd ..; rm -rf "$OLDPWD"; git clone "$r" "$OLDPWD"; cd "$OLDPWD"; }
 

User avatar
Topywo
Member
 
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Sat Dec 22, 2012 15:18

I found one, with .png's (thanks to Cornernote).

Changes already made (as far as I could see):
- tile images --> tiles

Changes I made:
- I put in a description (so it's visible in creative. However it will show all 14 .pngs, so if you don't like it, put -- before description in the init.lua)
- I changed the old materials digprop in the same groups as glass. At least it is diggable now. (long time ago I killed a nyanland clonestone with a non-diggable magic lantern on gameboom :-P )
- I copied the glass sound into it's init.lua.

I hope you enjoy this mod like I always did!

http://dl.dropbox.com/u/65428713/magic_lantern.zip
 

dsalt
Member
 
Posts: 12
Joined: Wed Feb 20, 2013 13:13

by dsalt » Wed Feb 20, 2013 13:39

There are problems with the lantern as it stands…
  • Flicker. When the brightness is checked, the object may briefly disappear. This is… sometimes rather noticeable in that it's briefly dark.
  • As others have noted, all variants (different brightnesses) appear in the palette in creative mode.
This version fixes these problems and makes a few brightness adjustments, but (currently) has a dependency on a patched minetest.

Code: Select all
local LANTERN_NODES = {}
local LIGHT_THRESHOLD_NIGHT = 4
local LIGHT_THRESHOLD_DAY = 10

-- Nodes
for i = 0, LIGHT_MAX do
    local name = 'magic_lantern:magic_lantern_' .. i
    table.insert(LANTERN_NODES, name)
    local obj = {
        tiles = { 'magic_lantern_' .. i .. '.png' },
        inventory_image = 'magic_lantern_' .. i .. '.png',
        drawtype = 'glasslike',
        paramtype = "light",
        walkable = true,
        sunlight_propagates = true,
        light_source = i,
        groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
        sounds = default.node_sound_glass_defaults(),
        furnace_burntime = 4,
    }
    if i == LIGHT_MAX then
        obj.description = "magic_lantern"
    end
    minetest.register_node(name, obj)
end

-- Functions
local function brightness_factor(level)
    -- we want non-linear; curve above x=y between 0 and LIGHT_MAX
    return math.floor((level / LIGHT_MAX) ^ (2 ^ 0.5 / 2) * LIGHT_MAX + 0.5)
end

minetest.register_abm({
    nodenames = LANTERN_NODES,
    interval = 3,
    chance = 1,
    action = function(pos, node, _, __)
        -- get ambient light only (ignore this source)
        local ambient = minetest.env:get_node_propagated_light(pos, nil) or 1

        -- current brightness and target brightness
        local current = minetest.registered_nodes[node.name].light_source or -1
        local target = brightness_factor(LIGHT_MAX + 1 - ambient)

        -- calculate the new setting
        local new = current + math.ceil((target - current) / 2)
        -- clip to the allowed range
        if new < 0 then
            new = 0
        elseif new > LIGHT_MAX then
            new = LIGHT_MAX
        end

        -- change the node if needed to set the new brightness
        if new ~= current then
            minetest.env:add_node(pos, { name = 'magic_lantern:magic_lantern_' .. new })
        end
    end
})

-- Crafts
minetest.register_craft({
    output = 'NodeItem "magic_lantern:magic_lantern_0" 1',
    recipe = {
        {'node "default:glass" 1', 'node "default:glass" 1', 'node "default:glass" 1'},
        {'node "default:glass" 1', 'node "default:torch" 1', 'node "default:glass" 1'},
        {'node "default:glass" 1', 'node "default:glass" 1', 'node "default:glass" 1'},
    },
})
Last edited by dsalt on Wed Feb 20, 2013 13:41, edited 1 time in total.
 

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

by bdjnk » Sun Mar 24, 2013 17:26

edit: I case I wasn't clear, it does solve the flicker without rely on anything special

Working off the dsalt version, I have spewed out some hideously disjointed Lua to accommodate the deficiencies in the script API. It is terribly inefficient, absurdly roundabout, and might not work in all circumstances. With that glowing recommendation, here lies the beast:

Code: Select all
local LANTERN_NODES = {}

-- Nodes
for i = 0, LIGHT_MAX do
    local name = 'magic_lantern:magic_lantern_' .. i
    table.insert(LANTERN_NODES, name)
    local obj = {
        tiles = { 'magic_lantern_' .. i .. '.png' },
        inventory_image = 'magic_lantern_' .. i .. '.png',
        drawtype = 'glasslike',
        paramtype = "light",
        walkable = true,
        sunlight_propagates = true,
        light_source = i,
        groups = { snappy=2, cracky=3, oddly_breakable_by_hand=3 },
        sounds = default.node_sound_glass_defaults(),
        furnace_burntime = 4,
    }
    if i == LIGHT_MAX then
        obj.description = "magic_lantern"
    end
    minetest.register_node(name, obj)
end

minetest.register_abm({
    nodenames = LANTERN_NODES,
    interval = 8,
    chance = 1,
    action = function(pos, node, _, __)

        if node.name == 'ignore' then return end

        local minp = {x = 0, y = 0, z = 0}
        local maxp = {x = 0, y = 0, z = 0}

        for key,value in pairs(pos) do
            minp.x = pos.x - 3
            minp.y = pos.y - 3
            minp.z = pos.z - 3
            maxp.x = pos.x + 3
            maxp.y = pos.y + 3
            maxp.z = pos.z + 3
        end
        local locs = minetest.env:find_nodes_in_area(minp, maxp, {"air", "default:water", "default:glass"})

        local average = 0
        local count = 0
        for key,loc in pairs(locs) do
            if pos ~= loc then
                average = average + minetest.env:get_node_light(loc, nil)
                count = count + 1
            end
        end
        average = average / count

        local dimmer = (average - 10) * 3
        brightness = math.min(math.max(0, math.ceil(LIGHT_MAX - dimmer)), 14)

        minetest.env:add_node(pos, {name = 'magic_lantern:magic_lantern_' .. brightness})
    end
})

-- Crafts
minetest.register_craft({
    output = 'NodeItem "magic_lantern:magic_lantern_0" 1',
    recipe = {
        {'node "default:glass" 1', 'node "default:glass" 1', 'node "default:glass" 1'},
        {'node "default:glass" 1', 'node "default:torch" 1', 'node "default:glass" 1'},
        {'node "default:glass" 1', 'node "default:glass" 1', 'node "default:glass" 1'},
    },
})


Looking at it is making me physically ill. Hopefully this motivates a core developer to add a function to get a node's light level sans enumerated light sources.
Last edited by bdjnk on Sun Mar 24, 2013 17:56, edited 1 time in total.
 

User avatar
Topywo
Member
 
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Tue Mar 04, 2014 18:57

Version with bdjnk's code (+ commented description. Remove the comment -- to have (a lot of) lanterns in creative):

https://dl.dropboxusercontent.com/u/65428713/magic_lantern_bdjnk.zip
 


Return to Mod Releases



Who is online

Users browsing this forum: Blockhead, osjc and 4 guests