From 2faa311546cd01073f44544d4da487e794be4016 Mon Sep 17 00:00:00 2001 From: epCode Date: Fri, 19 Mar 2021 14:48:08 -0700 Subject: [PATCH] make loading crossbow work like MC --- mods/ITEMS/mcl_bows/crossbow.lua | 71 +++++++++++++++++--------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index 9c297f591..be283650c 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -136,7 +136,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula }) minetest.register_tool("mcl_bows:loaded_crossbow", { - description = S("Crossbow (loaded)"), + description = S("Crossbow"), _tt_help = S("Launches arrows"), _doc_items_durability = BOW_DURABILITY, inventory_image = "mcl_bows_crossbow_3.png", @@ -144,7 +144,7 @@ minetest.register_tool("mcl_bows:loaded_crossbow", { stack_max = 1, range = 4, -- Trick to disable digging as well - on_use = function() return end, + --on_use = function() return end, on_place = function(itemstack, player, pointed_thing) if pointed_thing and pointed_thing.type == "node" then -- Call on_rightclick if the pointed node defines it @@ -230,7 +230,41 @@ end controls.register_on_release(function(player, key) if key~="RMB" then return end - reset_bows(player) + if player:get_wielded_item():get_name() == "mcl_bows:crossbow_2" then + local wielditem = player:get_wielded_item() + minetest.sound_play("mcl_bows_crossbow_load", {pos=playerpos, max_hear_distance=16}, true) + wielditem:set_name("mcl_bows:loaded_crossbow") + local arrow_stack, arrow_stack_id = get_arrow(player) + local arrow_itemstring + local has_infinity_enchantment = mcl_enchanting.has_enchantment(player:get_wielded_item(), "infinity") + local infinity_used = false + + if minetest.is_creative_enabled(player:get_player_name()) then + if arrow_stack then + arrow_itemstring = arrow_stack:get_name() + else + arrow_itemstring = "mcl_bows:arrow" + end + else + if not arrow_stack then + return false + end + arrow_itemstring = arrow_stack:get_name() + if has_infinity_enchantment and minetest.get_item_group(arrow_itemstring, "ammo_bow_regular") > 0 then + infinity_used = true + else + arrow_stack:take_item() + end + local inv = player:get_inventory() + inv:set_stack("main", arrow_stack_id, arrow_stack) + end + player:set_wielded_item(wielditem) + if not arrow_itemstring then + return false + end + else + reset_bows(player) + end end) controls.register_on_press(function(player, key) @@ -333,37 +367,6 @@ controls.register_on_hold(function(player, key, time) elseif wielditem:get_name() == "mcl_bows:crossbow_1" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then minetest.sound_play("mcl_bows_crossbow_drawback_2", {pos=playerpos, max_hear_distance=16}, true) wielditem:set_name("mcl_bows:crossbow_2") - if minetest.get_us_time() - bow_load[name] >= 1000000 then - minetest.sound_play("mcl_bows_crossbow_load", {pos=playerpos, max_hear_distance=16}, true) - wielditem:set_name("mcl_bows:loaded_crossbow") - local arrow_stack, arrow_stack_id = get_arrow(player) - local arrow_itemstring - local has_infinity_enchantment = mcl_enchanting.has_enchantment(player:get_wielded_item(), "infinity") - local infinity_used = false - - if minetest.is_creative_enabled(player:get_player_name()) then - if arrow_stack then - arrow_itemstring = arrow_stack:get_name() - else - arrow_itemstring = "mcl_bows:arrow" - end - else - if not arrow_stack then - return false - end - arrow_itemstring = arrow_stack:get_name() - if has_infinity_enchantment and minetest.get_item_group(arrow_itemstring, "ammo_bow_regular") > 0 then - infinity_used = true - else - arrow_stack:take_item() - end - local inv = player:get_inventory() - inv:set_stack("main", arrow_stack_id, arrow_stack) - end - if not arrow_itemstring then - return false - end - end elseif wielditem:get_name() == "mcl_bows:crossbow_1_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then minetest.sound_play("mcl_bows_crossbow_drawback_2", {pos=playerpos, max_hear_distance=16}, true) wielditem:set_name("mcl_bows:crossbow_2_enchanted")