Add flare gun.

This commit is contained in:
Duane 2016-07-17 01:10:40 -05:00
parent 357be42a0a
commit 193ad7e7ac
6 changed files with 118 additions and 1 deletions

View file

@ -397,3 +397,102 @@ minetest.register_craft({
{'', 'default:steelblock', 'default:coalblock'},
}
})
local function flares(player)
local dir = player:get_look_dir()
local pos = player:getpos()
if not pos then
return
end
pos.x = pos.x + dir.x * 10
pos.y = pos.y + dir.y * 10
pos.z = pos.z + dir.z * 10
pos = vector.round(pos)
local air = minetest.get_content_id('air')
local flare = minetest.get_content_id('fun_caves:flare')
local vm = minetest.get_voxel_manip()
if not vm then
return
end
local r = 8
local minp = vector.subtract(pos, r)
local maxp = vector.add(pos, r)
local emin, emax = vm:read_from_map(minp, maxp)
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local data = vm:get_data()
local count = 0
for i = 1, 50 do
local x = pos.x + math.random(2 * r + 1) - r - 1
local y = pos.y + math.random(2 * r + 1) - r - 1
local z = pos.z + math.random(2 * r + 1) - r - 1
local ivm = area:index(x, y, z)
if data[ivm] == air then
data[ivm] = flare
count = count + 1
end
end
vm:set_data(data)
vm:calc_lighting(minp, maxp)
vm:update_liquids()
vm:write_to_map()
vm:update_map()
return count
end
minetest.register_node("fun_caves:flare", {
description = "Fungal tree fruit",
drawtype = "plantlike",
visual_scale = 0.75,
tiles = {"fun_caves_flare.png"},
paramtype = "light",
sunlight_propagates = true,
light_source = 15,
walkable = false,
diggable = false,
pointable = false,
is_ground_content = false,
})
minetest.register_tool("fun_caves:flare_gun", {
description = "Flare Gun",
inventory_image = "fun_caves_flare_gun.png",
tool_capabilities = {
full_punch_interval = 1.2,
max_drop_level=0,
groupcaps={
snappy={times={[2]=1.6, [3]=0.40}, uses=10, maxlevel=1},
},
damage_groups = {fleshy=2},
},
on_use = function(itemstack, user, pointed_thing)
if not user then
return
end
local count = flares(user)
itemstack:add_wear(count * 400)
return itemstack
end,
})
minetest.register_craft({
output = 'fun_caves:flare_gun',
recipe = {
{'', '', ''},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
{'', 'tnt:gunpowder', 'group:stick'},
}
})
minetest.register_craft({
output = 'fun_caves:flare_gun',
recipe = {
{'', '', ''},
{'', 'fun_caves:flare_gun', ''},
{'', 'tnt:gunpowder', ''},
}
})