init.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. local S = minetest.get_translator("plasmascreen")
  2. local sc_disallow = minetest.get_modpath("screwdriver") and screwdriver.disallow or nil
  3. minetest.register_node("plasmascreen:stand", {
  4. description = S("Plasma Screen TV Stand"),
  5. tiles = {"plasmascreen_back.png"},
  6. paramtype = "light",
  7. paramtype2 = "facedir",
  8. drawtype = "nodebox",
  9. node_box = {
  10. type = "fixed",
  11. fixed = {
  12. {0.5000,-0.5000,0.0625,-0.5000,-0.4375,-0.5000}, --NodeBox 1
  13. {-0.1875,-0.5000,-0.3750,0.1875,0.1250,-0.1250}, --NodeBox 2
  14. {-0.5000,-0.2500,-0.5000,0.5000,0.5000,-0.3750}, --NodeBox 3
  15. {-0.3750,-0.1875,-0.3750,0.3750,0.3125,-0.2500}, --NodeBox 4
  16. }
  17. },
  18. selection_box = {
  19. type = "fixed",
  20. fixed = {
  21. {-0.5000, -0.5000, -0.5000, 0.5000, 0.5000, 0.0000},
  22. }
  23. },
  24. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2},
  25. })
  26. minetest.register_alias("plasmascreen:screen1", "air")
  27. minetest.register_alias("plasmascreen:screen2", "air")
  28. minetest.register_alias("plasmascreen:screen3", "air")
  29. minetest.register_alias("plasmascreen:screen4", "air")
  30. minetest.register_alias("plasmascreen:screen5", "plasmascreen:tv")
  31. minetest.register_alias("plasmascreen:screen6", "air")
  32. local fdir_to_left = {
  33. { -1, 0 },
  34. { 0, 1 },
  35. { 1, 0 },
  36. { 0, -1 },
  37. }
  38. local fdir_to_right = {
  39. { 1, 0 },
  40. { 0, -1 },
  41. { -1, 0 },
  42. { 0, 1 },
  43. }
  44. local tv_cbox = {
  45. type = "fixed",
  46. fixed = {-1.5050, -0.3125, 0.3700, 1.5050, 1.5050, 0.5050}
  47. }
  48. local function checkwall(pos)
  49. local fdir = minetest.get_node(pos).param2
  50. local dxl = fdir_to_left[fdir + 1][1] -- dxl = "[D]elta [X] [L]eft"
  51. local dzl = fdir_to_left[fdir + 1][2] -- Z left
  52. local dxr = fdir_to_right[fdir + 1][1] -- X right
  53. local dzr = fdir_to_right[fdir + 1][2] -- Z right
  54. local node1 = minetest.get_node({x=pos.x+dxl, y=pos.y, z=pos.z+dzl})
  55. if not node1 or not minetest.registered_nodes[node1.name]
  56. or not minetest.registered_nodes[node1.name].buildable_to then
  57. return false
  58. end
  59. local node2 = minetest.get_node({x=pos.x+dxr, y=pos.y, z=pos.z+dzr})
  60. if not node2 or not minetest.registered_nodes[node2.name]
  61. or not minetest.registered_nodes[node2.name].buildable_to then
  62. return false
  63. end
  64. local node3 = minetest.get_node({x=pos.x+dxl, y=pos.y+1, z=pos.z+dzl})
  65. if not node3 or not minetest.registered_nodes[node3.name]
  66. or not minetest.registered_nodes[node3.name].buildable_to then
  67. return false
  68. end
  69. local node4 = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
  70. if not node4 or not minetest.registered_nodes[node4.name]
  71. or not minetest.registered_nodes[node4.name].buildable_to then
  72. return false
  73. end
  74. local node5 = minetest.get_node({x=pos.x+dxr, y=pos.y+1, z=pos.z+dzr})
  75. if not node5 or not minetest.registered_nodes[node5.name]
  76. or not minetest.registered_nodes[node5.name].buildable_to then
  77. return false
  78. end
  79. return true
  80. end
  81. minetest.register_node("plasmascreen:tv", {
  82. description = S("Plasma TV"),
  83. drawtype = "mesh",
  84. mesh = "plasmascreen_tv.obj",
  85. tiles = {
  86. "plasmascreen_case.png",
  87. { name="plasmascreen_video.png",
  88. animation={
  89. type="vertical_frames",
  90. aspect_w = 42,
  91. aspect_h = 23,
  92. length = 44
  93. }
  94. }
  95. },
  96. inventory_image = "plasmascreen_tv_inv.png",
  97. wield_image = "plasmascreen_tv_inv.png",
  98. paramtype = "light",
  99. paramtype2 = "facedir",
  100. light_source = 10,
  101. selection_box = tv_cbox,
  102. collision_box = tv_cbox,
  103. on_rotate = sc_disallow or nil,
  104. groups = {snappy=1, choppy=2, oddly_breakable_by_hand=2},
  105. after_place_node = function(pos, placer, itemstack)
  106. if not checkwall(pos) then
  107. minetest.set_node(pos, {name = "air"})
  108. return true -- "API: If return true no item is taken from itemstack"
  109. end
  110. end,
  111. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  112. minetest.set_node(pos, {name = "plasmascreen:tv_off", param2 = node.param2})
  113. end
  114. })
  115. minetest.register_node("plasmascreen:tv_off", {
  116. description = S("Plasma TV (off)"),
  117. drawtype = "mesh",
  118. mesh = "plasmascreen_tv.obj",
  119. tiles = {
  120. "plasmascreen_case_off.png",
  121. "plasmascreen_screen_off.png",
  122. },
  123. inventory_image = "plasmascreen_tv_inv.png",
  124. wield_image = "plasmascreen_tv_inv.png",
  125. paramtype = "light",
  126. paramtype2 = "facedir",
  127. light_source = 10,
  128. selection_box = tv_cbox,
  129. collision_box = tv_cbox,
  130. on_rotate = sc_disallow or nil,
  131. groups = {snappy=1, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
  132. after_place_node = function(pos, placer, itemstack)
  133. if not checkwall(pos) then
  134. minetest.set_node(pos, {name = "air"})
  135. return true -- "API: If return true no item is taken from itemstack"
  136. end
  137. end,
  138. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  139. minetest.set_node(pos, {name = "plasmascreen:tv", param2 = node.param2})
  140. end,
  141. drop = "plasmascreen:tv"
  142. })
  143. -- crafting recipes
  144. minetest.register_craft({
  145. output = "plasmascreen:tv",
  146. recipe = {
  147. {'default:glass', 'default:coal_lump', 'default:glass'},
  148. {'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
  149. {'default:glass', 'default:glass', 'default:glass'},
  150. }
  151. })
  152. minetest.register_craft({
  153. type = "shapeless",
  154. output = "plasmascreen:tv",
  155. recipe = {'homedecor:television', 'homedecor:television'},
  156. })
  157. minetest.register_craft({
  158. output = "plasmascreen:stand",
  159. recipe = {
  160. {'', '', ''},
  161. {'', 'default:steel_ingot', ''},
  162. {'group:stick', 'default:coal_lump', 'group:stick'},
  163. }
  164. })