forked from mtcontrib/minetest-toolranks
Compare commits
2 Commits
nalc-1.2.0
...
v1.2
Author | SHA1 | Date | |
---|---|---|---|
d000b4b20f | |||
17994ed8db |
13
.github/workflows/build.yml
vendored
Normal file
13
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: Build
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: apt
|
||||||
|
run: sudo apt-get install -y luarocks
|
||||||
|
- name: luacheck install
|
||||||
|
run: luarocks install --local luacheck
|
||||||
|
- name: luacheck run
|
||||||
|
run: $HOME/.luarocks/bin/luacheck ./
|
18
.luacheckrc
Normal file
18
.luacheckrc
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
unused_args = false
|
||||||
|
allow_defined_top = true
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"minetest",
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
string = {fields = {"split"}},
|
||||||
|
table = {fields = {"copy", "getn"}},
|
||||||
|
|
||||||
|
-- Builtin
|
||||||
|
"vector", "ItemStack",
|
||||||
|
"dump", "DIR_DELIM", "VoxelArea", "Settings",
|
||||||
|
|
||||||
|
-- MTG
|
||||||
|
"default", "sfinv", "creative",
|
||||||
|
}
|
@ -13,7 +13,7 @@ If so, to support this mod, add this code to your mod, after your tool's code:
|
|||||||
if minetest.get_modpath("toolranks") then
|
if minetest.get_modpath("toolranks") then
|
||||||
minetest.override_item("mymod:mytool", {
|
minetest.override_item("mymod:mytool", {
|
||||||
original_description = "My Tool",
|
original_description = "My Tool",
|
||||||
description = toolranks.create_description("My Tool", 0, 1),
|
description = toolranks.create_description("My Tool"),
|
||||||
after_use = toolranks.new_afteruse
|
after_use = toolranks.new_afteruse
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
25
init.lua
25
init.lua
@ -32,12 +32,19 @@ function toolranks.get_tool_type(description)
|
|||||||
elseif string.find(d, "sword") then
|
elseif string.find(d, "sword") then
|
||||||
return "sword"
|
return "sword"
|
||||||
else
|
else
|
||||||
return "tool"
|
return "tool"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function toolranks.create_description(name, uses, level)
|
function toolranks.get_level(uses)
|
||||||
|
if type(uses) == "number" and uses > 0 then
|
||||||
|
return math.min(max_level, math.floor(uses / level_digs))
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function toolranks.create_description(name, uses)
|
||||||
local description = name
|
local description = name
|
||||||
local tooltype = toolranks.get_tool_type(description)
|
local tooltype = toolranks.get_tool_type(description)
|
||||||
local newdesc = S(
|
local newdesc = S(
|
||||||
@ -45,18 +52,14 @@ function toolranks.create_description(name, uses, level)
|
|||||||
toolranks.colors.green,
|
toolranks.colors.green,
|
||||||
description,
|
description,
|
||||||
toolranks.colors.gold,
|
toolranks.colors.gold,
|
||||||
(level or 1),
|
toolranks.get_level(uses),
|
||||||
S(tooltype),
|
S(tooltype),
|
||||||
toolranks.colors.grey,
|
toolranks.colors.grey,
|
||||||
(uses or 0)
|
(type(uses) == "number" and uses or 0)
|
||||||
)
|
)
|
||||||
return newdesc
|
return newdesc
|
||||||
end
|
end
|
||||||
|
|
||||||
function toolranks.get_level(uses)
|
|
||||||
return math.min(max_level, math.floor(uses / level_digs))
|
|
||||||
end
|
|
||||||
|
|
||||||
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
||||||
local itemmeta = itemstack:get_meta()
|
local itemmeta = itemstack:get_meta()
|
||||||
local itemdef = itemstack:get_definition()
|
local itemdef = itemstack:get_definition()
|
||||||
@ -107,7 +110,6 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|||||||
to_player = user:get_player_name(),
|
to_player = user:get_player_name(),
|
||||||
gain = 2.0,
|
gain = 2.0,
|
||||||
})
|
})
|
||||||
itemmeta:set_string("lastlevel", level)
|
|
||||||
|
|
||||||
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
||||||
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
||||||
@ -125,7 +127,8 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|||||||
itemmeta:set_tool_capabilities(caps)
|
itemmeta:set_tool_capabilities(caps)
|
||||||
end
|
end
|
||||||
|
|
||||||
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes, level))
|
itemmeta:set_string("lastlevel", level)
|
||||||
|
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes))
|
||||||
itemstack:add_wear(digparams.wear)
|
itemstack:add_wear(digparams.wear)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -135,7 +138,7 @@ function toolranks.add_tool(name)
|
|||||||
local desc = ItemStack(name):get_definition().description
|
local desc = ItemStack(name):get_definition().description
|
||||||
minetest.override_item(name, {
|
minetest.override_item(name, {
|
||||||
original_description = desc,
|
original_description = desc,
|
||||||
description = toolranks.create_description(desc, 0, 1),
|
description = toolranks.create_description(desc),
|
||||||
after_use = toolranks.new_afteruse
|
after_use = toolranks.new_afteruse
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user