2022-02-05 01:01:23 +02:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
|
|
|
function mcl_amethyst.grow_amethyst_bud(pos, ignore_budding_amethyst)
|
2022-02-05 00:39:40 +02:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
2022-02-05 01:01:23 +02:00
|
|
|
if not (def and def.groups and def.groups.amethyst_buds) then return end
|
2022-02-05 00:39:40 +02:00
|
|
|
local next_gen = def._mcl_amethyst_next_grade
|
2022-02-05 01:01:23 +02:00
|
|
|
if not next_gen then return end
|
|
|
|
|
2022-02-05 00:39:40 +02:00
|
|
|
-- Check Budding Amethyst
|
|
|
|
if not ignore_budding_amethyst then
|
|
|
|
local dir = minetest.wallmounted_to_dir(node.param2)
|
2022-02-05 01:01:23 +02:00
|
|
|
local ba_pos = vector.add(pos, dir)
|
2022-02-05 00:39:40 +02:00
|
|
|
local ba_node = minetest.get_node(ba_pos)
|
2022-02-05 01:01:23 +02:00
|
|
|
if ba_node.name ~= "mcl_amethyst:budding_amethyst_block" then return end
|
2022-02-05 00:39:40 +02:00
|
|
|
end
|
|
|
|
local swap_result = table.copy(node)
|
|
|
|
swap_result.name = next_gen
|
2022-02-05 01:01:23 +02:00
|
|
|
minetest.swap_node(pos, swap_result)
|
2022-02-05 00:39:40 +02:00
|
|
|
return true
|
2021-07-28 15:44:30 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function get_growing_tool_handle(ignore)
|
2022-02-05 00:39:40 +02:00
|
|
|
return function(itemstack, user, pointed_thing)
|
|
|
|
if not user:is_player() then return end
|
|
|
|
local name = user:get_player_name()
|
|
|
|
local pos = minetest.get_pointed_thing_position(pointed_thing)
|
|
|
|
if minetest.is_protected(pos, name) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
2022-02-05 01:01:23 +02:00
|
|
|
minetest.chat_send_player(name, S("Not allowed to use Amethyst Growing Tool in a protected area!"))
|
2022-02-05 00:39:40 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if not mcl_amethyst.grow_amethyst_bud(pos, ignore) then
|
2022-02-05 01:01:23 +02:00
|
|
|
minetest.chat_send_player(name, S("Growing Failed"))
|
2022-02-05 00:39:40 +02:00
|
|
|
end
|
|
|
|
end
|
2021-07-28 15:44:30 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_tool("mcl_amethyst:growing_tool",{
|
2022-02-05 01:01:23 +02:00
|
|
|
description = S("Amethyst Growing Tool"),
|
2022-02-05 00:39:40 +02:00
|
|
|
on_use = get_growing_tool_handle(true),
|
|
|
|
on_place = get_growing_tool_handle(false),
|
|
|
|
inventory_image = "amethyst_cluster.png^amethyst_shard.png",
|
|
|
|
groups = {
|
|
|
|
tool = 1,
|
|
|
|
},
|
2021-07-28 15:44:30 +03:00
|
|
|
})
|
2022-02-05 01:01:23 +02:00
|
|
|
|
2021-07-28 15:44:30 +03:00
|
|
|
mcl_wip.register_experimental_item("mcl_amethyst:growing_tool")
|