help with turning lights on in minetest (puncher thingy)

Post Reply
User avatar
durtective6
Member
Posts: 186
Joined: Sun Aug 12, 2012 14:19
In-game: derplez or BlockFrog
Location: a shed in the desert

help with turning lights on in minetest (puncher thingy)

by durtective6 » Post

k so ive added a new feature into my mod but when i go to punch it to turn it on, it doesnt turn on. Could someone help and if its needed heres the code

minetest.register_node("techno:techno_lamp", {
description = "techno lamp",
drawtype = "glasslike",
paramtype = "light",
sunlight_propagates = true,
tiles = {"techno_lamp.png"},
groups = {choppy=3,cracky=2},
})

minetest.register_node("techno:techno_lamp_on", {
description = "techno lamp",
tile_images = {"techno_lamp.png"},
drawtype = "glasslike",
paramtype = "light",
sunlight_propagates = true,
drop = 'techno:techno_lamp',
light_source = 14,
groups = {choppy=3,cracky=3,not_in_creative_inventory=1},
})
minetest.register_craft({
output = '"techno:techno_lamp"',
recipe = {
{'techno:steel_cluster', 'default:cobble', 'techno:steel_cluster'},
{'default:cobble', 'default:glass', 'default:cobble'},
{'techno:steel_cluster', 'default:cobble', 'techno:steel_cluster'},
}
})

local on_light_puncher = function (pos, node, puncher)
if node.name == 'techno:techno_lamp' then
minetest.env:add_node(pos, {name="techno:techno_lamp_on"})
nodeupdate(pos)
elseif node.name == 'techno:techno_lamp_on' then
minetest.env:add_node(pos, {name="techno:techno_lamp",})
nodeupdate(pos)
end
end

also the inventory image is really dark, dunno how to fix that...
I'm still here, last time I checked at least.

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

by LionsDen » Post

You need to register the on punch function like this:

Code: Select all

--   Register the function for use.
minetest.register_on_punchnode(on_light_puncher)
A problem that I can see is that the mod lights+ uses that exact same function name for the same purpose for it's lights. A better way to do it is to use the on_punch option in the node registration so that you don't need to use a separate function that is called every time any node is punched. This will save a tiny bit of cpu for people that have super slow machines. It will also be compatible with the mods that make use of the other method that you are trying to use.

NOTE: I did not test your code to see if there was any other problems, I just noticed that you weren't registering the function.

P.S. If you use the on punch part of the node registration, you wont have to check if the node is in fact the one that is getting punched as it will only do it if that node is in fact being punched. :)
Last edited by LionsDen on Wed Nov 20, 2013 18:16, edited 1 time in total.

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

by LionsDen » Post

Also, you are likely to be yelled at because this belongs in the modding discussion, not the general discussion.

User avatar
durtective6
Member
Posts: 186
Joined: Sun Aug 12, 2012 14:19
In-game: derplez or BlockFrog
Location: a shed in the desert

by durtective6 » Post

Not to be a bother but would i put that line of code anywhere or replace the on_light_puncher part with it?
Last edited by durtective6 on Wed Nov 20, 2013 22:04, edited 1 time in total.
I'm still here, last time I checked at least.

User avatar
qwrwed
Member
Posts: 325
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

by qwrwed » Post

LionsDen wrote:A problem that I can see is that the mod lights+ uses that exact same function name for the same purpose for it's lights.
I rewrote Lights+, and it no longer uses on_light_puncher.
durtective6: This code might help you - as LionsDen said, the on_punch code is in the node definition instead of at the end of the init.lua.

Code: Select all

minetest.register_node(mod:light_off, {
        description = "Light off",
        -- Other stuff here.
        on_punch = function(pos, node, puncher)
            minetest.set_node(pos, {name=mod:light_on})
        end
    })

minetest.register_node(mod:light_on, {
      description = "Light on",
      drop = off,
      -- Other stuff here.
      on_punch = function(pos, node, puncher)
          minetest.set_node(pos, {name=mod:light_off})
      end
})
For the inventory image problem, default:glass uses this in the node definition:

Code: Select all

inventory_image = minetest.inventorycube("default_glass.png"),
Last edited by qwrwed on Sun Nov 24, 2013 12:14, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: cuthbertdoublebarrel and 6 guests