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)
Items producing light
Items producing light
Texture Packs: N/A
Mods: N/A
Games: N/A
:3c
Mods: N/A
Games: N/A
:3c
- ExeterDad
- Member
- Posts: 1717
- Joined: Sun Jun 01, 2014 20:00
- In-game: ExeterDad
- Location: New Hampshire U.S.A
Re: Items producing light
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.
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.
HOMETOWN -Our little server. Keep the HOMETOWN chatter @ http://hometownserver.com - Our server map: http://media.hometownserver.com
Re: Items producing light
Thanks, I'll go check that out.
Texture Packs: N/A
Mods: N/A
Games: N/A
:3c
Mods: N/A
Games: N/A
:3c
Re: Items producing light
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.
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.
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)
Re: Items producing light
Another example is the torches mod: viewtopic.php?f=11&t=14359
Who is online
Users browsing this forum: No registered users and 11 guests