Head Lamp?

Post Reply
Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Head Lamp?

by Grubler » Post

How would a person make it so a light is made when you have a piece of armor equipped?

I figured out how to make a light get made when you hold the item, but yeah, not when equipped. Still a bit confused about it all. If somebody may know and could help a little bit, that would be cool, maybe. If it may even be possible.

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Head Lamp?

by Andrey01 » Post

So do you want to do a light to be emiited from your armor when you are equiped to it? You can define the armor as an entity and attach it to the player. In the entity definition table you need to set glow parameter > 0: https://github.com/minetest/minetest/bl ... .txt#L7074 You can also set it in any time with using player:set_properties({glow=<value>}).

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: Head Lamp?

by Grubler » Post

I am not sure how to do just about any of that, sorry. Is there a way I could learn how to do that?

User avatar
Andrey01
Member
Posts: 2574
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Head Lamp?

by Andrey01 » Post

I don't know any docs where you could learn about that, but in any case I can provide you a code sketch:

Code: Select all

-- This function registers an entity(armor)

minetest.register_entity("my_armor:armor", {
    visual_size = {x=0.5, y=0.5, z=0.5},
    physical = false,
    visual = "mesh",
    mesh = ...,    -- a name of your armor mesh object file, e.g. format .b3d, .x, .obj.
    textures = {...},    -- your armor's textures
    pointable = false,
    collisionbox = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
    glow = 7
})

-- The function that is passed to the other function (callback) will be called each time when any player joins a world

minetest.register_on_joinplayer(function(player_obj)
    local is_armor_attached = player_obj:get_meta():get_string("is_armor_attached")
    if is_armor_attached == "1" then
        local pos = player_obj:get_pos()
        local armor_obj = minetest.add_entity("armor:my_armor", pos)
        armor_obj:set_attach(player_obj)
    end
end)
It is only approximate code that you could use, further you need also to realize that how you will attach it on yourself. It may be just right-clicking with wielded item of corresponding armor part or putting it in corresponding slots in armor's inventory. I would recommend you to browse and learn source code of 3d_armor mod.

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: Head Lamp?

by Grubler » Post

I have messed with an armor mod and added glow to the armor item, but it only makes light happen when it is in your hand, not when it is on your character.

Actually, glow added to the item only made it visible in the dark when it was dropped on the ground. I actually used something from a different mod to make it so some light thing was on the item, but then it only made light when it was in my hand and not on the character.

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Head Lamp?

by Blockhead » Post

Unless I'm mistaken, you can only emit light from nodes, not entities. So the best hack available to get this to work would be to track the position of all players with head lamps attached and replace air with a light emitting invisible node, then remove those light nodes when the player moves. Some reading:

https://github.com/minetest/minetest/issues/6921

https://github.com/minetest-mods/wielded_light
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests