Items producing light

midimaze
New member
 
Posts: 3
Joined: Wed May 18, 2016 06:10
In-game: midimaze

Items producing light

by midimaze » Wed May 25, 2016 00:22

How do I make an item produce light while held in hand?
I've been looking all over tutorials and can't figure this out.
(I hope this belongs here)
Texture Packs: N/A
Mods: N/A
Games: N/A

:3c
 

User avatar
ExeterDad
Member
 
Posts: 1121
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad

Re: Items producing light

by ExeterDad » Wed May 25, 2016 00:48

There's been a walking light that you can wield around for a while. It's known to be a bit laggy and requires shaders I believe.
Sofar has about the most updated code I believe in his torch replacement mod.
viewtopic.php?f=11&t=14359&p=213834#p213834
Study the mod to figure it.
٩(̾●̮̮̃̾•̃̾)۶

Kibbie and I have a beautiful public server now! HOMETOWN
 

midimaze
New member
 
Posts: 3
Joined: Wed May 18, 2016 06:10
In-game: midimaze

Re: Items producing light

by midimaze » Wed May 25, 2016 01:35

Thanks, I'll go check that out.
Texture Packs: N/A
Mods: N/A
Games: N/A

:3c
 

User avatar
AiTechEye
Member
 
Posts: 409
Joined: Fri May 29, 2015 21:14

Re: Items producing light

by AiTechEye » Fri May 27, 2016 08:28

The light is produced by a node/block that replacing/updating it self.

this is a bit remade but fully working mod taken from the vaxcazer.
It works in water & turns of automacly in day light + after a while inside a wall.

vexcazer_flashlight.zip
(1.1 KiB) Downloaded 62 times


Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
vexcazer_flashlight={users={},timer=0}

minetest.register_on_leaveplayer(function(player)
   local name=player:get_player_name()
   if vexcazer_flashlight.users[name]~=nil then vexcazer_flashlight.users[name]=nil end
end)


minetest.register_tool("vexcazer_flashlight:fl", {
   description ="flashlight (USE = on .. PLACE = off .. It works in water and turns off in light)",
   inventory_image = "default_stick.png",
   on_use=function(itemstack, user, pointed_thing)
      local name=user:get_player_name()
      local index=user:get_wield_index()
      vexcazer_flashlight.users[name]={player=user,slot=index,inside=0,item=user:get_inventory():get_stack("main", index):get_name()}
   end,
   on_place=function(itemstack, user, pointed_thing)
      local name=user:get_player_name()
      vexcazer_flashlight.users[name]=nil
   end,
})

minetest.register_node("vexcazer_flashlight:flht", {
   description = "Flashlight source",
   light_source = 12,
   paramtype = "light",
   walkable=false,
   drawtype = "airlike",
   pointable=false,
   buildable_to=true,
   sunlight_propagates = true,
   groups = {not_in_creative_inventory=1},
   on_construct=function(pos)
      minetest.env:get_node_timer(pos):start(1.5)
   end,
   on_timer = function (pos, elapsed)
      minetest.set_node(pos, {name="air"})
   end,
})

minetest.register_node("vexcazer_flashlight:flhtw", {
   description = "Water light",
   drawtype = "liquid",
   tiles = {"default_water.png"},
   alpha = 160,
   light_source = 12,
   paramtype = "light",
   walkable = false,
   pointable = false,
   diggable = false,
   drop = "",
   liquid_viscosity = 1,
   liquidtype = "source",
   liquid_alternative_flowing="vexcazer_flashlight:flhtw",
   liquid_alternative_source="vexcazer_flashlight:flhtw",
   liquid_renewable = false,
   liquid_range = 0,
   drowning = 1,
   sunlight_propagates = true,
   post_effect_color = {a = 103, r = 30, g = 60, b = 90},
   groups = {water = 3, liquid = 3, puts_out_fire = 1},
   on_construct=function(pos)
      minetest.env:get_node_timer(pos):start(1.5)
   end,
   on_timer = function (pos, elapsed)
      minetest.set_node(pos, {name="air"})
   end,
})

minetest.register_globalstep(function(dtime)
   vexcazer_flashlight.timer=vexcazer_flashlight.timer+dtime
   if vexcazer_flashlight.timer>1 then
      vexcazer_flashlight.timer=0
      for i,ob in pairs(vexcazer_flashlight.users) do
         local name=ob.player:get_inventory():get_stack("main", ob.slot):get_name()
         local pos=ob.player:getpos()
         pos.y=pos.y+1.5
         local n=minetest.get_node(pos).name
         local light=minetest.get_node_light(pos)
         if light==nil then
            vexcazer_flashlight.users[i]=nil
            return false
         end
         if ob.inside>10 or name==nil or name~=ob.item or minetest.get_node_light(pos)>12 then
            vexcazer_flashlight.users[i]=nil
         elseif n=="air" or n=="vexcazer_flashlight:flht" then
            minetest.set_node(pos, {name="vexcazer_flashlight:flht"})
         elseif minetest.get_node_group(n, "water")>0 then
            minetest.set_node(pos, {name="vexcazer_flashlight:flhtw"})
         else
            ob.inside=ob.inside+1
         end
      end
   end
end)
Alive AI Mine/Build AI NPC
Gravitygun HL2
Portalgun Portal
Marssurvive Survive on mars
Bows bows + arrows
SoundCloud (Music)
SoundCloud (Classic)
YouTube
 

User avatar
oleastre
Member
 
Posts: 81
Joined: Wed Aug 13, 2014 21:39
GitHub: oleastre
In-game: oleastre

Re: Items producing light

by oleastre » Fri May 27, 2016 11:26

Another example is the torches mod: viewtopic.php?f=11&t=14359
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 11 guests

cron