init.lua 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. print("forumbug loading")
  2. local groups = {choppy=2, dig_immediate=3, picture=1}
  3. -- Texture for the frame
  4. local frame_texture = "metal_1.png"
  5. -- Pixel size of the resulting texture for the node. Higher resolutions for more details.
  6. local resulttexture_pix = 800
  7. -- Frame border width in percent
  8. local frame_widthpercent = 2.5
  9. -- Scaling of the picture
  10. local pic_scale = 2.5
  11. -- Get the width and height of the picture from the file in pixel
  12. local pic_pixwidth,pic_pixheight=32,24
  13. -- Get the max side lenght of the picture in pixel
  14. local pic_pixmax = math.max(pic_pixwidth,pic_pixheight)
  15. -- Frame border width in pixel
  16. local frame_widthpixel = math.ceil(frame_widthpercent * pic_pixmax / 100.0)
  17. -- Distance beetween the frame and the picture in pixel
  18. local border_pix = 4
  19. -- Pixel size of the combined square texture of the picture with frame and border
  20. local pictexture_pix = pic_pixmax + (frame_widthpixel * 2) + (border_pix * 2)
  21. -- X and Y position oft the picture in the combined square texture of the picture with frame and border
  22. local pic_xoffset = ((pic_pixmax - pic_pixwidth) / 2) + frame_widthpixel + border_pix
  23. local pic_yoffset = ((pic_pixmax - pic_pixheight) / 2) + frame_widthpixel + border_pix
  24. -- Frame border width of the node
  25. local frame_widthnode = 1.0 / pictexture_pix * frame_widthpixel
  26. -- Frame border thickness of the node
  27. local frame_thickness = 0.1
  28. -- Picture width of the node (whole picture including frame)
  29. local pic_width = 1.0
  30. -- Picture height of the node (whole picture including frame)
  31. local pic_height = 1.0
  32. -- Picture thickness of the node
  33. local pic_thickness = 0.05
  34. if pic_pixwidth > pic_pixheight then
  35. -- Landscape picture. Set the Picture height of the node (whole picture including frame) accordingly to the original picture aspect ratio
  36. pic_height = (pic_width / pictexture_pix) * (pic_pixheight + 2 * (frame_widthpixel + border_pix))
  37. else
  38. -- Potrait picture Set the Picture width of the node (whole picture including frame) accordingly to the original picture aspect ratio
  39. pic_width = (pic_height / pictexture_pix) * (pic_pixwidth + 2 * (frame_widthpixel + border_pix))
  40. end
  41. -- node
  42. minetest.register_node(":bughunt:bug", {
  43. description = "Picture #1",
  44. drawtype = "nodebox",
  45. -- Tile definition in the follwing order: +Y, -Y, +X, -X, +Z, -Z.
  46. tiles = {
  47. {name="("..frame_texture.."^[resize:"..resulttexture_pix.."x"..resulttexture_pix..")^([combine:"..pictexture_pix.."x"..pictexture_pix..":"..pic_xoffset..","..pic_yoffset.."=picture_1.png^[resize:"..resulttexture_pix.."x"..resulttexture_pix..")"},
  48. {name=frame_texture}
  49. },
  50. visual_scale = pic_scale,
  51. inventory_image = "gallery_inventory.png",
  52. wield_image = "gallery_inventory.png",
  53. paramtype = "light",
  54. paramtype2 = "wallmounted",
  55. sunlight_propagates = true,
  56. walkable = false,
  57. node_box = {
  58. type = "fixed",
  59. -- Box definition in following order: {x1, y1, z1, x2, y2, z2}
  60. fixed = {
  61. -- Picture
  62. {-pic_width/2.0, -0.5/pic_scale, -pic_height/2.0, pic_width/2.0, -(0.5 - pic_thickness) / pic_scale, pic_height/2.0},
  63. -- Left frame border
  64. {-pic_width/2.0, -0.5/pic_scale, -pic_height/2.0, -pic_width/2.0+frame_widthnode, -(0.5 - frame_thickness) / pic_scale, pic_height/2.0},
  65. -- Right frame border
  66. {pic_width/2.0-frame_widthnode, -0.5/pic_scale, -pic_height/2.0, pic_width/2.0, -(0.5 - frame_thickness) / pic_scale, pic_height/2.0},
  67. -- Bottom frame border
  68. {-pic_width/2.0, -0.5/pic_scale, -pic_height/2.0, pic_width/2.0, -(0.5 - frame_thickness) / pic_scale, -pic_height/2.0+frame_widthnode},
  69. -- Top frame border
  70. {-pic_width/2.0, -0.5/pic_scale, pic_height/2.0-frame_widthnode, pic_width/2.0, -(0.5 - frame_thickness) / pic_scale, pic_height/2.0},
  71. },
  72. },
  73. groups = groups,
  74. })