ExchangeClone/exchangeclone/hammers.lua

128 lines
4.9 KiB
Lua
Raw Normal View History

2023-11-19 01:48:35 +01:00
local S = minetest.get_translator()
2024-01-25 16:21:43 +01:00
function exchangeclone.hammer_action(itemstack, player, center)
if not (itemstack and player and center) then return end
if exchangeclone.check_cooldown(player, "hammer") 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 vector1, vector2 = exchangeclone.process_range(player, "hammer", charge)
if not (vector1 and vector2) then return end
local pos1, pos2 = vector.add(center, vector1), vector.add(center, vector2)
2024-02-13 01:25:25 +01:00
exchangeclone.play_sound(player, "exchangeclone_destruct")
2024-02-04 22:29:48 +01:00
local nodes = minetest.find_nodes_in_area(pos1, pos2, {"group:"..exchangeclone.pickaxe_group})
2024-01-25 16:21:43 +01:00
for _, pos in pairs(nodes) do
if minetest.is_protected(pos, player:get_player_name()) then
minetest.record_protection_violation(pos, player:get_player_name())
else
2024-01-25 16:46:13 +01:00
local drops = minetest.get_node_drops(minetest.get_node(pos).name, itemstack:get_name())
2024-01-25 16:21:43 +01:00
exchangeclone.drop_items_on_player(pos, drops, player)
2023-08-07 22:56:29 +02:00
end
end
2024-01-25 16:21:43 +01:00
exchangeclone.remove_nodes(nodes)
exchangeclone.start_cooldown(player, "hammer", charge/2)
end
local function hammer_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-24 04:23:32 +01:00
return exchangeclone.charge_update(itemstack, player)
end
if player:get_player_control().sneak then
2024-01-22 16:18:52 +01:00
local meta = itemstack:get_meta()
local current_mode = meta:get_string("exchangeclone_multidig_mode")
if current_mode == "3x3" then
meta:set_string("exchangeclone_multidig_mode", "1x1")
2023-11-19 01:48:35 +01:00
minetest.chat_send_player(player:get_player_name(), S("Single node mode"))
else
2024-01-22 16:18:52 +01:00
meta:set_string("exchangeclone_multidig_mode", "3x3")
2023-11-19 01:48:35 +01:00
minetest.chat_send_player(player:get_player_name(), S("3x3 mode"))
end
return itemstack
end
if pointed_thing.type == "node" then
2024-01-26 17:52:38 +01:00
exchangeclone.hammer_action(itemstack, player, pointed_thing.under)
end
end
minetest.register_tool("exchangeclone:dark_matter_hammer", {
2023-11-19 01:48:35 +01:00
description = S("Dark Matter Hammer").."\n"..S("Single node mode"),
wield_image = "exchangeclone_dark_matter_hammer.png",
inventory_image = "exchangeclone_dark_matter_hammer.png",
2023-12-25 18:56:50 +01:00
groups = { tool=1, hammer=1, dig_speed_class=5, enchantability=0, dark_matter_hammer = 1, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
wield_scale = exchangeclone.wield_scale,
tool_capabilities = {
-- 1/1.2
2024-01-25 16:21:43 +01:00
full_punch_interval = 1,
2023-10-30 23:42:11 +01:00
max_drop_level=6,
2024-01-25 16:21:43 +01:00
damage_groups = {fleshy=14},
punch_attack_uses = 0,
groupcaps={
cracky = {times = exchangeclone.get_mtg_times(14, nil, "cracky"), uses=0, maxlevel=4},
},
},
_mcl_toollike_wield = true,
_mcl_diggroups = {
2024-01-24 04:23:32 +01:00
pickaxey = { speed = 14, level = 5, uses = 0 }
},
on_place = hammer_on_place,
2024-02-16 22:44:08 +01:00
on_secondary_use = hammer_on_place,
wear_represents = "exchangeclone_charge_level"
})
2024-02-04 22:29:48 +01:00
exchangeclone.register_multidig_tool("exchangeclone:dark_matter_hammer", {"group:"..exchangeclone.pickaxe_group})
2024-01-23 00:31:22 +01:00
minetest.register_alias("exchangeclone:dark_matter_hammer_3x3", "exchangeclone:dark_matter_hammer")
2024-01-25 16:21:43 +01:00
exchangeclone.set_charge_type("exchangeclone:dark_matter_hammer", "dark_matter")
2023-11-19 01:48:35 +01:00
minetest.register_tool("exchangeclone:red_matter_hammer", {
2023-11-19 01:48:35 +01:00
description = S("Red Matter Hammer").."\n"..S("Single node mode"),
wield_image = "exchangeclone_red_matter_hammer.png",
inventory_image = "exchangeclone_red_matter_hammer.png",
2023-12-25 18:56:50 +01:00
groups = { tool=1, hammer=1, dig_speed_class=6, enchantability=0, red_matter_hammer = 1, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
wield_scale = exchangeclone.wield_scale,
tool_capabilities = {
-- 1/1.2
2024-01-25 16:21:43 +01:00
full_punch_interval = 1,
2023-10-30 23:42:11 +01:00
max_drop_level=7,
2024-01-25 16:21:43 +01:00
damage_groups = {fleshy=15},
punch_attack_uses = 0,
groupcaps={
cracky = {times = exchangeclone.get_mtg_times(16, nil, "cracky"), uses=0, maxlevel=5},
},
},
_mcl_toollike_wield = true,
_mcl_diggroups = {
2024-01-24 04:23:32 +01:00
pickaxey = { speed = 16, level = 6, uses = 0 }
},
on_place = hammer_on_place,
on_secondary_use = hammer_on_place,
2024-02-16 22:44:08 +01:00
wear_represents = "exchangeclone_charge_level"
})
2024-02-04 22:29:48 +01:00
exchangeclone.register_multidig_tool("exchangeclone:red_matter_hammer", {"group:"..exchangeclone.pickaxe_group})
2024-01-23 00:31:22 +01:00
minetest.register_alias("exchangeclone:red_matter_hammer_3x3", "exchangeclone:red_matter_hammer")
2024-01-25 16:21:43 +01:00
exchangeclone.set_charge_type("exchangeclone:red_matter_hammer", "red_matter")
2023-11-19 01:48:35 +01:00
minetest.register_craft({
output = "exchangeclone:dark_matter_hammer",
recipe = {
2023-11-10 03:35:23 +01:00
{"exchangeclone:dark_matter", exchangeclone.itemstrings.diamond, "exchangeclone:dark_matter"},
{"", exchangeclone.itemstrings.diamond, ""},
{"", exchangeclone.itemstrings.diamond, ""}
}
})
minetest.register_craft({
output = "exchangeclone:red_matter_hammer",
recipe = {
{"exchangeclone:red_matter", "exchangeclone:dark_matter", "exchangeclone:red_matter"},
{"", "group:dark_matter_hammer", ""},
{"", "exchangeclone:dark_matter", ""}
}
})