init.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. minetest.register_chatcommand("hotbar", {
  2. params = "<size>",
  3. description = "Set hotbar size",
  4. func = function(name, param)
  5. local player = minetest.get_player_by_name(name)
  6. if not player then
  7. return false, "No player."
  8. end
  9. local size = tonumber(param)
  10. if not size then
  11. return false, "Missing or incorrect size parameter!"
  12. end
  13. local ok = player:hud_set_hotbar_itemcount(size)
  14. if ok then
  15. return true
  16. else
  17. return false, "Invalid item count!"
  18. end
  19. end,
  20. })
  21. minetest.register_chatcommand("hp", {
  22. params = "<hp>",
  23. description = "Set your health",
  24. func = function(name, param)
  25. local player = minetest.get_player_by_name(name)
  26. if not player then
  27. return false, "No player."
  28. end
  29. local hp = tonumber(param)
  30. if not hp then
  31. return false, "Missing or incorrect hp parameter!"
  32. end
  33. player:set_hp(hp)
  34. return true
  35. end,
  36. })
  37. minetest.register_on_joinplayer(function(player)
  38. player:set_properties({zoom_fov = 15})
  39. end)
  40. minetest.register_chatcommand("zoomfov", {
  41. params = "[<FOV>]",
  42. description = "Set or display your zoom_fov",
  43. func = function(name, param)
  44. local player = minetest.get_player_by_name(name)
  45. if not player then
  46. return false, "No player."
  47. end
  48. if param == "" then
  49. local fov = player:get_properties().zoom_fov
  50. return true, "zoom_fov = "..tostring(fov)
  51. end
  52. local fov = tonumber(param)
  53. if not fov then
  54. return false, "Missing or incorrect zoom_fov parameter!"
  55. end
  56. player:set_properties({zoom_fov = fov})
  57. fov = player:get_properties().zoom_fov
  58. return true, "zoom_fov = "..tostring(fov)
  59. end,
  60. })
  61. local s_infplace = minetest.settings:get("devtest_infplace")
  62. if s_infplace == "true" then
  63. infplace = true
  64. elseif s_infplace == "false" then
  65. infplace = false
  66. else
  67. infplace = minetest.is_creative_enabled("")
  68. end
  69. minetest.register_chatcommand("infplace", {
  70. params = "",
  71. description = "Toggle infinite node placement",
  72. func = function(name, param)
  73. infplace = not infplace
  74. if infplace then
  75. minetest.chat_send_all("Infinite node placement enabled!")
  76. minetest.log("action", "Infinite node placement enabled")
  77. else
  78. minetest.chat_send_all("Infinite node placement disabled!")
  79. minetest.log("action", "Infinite node placement disabled")
  80. end
  81. return true
  82. end,
  83. })
  84. minetest.register_chatcommand("detach", {
  85. params = "[<radius>]",
  86. description = "Detach all objects nearby",
  87. func = function(name, param)
  88. local radius = tonumber(param)
  89. if type(radius) ~= "number" then
  90. radius = 8
  91. end
  92. if radius < 1 then
  93. radius = 1
  94. end
  95. local player = minetest.get_player_by_name(name)
  96. if not player then
  97. return false, "No player."
  98. end
  99. local objs = minetest.get_objects_inside_radius(player:get_pos(), radius)
  100. local num = 0
  101. for o=1, #objs do
  102. if objs[o]:get_attach() then
  103. objs[o]:set_detach()
  104. num = num + 1
  105. end
  106. end
  107. return true, string.format("%d object(s) detached.", num)
  108. end,
  109. })
  110. -- Use this to test waypoint capabilities
  111. minetest.register_chatcommand("test_waypoints", {
  112. params = "[change_immediate]",
  113. description = "tests waypoint capabilities",
  114. func = function(name, params)
  115. local player = minetest.get_player_by_name(name)
  116. local regular = player:hud_add {
  117. hud_elem_type = "waypoint",
  118. name = "regular waypoint",
  119. text = "m",
  120. number = 0xFF0000,
  121. world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0})
  122. }
  123. local reduced_precision = player:hud_add {
  124. hud_elem_type = "waypoint",
  125. name = "better waypoint",
  126. text = "m (0.5 steps, precision = 2)",
  127. precision = 10,
  128. number = 0xFFFF00,
  129. world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0})
  130. }
  131. local function change()
  132. if regular then
  133. player:hud_change(regular, "world_pos", vector.add(player:get_pos(), {x = 0, y = 3, z = 0}))
  134. end
  135. if reduced_precision then
  136. player:hud_change(reduced_precision, "precision", 2)
  137. end
  138. end
  139. if params ~= "" then
  140. -- change immediate
  141. change()
  142. else
  143. minetest.after(0.5, change)
  144. end
  145. regular = regular or "error"
  146. reduced_precision = reduced_precision or "error"
  147. local hidden_distance = player:hud_add {
  148. hud_elem_type = "waypoint",
  149. name = "waypoint with hidden distance",
  150. text = "this text is hidden as well (precision = 0)",
  151. precision = 0,
  152. number = 0x0000FF,
  153. world_pos = vector.add(player:get_pos(), {x = 0, y = 0.5, z = 0})
  154. } or "error"
  155. local image_waypoint = player:hud_add {
  156. hud_elem_type = "image_waypoint",
  157. text = "wieldhand.png",
  158. world_pos = player:get_pos(),
  159. scale = {x = 10, y = 10},
  160. offset = {x = 0, y = -32}
  161. } or "error"
  162. minetest.chat_send_player(name, "Waypoint IDs: regular: " .. regular .. ", reduced precision: " .. reduced_precision ..
  163. ", hidden distance: " .. hidden_distance .. ", image waypoint: " .. image_waypoint)
  164. end
  165. })
  166. -- Unlimited node placement
  167. minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
  168. if placer and placer:is_player() then
  169. return infplace
  170. end
  171. end)
  172. -- Don't pick up if the item is already in the inventory
  173. local old_handle_node_drops = minetest.handle_node_drops
  174. function minetest.handle_node_drops(pos, drops, digger)
  175. if not digger or not digger:is_player() or not infplace then
  176. return old_handle_node_drops(pos, drops, digger)
  177. end
  178. local inv = digger:get_inventory()
  179. if inv then
  180. for _, item in ipairs(drops) do
  181. if not inv:contains_item("main", item, true) then
  182. inv:add_item("main", item)
  183. end
  184. end
  185. end
  186. end