123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- local MT = minetest
- local vMod = vm_lighting_wand
- local locate = vMod.locate
- -- Actually places the light node and logs it as a action
- local place_light = function(lighting_node, lighting_pos, player)
- local player_name = player:get_player_name()
- -- do cost and subtract sun_power or error
- if not vMod.do_power_cost(player, lighting_pos) then
- return
- end
- MT.set_node(lighting_pos, {name = lighting_node})
- vMod.play_effects(player:get_pos(), lighting_pos)
- vMod.logger(player_name .. " places node " .. lighting_node .. " at " .. MT.pos_to_string(lighting_pos))
- end
- -- undoes what place_lighting_node did
- local remove_light = function(lighting_node, lighting_pos, player)
- local player_name = player:get_player_name()
- -- do cost and subtract sun_power or error
- if not vMod.do_power_cost(player, lighting_pos, true) then
- return
- end
- MT.remove_node(lighting_pos)
- vMod.logger(player_name .. " removes node " .. lighting_node .. " at " .. MT.pos_to_string(lighting_pos))
- end
- -- main function called by the wand on_use()
- vMod.cast_wand = function(player)
- if not player then
- return
- end
- local player_name = player:get_player_name()
- local range = vMod.get_level(player).max_range
- local pointed_node = vMod.get_pointed_node(player, false, true, range)
- if not pointed_node then
- --todo: Add failed particle effect
- return
- end
- -- ensure pos are set (should always be set)
- if not pointed_node.pos_above then
- vMod.logger(locate("could not place light"))
- return
- end
- -- protection, not sure if this is needed?
- if MT.is_protected(pointed_node.pos_above, player_name) then
- MT.record_protection_violation(pointed_node.pos_above, player_name)
- return
- end
- -- ensure a node was found
- if pointed_node.node_above and not vMod.is_ignored_onlighting(pointed_node.node_above.name) then
- local node_light
- if pointed_node.node_above.drawtype == "airlike" then
- node_light = vMod.air_light
- end
- if pointed_node.node_above.drawtype == "liquid" then
- node_light = vMod.water_light
- end
- if node_light then
- local fn
- if pointed_node.node_above.name == node_light then
- fn = remove_light
- else
- fn = place_light
- end
- fn(node_light, pointed_node.pos_above, player)
- return
- end
- end
- end
|