2019-03-07 21:55:56 +02:00
local S = minetest.get_translator ( " mcl_doc " )
2017-03-18 04:27:36 +02:00
-- Disable built-in factoids; it is planned to add custom ones as replacements
2017-03-18 02:06:10 +02:00
doc.sub . items.disable_core_factoid ( " node_mining " )
doc.sub . items.disable_core_factoid ( " tool_capabilities " )
2017-03-18 04:27:36 +02:00
-- Help button callback
minetest.register_on_player_receive_fields ( function ( player , formname , fields )
if fields.__mcl_doc then
doc.show_doc ( player : get_player_name ( ) )
end
end )
2017-03-18 18:18:12 +02:00
-- doc_items factoids
-- dig_by_water
doc.sub . items.register_factoid ( " nodes " , " drop_destroy " , function ( itemstring , def )
if def.groups . dig_by_water then
2019-03-07 21:55:56 +02:00
return S ( " Water can flow into this block and cause it to drop as an item. " )
2017-03-18 18:18:12 +02:00
end
return " "
end )
-- usable by hoes
doc.sub . items.register_factoid ( " nodes " , " groups " , function ( itemstring , def )
if def.groups . cultivatable == 2 then
2019-03-07 21:55:56 +02:00
return S ( " This block can be turned into dirt with a hoe. " )
2017-03-18 18:18:12 +02:00
elseif def.groups . cultivatable == 2 then
2019-03-07 21:55:56 +02:00
return S ( " This block can be turned into farmland with a hoe. " )
2017-03-18 18:18:12 +02:00
end
return " "
end )
-- soil
doc.sub . items.register_factoid ( " nodes " , " groups " , function ( itemstring , def )
local datastring = " "
if def.groups . soil_sapling == 2 then
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " This block acts as a soil for all saplings. " ) .. " \n "
2017-03-18 18:18:12 +02:00
elseif def.groups . soil_sapling == 1 then
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " This block acts as a soil for some saplings. " ) .. " \n "
2017-03-18 18:18:12 +02:00
end
if def.groups . soil_sugarcane then
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " Sugar canes will grow on this block. " ) .. " \n "
2017-03-18 18:18:12 +02:00
end
if def.groups . soil_nether_wart then
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " Nether wart will grow on this block. " ) .. " \n "
2017-03-18 18:18:12 +02:00
end
return datastring
end )
2017-08-31 03:06:35 +03:00
doc.sub . items.register_factoid ( " nodes " , " groups " , function ( itemstring , def )
local formstring = " "
if def.groups . leafdecay ~= nil then
if def.drop ~= " " and def.drop ~= nil and def.drop ~= itemstring then
2019-03-07 21:55:56 +02:00
formstring = S ( " This block quickly decays when there is no wood block of any species within a distance of @1. When decaying, it disappears and may drop one of its regular drops. The block does not decay when the block has been placed by a player. " , def.groups . leafdecay )
2017-08-31 03:06:35 +03:00
else
2019-03-07 21:55:56 +02:00
formstring = S ( " This block quickly decays and disappears when there is no wood block of any species within a distance of @1. The block does not decay when the block has been placed by a player. " , def.groups . leafdecay )
2017-08-31 03:06:35 +03:00
end
end
return formstring
end )
2017-06-12 00:20:50 +03:00
-- nodes which have flower placement rules
2017-06-09 22:26:26 +03:00
doc.sub . items.register_factoid ( " nodes " , " groups " , function ( itemstring , def )
local datastring = " "
2017-06-12 00:20:50 +03:00
if def.groups . place_flowerlike == 1 then
2019-03-07 21:55:56 +02:00
return S ( " This plant can only grow on grass blocks and dirt. To survive, it needs to have an unobstructed view to the sky above or be exposed to a light level of 8 or higher. " )
2017-11-15 06:02:37 +02:00
elseif def.groups . place_flowerlike == 2 then
2019-03-07 21:55:56 +02:00
return S ( " This plant can grow on grass blocks, podzol, dirt and coarse dirt. To survive, it needs to have an unobstructed view to the sky above or be exposed to a light level of 8 or higher. " )
2017-06-09 22:26:26 +03:00
end
return " "
end )
2017-03-18 18:18:12 +02:00
-- flammable
doc.sub . items.register_factoid ( " nodes " , " groups " , function ( itemstring , def )
if def.groups . flammable then
2019-03-07 21:55:56 +02:00
return S ( " This block is flammable. " )
2017-03-18 18:18:12 +02:00
end
return " "
end )
-- destroys_items
doc.sub . items.register_factoid ( " nodes " , " groups " , function ( itemstring , def )
if def.groups . destroys_items then
2019-03-07 21:55:56 +02:00
return S ( " This block destroys any item it touches. " )
2017-03-18 18:18:12 +02:00
end
return " "
end )
-- Comestibles
doc.sub . items.register_factoid ( nil , " use " , function ( itemstring , def )
2017-05-23 03:55:48 +03:00
local s = " "
2017-03-18 18:18:12 +02:00
if def.groups . eatable and not def._doc_items_usagehelp then
if def.groups . food == 2 then
2019-03-07 21:55:56 +02:00
s = s .. S ( " To eat it, wield it, then rightclick. " )
2017-05-23 03:55:48 +03:00
if def.groups . can_eat_when_full == 1 then
2019-03-07 21:55:56 +02:00
s = s .. " \n " .. S ( " You can eat this even when your hunger bar is full. " )
2017-05-23 03:55:48 +03:00
else
2019-03-07 21:55:56 +02:00
s = s .. " \n " .. S ( " You cannot eat this when your hunger bar is full. " )
2017-05-23 03:55:48 +03:00
end
2017-03-18 18:18:12 +02:00
elseif def.groups . food == 3 then
2019-03-07 21:55:56 +02:00
s = s .. S ( " To drink it, wield it, then rightclick. " )
2017-05-23 03:55:48 +03:00
if def.groups . can_eat_when_full ~= 1 then
2019-03-07 21:55:56 +02:00
s = s .. " \n " .. S ( " You cannot drink this when your hunger bar is full. " )
2017-05-23 03:55:48 +03:00
end
2017-03-18 18:18:12 +02:00
else
2019-03-07 21:55:56 +02:00
s = s .. S ( " To consume it, wield it, then rightclick. " )
2017-05-23 03:55:48 +03:00
if def.groups . can_eat_when_full ~= 1 then
2019-03-07 21:55:56 +02:00
s = s .. " \n " .. S ( " You cannot consume this when your hunger bar is full. " )
2017-05-23 03:55:48 +03:00
end
end
if def.groups . no_eat_delay ~= 1 then
2019-03-07 21:55:56 +02:00
s = s .. " \n " .. S ( " You have to wait for about 2 seconds before you can eat or drink again. " )
2017-03-18 18:18:12 +02:00
end
end
2017-05-23 03:55:48 +03:00
return s
2017-03-18 18:18:12 +02:00
end )
2017-03-18 20:38:40 +02:00
2017-05-21 04:12:17 +03:00
doc.sub . items.register_factoid ( nil , " groups " , function ( itemstring , def )
local s = " "
if def.groups . eatable and def.groups . eatable > 0 then
2019-03-07 21:55:56 +02:00
s = s .. S ( " Hunger points restored: @1 " , def.groups . eatable )
2017-05-21 04:12:17 +03:00
end
if def._mcl_saturation and def._mcl_saturation > 0 then
2019-03-07 21:55:56 +02:00
s = s .. " \n " .. S ( " Saturation points restored: @1%.1f " , string.format ( " %.1f " , def._mcl_saturation ) )
2017-05-21 04:12:17 +03:00
end
return s
end )
2018-02-03 05:40:31 +02:00
-- TODO: Move this info to the crafting guide
doc.sub . items.register_factoid ( nil , " groups " , function ( itemstring , def )
if def._repair_material then
local mdef = minetest.registered_items [ def._repair_material ]
local desc
if mdef and mdef.description and mdef.description ~= " " then
2019-03-07 21:55:56 +02:00
return S ( " This item can be repaired at an anvil with: @1. " , mdef.description )
2018-02-03 05:40:31 +02:00
elseif def._repair_material == " group:wood " then
2019-03-07 21:55:56 +02:00
return S ( " This item can be repaired at an anvil with any wooden planks. " )
2018-02-03 05:40:31 +02:00
elseif string.sub ( def._repair_material , 1 , 6 ) == " group: " then
local group = string.sub ( def._repair_material , 7 )
2019-03-07 21:55:56 +02:00
return S ( " This item can be repaired at an anvil with any item in the “@1” group. " , group )
2018-02-03 05:40:31 +02:00
end
end
return " "
end )
doc.sub . items.register_factoid ( nil , " groups " , function ( itemstring , def )
if minetest.get_item_group ( itemstring , " no_rename " ) == 1 then
2019-03-07 21:55:56 +02:00
return S ( " This item cannot be renamed at an anvil. " )
2018-02-03 05:40:31 +02:00
else
return " "
end
end )
doc.sub . items.register_factoid ( " nodes " , " gravity " , function ( itemstring , def )
2018-02-04 08:00:07 +02:00
local s = " "
if minetest.get_item_group ( itemstring , " crush_after_fall " ) == 1 then
2019-03-07 21:55:56 +02:00
s = s .. S ( " This block crushes any block it falls into. " )
2018-02-03 05:40:31 +02:00
end
2018-02-04 08:00:07 +02:00
return s
2018-02-03 05:40:31 +02:00
end )
2018-02-05 20:01:54 +02:00
doc.sub . items.register_factoid ( " nodes " , " gravity " , function ( itemstring , def )
local s = " "
if minetest.get_item_group ( itemstring , " crush_after_fall " ) == 1 then
2019-03-07 21:55:56 +02:00
s = s .. S ( " When this block falls deeper than 1 block, it causes damage to any player it hits. The damage dealt is B× 2− 2 hit points with B = number of blocks fallen. The damage can never be more than 40 HP. " )
2018-02-05 20:01:54 +02:00
end
return s
end )
2017-03-22 19:48:27 +02:00
-- Mining, hardness and all that
2017-03-18 20:38:40 +02:00
doc.sub . items.register_factoid ( " nodes " , " mining " , function ( itemstring , def )
2019-03-07 21:55:56 +02:00
local pickaxey = { S ( " Diamond Pickaxe " ) , S ( " Iron Pickaxe " ) , S ( " Stone Pickaxe " ) , S ( " Golden Pickaxe " ) , S ( " Wooden Pickaxe " ) }
local axey = { S ( " Diamond Axe " ) , S ( " Iron Axe " ) , S ( " Stone Axe " ) , S ( " Golden Axe " ) , S ( " Wooden Axe " ) }
local shovely = { S ( " Diamond Shovel " ) , S ( " Iron Shovel " ) , S ( " Stone Shovel " ) , S ( " Golden Shovel " ) , S ( " Wooden Shovel " ) }
2017-03-22 19:48:27 +02:00
local datastring = " "
local groups = def.groups
if groups then
if groups.dig_immediate == 3 then
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " This block can be mined by any tool instantly. " ) .. " \n "
2017-03-22 19:48:27 +02:00
else
local tool_minable = false
if groups.pickaxey then
for g = 1 , 6 - groups.pickaxey do
datastring = datastring .. " • " .. pickaxey [ g ] .. " \n "
end
tool_minable = true
end
if groups.axey then
for g = 1 , 6 - groups.axey do
datastring = datastring .. " • " .. axey [ g ] .. " \n "
end
tool_minable = true
end
if groups.shovely then
for g = 1 , 6 - groups.shovely do
datastring = datastring .. " • " .. shovely [ g ] .. " \n "
end
tool_minable = true
end
2017-08-03 04:50:02 +03:00
if groups.shearsy or groups.shearsy_wool then
2019-03-18 13:20:10 +02:00
datastring = datastring .. S ( " • Shears " ) .. " \n "
2017-03-22 19:48:27 +02:00
tool_minable = true
end
2017-08-03 04:50:02 +03:00
if groups.swordy or groups.swordy_cobweb then
2019-03-18 13:20:10 +02:00
datastring = datastring .. S ( " • Sword " ) .. " \n "
2017-03-22 19:48:27 +02:00
tool_minable = true
end
if groups.handy then
2019-03-18 13:20:10 +02:00
datastring = datastring .. S ( " • Hand " ) .. " \n "
2017-03-22 19:48:27 +02:00
tool_minable = true
end
if tool_minable then
2019-03-07 21:55:56 +02:00
datastring = S ( " This block can be mined by: " ) .. " \n " .. datastring .. " \n "
2017-03-22 19:48:27 +02:00
end
end
end
2017-03-18 20:38:40 +02:00
local hardness = def._mcl_hardness
if not hardness then
hardness = 0
end
2017-03-20 22:41:27 +02:00
if hardness == - 1 then
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " Hardness: ∞ " )
2017-03-20 22:41:27 +02:00
else
2019-03-07 21:55:56 +02:00
datastring = datastring .. S ( " Hardness: @1 " , string.format ( " %.2f " , hardness ) )
2017-03-20 22:41:27 +02:00
end
2017-06-05 23:20:27 +03:00
local blast = def._mcl_blast_resistance
if not blast then
blast = 0
end
2018-02-03 05:40:31 +02:00
-- TODO: Blast resistance as number
2017-06-05 23:20:27 +03:00
if blast >= 1000 then
2019-03-07 21:55:56 +02:00
datastring = datastring .. " \n " .. S ( " This block will not be destroyed by TNT explosions. " )
2017-06-05 23:20:27 +03:00
end
2017-03-22 19:48:27 +02:00
return datastring
2017-03-18 20:38:40 +02:00
end )
2017-08-03 04:05:41 +03:00
-- Special drops when mined by shears
doc.sub . items.register_factoid ( " nodes " , " drops " , function ( itemstring , def )
if def._mcl_shears_drop == true then
2019-03-07 21:55:56 +02:00
return S ( " This block drops itself when mined by shears. " )
2017-08-03 04:05:41 +03:00
elseif type ( def._mcl_shears_drop ) == " table " then
local drops = { }
2017-08-03 04:21:39 +03:00
for d = 1 , # def._mcl_shears_drop do
local item = ItemStack ( def._mcl_shears_drop [ d ] )
local itemname = item : get_name ( )
local itemcount = item : get_count ( )
local idef = minetest.registered_items [ itemname ]
local text = " "
if idef.description and idef.description ~= " " then
text = idef.description
2017-08-03 04:05:41 +03:00
else
2017-08-03 04:21:39 +03:00
text = itemname
2017-08-03 04:05:41 +03:00
end
2017-08-03 04:21:39 +03:00
if itemcount > 1 then
2019-03-07 21:55:56 +02:00
text = S ( " @1× @2 " , itemcount , text )
2017-08-03 04:21:39 +03:00
end
table.insert ( drops , text )
2017-08-03 04:05:41 +03:00
end
2019-03-07 21:55:56 +02:00
local ret = S ( " This blocks drops the following when mined by shears: @1 " , table.concat ( drops , S ( " , " ) ) )
2017-08-03 04:05:41 +03:00
return ret
end
return " "
end )
2020-02-17 17:17:35 +02:00
-- Digging capabilities of tool
doc.sub . items.register_factoid ( " tools " , " misc " , function ( itemstring , def )
if not def.tool_capabilities then
return " "
end
local groupcaps = def.tool_capabilities . groupcaps
if not groupcaps then
return " "
end
local formstring = " "
local capstr = " "
local caplines = 0
for k , v in pairs ( groupcaps ) do
local speedstr = " "
local miningusesstr = " "
-- Mining capabilities
caplines = caplines + 1
local maxlevel = v.maxlevel
if not maxlevel then
-- Default from tool.h
maxlevel = 1
end
-- Digging speed
local speed_class = def.groups and def.groups . dig_speed_class
if speed_class == 1 then
speedstr = S ( " Painfully slow " )
elseif speed_class == 2 then
speedstr = S ( " Very slow " )
elseif speed_class == 3 then
speedstr = S ( " Slow " )
elseif speed_class == 4 then
speedstr = S ( " Fast " )
elseif speed_class == 5 then
speedstr = S ( " Very fast " )
elseif speed_class == 6 then
speedstr = S ( " Extremely fast " )
elseif speed_class == 7 then
speedstr = S ( " Instantaneous " )
end
-- Number of mining uses
local base_uses = v.uses
if not base_uses then
-- Default from tool.h
base_uses = 20
end
if def._doc_items_durability == nil and base_uses > 0 then
local real_uses = base_uses * math.pow ( 3 , maxlevel )
if real_uses < 65535 then
miningusesstr = S ( " @1 uses " , real_uses )
else
miningusesstr = S ( " Unlimited uses " )
end
end
if speedstr ~= " " then
capstr = capstr .. S ( " Mining speed: @1 " , speedstr ) .. " \n "
end
if miningusesstr ~= " " then
capstr = capstr .. S ( " Mining durability: @1 " , miningusesstr ) .. " \n "
end
-- Only show one group at max
break
end
if caplines > 0 then
formstring = formstring .. S ( " This tool is capable of mining. " ) .. " \n "
-- Capabilities
formstring = formstring .. capstr
-- Max. drop level
local mdl = def.tool_capabilities . max_drop_level
if not def.tool_capabilities . max_drop_level then
mdl = 0
end
formstring = formstring .. S ( " Block breaking strength: @1 " , mdl ) .. " \n "
end
if caplines > 0 then
formstring = formstring .. " \n \n "
end
return formstring
end )
-- Melee damage
doc.sub . items.register_factoid ( " tools " , " misc " , function ( itemstring , def )
local tool_capabilities = def.tool_capabilities
if not tool_capabilities then
return " "
end
local formstring = " "
-- Weapon data
local damage_groups = tool_capabilities.damage_groups
if damage_groups ~= nil and damage_groups.fleshy ~= nil then
formstring = formstring .. S ( " This is a melee weapon which deals damage by punching. " ) .. " \n "
-- Damage groups
local dmg = damage_groups.fleshy
formstring = formstring .. S ( " Maximum damage: @1 HP " , dmg ) .. " \n "
-- Full punch interval
local punch = 1.0
if tool_capabilities.full_punch_interval ~= nil then
punch = tool_capabilities.full_punch_interval
end
formstring = formstring .. S ( " Full punch interval: @1 s " , string.format ( " %.1f " , punch ) )
formstring = formstring .. " \n "
end
return formstring
end )
2017-08-03 04:05:41 +03:00