init.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. -- Edited version of bucket mod
  2. -- See README.txt for licensing and other information.
  3. minetest.register_privilege("spill", {description = "Can place liquids.", give_to_singleplayer=false,})
  4. minetest.register_alias("bucket", "bucket:bucket_empty")
  5. minetest.register_alias("bucket_water", "bucket:bucket_water")
  6. minetest.register_alias("bucket_lava", "bucket:bucket_lava")
  7. minetest.register_craft({
  8. output = 'bucket:bucket_empty 1',
  9. recipe = {
  10. {'default:steel_ingot', '', 'default:steel_ingot'},
  11. {'', 'default:steel_ingot', ''},
  12. }
  13. })
  14. bucket = {}
  15. bucket.liquids = {}
  16. local function check_protection(pos, name, text)
  17. if minetest.is_protected(pos, name) then
  18. minetest.log("action", (name ~= "" and name or "A mod")
  19. .. " tried to " .. text
  20. .. " at protected position "
  21. .. minetest.pos_to_string(pos)
  22. .. " with a bucket")
  23. minetest.record_protection_violation(pos, name)
  24. return true
  25. end
  26. return false
  27. end
  28. -- Register a new liquid
  29. -- source = name of the source node
  30. -- flowing = name of the flowing node
  31. -- itemname = name of the new bucket item (or nil if liquid is not takeable)
  32. -- inventory_image = texture of the new bucket item (ignored if itemname == nil)
  33. -- name = text description of the bucket item
  34. -- groups = (optional) groups of the bucket item, for example {water_bucket = 1}
  35. -- This function can be called from any mod (that depends on bucket).
  36. function bucket.register_liquid(source, flowing, itemname, inventory_image, name, groups)
  37. bucket.liquids[source] = {
  38. source = source,
  39. flowing = flowing,
  40. itemname = itemname,
  41. }
  42. bucket.liquids[flowing] = bucket.liquids[source]
  43. if itemname ~= nil then
  44. minetest.register_craftitem(itemname, {
  45. description = name,
  46. inventory_image = inventory_image,
  47. stack_max = 1,
  48. liquids_pointable = true,
  49. groups = groups,
  50. on_place = function(itemstack, user, pointed_thing)
  51. --priv check here
  52. if minetest.check_player_privs(user.get_player_name(user), {spill=true}) then
  53. -- Must be pointing to node
  54. if pointed_thing.type ~= "node" then
  55. return
  56. end
  57. local node = minetest.get_node_or_nil(pointed_thing.under)
  58. local ndef
  59. if node then
  60. ndef = minetest.registered_nodes[node.name]
  61. end
  62. -- Call on_rightclick if the pointed node defines it
  63. if ndef and ndef.on_rightclick and
  64. user and not user:get_player_control().sneak then
  65. return ndef.on_rightclick(
  66. pointed_thing.under,
  67. node, user,
  68. itemstack) or itemstack
  69. end
  70. local place_liquid = function(pos, node, source, flowing)
  71. if check_protection(pos,
  72. user and user:get_player_name() or "",
  73. "place "..source) then
  74. return
  75. end
  76. minetest.add_node(pos, {name=source})
  77. minetest.log('action', user:get_player_name()..' placed '..source..' at '..minetest.pos_to_string(pos))
  78. end
  79. -- Check if pointing to a buildable node
  80. if ndef and ndef.buildable_to then
  81. -- buildable; replace the node
  82. place_liquid(pointed_thing.under, node,
  83. source, flowing)
  84. else
  85. -- not buildable to; place the liquid above
  86. -- check if the node above can be replaced
  87. local node = minetest.get_node_or_nil(pointed_thing.above)
  88. if node and minetest.registered_nodes[node.name].buildable_to then
  89. place_liquid(pointed_thing.above,
  90. node, source,
  91. flowing)
  92. else
  93. -- do not remove the bucket with the liquid
  94. return
  95. end
  96. end
  97. return {name="bucket:bucket_empty"}
  98. else
  99. minetest.chat_send_player(user:get_player_name(), "You need the spill priv.")
  100. return
  101. end
  102. end
  103. })
  104. end
  105. end
  106. minetest.register_craftitem("bucket:bucket_empty", {
  107. description = "Empty Bucket",
  108. inventory_image = "bucket.png",
  109. stack_max = 99,
  110. liquids_pointable = true,
  111. on_use = function(itemstack, user, pointed_thing)
  112. -- Must be pointing to node
  113. if pointed_thing.type ~= "node" then
  114. return
  115. end
  116. -- Check if pointing to a liquid source
  117. local node = minetest.get_node(pointed_thing.under)
  118. local liquiddef = bucket.liquids[node.name]
  119. local item_count = user:get_wielded_item():get_count()
  120. if liquiddef ~= nil
  121. and liquiddef.itemname ~= nil
  122. and node.name == liquiddef.source then
  123. if check_protection(pointed_thing.under,
  124. user:get_player_name(),
  125. "take ".. node.name) then
  126. return
  127. end
  128. -- default set to return filled bucket
  129. local giving_back = liquiddef.itemname
  130. -- check if holding more than 1 empty bucket
  131. if item_count > 1 then
  132. -- if space in inventory add filled bucked, otherwise drop as item
  133. local inv = user:get_inventory()
  134. if inv:room_for_item("main", {name=liquiddef.itemname}) then
  135. inv:add_item("main", liquiddef.itemname)
  136. else
  137. local pos = user:getpos()
  138. pos.y = math.floor(pos.y + 0.5)
  139. core.add_item(pos, liquiddef.itemname)
  140. end
  141. -- set to return empty buckets minus 1
  142. giving_back = "bucket:bucket_empty "..tostring(item_count-1)
  143. end
  144. minetest.add_node(pointed_thing.under, {name="air"})
  145. return ItemStack(giving_back)
  146. end
  147. end,
  148. })
  149. bucket.register_liquid(
  150. "default:water_source",
  151. "default:water_flowing",
  152. "bucket:bucket_water",
  153. "bucket_water.png",
  154. "Water Bucket",
  155. {water_bucket = 1}
  156. )
  157. bucket.register_liquid(
  158. "default:river_water_source",
  159. "default:river_water_flowing",
  160. "bucket:bucket_river_water",
  161. "bucket_river_water.png",
  162. "River Water Bucket",
  163. {water_bucket = 1}
  164. )
  165. bucket.register_liquid(
  166. "default:lava_source",
  167. "default:lava_flowing",
  168. "bucket:bucket_lava",
  169. "bucket_lava.png",
  170. "Lava Bucket"
  171. )
  172. minetest.register_craft({
  173. type = "fuel",
  174. recipe = "bucket:bucket_lava",
  175. burntime = 60,
  176. replacements = {{"bucket:bucket_lava", "bucket:bucket_empty"}},
  177. })
  178. -- protected nodes requiring spill priv for placement
  179. -- to add additional nodes, insert new entries for source_list
  180. local source_list = {
  181. "default:water_source",
  182. "default:river_water_source",
  183. "default:lava_source",
  184. }
  185. for sourcecount = 1, #source_list do
  186. minetest.override_item(source_list[sourcecount], {
  187. on_place = function(itemstack, placer, pointed_thing)
  188. local can_spill = minetest.check_player_privs(placer.get_player_name(placer), {spill=true})
  189. if not can_spill then
  190. minetest.chat_send_player(placer:get_player_name(), "Ask the Admin if you need to place liquids.")
  191. return
  192. end
  193. return minetest.item_place(itemstack, placer, pointed_thing)
  194. end
  195. })
  196. end
  197. --corium protection
  198. if minetest.get_modpath("technic") then
  199. minetest.override_item("technic:bucket_corium", {
  200. groups = {not_in_creative_inventory=1},
  201. })
  202. minetest.override_item("technic:chernobylite_block", {
  203. groups = {not_in_creative_inventory=1},
  204. })
  205. minetest.override_item("technic:corium_source", {
  206. groups = {not_in_creative_inventory=1},
  207. })
  208. end