1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Fix number of tool uses being off by 1..32767 (#11110)

This commit is contained in:
Wuzzy 2021-10-31 22:33:33 +00:00 committed by GitHub
parent 38ba813c55
commit 6910c8d920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 229 additions and 71 deletions

View file

@ -16,11 +16,11 @@ Tool types:
Tool materials:
* Dirt: dig nodes of rating 3, one use only
* Wood: dig nodes of rating 3
* Stone: dig nodes of rating 3 or 2
* Steel: dig nodes of rating 3, 2 or 1
* Mese: dig "everything" instantly
* n-Uses: can be used n times before breaking
]]
-- The hand
@ -92,20 +92,6 @@ minetest.register_tool("basetools:pick_mese", {
-- Pickaxes: Dig cracky
--
-- This should break after only 1 use
minetest.register_tool("basetools:pick_dirt", {
description = "Dirt Pickaxe".."\n"..
"Digs cracky=3".."\n"..
"1 use only",
inventory_image = "basetools_dirtpick.png",
tool_capabilities = {
max_drop_level=0,
groupcaps={
cracky={times={[3]=2.00}, uses=1, maxlevel=0}
},
},
})
minetest.register_tool("basetools:pick_wood", {
description = "Wooden Pickaxe".."\n"..
"Digs cracky=3",
@ -348,3 +334,31 @@ minetest.register_tool("basetools:dagger_steel", {
damage_groups = {fleshy=2},
}
})
-- Test tool uses and punch_attack_uses
local uses = { 1, 2, 3, 5, 10, 50, 100, 1000, 10000, 65535 }
for i=1, #uses do
local u = uses[i]
local color = string.format("#FF00%02X", math.floor(((i-1)/#uses) * 255))
minetest.register_tool("basetools:pick_uses_"..string.format("%05d", u), {
description = u.."-Uses Pickaxe".."\n"..
"Digs cracky=3",
inventory_image = "basetools_steelpick.png^[colorize:"..color..":127",
tool_capabilities = {
max_drop_level=0,
groupcaps={
cracky={times={[3]=0.1, [2]=0.2, [1]=0.3}, uses=u, maxlevel=0}
},
},
})
minetest.register_tool("basetools:sword_uses_"..string.format("%05d", u), {
description = u.."-Uses Sword".."\n"..
"Damage: fleshy=1",
inventory_image = "basetools_woodsword.png^[colorize:"..color..":127",
tool_capabilities = {
damage_groups = {fleshy=1},
punch_attack_uses = u,
},
})
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 B

View file

@ -114,6 +114,59 @@ minetest.register_chatcommand("detach", {
end,
})
minetest.register_chatcommand("use_tool", {
params = "(dig <group> <leveldiff>) | (hit <damage_group> <time_from_last_punch>) [<uses>]",
description = "Apply tool wear a number of times, as if it were used for digging",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "No player."
end
local mode, group, level, uses = string.match(param, "([a-z]+) ([a-z0-9]+) (-?%d+) (%d+)")
if not mode then
mode, group, level = string.match(param, "([a-z]+) ([a-z0-9]+) (-?%d+)")
uses = 1
end
if not mode or not group or not level then
return false
end
if mode ~= "dig" and mode ~= "hit" then
return false
end
local tool = player:get_wielded_item()
local caps = tool:get_tool_capabilities()
if not caps or tool:get_count() == 0 then
return false, "No tool in hand."
end
local actual_uses = 0
for u=1, uses do
local wear = tool:get_wear()
local dp
if mode == "dig" then
dp = minetest.get_dig_params({[group]=3, level=level}, caps, wear)
else
dp = minetest.get_hit_params({[group]=100}, caps, level, wear)
end
tool:add_wear(dp.wear)
actual_uses = actual_uses + 1
if tool:get_count() == 0 then
break
end
end
player:set_wielded_item(tool)
if tool:get_count() == 0 then
return true, string.format("Tool used %d time(s). "..
"The tool broke after %d use(s).", uses, actual_uses)
else
local wear = tool:get_wear()
return true, string.format("Tool used %d time(s). "..
"Final wear=%d", uses, wear)
end
end,
})
-- Use this to test waypoint capabilities
minetest.register_chatcommand("test_waypoints", {
params = "[change_immediate]",