2024-01-25 16:21:43 +01:00
|
|
|
function exchangeclone.shovel_action(itemstack, player, center)
|
|
|
|
if not (itemstack and player and center) then return end
|
|
|
|
if exchangeclone.check_cooldown(player, "shovel") then return end
|
2024-01-26 17:52:38 +01:00
|
|
|
local charge = math.max(itemstack:get_meta():get_int("exchangeclone_tool_charge"), 1)
|
2024-01-25 16:21:43 +01:00
|
|
|
local start_node = minetest.get_node(center)
|
|
|
|
local action
|
|
|
|
if exchangeclone.mcl then
|
|
|
|
if minetest.registered_items[start_node.name]._on_shovel_place
|
|
|
|
or minetest.get_item_group(start_node.name, "path_creation_possible") == 1 then
|
|
|
|
if minetest.get_node(vector.offset(center,0,1,0)).name == "air" then
|
2024-01-26 17:52:38 +01:00
|
|
|
if (not player:get_player_control().sneak or charge == 1) then
|
|
|
|
action = "path"
|
|
|
|
end
|
2024-01-25 16:21:43 +01:00
|
|
|
end
|
2023-06-23 23:02:22 +02:00
|
|
|
end
|
2024-01-25 16:21:43 +01:00
|
|
|
end
|
|
|
|
if action ~= "path" then
|
2024-01-26 17:52:38 +01:00
|
|
|
if exchangeclone.mcl2 and start_node.name == "mcl_core:grass_path" and
|
|
|
|
(not player:get_player_control().sneak or charge == 1) then
|
2024-01-25 16:21:43 +01:00
|
|
|
action = "unpath"
|
2024-01-26 17:52:38 +01:00
|
|
|
elseif start_node.name == exchangeclone.itemstrings.gravel or start_node.name == exchangeclone.itemstrings.clay then
|
2024-02-04 22:29:48 +01:00
|
|
|
if charge > 1 then
|
2024-01-26 17:52:38 +01:00
|
|
|
action = "crumbly"
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2024-02-04 22:29:48 +01:00
|
|
|
elseif charge > 1 then
|
|
|
|
action = "crumbly_flat"
|
2023-06-23 23:02:22 +02:00
|
|
|
end
|
2024-01-25 16:21:43 +01:00
|
|
|
end
|
2024-01-26 17:52:38 +01:00
|
|
|
|
2024-01-25 16:21:43 +01:00
|
|
|
local groups_to_search, range_type
|
|
|
|
if action == "path" then
|
|
|
|
groups_to_search = exchangeclone.mcl2 and {"group:path_creation_possible"} or {"group:exchangeclone_dirt"}
|
|
|
|
range_type = "flat"
|
|
|
|
elseif action == "unpath" then
|
|
|
|
groups_to_search = {"mcl_core:grass_path"}
|
|
|
|
range_type = "flat"
|
2024-01-26 17:52:38 +01:00
|
|
|
elseif action == "crumbly" then
|
2024-01-25 16:21:43 +01:00
|
|
|
groups_to_search = {start_node.name}
|
|
|
|
range_type = "large_radius"
|
2024-01-26 17:52:38 +01:00
|
|
|
else
|
|
|
|
groups_to_search = {"group:"..(exchangeclone.mcl and "shovely" or "crumbly")}
|
|
|
|
range_type = "flat"
|
|
|
|
end
|
|
|
|
local nodes
|
|
|
|
if charge > 1 then
|
|
|
|
local vector1, vector2 = exchangeclone.process_range(player, range_type, charge)
|
|
|
|
local pos1, pos2 = vector.add(center, vector1), vector.add(center, vector2)
|
2024-02-13 01:25:25 +01:00
|
|
|
if action == "path" or action == "unpath" then
|
|
|
|
exchangeclone.play_sound(player, "exchangeclone_charge_up")
|
|
|
|
else
|
|
|
|
exchangeclone.play_sound(player, "exchangeclone_destruct")
|
|
|
|
end
|
2024-01-26 17:52:38 +01:00
|
|
|
nodes = minetest.find_nodes_in_area(pos1, pos2, groups_to_search)
|
|
|
|
else
|
|
|
|
if action == "path" or action == "unpath" then
|
|
|
|
nodes = {center}
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2024-01-25 16:21:43 +01:00
|
|
|
end
|
|
|
|
for _, pos in pairs(nodes) do
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
minetest.record_protection_violation(pos, player:get_player_name())
|
|
|
|
else
|
|
|
|
if action == "path" then
|
|
|
|
if exchangeclone.mcla then
|
2024-01-26 17:52:38 +01:00
|
|
|
local on_shovel_place = minetest.registered_items[node.name]._on_shovel_place
|
|
|
|
if on_shovel_place then
|
2024-02-04 22:29:48 +01:00
|
|
|
on_shovel_place(itemstack, player, {type="node",under=pos,above=vector.offset(pos,0,1,0)})
|
2024-01-26 17:52:38 +01:00
|
|
|
end
|
|
|
|
else -- in MCL2, it only searches for pathable nodes
|
2024-02-04 22:29:48 +01:00
|
|
|
if minetest.get_node(vector.offset(pos,0,1,0)).name == "air" then
|
2024-01-25 16:21:43 +01:00
|
|
|
minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = pos}, true)
|
|
|
|
minetest.swap_node(pos, {name="mcl_core:grass_path"})
|
|
|
|
end
|
|
|
|
end
|
2024-01-26 17:52:38 +01:00
|
|
|
elseif action == "unpath" then
|
|
|
|
minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = pos}, true)
|
|
|
|
minetest.swap_node(pos, {name="mcl_core:dirt"})
|
|
|
|
else
|
|
|
|
local drops = minetest.get_node_drops(minetest.get_node(pos).name, itemstack)
|
|
|
|
exchangeclone.drop_items_on_player(pos, drops, player)
|
2024-01-25 16:21:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-26 17:52:38 +01:00
|
|
|
if action == "crumbly" or action == "crumbly_flat" then
|
|
|
|
exchangeclone.remove_nodes(nodes)
|
2023-06-23 23:02:22 +02:00
|
|
|
end
|
2024-01-26 17:52:38 +01:00
|
|
|
if charge > 1 then
|
|
|
|
exchangeclone.start_cooldown(player, "shovel", charge/2)
|
|
|
|
end
|
|
|
|
end
|
2023-06-23 23:02:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
local function shovel_on_place(itemstack, player, pointed_thing)
|
|
|
|
local click_test = exchangeclone.check_on_rightclick(itemstack, player, pointed_thing)
|
|
|
|
if click_test ~= false then
|
|
|
|
return click_test
|
|
|
|
end
|
|
|
|
|
|
|
|
if player:get_player_control().aux1 then
|
2024-01-26 17:52:38 +01:00
|
|
|
return exchangeclone.charge_update(itemstack, player)
|
2023-06-23 23:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if pointed_thing.type == "node" then
|
2024-01-26 17:52:38 +01:00
|
|
|
exchangeclone.shovel_action(itemstack, player, pointed_thing.under)
|
2023-06-23 23:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_tool("exchangeclone:dark_matter_shovel", {
|
|
|
|
description = "Dark Matter Shovel",
|
|
|
|
wield_image = "exchangeclone_dark_matter_shovel.png",
|
|
|
|
inventory_image = "exchangeclone_dark_matter_shovel.png",
|
2023-12-25 18:56:50 +01:00
|
|
|
groups = { tool=1, shovel=1, dig_speed_class=5, enchantability=0, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
|
2023-06-23 23:02:22 +02:00
|
|
|
wield_scale = exchangeclone.wield_scale,
|
|
|
|
tool_capabilities = {
|
|
|
|
-- 1/1.2
|
2024-01-26 17:52:38 +01:00
|
|
|
full_punch_interval = 1,
|
2023-10-30 23:42:11 +01:00
|
|
|
max_drop_level=6,
|
2024-01-26 17:52:38 +01:00
|
|
|
damage_groups = {fleshy=6},
|
2023-06-23 23:02:22 +02:00
|
|
|
punch_attack_uses = 0,
|
|
|
|
groupcaps={
|
|
|
|
crumbly = {times={[1]=0.9, [2]=0.45, [3]=0.225}, uses=0, maxlevel=4},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sound = { breaks = "default_tool_breaks" },
|
|
|
|
on_place = shovel_on_place,
|
|
|
|
on_secondary_use = shovel_on_place,
|
|
|
|
_mcl_toollike_wield = true,
|
|
|
|
_mcl_diggroups = {
|
2024-01-26 17:52:38 +01:00
|
|
|
shovely = { speed = 14, level = 5, uses = 0 }
|
2023-06-23 23:02:22 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-01-26 17:52:38 +01:00
|
|
|
exchangeclone.set_charge_type("exchangeclone:dark_matter_shovel", "dark_matter")
|
|
|
|
|
2023-06-23 23:02:22 +02:00
|
|
|
minetest.register_tool("exchangeclone:red_matter_shovel", {
|
|
|
|
description = "Red Matter Shovel",
|
|
|
|
wield_image = "exchangeclone_red_matter_shovel.png",
|
|
|
|
inventory_image = "exchangeclone_red_matter_shovel.png",
|
2023-12-25 18:56:50 +01:00
|
|
|
groups = { tool=1, shovel=1, dig_speed_class=6, enchantability=0, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
|
2023-06-23 23:02:22 +02:00
|
|
|
wield_scale = exchangeclone.wield_scale,
|
|
|
|
tool_capabilities = {
|
|
|
|
-- 1/1.2
|
2024-01-26 17:52:38 +01:00
|
|
|
full_punch_interval = 1,
|
2023-10-30 23:42:11 +01:00
|
|
|
max_drop_level=7,
|
2024-01-26 17:52:38 +01:00
|
|
|
damage_groups = {fleshy=7},
|
2023-06-23 23:02:22 +02:00
|
|
|
punch_attack_uses = 0,
|
|
|
|
groupcaps={
|
|
|
|
crumbly = {times={[1]=0.6, [2]=0.25, [3]=0.1}, uses=0, maxlevel=5},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sound = { breaks = "default_tool_breaks" },
|
|
|
|
on_place = shovel_on_place,
|
|
|
|
on_secondary_use = shovel_on_place,
|
|
|
|
_mcl_toollike_wield = true,
|
|
|
|
_mcl_diggroups = {
|
2024-01-26 17:52:38 +01:00
|
|
|
shovely = { speed = 16, level = 6, uses = 0 }
|
2023-06-23 23:02:22 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-01-26 17:52:38 +01:00
|
|
|
exchangeclone.set_charge_type("exchangeclone:red_matter_shovel", "red_matter")
|
|
|
|
|
2023-06-23 23:02:22 +02:00
|
|
|
--Crafting recipes
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "exchangeclone:dark_matter_shovel",
|
|
|
|
recipe = {
|
|
|
|
{"exchangeclone:dark_matter"},
|
2023-11-10 03:35:23 +01:00
|
|
|
{exchangeclone.itemstrings.diamond},
|
|
|
|
{exchangeclone.itemstrings.diamond}
|
2023-06-23 23:02:22 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "exchangeclone:red_matter_shovel",
|
|
|
|
recipe = {
|
|
|
|
{"exchangeclone:red_matter"},
|
|
|
|
{"exchangeclone:dark_matter_shovel"},
|
|
|
|
{"exchangeclone:dark_matter"}
|
|
|
|
}
|
|
|
|
})
|