ExchangeClone/exchangeclone/pickaxes.lua

174 lines
6.9 KiB
Lua
Raw Normal View History

2023-11-19 01:48:35 +01:00
local S = minetest.get_translator()
2024-01-22 16:18:52 +01:00
function exchangeclone.mine_vein(player, start_pos, node_name, pos, depth, visited)
if not player or not start_pos then
return
end
pos = pos or start_pos
2023-11-19 01:48:35 +01:00
depth = depth or 0
2024-01-22 16:18:52 +01:00
visited = visited or {}
local pos_str = minetest.pos_to_string(pos)
if visited[pos_str] then
return
end
visited[pos_str] = true
local node = minetest.get_node(pos)
2024-01-22 16:18:52 +01:00
if not node_name then
node_name = node.name
end
if node_name == node.name then
2024-01-22 16:18:52 +01:00
local drops = minetest.get_node_drops(node.name, "exchangeclone:red_matter_pickaxe")
exchangeclone.drop_items_on_player(pos, drops, player)
exchangeclone.check_nearby_falling(pos)
minetest.set_node(pos, {name = "air"})
2024-01-22 16:18:52 +01:00
if depth < 10 then
for _, neighbor_pos in ipairs(minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
node_name)) do
exchangeclone.mine_vein(player, start_pos, node_name, neighbor_pos, depth + 1, visited)
end
2024-01-22 16:18:52 +01:00
end
end
end
local function pickaxe_on_use(itemstack, player, pointed_thing)
local click_test = exchangeclone.check_on_rightclick(itemstack, player, pointed_thing)
if click_test ~= false then
return click_test
end
2024-01-25 16:21:43 +01:00
if player:get_player_control().aux1 then
return exchangeclone.charge_update(itemstack, player)
elseif player:get_player_control().sneak then
local meta = itemstack:get_meta()
2024-01-25 16:21:43 +01:00
local current_mode = itemstack:get_meta():get_string("exchangeclone_multidig_mode") or "1x1"
if current_mode == "1x1" then
2024-01-25 16:21:43 +01:00
meta:set_string("exchangeclone_multidig_mode", "3x1_tall")
2023-11-19 01:48:35 +01:00
minetest.chat_send_player(player:get_player_name(), S("3x1 tall mode"))
elseif current_mode == "tall" then
2024-01-25 16:21:43 +01:00
meta:set_string("exchangeclone_multidig_mode", "3x1_wide")
2023-11-19 01:48:35 +01:00
minetest.chat_send_player(player:get_player_name(), S("3x1 wide mode"))
elseif current_mode == "wide" then
2024-01-25 16:21:43 +01:00
meta:set_string("exchangeclone_multidig_mode", "3x1_long")
2023-11-19 01:48:35 +01:00
minetest.chat_send_player(player:get_player_name(), S("3x1 long mode"))
2024-01-25 16:21:43 +01:00
else
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"))
end
return itemstack
2024-01-25 16:21:43 +01:00
elseif pointed_thing.type == "node" then
2024-02-13 01:25:25 +01:00
if minetest.get_item_group(minetest.get_node(pointed_thing.under).name, "exchangeclone_ore") > 0 then
2024-01-25 16:21:43 +01:00
if exchangeclone.check_cooldown(player, "pickaxe") then return itemstack end
2024-02-13 01:25:25 +01:00
exchangeclone.play_sound(player, "exchangeclone_destruct")
2023-11-19 01:48:35 +01:00
exchangeclone.mine_vein(player, pointed_thing.under)
2024-01-25 16:21:43 +01:00
exchangeclone.start_cooldown(player, "pickaxe", 0.5)
elseif itemstack:get_name():find("red_") then
2024-02-26 01:22:45 +01:00
local result = exchangeclone.place_torch(player, pointed_thing)
if result then
exchangeclone.add_player_emc(player, result)
-- If the torch could not be placed, it still costs EMC... not sure how to fix that
end
end
end
end
2024-01-25 16:21:43 +01:00
minetest.register_tool("exchangeclone:dark_matter_pickaxe", {
2023-11-19 01:48:35 +01:00
description = S("Dark Matter Pickaxe").."\n"..S("Single node mode"),
wield_image = "exchangeclone_dark_matter_pickaxe.png",
inventory_image = "exchangeclone_dark_matter_pickaxe.png",
2023-12-25 18:56:50 +01:00
groups = { tool=1, pickaxe=1, dig_speed_class=5, enchantability=0, dark_matter_pickaxe=1, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
wield_scale = exchangeclone.wield_scale,
2024-01-23 00:31:22 +01:00
tool_capabilities = exchangeclone.mtg and {
2024-01-25 16:21:43 +01:00
full_punch_interval = 1/1.2,
2023-10-30 23:42:11 +01:00
max_drop_level=6,
2024-01-25 16:21:43 +01:00
damage_groups = {fleshy=8},
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-25 16:21:43 +01:00
pickaxey = { speed = 14, level = 5, uses = 0 }
},
on_secondary_use = pickaxe_on_use,
on_place = pickaxe_on_use,
2024-02-16 22:44:08 +01:00
wear_represents = "exchangeclone_charge_level"
2024-01-25 16:21:43 +01:00
})
2023-08-07 22:56:29 +02:00
2024-02-04 22:29:48 +01:00
exchangeclone.register_multidig_tool("exchangeclone:dark_matter_pickaxe", {"group:"..exchangeclone.pickaxe_group})
2024-01-25 16:21:43 +01:00
minetest.register_alias("exchangeclone:dark_matter_pickaxe_3x1", "exchangeclone:dark_matter_pickaxe")
exchangeclone.set_charge_type("exchangeclone:dark_matter_pickaxe", "dark_matter")
2023-11-19 01:48:35 +01:00
2024-01-25 16:21:43 +01:00
minetest.register_tool("exchangeclone:red_matter_pickaxe", {
description = S("Red Matter Pickaxe").."\n"..S("Single node mode"),
wield_image = "exchangeclone_red_matter_pickaxe.png",
inventory_image = "exchangeclone_red_matter_pickaxe.png",
groups = { tool=1, pickaxe=1, dig_speed_class=5, enchantability=0, red_matter_pickaxe=1, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
wield_scale = exchangeclone.wield_scale,
tool_capabilities = exchangeclone.mtg and {
full_punch_interval = 1/1.2,
max_drop_level=7,
damage_groups = {fleshy=9},
punch_attack_uses = 0,
groupcaps={
cracky = {times = exchangeclone.get_mtg_times(16, nil, "cracky"), uses=0, maxlevel=5},
2024-01-25 16:21:43 +01:00
},
},
_mcl_toollike_wield = true,
_mcl_diggroups = {
pickaxey = { speed = 16, level = 6, uses = 0 }
},
on_secondary_use = pickaxe_on_use,
on_place = pickaxe_on_use,
2024-02-16 22:44:08 +01:00
wear_represents = "exchangeclone_charge_level"
2024-01-25 16:21:43 +01:00
})
2024-02-04 22:29:48 +01:00
exchangeclone.register_multidig_tool("exchangeclone:red_matter_pickaxe", {"group:"..exchangeclone.pickaxe_group})
2024-01-25 16:21:43 +01:00
minetest.register_alias("exchangeclone:red_matter_pickaxe_3x1", "exchangeclone:red_matter_pickaxe")
exchangeclone.set_charge_type("exchangeclone:red_matter_pickaxe", "red_matter")
2023-11-19 01:48:35 +01:00
minetest.register_craft({
output = "exchangeclone:dark_matter_pickaxe",
recipe = {
{"exchangeclone:dark_matter", "exchangeclone:dark_matter", "exchangeclone:dark_matter"},
2023-11-10 03:35:23 +01:00
{"", exchangeclone.itemstrings.diamond, ""},
{"", exchangeclone.itemstrings.diamond, ""}
}
})
minetest.register_craft({
output = "exchangeclone:red_matter_pickaxe",
recipe = {
{"exchangeclone:red_matter", "exchangeclone:red_matter", "exchangeclone:red_matter"},
{"", "group:dark_matter_pickaxe", ""},
{"", "exchangeclone:dark_matter", ""}
}
})
2024-01-19 23:12:25 +01:00
-- Can't find a good way to automate this...
minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_nodes) do
if name:find("_ore")
or name:find("stone_with")
or name:find("deepslate_with")
or name:find("diorite_with")
or name:find("andesite_with")
or name:find("granite_with")
or name:find("tuff_with")
or name:find("mineral_")
or (name == "mcl_blackstone:nether_gold")
or (name == "mcl_nether:ancient_debris") then
local groups = table.copy(def.groups)
groups.exchangeclone_ore = 1
minetest.override_item(name, {groups = groups})
end
end
end)