ExchangeClone/exchangeclone/axes.lua

162 lines
6.0 KiB
Lua
Raw Normal View History

2023-11-19 01:48:35 +01:00
local S = minetest.get_translator()
2024-02-24 18:12:30 +01:00
function exchangeclone.axe_action(itemstack, player, center, force_strip)
2024-01-26 17:52:38 +01:00
if exchangeclone.check_cooldown(player, "axe") then return end
local strip
local start_node = minetest.get_node(center)
local charge = math.max(itemstack:get_meta():get_int("exchangeclone_tool_charge"), 1)
local start_def = minetest.registered_items[start_node.name]
local stripped_variant = start_def._mcl_stripped_variant
if exchangeclone.mcl then
2024-02-24 18:12:30 +01:00
if force_strip then
strip = true
elseif charge == 1 then
2024-01-26 17:52:38 +01:00
strip = true
else
strip = not player:get_player_control().sneak
end
2024-02-24 18:12:30 +01:00
if strip and not (exchangeclone.mcla or stripped_variant) then return end
2024-01-26 17:52:38 +01:00
end
local nodes
2024-02-24 18:12:30 +01:00
local groups_to_search = strip and {start_node.name} or {"group:tree", "group:leaves", "group:bamboo_block"}
2024-01-26 17:52:38 +01:00
local range_type = strip and "basic_radius" or "large_radius"
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
exchangeclone.play_sound(player, strip and "exchangeclone_charge_up" or "exchangeclone_destruct")
2024-01-26 17:52:38 +01:00
nodes = minetest.find_nodes_in_area(pos1, pos2, groups_to_search)
else
nodes = {center}
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 strip then
if node.param2 == start_node.param2 then
2024-02-24 18:12:30 +01:00
if exchangeclone.mcla then
local on_axe_place = minetest.registered_items[node.name]._on_axe_place
if on_axe_place then
on_axe_place(itemstack, player, {type="node",under=pos})
end
else
minetest.swap_node(pos, {name=stripped_variant, param2=node.param2})
2024-02-04 22:29:48 +01:00
end
end
2024-01-26 17:52:38 +01:00
else
2024-02-23 19:53:21 +01:00
local drops = minetest.get_node_drops(node.name, itemstack:get_name())
2024-01-26 17:52:38 +01:00
exchangeclone.drop_items_on_player(pos, drops, player)
end
end
end
2024-01-26 17:52:38 +01:00
if not strip then
exchangeclone.remove_nodes(nodes)
end
if charge > 1 or not strip then
exchangeclone.start_cooldown(player, "axe", charge/3)
end
end
local function axe_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)
end
2024-01-26 17:52:38 +01:00
if pointed_thing.type == "node" then
2024-02-24 18:12:30 +01:00
local name = minetest.get_node(pointed_thing.under).name
if (minetest.get_item_group(name, "tree") > 0)
or (minetest.get_item_group(name, "bamboo_block") > 0) then
2024-01-26 17:52:38 +01:00
exchangeclone.axe_action(itemstack, player, pointed_thing.under)
2024-02-24 18:12:30 +01:00
elseif exchangeclone.mcl then
if minetest.registered_items[name]._mcl_stripped_variant then
exchangeclone.axe_action(itemstack, player, pointed_thing.under, true)
end
elseif exchangeclone.mcla then
if minetest.registered_items[name]._on_axe_place then
exchangeclone.axe_action(itemstack, player, pointed_thing.under, true)
end
2024-01-26 17:52:38 +01:00
end
end
return itemstack
end
minetest.register_tool("exchangeclone:dark_matter_axe", {
2023-11-19 01:48:35 +01:00
description = S("Dark Matter Axe"),
wield_image = "exchangeclone_dark_matter_axe.png",
inventory_image = "exchangeclone_dark_matter_axe.png",
2023-12-25 18:56:50 +01:00
groups = { tool=1, axe=1, dig_speed_class=5, enchantability=0, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
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=9},
punch_attack_uses = 0,
groupcaps={
choppy = {times = exchangeclone.get_mtg_times(14, nil, "choppy"), uses=0, maxlevel=4},
},
},
sound = { breaks = "default_tool_breaks" },
on_place = axe_on_place,
on_secondary_use = axe_on_place,
_mcl_toollike_wield = true,
_mcl_diggroups = {
2024-01-26 17:52:38 +01:00
axey = { speed = 14, level = 5, uses = 0 }
},
2024-02-16 22:44:08 +01:00
wear_represents = "exchangeclone_charge_level"
})
2024-01-26 17:52:38 +01:00
exchangeclone.set_charge_type("exchangeclone:dark_matter_axe", "dark_matter")
minetest.register_tool("exchangeclone:red_matter_axe", {
2023-11-19 01:48:35 +01:00
description = S("Red Matter Axe"),
wield_image = "exchangeclone_red_matter_axe.png",
inventory_image = "exchangeclone_red_matter_axe.png",
2023-12-25 18:56:50 +01:00
groups = { tool=1, axe=1, dig_speed_class=6, enchantability=0, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
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=10},
punch_attack_uses = 0,
groupcaps={
choppy = {times = exchangeclone.get_mtg_times(16, nil, "choppy"), uses=0, maxlevel=5},
},
},
sound = { breaks = "default_tool_breaks" },
on_place = axe_on_place,
on_secondary_use = axe_on_place,
_mcl_toollike_wield = true,
_mcl_diggroups = {
2024-01-26 17:52:38 +01:00
axey = { speed = 16, level = 6, uses = 0 }
},
2024-02-16 22:44:08 +01:00
wear_represents = "exchangeclone_charge_level"
})
2024-01-26 17:52:38 +01:00
exchangeclone.set_charge_type("exchangeclone:red_matter_axe", "red_matter")
minetest.register_craft({
output = "exchangeclone:dark_matter_axe",
recipe = {
2023-06-23 23:02:22 +02:00
{"exchangeclone:dark_matter", "exchangeclone:dark_matter"},
2023-11-10 03:35:23 +01:00
{"exchangeclone:dark_matter", exchangeclone.itemstrings.diamond},
{"", exchangeclone.itemstrings.diamond}
}
})
minetest.register_craft({
output = "exchangeclone:red_matter_axe",
recipe = {
2023-06-23 23:02:22 +02:00
{"exchangeclone:red_matter", "exchangeclone:red_matter"},
{"exchangeclone:red_matter", "exchangeclone:dark_matter_axe"},
{"", "exchangeclone:dark_matter"}
}
})