tech_additions/airblock.lua

48 lines
1.3 KiB
Lua
Raw Normal View History

2024-01-06 14:15:07 +03:00
local S = minetest.get_translator("tech_additions")
2024-12-22 15:27:05 +03:00
local replace_allowed = {}
replace_allowed["air"] = true
replace_allowed["default:water_source"] = true
replace_allowed["default:water_flowing"] = true
replace_allowed["default:river_water_source"] = true
replace_allowed["default:river_water_flowing"] = true
2024-01-06 14:15:07 +03:00
local placeairblock = function ()
return function(itemstack, user, pointed_thing)
2024-12-22 14:08:52 +03:00
local name = user:get_player_name()
2024-12-22 15:26:28 +03:00
if not minetest.is_creative_enabled(name) then
return
end
2024-12-22 14:08:52 +03:00
local pos = user:getpos()
local dir = user:get_look_dir()
local distancefromplayer = 3
local new_pos = {
x = pos.x + (dir.x * distancefromplayer),
y = pos.y + 1 + (dir.y * distancefromplayer),
z = pos.z + (dir.z * distancefromplayer),
}
2024-12-22 15:26:28 +03:00
if minetest.is_protected(new_pos, name) then
minetest.record_protection_violation(new_pos, name)
return
end
2024-12-22 14:08:52 +03:00
local getPos = minetest.get_node(new_pos)
2024-12-22 15:27:05 +03:00
if replace_allowed[getPos.name] then
2024-12-22 15:26:28 +03:00
minetest.set_node(new_pos, {name="tech_additions:air_block"})
2024-01-06 14:15:07 +03:00
end
end
end
minetest.register_node("tech_additions:air_block", {
description = S("Air Block"),
tiles = {"tech_additions_air_block.png"},
groups = {snappy=3, fall_damage_add_percent = -99, bouncy=70},
light_source = 30,
paramtype = "light",
sunlight_propagates = true,
on_secondary_use = placeairblock(),
})