Add disable_repair group to prevent tool repair (#7381)
authorWuzzy <wuzzy2@mail.ru>
Tue, 16 Oct 2018 04:25:34 +0000 (06:25 +0200)
committerParamat <paramat@users.noreply.github.com>
Tue, 16 Oct 2018 04:25:34 +0000 (05:25 +0100)
doc/lua_api.txt
games/minimal/mods/experimental/init.lua
src/craftdef.cpp

index 19d6482ae2401d28e2ed52777d6b18cce8396dd2..b079ac82261e6be3eb010cca7e76a63d89b37872 100644 (file)
@@ -1551,6 +1551,8 @@ Special groups
   connect to each other
 * `slippery`: Players and items will slide on the node.
   Slipperiness rises steadily with `slippery` value, starting at 1.
+* `disable_repair`: If set to 1 for a tool, it cannot be repaired using the
+  `"toolrepair"` crafting recipe
 
 
 Known damage and digging time defining groups
@@ -6156,6 +6158,8 @@ Used by `minetest.register_craft`.
         additional_wear = -0.02,
     }
 
+Note: Tools with group `disable_repair=1` will not repairable by this recipe.
+
 ### Cooking
 
     {
index 4d4e3e90cc0877661e07ad4a198737b588d80550..e8aeff2b30b3ab21021c22ce75bea0966009b647 100644 (file)
@@ -615,6 +615,34 @@ minetest.register_craftitem("experimental:tester_tool_2", {
        end,
 })
 
+-- Test the disable_repair=1 group
+minetest.register_tool("experimental:unrepairable_tool", {
+       description = "Unrepairable Tool",
+       wield_image = "default_stone.png",
+       inventory_image = "default_stone.png",
+       tool_capabilities = {
+               groupcaps = {
+                       cracky = {
+                               times = {3, 2, 1},
+                       }
+               }
+       },
+       groups = { disable_repair = 1 }
+})
+
+minetest.register_tool("experimental:repairable_tool", {
+       description = "Repairable Tool",
+       wield_image = "default_dirt.png",
+       inventory_image = "default_dirt.png",
+       tool_capabilities = {
+               groupcaps = {
+                       cracky = {
+                               times = {3, 2, 1},
+                       }
+               }
+       },
+})
+
 minetest.register_craft({
        output = 'experimental:tester_tool_2',
        recipe = {
index 922ea345ee5b73c92560e42f110c9c65aa743954..d64b7e55ec28895595fb36610dfad62226c5197e 100644 (file)
@@ -579,7 +579,7 @@ static ItemStack craftToolRepair(
        IItemDefManager *idef = gamedef->idef();
        if (item1.count != 1 || item2.count != 1 || item1.name != item2.name
                        || idef->get(item1.name).type != ITEM_TOOL
-                       || idef->get(item2.name).type != ITEM_TOOL) {
+                       || itemgroup_get(idef->get(item1.name).groups, "disable_repair") == 1) {
                // Failure
                return ItemStack();
        }