init.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. dofile(minetest.get_modpath("castle").."/pillars.lua")
  2. dofile(minetest.get_modpath("castle").."/arrowslit.lua")
  3. dofile(minetest.get_modpath("castle").."/town_item.lua")
  4. dofile(minetest.get_modpath("castle").."/autocraft.lua") -- from buildcraft
  5. minetest.register_node("castle:stonewall", {
  6. description = "Castle Wall",
  7. drawtype = "normal",
  8. tiles = {"castle_stonewall.png"},
  9. paramtype = "light",
  10. drop = "castle:stonewall",
  11. groups = {cracky = 3},
  12. sounds = default.node_sound_stone_defaults(),
  13. })
  14. minetest.register_node("castle:rubble", {
  15. description = "Castle Rubble",
  16. drawtype = "normal",
  17. tiles = {"castle_rubble.png"},
  18. paramtype = "light",
  19. groups = {crumbly = 3},
  20. sounds = default.node_sound_stone_defaults(),
  21. })
  22. minetest.register_craft({
  23. output = "castle:stonewall",
  24. recipe = {
  25. {"default:cobble"},
  26. {"default:desert_stone"},
  27. }
  28. })
  29. minetest.register_craft({
  30. output = "castle:rubble",
  31. recipe = {
  32. {"castle:stonewall"},
  33. }
  34. })
  35. minetest.register_craft({
  36. output = "castle:rubble 2",
  37. recipe = {
  38. {"default:gravel"},
  39. {"default:desert_stone"},
  40. }
  41. })
  42. minetest.register_node("castle:stonewall_corner", {
  43. drawtype = "normal",
  44. paramtype = "light",
  45. paramtype2 = "facedir",
  46. description = "Castle Corner",
  47. tiles = {
  48. "castle_stonewall.png",
  49. "castle_stonewall.png",
  50. "castle_corner_stonewall1.png",
  51. "castle_stonewall.png",
  52. "castle_stonewall.png",
  53. "castle_corner_stonewall2.png"
  54. },
  55. groups = {cracky = 3},
  56. sounds = default.node_sound_stone_defaults(),
  57. })
  58. minetest.register_craft({
  59. output = "castle:stonewall_corner",
  60. recipe = {
  61. {"", "castle:stonewall"},
  62. {"castle:stonewall", "default:sandstone"},
  63. }
  64. })
  65. doors.register("door_oak", {
  66. tiles = {{ name = "doors_door_oak.png", backface_culling = true }},
  67. description = "Oak Door",
  68. inventory_image = "doors_item_oak.png",
  69. protected = true,
  70. groups = {door = 1, choppy = 2, flammable = 2},
  71. material = "default:tree",
  72. recipe = {
  73. {"default:tree", "default:tree"},
  74. {"default:tree", "default:tree"},
  75. {"default:tree", "default:tree"},
  76. }
  77. })
  78. function default.get_ironbound_chest_formspec(pos)
  79. local spos = pos.x .. "," .. pos.y .. "," ..pos.z
  80. local formspec =
  81. "size[8,9]"
  82. .. default.gui_bg..default.gui_bg_img..default.gui_slots
  83. .. "list[nodemeta:".. spos .. ";main;0,0;8,4;]"
  84. .. "list[current_player;main;0,5;8,4;]"
  85. .. "listring[nodemeta:" .. spos .. ";main]"
  86. .. "listring[current_player;main]"
  87. return formspec
  88. end
  89. local function has_ironbound_chest_privilege(meta, player)
  90. if player:get_player_name() == meta:get_string("owner")
  91. or minetest.check_player_privs(player, {protection_bypass = true}) then
  92. return true
  93. end
  94. return false
  95. end
  96. minetest.register_node("castle:ironbound_chest",{
  97. drawtype = "nodebox",
  98. description = "Ironbound Chest",
  99. tiles = {
  100. "castle_ironbound_chest_top.png",
  101. "castle_ironbound_chest_top.png",
  102. "castle_ironbound_chest_side.png",
  103. "castle_ironbound_chest_side.png",
  104. "castle_ironbound_chest_back.png",
  105. "castle_ironbound_chest_front.png",
  106. },
  107. paramtype = "light",
  108. paramtype2 = "facedir",
  109. groups = {cracky=2},
  110. node_box = {
  111. type = "fixed",
  112. fixed = {
  113. {-0.500000,-0.500000,-0.312500,0.500000,-0.062500,0.312500},
  114. {-0.500000,-0.062500,-0.250000,0.500000,0.000000,0.250000},
  115. {-0.500000,0.000000,-0.187500,0.500000,0.062500,0.187500},
  116. {-0.500000,0.062500,-0.062500,0.500000,0.125000,0.062500},
  117. },
  118. },
  119. selection_box = {
  120. type = "fixed",
  121. fixed = {
  122. {-0.5,-0.500000,-0.400000,0.5,0.200000,0.4},
  123. },
  124. },
  125. sounds = default.node_sound_wood_defaults(),
  126. after_place_node = function(pos, placer)
  127. local meta = minetest.get_meta(pos)
  128. meta:set_string("owner", placer:get_player_name() or "")
  129. meta:set_string("infotext", "Ironbound Chest (owned by "..
  130. meta:get_string("owner")..")")
  131. end,
  132. on_construct = function(pos)
  133. local meta = minetest.get_meta(pos)
  134. meta:set_string("infotext", "Ironbound Chest")
  135. meta:set_string("owner", "")
  136. local inv = meta:get_inventory()
  137. inv:set_size("main", 8*4)
  138. end,
  139. can_dig = function(pos,player)
  140. local meta = minetest.get_meta(pos);
  141. local inv = meta:get_inventory()
  142. return inv:is_empty("main") and has_ironbound_chest_privilege(meta, player)
  143. end,
  144. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  145. local meta = minetest.get_meta(pos)
  146. if not has_ironbound_chest_privilege(meta, player) then
  147. minetest.log("action", player:get_player_name()..
  148. " tried to access a locked chest belonging to "..
  149. meta:get_string("owner").." at "..
  150. minetest.pos_to_string(pos))
  151. return 0
  152. end
  153. return count
  154. end,
  155. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  156. local meta = minetest.get_meta(pos)
  157. if not has_ironbound_chest_privilege(meta, player) then
  158. minetest.log("action", player:get_player_name()..
  159. " tried to access a locked chest belonging to "..
  160. meta:get_string("owner").." at "..
  161. minetest.pos_to_string(pos))
  162. return 0
  163. end
  164. return stack:get_count()
  165. end,
  166. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  167. local meta = minetest.get_meta(pos)
  168. if not has_ironbound_chest_privilege(meta, player) then
  169. minetest.log("action", player:get_player_name()..
  170. " tried to access a locked chest belonging to "..
  171. meta:get_string("owner").." at "..
  172. minetest.pos_to_string(pos))
  173. return 0
  174. end
  175. return stack:get_count()
  176. end,
  177. on_rightclick = function(pos, node, clicker)
  178. local meta = minetest.get_meta(pos)
  179. if has_ironbound_chest_privilege(meta, clicker) then
  180. minetest.show_formspec(
  181. clicker:get_player_name(),
  182. "castle:ironbound_chest",
  183. default.get_ironbound_chest_formspec(pos)
  184. )
  185. end
  186. end,
  187. })
  188. minetest.register_craft({
  189. output = "castle:ironbound_chest",
  190. recipe = {
  191. {"group:wood", "default:steel_ingot","group:wood"},
  192. {"group:wood", "default:steel_ingot","group:wood"}
  193. }
  194. })
  195. -- Wooden tapestry top
  196. minetest.register_node("castle:tapestry_top", {
  197. drawtype = "nodebox",
  198. description = "Tapestry Top",
  199. tiles = {"default_wood.png"},
  200. sunlight_propagates = true,
  201. groups = {flammable=3,choppy=2,oddly_breakable_by_hand=1},
  202. sounds = default.node_sound_defaults(),
  203. paramtype = "light",
  204. paramtype2 = "facedir",
  205. node_box = {
  206. type = "fixed",
  207. fixed = {-0.6,-0.5,0.375,0.6,-0.375,0.5},
  208. },
  209. selection_box = {
  210. type = "fixed",
  211. fixed = {-0.6,-0.5,0.375,0.6,-0.375,0.5},
  212. },
  213. })
  214. minetest.register_craft({
  215. type = "shapeless",
  216. output = "castle:tapestry_top",
  217. recipe = {"default:stick"},
  218. })
  219. minetest.register_craft({
  220. type = "shapeless",
  221. recipe = {"castle:tapestry_top"},
  222. output = "default:stick",
  223. })
  224. print ("[MOD] Castle loaded")