code lint and add player_monoids support
This commit is contained in:
commit
8f21c829f2
|
@ -0,0 +1,16 @@
|
|||
globals = {
|
||||
'x_bows'
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
'minetest',
|
||||
'default',
|
||||
'vector',
|
||||
'table',
|
||||
'ItemStack',
|
||||
'armor',
|
||||
'playerphysics',
|
||||
'hb',
|
||||
'mesecon',
|
||||
'player_monoids'
|
||||
}
|
37
arrow.lua
37
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
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
image: atlassian/default-image:3
|
||||
|
||||
pipelines:
|
||||
pull-requests:
|
||||
"**":
|
||||
- step:
|
||||
name: Lint code
|
||||
script:
|
||||
- apt-get update
|
||||
- apt-get -y install lua5.1
|
||||
- apt-get -y install luarocks
|
||||
- luarocks install luacheck
|
||||
- luacheck .
|
35
init.lua
35
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 = {},
|
||||
|
@ -32,7 +34,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 +47,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 +74,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 +107,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 +160,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 +202,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
|
||||
|
@ -328,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
|
||||
|
|
2
mod.conf
2
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
|
|
@ -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,
|
||||
|
|
Ŝarĝante…
Reference in New Issue