init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. local compressed_sound = default.node_sound_dirt_defaults()
  2. local nb_iterations = 3
  3. local function add_one_compression(p)
  4. def = {
  5. description = p["desc"],
  6. tiles = p["img"],
  7. groups = {dig_immediate=3},
  8. is_ground_content = false,
  9. sounds = compressed_sound
  10. }
  11. minetest.register_node(p["name"], def)
  12. recipe = {}
  13. for i=1,8 do
  14. recipe[i]=p["base"]
  15. end
  16. minetest.register_craft({
  17. output = p["name"],
  18. type = "shapeless",
  19. recipe = recipe
  20. })
  21. minetest.register_craft({
  22. output = p["base"].." 8",
  23. type = "shapeless",
  24. recipe = {p["name"]}
  25. })
  26. end
  27. local function shallow_copy(t)
  28. local t2 = {}
  29. for k,v in pairs(t) do
  30. t2[k] = v
  31. end
  32. return t2
  33. end
  34. local function mark_texture(t, i)
  35. mark = "^(compresser_"..i..".png^[opacity:200)"
  36. t = shallow_copy(t)
  37. if t["name"] then
  38. t["name"] = t["name"]..mark
  39. else
  40. k = 1
  41. while t[k] do
  42. t[k] = t[k]..mark
  43. k = k+1
  44. end
  45. end
  46. return t
  47. end
  48. local function add_compressions(p, n)
  49. -- Assume n>=1
  50. basenode = minetest.registered_nodes[p["base"]]
  51. p["img"] = basenode.tiles
  52. add_one_compression({
  53. desc="\27(compressed)8 "..p["description"],
  54. name="compresser:compressed1_"..p["name"],
  55. base=p["base"],
  56. img=mark_texture(p["img"],1)
  57. })
  58. for i=2,n do
  59. add_one_compression({
  60. desc="\27(compressed)8^"..i.." "..p["description"],
  61. name="compresser:compressed"..i.."_"..p["name"],
  62. base="compresser:compressed"..(i-1).."_"..p["name"],
  63. img=mark_texture(p["img"],i)
  64. })
  65. end
  66. end
  67. local function add_compressions_helper(base)
  68. basenode = minetest.registered_nodes[base]
  69. pos_col,_ = string.find(base,":")
  70. desc = basenode.description
  71. desc = desc:gsub("\27E", "")
  72. desc = desc:gsub("\27%(%w*@?%w*%)", "") -- Or keep it maybe?
  73. add_compressions({
  74. description=desc,
  75. name=string.sub(base,pos_col+1),
  76. base=base
  77. },nb_iterations)
  78. end
  79. local to_compress_default = {
  80. "glass", "dirt", "stone",
  81. "cobble", "gravel",
  82. "bronzeblock", "coalblock", "copperblock", "diamondblock", "goldblock", "mese_block", "obsidian_block", "steelblock", "tinblock", "stone_block", "sandstone_block", "sand",
  83. "acacia_tree", "tree","silver_sand", "silver_sandstone", "silver_sandstone_brick", "aspen_tree", "pine_tree", "acacia_wood", "wood", "aspen_wood", "pine_wood"
  84. }
  85. for _,p in ipairs(to_compress_default) do
  86. add_compressions_helper("default:"..p)
  87. end
  88. for i=1,nb_iterations do
  89. n = minetest.registered_nodes["compresser:compressed"..i.."_glass"]
  90. n = shallow_copy(n)
  91. n.drawtype = "glasslike_framed_optional"
  92. n.paramtype = "light"
  93. minetest.register_node("compresser:compressed"..i.."_glass", n)
  94. -- Doesn't work by modifying directly, I don't know why.
  95. end