From 4529b2edf8f8e78f1dc1aaf86038398304447b96 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 20:54:07 -0400 Subject: [PATCH 1/9] code improvements --- .luacheckrc | 15 +++++++++++++++ arrow.lua | 37 +++++++++++++++++++++++++++++++------ bitbucket-pipelines.yml | 13 +++++++++++++ init.lua | 25 ++++++++++++++++++------- nodes.lua | 2 +- requirements.txt | 1 + 6 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 .luacheckrc create mode 100644 bitbucket-pipelines.yml create mode 100644 requirements.txt diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..72a3d02 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,15 @@ +globals = { + 'x_bows' +} + +read_globals = { + 'minetest', + 'default', + 'vector', + 'table', + 'ItemStack', + 'armor', + 'playerphysics', + 'hb', + 'mesecon' +} diff --git a/arrow.lua b/arrow.lua index 0709520..a69d2b9 100644 --- a/arrow.lua +++ b/arrow.lua @@ -40,7 +40,17 @@ function x_bows.poison_effect(tick, time, time_left, arrow_obj, target_obj, old_ time_left = time_left + tick if time_left <= time then - minetest.after(tick, x_bows.poison_effect, tick, time, time_left, arrow_obj, target_obj, old_damage_texture_modifier, punch_def) + minetest.after( + tick, + x_bows.poison_effect, + tick, + time, + time_left, + arrow_obj, + target_obj, + old_damage_texture_modifier, + punch_def + ) elseif target_obj:is_player() then if x_bows.hbhunger then -- Reset HUD bar color @@ -135,7 +145,7 @@ minetest.register_entity('x_bows:arrow_entity', { }) end, - on_death = function(self, killer) + on_death = function(self, killer) --luacheck:ignore if not self._old_pos then self.object:remove() return @@ -221,7 +231,14 @@ minetest.register_entity('x_bows:arrow_entity', { if pointed_thing.type == 'object' and pointed_thing.ref ~= self.object and pointed_thing.ref:get_hp() > 0 - and ((pointed_thing.ref:is_player() and pointed_thing.ref:get_player_name() ~= self.user:get_player_name()) or (pointed_thing.ref:get_luaentity() and pointed_thing.ref:get_luaentity().physical and pointed_thing.ref:get_luaentity().name ~= '__builtin:item')) + and ( + (pointed_thing.ref:is_player() and pointed_thing.ref:get_player_name() ~= self.user:get_player_name()) + or ( + pointed_thing.ref:get_luaentity() + and pointed_thing.ref:get_luaentity().physical + and pointed_thing.ref:get_luaentity().name ~= '__builtin:item' + ) + ) and self.object:get_attach() == nil then if pointed_thing.ref:is_player() then @@ -402,12 +419,20 @@ minetest.register_entity('x_bows:arrow_entity', { -- @TODO missing `active` posion arrow check for player (see lua_ent below) if x_bows.hbhunger then -- Set poison bar - hb.change_hudbar(pointed_thing.ref, 'health', nil, nil, 'hbhunger_icon_health_poison.png', nil, 'hbhunger_bar_health_poison.png') + hb.change_hudbar( + pointed_thing.ref, + 'health', + nil, + nil, + 'hbhunger_icon_health_poison.png', + nil, + 'hbhunger_bar_health_poison.png' + ) end x_bows.poison_effect(1, 5, 0, self, pointed_thing.ref, old_damage_texture_modifier, punch_def) else - local lua_ent = pointed_thing.ref:get_luaentity() + -- local lua_ent = pointed_thing.ref:get_luaentity() -- if not lua_ent[self.arrow .. '_active'] or lua_ent[self.arrow .. '_active'] == 'false' then -- lua_ent[self.arrow .. '_active'] = true x_bows.poison_effect(1, 5, 0, self, pointed_thing.ref, old_damage_texture_modifier, punch_def) @@ -493,7 +518,7 @@ minetest.register_entity('x_bows:arrow_entity', { -- remove last arrow when too many already attached local children = {} - for k, object in ipairs(minetest.get_objects_inside_radius(pointed_thing.under, 1)) do + for _, object in ipairs(minetest.get_objects_inside_radius(pointed_thing.under, 1)) do if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == 'x_bows:arrow_entity' then table.insert(children ,object) end diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml new file mode 100644 index 0000000..872eea8 --- /dev/null +++ b/bitbucket-pipelines.yml @@ -0,0 +1,13 @@ +image: python:3.8 + +pipelines: + pull-requests: + "**": + - step: + name: Lint code + caches: + - pip + script: + - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - sudo apt install lua5.1 + - luacheck . diff --git a/init.lua b/init.lua index c244a93..0ab9546 100644 --- a/init.lua +++ b/init.lua @@ -32,7 +32,8 @@ function x_bows.register_bow(name, def) -- not charged bow minetest.register_tool(def.name, { - description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: ' .. (1 / def.crit_chance) * 100 .. '%'), + description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: ' + .. (1 / def.crit_chance) * 100 .. '%'), inventory_image = def.inventory_image or 'x_bows_bow_wood.png', -- on_use = function(itemstack, user, pointed_thing) -- end, @@ -44,7 +45,8 @@ function x_bows.register_bow(name, def) -- charged bow minetest.register_tool(def.name_charged, { - description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: ' .. (1 / def.crit_chance) * 100 .. '%'), + description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: ' + .. (1 / def.crit_chance) * 100 .. '%'), inventory_image = def.inventory_image_charged or 'x_bows_bow_wood_charged.png', on_use = x_bows.shoot, groups = {bow = 1, flammable = 1, not_in_creative_inventory = 1}, @@ -70,7 +72,9 @@ function x_bows.register_arrow(name, def) x_bows.registered_arrows[def.name] = def minetest.register_craftitem('x_bows:' .. name, { - description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Damage: ' .. def.tool_capabilities.damage_groups.fleshy) .. '\n' .. minetest.colorize('#00BFFF', 'Charge Time: ' .. def.tool_capabilities.full_punch_interval .. 's'), + description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Damage: ' + .. def.tool_capabilities.damage_groups.fleshy) .. '\n' .. minetest.colorize('#00BFFF', 'Charge Time: ' + .. def.tool_capabilities.full_punch_interval .. 's'), inventory_image = def.inventory_image, groups = {arrow = 1, flammable = 1} }) @@ -101,7 +105,7 @@ function x_bows.load(itemstack, user, pointed_thing) end end - for k, st in ipairs(inv_list) do + for _, st in ipairs(inv_list) do if not st:is_empty() and x_bows.registered_arrows[st:get_name()] then table.insert(itemstack_arrows, st) end @@ -154,7 +158,7 @@ function x_bows.load(itemstack, user, pointed_thing) end end -function x_bows.shoot(itemstack, user, pointed_thing) +function x_bows.shoot(itemstack, user, pointed_thing) --luacheck:ignore local time_shoot = minetest.get_us_time(); local meta = itemstack:get_meta() local meta_arrow = meta:get_string('arrow') @@ -196,13 +200,20 @@ function x_bows.shoot(itemstack, user, pointed_thing) 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}, 'x_bows:arrow_entity', minetest.serialize(staticdata)) + local obj = minetest.add_entity( + { + x = pos.x, + y = pos.y + 1.5, + z = pos.z + }, + 'x_bows:arrow_entity', + minetest.serialize(staticdata) + ) if not obj then return itemstack end - local lua_ent = obj:get_luaentity() local strength_multiplier = tflp if strength_multiplier > _tool_capabilities.full_punch_interval then diff --git a/nodes.lua b/nodes.lua index 9c8200c..6dfe303 100644 --- a/nodes.lua +++ b/nodes.lua @@ -32,7 +32,7 @@ minetest.register_node('x_bows:target', { groups = {snappy=3, flammable=4, fall_damage_add_percent=-30}, sounds = default.node_sound_leaves_defaults(), mesecons = {receptor = {state = 'off'}}, - on_timer = function (pos, elapsed) + on_timer = function (pos, elapsed) --luacheck:ignore mesecon.receptor_off(pos) return false end, diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9c289ad --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +luarocks \ No newline at end of file From 5ad428f9d3441be6cc81166bc209a509a5252cce Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 20:56:39 -0400 Subject: [PATCH 2/9] code improvements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9c289ad..590e915 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -luarocks \ No newline at end of file +luarocks>=3.9.1 \ No newline at end of file From b778cc268ca185a328e140ebe303ee9a358b52c0 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 20:59:18 -0400 Subject: [PATCH 3/9] code improvements --- bitbucket-pipelines.yml | 2 ++ requirements.txt | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 requirements.txt diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 872eea8..4679ba2 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -9,5 +9,7 @@ pipelines: - pip script: - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - sudo apt install luarocks - sudo apt install lua5.1 + - luarocks install luacheck - luacheck . diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 590e915..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -luarocks>=3.9.1 \ No newline at end of file From 658ece3b5e5325f7019fa03ec96b9c1b0a1a8f69 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 21:00:42 -0400 Subject: [PATCH 4/9] code improvements --- bitbucket-pipelines.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 4679ba2..dffb86d 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -8,7 +8,6 @@ pipelines: caches: - pip script: - - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - sudo apt install luarocks - sudo apt install lua5.1 - luarocks install luacheck From d766a04d7c4da4bf3240d3071dbfcfc2de2d5bfe Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 21:03:07 -0400 Subject: [PATCH 5/9] code improvements --- bitbucket-pipelines.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index dffb86d..7d0e10d 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -1,12 +1,10 @@ -image: python:3.8 +image: atlassian/default-image:3 pipelines: pull-requests: "**": - step: name: Lint code - caches: - - pip script: - sudo apt install luarocks - sudo apt install lua5.1 From 7b894ca32dbfac2478c03fe65d8e271f357e6790 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 21:04:05 -0400 Subject: [PATCH 6/9] code improvements --- bitbucket-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 7d0e10d..bec61fd 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -6,7 +6,7 @@ pipelines: - step: name: Lint code script: - - sudo apt install luarocks - - sudo apt install lua5.1 + - apt install luarocks + - apt install lua5.1 - luarocks install luacheck - luacheck . From fa6d8becda8e6fb87bc866ed411795818c340511 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 21:06:46 -0400 Subject: [PATCH 7/9] code improvements --- bitbucket-pipelines.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index bec61fd..f194e6f 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -6,7 +6,8 @@ pipelines: - step: name: Lint code script: - - apt install luarocks - - apt install lua5.1 + - apt-get update + - apt-get -y install lua5.1 + - apt-get -y install luarocks - luarocks install luacheck - luacheck . From fe58ff51977fa96af9a9a9556606979c5dc6baf6 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 21:07:47 -0400 Subject: [PATCH 8/9] code improvements --- nodes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes.lua b/nodes.lua index 6dfe303..9c8200c 100644 --- a/nodes.lua +++ b/nodes.lua @@ -32,7 +32,7 @@ minetest.register_node('x_bows:target', { groups = {snappy=3, flammable=4, fall_damage_add_percent=-30}, sounds = default.node_sound_leaves_defaults(), mesecons = {receptor = {state = 'off'}}, - on_timer = function (pos, elapsed) --luacheck:ignore + on_timer = function (pos, elapsed) mesecon.receptor_off(pos) return false end, From 62c39d1145a84f7beee5263998b08c765755aab7 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 5 Oct 2022 21:26:43 -0400 Subject: [PATCH 9/9] add player_monoids support --- .luacheckrc | 3 ++- init.lua | 10 ++++++++-- mod.conf | 2 +- nodes.lua | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 72a3d02..076aa9e 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -11,5 +11,6 @@ read_globals = { 'armor', 'playerphysics', 'hb', - 'mesecon' + 'mesecon', + 'player_monoids' } diff --git a/init.lua b/init.lua index 0ab9546..c014443 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,8 @@ x_bows = { creative = minetest.settings:get_bool('creative_mode') or false, mesecons = minetest.get_modpath('mesecons'), hbhunger = minetest.get_modpath('hbhunger'), + playerphysics = minetest.get_modpath('playerphysics'), + player_monoids = minetest.get_modpath('player_monoids'), registered_arrows = {}, registered_bows = {}, player_bow_sneak = {}, @@ -339,15 +341,19 @@ minetest.register_globalstep(function(dtime) end if item == 'x_bows:bow_wood_charged' and not x_bows.player_bow_sneak[name].sneak then - if minetest.get_modpath('playerphysics') then + if x_bows.playerphysics then playerphysics.add_physics_factor(player, 'speed', 'x_bows:bow_wood_charged', 0.25) + elseif x_bows.player_monoids then + player_monoids.speed:add_change(player, 0.25, 'x_bows:bow_wood_charged') end x_bows.player_bow_sneak[name].sneak = true player:set_fov(0.9, true, 0.4) elseif item ~= 'x_bows:bow_wood_charged' and x_bows.player_bow_sneak[name].sneak then - if minetest.get_modpath('playerphysics') then + if x_bows.playerphysics then playerphysics.remove_physics_factor(player, 'speed', 'x_bows:bow_wood_charged') + elseif x_bows.player_monoids then + player_monoids.speed:del_change(player, 'x_bows:bow_wood_charged') end x_bows.player_bow_sneak[name].sneak = false diff --git a/mod.conf b/mod.conf index f5c7e0d..58df3cf 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = x_bows description = Adds bow and arrows to Minetest. depends = -optional_depends = default, farming, 3d_armor, hbhunger, mesecons, playerphysics +optional_depends = default, farming, 3d_armor, hbhunger, mesecons, playerphysics, player_monoids min_minetest_version = 5.0 \ No newline at end of file diff --git a/nodes.lua b/nodes.lua index 9c8200c..6dfe303 100644 --- a/nodes.lua +++ b/nodes.lua @@ -32,7 +32,7 @@ minetest.register_node('x_bows:target', { groups = {snappy=3, flammable=4, fall_damage_add_percent=-30}, sounds = default.node_sound_leaves_defaults(), mesecons = {receptor = {state = 'off'}}, - on_timer = function (pos, elapsed) + on_timer = function (pos, elapsed) --luacheck:ignore mesecon.receptor_off(pos) return false end,