2020-02-10 20:48:27 +01:00
|
|
|
-- Translation support
|
|
|
|
local S = minetest.get_translator("throwing_arrows")
|
2020-02-11 19:48:42 +01:00
|
|
|
|
|
|
|
local function register_bow_craft(name, itemcraft)
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "throwing:" .. name,
|
|
|
|
recipe = {
|
2020-02-16 21:22:23 +01:00
|
|
|
{"farming:string", itemcraft, ""},
|
|
|
|
{"farming:string", "", itemcraft},
|
|
|
|
{"farming:string", itemcraft, ""},
|
2020-02-11 19:48:42 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_wood", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Wooden Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_wood.png",
|
|
|
|
uses = 50
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_wood", "default:wood")
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_stone", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Stone Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_stone.png",
|
|
|
|
uses = 100
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_stone", "default:cobble")
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_steel", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Steel Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_steel.png",
|
|
|
|
uses = 150
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_steel", "default:steel_ingot")
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_bronze", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Bronze Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_bronze.png",
|
|
|
|
uses = 200
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_bronze", "default:bronze_ingot")
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_gold", {
|
2020-02-11 19:48:42 +01:00
|
|
|
description = S("Gold Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_gold.png",
|
|
|
|
uses = 250
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_gold", "default:gold_ingot")
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_mese", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Mese Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_mese.png",
|
|
|
|
uses = 300
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_mese", "default:mese_crystal")
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
throwing.register_bow(":throwing:bow_diamond", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Diamond Bow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
texture = "throwing_bow_diamond.png",
|
|
|
|
uses = 320
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_bow_craft("bow_diamond", "default:diamond")
|
2017-07-09 18:48:28 +02:00
|
|
|
|
|
|
|
local function get_setting(name)
|
|
|
|
local value = minetest.settings:get_bool("throwing.enable_"..name)
|
|
|
|
if value == true or value == nil then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-11 19:48:42 +01:00
|
|
|
local function register_arrow_craft(name, itemcraft, craft_quantity)
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "throwing:"..name.." "..tostring(craft_quantity or 1),
|
|
|
|
recipe = {
|
|
|
|
{itemcraft, "default:stick", "default:stick"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "throwing:"..name.." "..tostring(craft_quantity or 1),
|
|
|
|
recipe = {
|
|
|
|
{ "default:stick", "default:stick", itemcraft}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-08-30 18:10:58 +02:00
|
|
|
local last_punch_times = {}
|
|
|
|
|
|
|
|
local function arrow_punch(object, hitter, caps)
|
|
|
|
local time_from_last_punch = caps.full_punch_interval or 1
|
|
|
|
local hitter_name = hitter:get_player_name()
|
|
|
|
local player_name = object:get_player_name()
|
|
|
|
if last_punch_times[hitter_name] then
|
|
|
|
if last_punch_times[hitter_name][player_name] then
|
|
|
|
time_from_last_punch = os.difftime(os.time(), last_punch_times[hitter_name][player_name])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
last_punch_times[hitter_name] = {}
|
|
|
|
end
|
|
|
|
if time_from_last_punch >= (caps.full_punch_interval or 1) then
|
|
|
|
last_punch_times[hitter_name][player_name] = os.time()
|
|
|
|
end
|
|
|
|
object:punch(hitter, time_from_last_punch, caps)
|
|
|
|
end
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
if get_setting("arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow.png", "throwing_arrow.png", "throwing_arrow_back.png", "throwing_arrow_front.png", "throwing_arrow_2.png", "throwing_arrow.png"},
|
|
|
|
target = throwing.target_both,
|
|
|
|
allow_protected = true,
|
|
|
|
on_hit_sound = "throwing_arrow",
|
|
|
|
on_hit = function(self, pos, _, node, object, hitter)
|
|
|
|
if object then
|
2019-08-30 18:10:58 +02:00
|
|
|
arrow_punch(object, hitter, {
|
|
|
|
full_punch_interval = 0.7,
|
2019-08-29 18:17:49 +02:00
|
|
|
max_drop_level = 1,
|
2017-07-09 18:48:28 +02:00
|
|
|
damage_groups = {fleshy = 3}
|
|
|
|
})
|
|
|
|
elseif node then
|
|
|
|
if node.name == "mesecons_button:button_off" and minetest.get_modpath("mesecons_button") and minetest.get_modpath("mesecons") then
|
|
|
|
minetest.registered_items["mesecons_button:button_off"].on_rightclick(vector.round(pos), node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow", "default:steel_ingot", 16)
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if get_setting("golden_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_gold", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Golden Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_gold.png", "throwing_arrow_gold.png", "throwing_arrow_gold_back.png", "throwing_arrow_gold_front.png", "throwing_arrow_gold_2.png", "throwing_arrow_gold.png"},
|
|
|
|
target = throwing.target_object,
|
|
|
|
allow_protected = true,
|
|
|
|
on_hit_sound = "throwing_arrow",
|
|
|
|
on_hit = function(self, pos, _, _, object, hitter)
|
2019-08-30 18:10:58 +02:00
|
|
|
arrow_punch(object, hitter, {
|
|
|
|
full_punch_interval = 0.6,
|
2019-08-29 18:17:49 +02:00
|
|
|
max_drop_level = 1,
|
2017-07-09 18:48:28 +02:00
|
|
|
damage_groups = {fleshy = 5}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_gold", "default:gold_ingot", 16)
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
|
2019-08-29 18:08:20 +02:00
|
|
|
if get_setting("diamond_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_diamond", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Diamond Arrow"),
|
2019-08-29 18:08:20 +02:00
|
|
|
tiles = {"throwing_arrow_diamond.png", "throwing_arrow_diamond.png", "throwing_arrow_diamond_back.png", "throwing_arrow_diamond_front.png", "throwing_arrow_diamond_2.png", "throwing_arrow_diamond.png"},
|
|
|
|
target = throwing.target_object,
|
|
|
|
allow_protected = true,
|
|
|
|
on_hit_sound = "throwing_arrow",
|
|
|
|
on_hit = function(self, pos, _, _, object, hitter)
|
2019-08-30 18:10:58 +02:00
|
|
|
arrow_punch(object, hitter, {
|
|
|
|
full_punch_interval = 0.5,
|
2019-08-29 18:17:49 +02:00
|
|
|
max_drop_level = 1,
|
2019-08-29 23:46:12 +02:00
|
|
|
damage_groups = {fleshy = 7}
|
2019-08-29 18:08:20 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_diamond", "default:diamond", 4)
|
2019-08-29 18:08:20 +02:00
|
|
|
end
|
|
|
|
|
2017-07-09 18:48:28 +02:00
|
|
|
if get_setting("dig_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_dig", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Dig Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_dig.png", "throwing_arrow_dig.png", "throwing_arrow_dig_back.png", "throwing_arrow_dig_front.png", "throwing_arrow_dig_2.png", "throwing_arrow_dig.png"},
|
|
|
|
target = throwing.target_node,
|
|
|
|
on_hit_sound = "throwing_dig_arrow",
|
|
|
|
on_hit = function(self, pos, _, node, _, hitter)
|
|
|
|
return minetest.dig_node(pos)
|
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_dig", "default:pick_wood")
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if get_setting("dig_arrow_admin") then
|
|
|
|
throwing.register_arrow("throwing:arrow_dig_admin", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Admin Dig Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_dig.png", "throwing_arrow_dig.png", "throwing_arrow_dig_back.png", "throwing_arrow_dig_front.png", "throwing_arrow_dig_2.png", "throwing_arrow_dig.png"},
|
|
|
|
target = throwing.target_node,
|
|
|
|
on_hit = function(self, pos, _, node, _, _)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end,
|
|
|
|
groups = {not_in_creative_inventory = 1}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
if get_setting("teleport_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_teleport", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Teleport Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_teleport.png", "throwing_arrow_teleport.png", "throwing_arrow_teleport_back.png", "throwing_arrow_teleport_front.png", "throwing_arrow_teleport_2.png", "throwing_arrow_teleport.png"},
|
|
|
|
allow_protected = true,
|
|
|
|
on_hit_sound = "throwing_teleport_arrow",
|
|
|
|
on_hit = function(self, _, last_pos, _, _, hitter)
|
|
|
|
if minetest.get_node(last_pos).name ~= "air" then
|
2020-02-10 20:48:27 +01:00
|
|
|
minetest.log("warning", S("[throwing] BUG: node at @1 was not air", last_pos))
|
2017-07-09 18:48:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-10-28 09:17:36 +01:00
|
|
|
if minetest.settings:get_bool("throwing.allow_teleport_in_protected") == false then
|
2017-07-09 18:48:28 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2019-10-28 09:17:36 +01:00
|
|
|
hitter:move_to(last_pos)
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_teleport", "default:mese_crystal")
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if get_setting("fire_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_fire", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Torch Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_fire.png", "throwing_arrow_fire.png", "throwing_arrow_fire_back.png", "throwing_arrow_fire_front.png", "throwing_arrow_fire_2.png", "throwing_arrow_fire.png"},
|
|
|
|
on_hit_sound = "default_place_node",
|
|
|
|
on_hit = function(self, pos, last_pos, _, _, hitter)
|
|
|
|
if minetest.get_node(last_pos).name ~= "air" then
|
2020-02-10 20:48:27 +01:00
|
|
|
minetest.log(S("warning", "[throwing] BUG: node at @1 was not air", last_pos))
|
2017-07-09 18:48:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local r_pos = vector.round(pos)
|
|
|
|
local r_last_pos = vector.round(last_pos)
|
|
|
|
-- Make sure that only one key is different
|
|
|
|
if r_pos.y ~= r_last_pos.y then
|
|
|
|
r_last_pos.x = r_pos.x
|
|
|
|
r_last_pos.z = r_pos.z
|
|
|
|
elseif r_pos.x ~= r_last_pos.x then
|
|
|
|
r_last_pos.y = r_pos.y
|
|
|
|
r_last_pos.z = r_pos.z
|
|
|
|
end
|
|
|
|
minetest.registered_items["default:torch"].on_place(ItemStack("default:torch"), hitter,
|
|
|
|
{type="node", under=r_pos, above=r_last_pos})
|
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_fire", "default:torch")
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if get_setting("build_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_build", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Build Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_build.png", "throwing_arrow_build.png", "throwing_arrow_build_back.png", "throwing_arrow_build_front.png", "throwing_arrow_build_2.png", "throwing_arrow_build.png"},
|
|
|
|
on_hit_sound = "throwing_build_arrow",
|
2018-08-19 11:02:50 +02:00
|
|
|
on_hit = function(self, pos, last_pos, _, _, hitter)
|
2017-07-09 18:48:28 +02:00
|
|
|
if minetest.get_node(last_pos).name ~= "air" then
|
2020-02-10 20:48:27 +01:00
|
|
|
minetest.log(S("warning", "[throwing] BUG: node at @1 was not air", last_pos))
|
2017-07-09 18:48:28 +02:00
|
|
|
return
|
|
|
|
end
|
2018-08-19 11:02:50 +02:00
|
|
|
|
|
|
|
local r_pos = vector.round(pos)
|
|
|
|
local r_last_pos = vector.round(last_pos)
|
|
|
|
-- Make sure that only one key is different
|
|
|
|
if r_pos.y ~= r_last_pos.y then
|
|
|
|
r_last_pos.x = r_pos.x
|
|
|
|
r_last_pos.z = r_pos.z
|
|
|
|
elseif r_pos.x ~= r_last_pos.x then
|
|
|
|
r_last_pos.y = r_pos.y
|
|
|
|
r_last_pos.z = r_pos.z
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
2018-08-19 11:02:50 +02:00
|
|
|
minetest.registered_items["default:obsidian_glass"].on_place(ItemStack("default:obsidian_glass"), hitter,
|
|
|
|
{type="node", under=r_pos, above=r_last_pos})
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_build", "default:obsidian_glass")
|
2017-07-09 18:48:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if get_setting("drop_arrow") then
|
|
|
|
throwing.register_arrow("throwing:arrow_drop", {
|
2020-02-10 20:48:27 +01:00
|
|
|
description = S("Drop Arrow"),
|
2017-07-09 18:48:28 +02:00
|
|
|
tiles = {"throwing_arrow_drop.png", "throwing_arrow_drop.png", "throwing_arrow_drop_back.png", "throwing_arrow_drop_front.png", "throwing_arrow_drop_2.png", "throwing_arrow_drop.png"},
|
|
|
|
on_hit_sound = "throwing_build_arrow",
|
|
|
|
allow_protected = true,
|
|
|
|
on_throw = function(self, _, thrower, _, index, data)
|
|
|
|
local inventory = thrower:get_inventory()
|
|
|
|
if index >= inventory:get_size("main") or inventory:get_stack("main", index+1):get_name() == "" then
|
|
|
|
return false, "nothing to drop"
|
|
|
|
end
|
|
|
|
data.itemstack = inventory:get_stack("main", index+1)
|
|
|
|
data.index = index+1
|
|
|
|
thrower:get_inventory():set_stack("main", index+1, nil)
|
|
|
|
end,
|
|
|
|
on_hit = function(self, _, last_pos, _, _, hitter, data)
|
|
|
|
minetest.item_drop(ItemStack(data.itemstack), hitter, last_pos)
|
|
|
|
end,
|
2018-01-06 10:17:25 +01:00
|
|
|
on_hit_fails = function(self, _, thrower, data)
|
2019-10-28 09:17:36 +01:00
|
|
|
if not minetest.settings:get_bool("creative_mode") then
|
2017-07-09 18:48:28 +02:00
|
|
|
thrower:get_inventory():set_stack("main", data.index, data.itemstack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
2020-02-11 19:48:42 +01:00
|
|
|
register_arrow_craft("arrow_drop", "default:copper_ingot", 16)
|
2020-02-10 20:48:27 +01:00
|
|
|
end
|