craftitems.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. -- mods/default/craftitems.lua
  2. if not minetest.global_exists("default") then default = {} end
  3. -- To be called by "stick" items to force infotext/formspec/entity node updates.
  4. function default.strike_protection(itemstack, user, pt)
  5. if not user or not user:is_player() then
  6. return
  7. end
  8. if pt.type ~= "node" then
  9. return
  10. end
  11. local pname = user:get_player_name()
  12. if minetest.test_protection(pt.under, pname) then
  13. ambiance.sound_play("default_metal_footstep", pt.under, 1.0, 20)
  14. else
  15. ambiance.sound_play("default_wood_footstep", pt.under, 1.0, 20)
  16. end
  17. -- Update names in infotext.
  18. local node = minetest.get_node(pt.under)
  19. local ndef = minetest.registered_items[node.name]
  20. if not ndef then
  21. return
  22. end
  23. -- Note: this callback shall only update "infotext" metadata key, and any data
  24. -- directly related to infotext (such as a cached "dname" variable). The
  25. -- reason for this is that this callback can also be called from LBM.
  26. if ndef._on_update_infotext then
  27. ndef._on_update_infotext(pt.under)
  28. end
  29. -- Note: this callback can do whatever (it is not called from LBM) but usually
  30. -- you should only update the node formspec and directly related invlists, if
  31. -- needed.
  32. --
  33. -- Special note on names: since this function is NOT called from LBM, you
  34. -- should always avoid using a player's name in formspecs, since it will not
  35. -- automatically update if the player changes their display name.
  36. if ndef._on_update_formspec then
  37. ndef._on_update_formspec(pt.under)
  38. end
  39. -- Note: this callback should only be used to force-update entity displays
  40. -- such as on itemframe and armor stand nodes.
  41. if ndef._on_update_entity then
  42. ndef._on_update_entity(pt.under)
  43. end
  44. end
  45. minetest.register_craftitem("default:stick", {
  46. description = "Stick\n\nCan be used to test protection.\nAlso updates infotext names.",
  47. inventory_image = "default_stick.png",
  48. groups = {stick = 1, flammable = 2},
  49. on_use = default.strike_protection,
  50. })
  51. minetest.register_craftitem("default:paper", {
  52. description = "Paper",
  53. inventory_image = "default_paper.png",
  54. groups = {flammable = 3},
  55. })
  56. minetest.register_craftitem("default:padlock", {
  57. description = "Lock",
  58. inventory_image = "lock_item.png",
  59. })
  60. minetest.register_craftitem("default:coal_lump", {
  61. description = "Coal Lump",
  62. inventory_image = "default_coal_lump.png",
  63. groups = {coal = 1, flammable = 1}
  64. })
  65. minetest.register_craftitem("default:iron_lump", {
  66. description = "Iron Lump",
  67. inventory_image = "default_iron_lump.png",
  68. })
  69. minetest.register_craftitem("default:copper_lump", {
  70. description = "Copper Lump",
  71. inventory_image = "default_copper_lump.png",
  72. })
  73. minetest.register_craftitem("default:mese_crystal", {
  74. description = "Mese Crystal",
  75. inventory_image = "default_mese_crystal.png",
  76. })
  77. minetest.register_craftitem("default:gold_lump", {
  78. description = "Gold Lump",
  79. inventory_image = "default_gold_lump.png",
  80. })
  81. minetest.register_craftitem("default:diamond", {
  82. description = "Diamond",
  83. inventory_image = "default_diamond.png",
  84. groups = {gem = 1, crystal = 1},
  85. })
  86. -- 'default_adamant_shard.png' texture by 'WintersKnight94', CC0 1.0 Universal
  87. minetest.register_craftitem("default:adamant_shard", {
  88. description = "Adamant Shard",
  89. inventory_image = "default_adamant_shard.png",
  90. groups = {gem = 1, crystal = 1},
  91. })
  92. minetest.register_craftitem("default:clay_lump", {
  93. description = "Clay Lump",
  94. inventory_image = "default_clay_lump.png",
  95. })
  96. minetest.register_craftitem("default:steel_ingot", {
  97. description = "Wrought Iron Ingot",
  98. inventory_image = "default_steel_ingot.png",
  99. groups = {ingot = 1},
  100. })
  101. minetest.register_craftitem("default:copper_ingot", {
  102. description = "Copper Ingot",
  103. inventory_image = "default_copper_ingot.png",
  104. groups = {ingot = 1},
  105. })
  106. minetest.register_craftitem("default:bronze_ingot", {
  107. description = "Bronze Ingot",
  108. inventory_image = "default_bronze_ingot.png",
  109. groups = {ingot = 1},
  110. })
  111. minetest.register_craftitem("default:gold_ingot", {
  112. description = "Gold Ingot",
  113. inventory_image = "default_gold_ingot.png",
  114. groups = {ingot = 1},
  115. })
  116. minetest.register_craftitem("default:mese_crystal_fragment", {
  117. description = "Mese Crystal Fragment",
  118. inventory_image = "default_mese_crystal_fragment.png",
  119. })
  120. minetest.register_craftitem("default:clay_brick", {
  121. description = "Clay Brick",
  122. inventory_image = "default_clay_brick.png",
  123. })
  124. minetest.register_craftitem("default:obsidian_shard", {
  125. description = "Obsidian Shard",
  126. inventory_image = "default_obsidian_shard.png",
  127. })
  128. minetest.register_craftitem("default:flint", {
  129. description = "Flint",
  130. inventory_image = "default_flint.png"
  131. })