From 5e194b33bd612cc1cc088c0aa42e4366ee79ac31 Mon Sep 17 00:00:00 2001 From: SmokeyDope Date: Mon, 11 Sep 2023 18:04:07 +0000 Subject: [PATCH] Adjust make_grass_path function to let shovels turn grass paths back to dirt with shift+rightclick --- mods/ITEMS/mcl_tools/init.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index e60fd11b2..01040477b 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -165,11 +165,35 @@ local make_grass_path = function(itemstack, placer, pointed_thing) end end - -- Only make grass path if tool used on side or top of target node + -- Only make or remove grass path if tool used on side or top of target node if pointed_thing.above.y < pointed_thing.under.y then return itemstack end +-- Remove grass paths + if (minetest.get_item_group(node.name, "path_remove_possible") == 1) and placer:get_player_control().sneak == true then + local above = table.copy(pointed_thing.under) + above.y = above.y + 1 + if minetest.get_node(above).name == "air" then + if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then + minetest.record_protection_violation(pointed_thing.under, placer:get_player_name()) + return itemstack + end + + if not minetest.is_creative_enabled(placer:get_player_name()) then + -- Add wear (as if digging a shovely node) + local toolname = itemstack:get_name() + local wear = mcl_autogroup.get_wear(toolname, "shovely") + if wear then + itemstack:add_wear(wear) + end + end + minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above, max_hear_distance = 16}, true) + minetest.swap_node(pointed_thing.under, {name="mcl_core:dirt"}) + end + end + +-- Make grass paths if (minetest.get_item_group(node.name, "path_creation_possible") == 1) then local above = table.copy(pointed_thing.under) above.y = above.y + 1