box_steel.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. --[[
  2. TechPack Warehouse
  3. ==================
  4. Copyright (C) 2017-2020 Joachim Stolberg
  5. AGPL v3
  6. See LICENSE.txt for more information
  7. box_steel.lua
  8. ]]--
  9. -- Load support for I18n
  10. local S = techpack_warehouse.S
  11. --- for lazy programmers
  12. local P = minetest.string_to_pos
  13. local M = minetest.get_meta
  14. local wh = techpack_warehouse
  15. local NODE_NAME = "techpack_warehouse:box_steel"
  16. local DESCRIPTION = S("Warehouse Box Steel")
  17. local INV_SIZE = 400
  18. local BACKGROUND_IMG = "default_steel_block.png"
  19. local Box = wh.Box:new({
  20. node_name = NODE_NAME,
  21. description = DESCRIPTION,
  22. inv_size = INV_SIZE,
  23. background_img = BACKGROUND_IMG,
  24. })
  25. minetest.register_node(NODE_NAME, {
  26. description = DESCRIPTION.." (8 x "..INV_SIZE.." items)",
  27. tiles = wh.tiles(BACKGROUND_IMG),
  28. after_place_node = function(pos, placer, itemstack)
  29. return wh.after_place_node(Box, pos, placer, itemstack)
  30. end,
  31. on_receive_fields = function(pos, formname, fields, player)
  32. wh.on_receive_fields(Box, pos, formname, fields, player)
  33. end,
  34. on_timer = function(pos,elapsed)
  35. return wh.on_timer(Box, pos,elapsed)
  36. end,
  37. can_dig = function(pos)
  38. return wh.can_dig(Box, pos)
  39. end,
  40. on_dig = function(pos, node, player)
  41. wh.on_dig_node(Box, pos, node, player)
  42. end,
  43. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  44. return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player)
  45. end,
  46. on_metadata_inventory_put = wh.on_metadata_inventory_put,
  47. allow_metadata_inventory_take = wh.allow_metadata_inventory_take,
  48. allow_metadata_inventory_move = wh.allow_metadata_inventory_move,
  49. on_rotate = screwdriver.disallow,
  50. paramtype = "light",
  51. sunlight_propagates = true,
  52. paramtype2 = "facedir",
  53. groups = {choppy=2, cracky=2, crumbly=2},
  54. is_ground_content = false,
  55. sounds = default.node_sound_metal_defaults(),
  56. })
  57. minetest.register_node(NODE_NAME.."_active", {
  58. description = DESCRIPTION.." (8 x "..INV_SIZE.." items)",
  59. tiles = wh.tiles_active(BACKGROUND_IMG),
  60. after_place_node = function(pos, placer, itemstack)
  61. return wh.after_place_node(Box, pos, placer, itemstack)
  62. end,
  63. on_receive_fields = function(pos, formname, fields, player)
  64. wh.on_receive_fields(Box, pos, formname, fields, player)
  65. end,
  66. on_timer = function(pos,elapsed)
  67. return wh.on_timer(Box, pos,elapsed)
  68. end,
  69. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  70. return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player)
  71. end,
  72. on_metadata_inventory_put = wh.on_metadata_inventory_put,
  73. allow_metadata_inventory_take = wh.allow_metadata_inventory_take,
  74. allow_metadata_inventory_move = wh.allow_metadata_inventory_move,
  75. diggable = false,
  76. can_dig = function() return false end,
  77. on_rotate = screwdriver.disallow,
  78. paramtype = "light",
  79. sunlight_propagates = true,
  80. paramtype2 = "facedir",
  81. groups = {crumbly=0, not_in_creative_inventory=1},
  82. is_ground_content = false,
  83. sounds = default.node_sound_metal_defaults(),
  84. })
  85. minetest.register_node(NODE_NAME.."_defect", {
  86. description = DESCRIPTION.." (8 x "..INV_SIZE.." items)",
  87. tiles = wh.tiles_defect(BACKGROUND_IMG),
  88. after_place_node = function(pos, placer, itemstack)
  89. wh.after_place_node(Box, pos, placer, itemstack)
  90. Box.State:defect(pos, M(pos))
  91. end,
  92. can_dig = function(pos)
  93. return wh.can_dig(Box, pos)
  94. end,
  95. on_dig = function(pos, node, player)
  96. wh.on_dig_node(Box, pos, node, player)
  97. end,
  98. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  99. return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player)
  100. end,
  101. on_metadata_inventory_put = wh.on_metadata_inventory_put,
  102. allow_metadata_inventory_take = wh.allow_metadata_inventory_take,
  103. allow_metadata_inventory_move = wh.allow_metadata_inventory_move,
  104. on_rotate = screwdriver.disallow,
  105. paramtype = "light",
  106. sunlight_propagates = true,
  107. paramtype2 = "facedir",
  108. groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
  109. is_ground_content = false,
  110. sounds = default.node_sound_metal_defaults(),
  111. })
  112. tubelib.register_node(NODE_NAME,
  113. {NODE_NAME.."_active", NODE_NAME.."_defect"}, {
  114. on_push_item = function(pos, side, item)
  115. local meta = M(pos)
  116. meta:set_string("push_dir", wh.Turn180[side])
  117. local num = wh.inv_add_item(Box, meta, item)
  118. if num > 0 then
  119. item:set_count(num)
  120. return tubelib.put_item(meta, "shift", item)
  121. end
  122. return true
  123. end,
  124. on_pull_stack = function(pos, side)
  125. return tubelib.get_stack(M(pos), "main")
  126. end,
  127. on_pull_item = function(pos, side)
  128. return tubelib.get_item(M(pos), "main")
  129. end,
  130. on_unpull_item = function(pos, side, item)
  131. local meta = M(pos)
  132. local num = wh.inv_add_item(Box, meta, item)
  133. if num > 0 then
  134. -- this should never happen, but better safe than sorry
  135. item:set_count(num)
  136. return tubelib.put_item(meta, "shift", item)
  137. end
  138. return true
  139. end,
  140. on_recv_message = function(pos, topic, payload)
  141. local resp = Box.State:on_receive_message(pos, topic, payload)
  142. if resp then
  143. return resp
  144. elseif topic == "num_items" then
  145. return wh.get_num_items(M(pos), payload)
  146. else
  147. return "unsupported"
  148. end
  149. end,
  150. on_node_load = function(pos)
  151. Box.State:on_node_load(pos)
  152. end,
  153. on_node_repair = function(pos)
  154. return Box.State:on_node_repair(pos)
  155. end,
  156. })
  157. minetest.register_craft({
  158. output = NODE_NAME,
  159. recipe = {
  160. {"default:steel_ingot", "tubelib:pusher", "default:steel_ingot"},
  161. {"", "tubelib_addons1:chest", ""},
  162. {"", "", ""},
  163. }
  164. })