From 76e3be56acdc789b33aa4b538fda7fd028ed0618 Mon Sep 17 00:00:00 2001 From: MultiCraft Date: Thu, 1 Feb 2024 01:27:27 +0100 Subject: [PATCH] Nextgen_bows: update --- MODS/nextgen_bows/arrow.lua | 16 +++---- MODS/nextgen_bows/crosshair.lua | 25 ----------- MODS/nextgen_bows/init.lua | 78 ++++++++++++++------------------- MODS/nextgen_bows/items.lua | 21 +++++---- 4 files changed, 51 insertions(+), 89 deletions(-) delete mode 100644 MODS/nextgen_bows/crosshair.lua diff --git a/MODS/nextgen_bows/arrow.lua b/MODS/nextgen_bows/arrow.lua index 47d73b5ba..820e8e1df 100644 --- a/MODS/nextgen_bows/arrow.lua +++ b/MODS/nextgen_bows/arrow.lua @@ -28,7 +28,7 @@ minetest.register_entity("nextgen_bows:arrow_entity", { selectionbox = {0, 0, 0, 0, 0, 0}, physical = false, textures = {"air"}, - hp_max = 0.5 + hp_max = 1 }, on_activate = function(self, staticdata) @@ -58,10 +58,6 @@ minetest.register_entity("nextgen_bows:arrow_entity", { self._tflp = _staticdata._tflp self._tool_capabilities = _staticdata._tool_capabilities self._is_critical_hit = _staticdata.is_critical_hit - - self.object:set_properties({ - textures = {"nextgen_bows:arrow_node"} - }) end, on_death = function(self) @@ -151,12 +147,12 @@ minetest.register_entity("nextgen_bows:arrow_entity", { minetest.sound_play("nextgen_bows_arrow_successful_hit", { to_player = self.user:get_player_name(), gain = 0.3 - }) + }, true) else minetest.sound_play("nextgen_bows_arrow_hit", { to_player = self.user:get_player_name(), gain = 0.6 - }) + }, true) end self.object:set_velocity({x = 0, y = 0, z = 0}) @@ -195,7 +191,7 @@ minetest.register_entity("nextgen_bows:arrow_entity", { pointed_ref:add_velocity({ x = dir.x * knockback * -1, - y = 7, + y = 1, z = dir.z * knockback * -1 }) @@ -208,7 +204,7 @@ minetest.register_entity("nextgen_bows:arrow_entity", { }, { x = dir.x * -1, - y = 7, + y = 1, z = dir.z * -1 } ) @@ -288,7 +284,7 @@ minetest.register_entity("nextgen_bows:arrow_entity", { pos = pointed_thing.under, gain = 0.6, max_hear_distance = 16 - }) + }, true) return end diff --git a/MODS/nextgen_bows/crosshair.lua b/MODS/nextgen_bows/crosshair.lua deleted file mode 100644 index c105a0cf7..000000000 --- a/MODS/nextgen_bows/crosshair.lua +++ /dev/null @@ -1,25 +0,0 @@ -local hud_id - --- Note: This function won't work with multiple different players -local function update_hud(player) - local stack = player:get_wielded_item() - if stack:get_name():sub(1, 17) == "nextgen_bows:bow_" then - if not hud_id then - hud_id = player:hud_add({ - hud_elem_type = "image", - position = {x = 0.5, y = 0.5}, - text = "crosshair.png", - scale = {x = 0.75, y = 0.75} - }) - end - elseif hud_id then - player:hud_remove(hud_id) - hud_id = nil - end -end - -if minetest.localplayer then - sscsm.every(0.125, update_hud, minetest.localplayer) -else - return update_hud -end diff --git a/MODS/nextgen_bows/init.lua b/MODS/nextgen_bows/init.lua index e6d1e93f7..557455c0b 100644 --- a/MODS/nextgen_bows/init.lua +++ b/MODS/nextgen_bows/init.lua @@ -31,11 +31,11 @@ function nextgen_bows.register_bow(name, def) -- charged bow minetest.register_tool(def.name_charged, { - description = def.description, + description = def.description_charged or def.description, inventory_image = def.inventory_image_charged or "nextgen_bows_bow_wood_charged.png", on_use = nextgen_bows.shoot, groups = {bow = 1, flammable = 1, wieldview = 1, not_in_creative_inventory = 1}, - range = 0 -- player can"t interact with charged bow + range = 0 -- player can't interact with charged bow }) -- recipes @@ -77,6 +77,7 @@ function nextgen_bows.load(itemstack, user, pointed_thing) local inv = user:get_inventory() local inv_list = inv:get_list("main") local bow_name = itemstack:get_name() + local bow_def = nextgen_bows.registered_bows[bow_name .. "_charged"] local itemstack_arrows = {} @@ -99,44 +100,46 @@ function nextgen_bows.load(itemstack, user, pointed_thing) local itemstack_arrow = itemstack_arrows[1] if itemstack_arrow and bow_def then - local _tool_capabilities = nextgen_bows.registered_arrows[itemstack_arrow:get_name()].tool_capabilities + local arrow_name = itemstack_arrow:get_name() + local bow_name_charged = nextgen_bows.registered_arrows[arrow_name].charded_bow or "nextgen_bows:bow_wood_charged" + local _tool_capabilities = nextgen_bows.registered_arrows[arrow_name].tool_capabilities - minetest.after(0, function(v_user, v_bow_name, v_time_load) + minetest.after(0, function(v_user, v_bow_name, v_bow_name_charged, v_time_load) local wielded_item = v_user:get_wielded_item() local wielded_item_name = wielded_item:get_name() if wielded_item_name == v_bow_name then local meta = wielded_item:get_meta() - meta:set_string("arrow", itemstack_arrow:get_name()) + meta:set_string("arrow", arrow_name) meta:set_string("time_load", tostring(v_time_load)) - wielded_item:set_name(v_bow_name .. "_charged") + wielded_item:set_name(v_bow_name_charged) v_user:set_wielded_item(wielded_item) if not minetest.is_creative_enabled(user:get_player_name()) then - inv:remove_item("main", itemstack_arrow:get_name()) + inv:remove_item("main", arrow_name) end end - end, user, bow_name, time_load) + end, user, bow_name, bow_name_charged, time_load) -- sound plays when charge time reaches full punch interval time -- @TODO: find a way to prevent this from playing when not fully charged - minetest.after(_tool_capabilities.full_punch_interval, function(v_user, v_bow_name) + minetest.after(_tool_capabilities.full_punch_interval, function(v_user, v_bow_name_charged) local wielded_item = v_user:get_wielded_item() local wielded_item_name = wielded_item:get_name() - if wielded_item_name == v_bow_name .. "_charged" then + if wielded_item_name == v_bow_name_charged then minetest.sound_play("nextgen_bows_bow_loaded", { to_player = user:get_player_name(), gain = 0.6 - }) + }, true) end - end, user, bow_name) + end, user, bow_name_charged) minetest.sound_play("nextgen_bows_bow_load", { to_player = user:get_player_name(), gain = 0.6 - }) + }, true) return itemstack end @@ -149,15 +152,20 @@ function nextgen_bows.shoot(itemstack, user) local time_load = tonumber(meta:get_string("time_load")) or 0 local tflp = max((time_shoot - time_load) / 1000000, 0) - if not nextgen_bows.registered_arrows[meta_arrow] then + local arrow_meta = nextgen_bows.registered_arrows[meta_arrow] + + if not arrow_meta then return itemstack end local bow_name_charged = itemstack:get_name() - local bow_name = nextgen_bows.registered_bows[bow_name_charged].name - local uses = nextgen_bows.registered_bows[bow_name_charged].uses - local crit_chance = nextgen_bows.registered_bows[bow_name_charged].crit_chance - local _tool_capabilities = nextgen_bows.registered_arrows[meta_arrow].tool_capabilities + local bow_def = nextgen_bows.registered_bows[bow_name_charged] + + local bow_name = bow_def.uncharged or bow_def.name + local uses = bow_def.uses + local crit_chance = bow_def.crit_chance + local _tool_capabilities = arrow_meta.tool_capabilities + local entity_node = arrow_meta.entity_node local staticdata = { arrow = meta_arrow, @@ -184,12 +192,17 @@ function nextgen_bows.shoot(itemstack, user) local pos = user:get_pos() local dir = user:get_look_dir() - local obj = minetest.add_entity({x = pos.x, y = pos.y + 1.5, z = pos.z}, "nextgen_bows:arrow_entity", minetest.serialize(staticdata)) + local arrow_pos = {x = pos.x, y = pos.y + 1.5, z = pos.z} + local obj = minetest.add_entity(arrow_pos, "nextgen_bows:arrow_entity", minetest.serialize(staticdata)) if not obj then return itemstack end + obj:set_properties({ + textures = {entity_node} + }) + local strength_multiplier = tflp if strength_multiplier > _tool_capabilities.full_punch_interval then @@ -210,7 +223,7 @@ function nextgen_bows.shoot(itemstack, user) gain = 0.3, pos = user:get_pos(), max_hear_distance = 10 - }) + }, true) return itemstack end @@ -273,30 +286,5 @@ minetest.register_on_leaveplayer(function(player) end) local path = minetest.get_modpath("nextgen_bows") - dofile(path .. "/arrow.lua") dofile(path .. "/items.lua") - -if minetest.is_singleplayer() and (PLATFORM == "Android" or PLATFORM == "iOS") and - minetest.settings:get_bool("touchtarget") then - local update_hud = dofile(path .. "/crosshair.lua") - local function poll() - -- Since this is singleplayer there should only be one player - local player = minetest.get_connected_players()[1] - if player then - update_hud(player) - end - minetest.after(0.125, poll) - end - - minetest.after(0.125, poll) -elseif minetest.global_exists("sscsm") then - sscsm.register({ - name = "nextgen_bows", - file = path .. "/crosshair.lua", - is_enabled_for = function(name) - local info = minetest.get_player_information(name) - return info.platform == "Android" or info.platform == "iOS" - end - }) -end diff --git a/MODS/nextgen_bows/items.lua b/MODS/nextgen_bows/items.lua index 9a08083f9..cffc8e092 100644 --- a/MODS/nextgen_bows/items.lua +++ b/MODS/nextgen_bows/items.lua @@ -2,6 +2,7 @@ local S = minetest.get_translator("nextgen_bows") nextgen_bows.register_bow("bow_wood", { description = S("Bow"), + description_charged = S("Bow with Arrow"), uses = 385, -- `crit_chance` 10% chance, 5 is 20% chance -- (1 / crit_chance) * 100 = % chance @@ -9,35 +10,36 @@ nextgen_bows.register_bow("bow_wood", { recipe = { {"", "group:wood", "farming:string"}, {"group:wood", "", "farming:string"}, - {"", "group:wood", "farming:string"}, + {"", "group:wood", "farming:string"} } }) nextgen_bows.register_arrow("arrow", { description = S("Arrow"), inventory_image = "nextgen_bows_arrow.png", + entity_node = "nextgen_bows:arrow_node", craft = { {"default:flint"}, {"default:stick"}, - {"default:paper"} + {"group:feather"} }, tool_capabilities = { full_punch_interval = 1, max_drop_level = 0, - damage_groups = {fleshy=2} + damage_groups = {fleshy = 2} } }) minetest.register_craft({ type = "fuel", recipe = "nextgen_bows:bow_wood", - burntime = 3, + burntime = 3 }) minetest.register_craft({ type = "fuel", recipe = "nextgen_bows:arrow", - burntime = 1, + burntime = 1 }) minetest.register_craftitem("nextgen_bows:arrow_node", { @@ -45,7 +47,8 @@ minetest.register_craftitem("nextgen_bows:arrow_node", { groups = {not_in_creative_inventory = 1} }) -minetest.register_alias("throwing:bow", "nextgen_bows:bow_wood") -minetest.register_alias("throwing:bow_arrow", "nextgen_bows:bow_wood_charged") -minetest.register_alias("throwing:arrow", "nextgen_bows:arrow") -minetest.register_alias("throwing:arrow_item", "nextgen_bows:arrow_node") +minetest.register_craft({ + type = "fuel", + recipe = "nextgen_bows:arrow", + burntime = 15 +})