Advertisement
Guest User

Untitled

a guest
Jan 27th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. creative = {}
  2.  
  3. minetest.register_privilege("creative", {"Allow player to use creative inventory",
  4. give_to_singleplayer = false})
  5.  
  6. function creative.is_enabled_for(name)
  7.  
  8. if minetest.check_player_privs(name, {creative = true}) then
  9. return true
  10. else
  11. return minetest.setting_getbool("creative_mode")
  12. end
  13. end
  14.  
  15. dofile(minetest.get_modpath("creative") .. "/inventory.lua")
  16.  
  17. if minetest.setting_getbool("creative_mode") then
  18. -- Dig time is modified according to difference (leveldiff) between tool
  19. -- 'maxlevel' and node 'level'. Digtime is divided by the larger of
  20. -- leveldiff and 1.
  21. -- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been
  22. -- increased such that nodes of differing levels have an insignificant
  23. -- effect on digtime.
  24. local digtime = 42
  25. local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
  26.  
  27. minetest.register_item(":", {
  28. type = "none",
  29. wield_image = "wieldhand.png",
  30. wield_scale = {x = 1, y = 1, z = 2.5},
  31. range = 10,
  32. tool_capabilities = {
  33. full_punch_interval = 0.5,
  34. max_drop_level = 3,
  35. groupcaps = {
  36. crumbly = caps,
  37. cracky = caps,
  38. snappy = caps,
  39. choppy = caps,
  40. oddly_breakable_by_hand = caps,
  41. },
  42. damage_groups = {fleshy = 10},
  43. }
  44. })
  45. end
  46.  
  47. -- Unlimited node placement
  48. minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
  49. return creative.is_enabled_for(placer:get_player_name())
  50. end)
  51.  
  52. -- Don't pick up if the item is already in the inventory
  53. local old_handle_node_drops = minetest.handle_node_drops
  54. function minetest.handle_node_drops(pos, drops, digger)
  55. if not digger or not digger:is_player() then
  56. return
  57. end
  58. if not creative.is_enabled_for(digger:get_player_name()) then
  59. return old_handle_node_drops(pos, drops, digger)
  60. end
  61. local inv = digger:get_inventory()
  62. if inv then
  63. for _, item in ipairs(drops) do
  64. item = ItemStack(item):get_name()
  65. if not inv:contains_item("main", item) then
  66. inv:add_item("main", item)
  67. end
  68. end
  69. end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement