2018-09-30 19:38:04 +02:00
|
|
|
-- Register replacements for the hammer. Entry ID is the ID of the node to
|
|
|
|
-- replace and entry value is the ID of the node to replace with.
|
|
|
|
local replacements = {
|
|
|
|
-- sefault stone crushing
|
|
|
|
['default:obsidian'] = 'default:stone',
|
|
|
|
['default:stone'] = 'default:cobble',
|
|
|
|
['default:cobble'] = 'default:gravel',
|
|
|
|
['default:gravel'] = 'default:sand',
|
|
|
|
-- sandstone types to sand
|
|
|
|
['default:sandstone'] = 'default:sand',
|
|
|
|
['default:desert_sandstone'] = 'default:desert_cobble',
|
|
|
|
['default:desert_cobble'] = 'default:desert_sand',
|
|
|
|
['default:silver_sandstone'] = 'default:silver_sand',
|
|
|
|
}
|
2018-09-22 16:12:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Hammer use function
|
|
|
|
--
|
|
|
|
-- The function is called when using the hammer. It either converts the node to
|
|
|
|
-- its replacement or does nothing. When converting the modified (added wear)
|
|
|
|
-- itemstack is returned.
|
|
|
|
--
|
|
|
|
-- @param itemstack The `itemstack` as per on_use definition
|
|
|
|
-- @param player The `player` as per on_use definition
|
|
|
|
-- @param pointed_thing The `pointed_thing` as per on_use definition
|
|
|
|
-- @see <https://dev.minetest.net/on_use#on_use>
|
|
|
|
-- @return itemstack|void
|
2018-09-30 19:42:44 +02:00
|
|
|
uniham.crush_nodes = function (itemstack, player, pointed_thing)
|
2018-09-30 01:30:57 +02:00
|
|
|
if pointed_thing.type ~= 'node' then return end
|
2018-09-22 16:12:22 +02:00
|
|
|
local node_pos = minetest.get_pointed_thing_position(pointed_thing)
|
|
|
|
local node_name = minetest.get_node(node_pos).name
|
|
|
|
local node_sounds = minetest.registered_nodes[node_name].sounds
|
|
|
|
|
|
|
|
if not replacements[node_name] then
|
|
|
|
minetest.sound_play(node_sounds.dug.name, {
|
|
|
|
pos = node_pos,
|
|
|
|
max_hear_distance = 8,
|
|
|
|
gain = node_sounds.dug.gain,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local replacement = replacements[node_name]
|
|
|
|
local replacement_sounds = minetest.registered_nodes[replacement].sounds
|
|
|
|
local uses = minetest.registered_tools[itemstack:get_name()]._uniham.uses
|
|
|
|
|
|
|
|
minetest.sound_play(replacement_sounds.dug.name, {
|
|
|
|
pos = node_pos,
|
|
|
|
max_hear_distance = 8,
|
|
|
|
gain = replacement_sounds.dug.gain,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.set_node(node_pos, { name = replacement })
|
|
|
|
minetest.check_for_falling(node_pos)
|
|
|
|
|
|
|
|
itemstack:add_wear(math.ceil(65535 / uses) + 1)
|
|
|
|
return itemstack
|
|
|
|
end
|