Items producing light

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

Items producing light

by midimaze » Post

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: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: Items producing light

by ExeterDad » Post

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.

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

Re: Items producing light

by midimaze » Post

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

:3c

User avatar
AiTechEye
Member
Posts: 1000
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: Sweden

Re: Items producing light

by AiTechEye » Post

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 48 times

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)

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

Re: Items producing light

by oleastre » Post

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

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests