init.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. plastic = plastic or {}
  2. plastic.modpath = minetest.get_modpath("plastic")
  3. -- Important: the ability to oil door/chest hinges does NOT require protection access.
  4. -- Can also polish infotext engravings so they become permanent (requires protection check).
  5. function plastic.oil_extract_on_use(itemstack, user, pt)
  6. if not user or not user:is_player() then
  7. return
  8. end
  9. if pt.type ~= "node" then
  10. return
  11. end
  12. local under = pt.under
  13. local node = minetest.get_node(under)
  14. local ndef = minetest.registered_nodes[node.name]
  15. if not ndef then
  16. return
  17. end
  18. local groups = ndef.groups or {}
  19. local success = false
  20. local meta = minetest.get_meta(under)
  21. local oil_hinge = function(pos, meta)
  22. local meta = meta or minetest.get_meta(pos)
  23. meta:set_int("oiled_hinge", 1)
  24. meta:set_int("oiled_time", os.time())
  25. meta:mark_as_private({"oiled_hinge", "oiled_time"})
  26. end
  27. -- Check for `groups.door` or `groups.trapdoor`.
  28. if (groups.door and groups.door > 0) or (groups.trapdoor and groups.trapdoor > 0) then
  29. local pname = user:get_player_name()
  30. oil_hinge(under, meta)
  31. minetest.chat_send_player(pname, "# Server: Door hinges at " .. rc.pos_to_namestr(under) .. " have been oiled.")
  32. success = true
  33. elseif (groups.chest_node and groups.chest_node > 0) then
  34. local pname = user:get_player_name()
  35. oil_hinge(under, meta)
  36. minetest.chat_send_player(pname, "# Server: Chest hinges at " .. rc.pos_to_namestr(under) .. " have been oiled.")
  37. success = true
  38. elseif meta:get_int("engraver_chiseled") ~= 0 then
  39. if meta:get_int("chiseled_polished") == 0 then -- Only if text wasn't already polished.
  40. -- Node has text engraving, polish it so that it cannot be modified anymore.
  41. local pname = user:get_player_name()
  42. if not minetest.test_protection(under, pname) then -- Requires protection access.
  43. minetest.chat_send_player(pname, "# Server: Text engraving at " .. rc.pos_to_namestr(under) .. " has been polished.")
  44. meta:set_int("chiseled_polished", 1)
  45. meta:mark_as_private("chiseled_polished")
  46. success = true
  47. end
  48. end
  49. end
  50. if success then
  51. itemstack:take_item()
  52. return itemstack
  53. end
  54. end
  55. if not plastic.registered then
  56. minetest.register_craftitem("plastic:oil_extract", {
  57. description = "Oil Extract",
  58. inventory_image = "homedecor_oil_extract.png",
  59. on_use = function(...)
  60. return plastic.oil_extract_on_use(...)
  61. end,
  62. })
  63. minetest.register_craftitem("plastic:raw_paraffin", {
  64. description = "Unprocessed Paraffin",
  65. inventory_image = "homedecor_paraffin.png",
  66. })
  67. minetest.register_craftitem("plastic:plastic_sheeting", {
  68. description = "Plastic Sheet",
  69. inventory_image = "homedecor_plastic_sheeting.png",
  70. })
  71. -- By machine: 3 leaves --> 1 oil
  72. minetest.register_craft({
  73. type = "compressing",
  74. output = "plastic:oil_extract 1",
  75. recipe = "group:leaves 3",
  76. time = 5,
  77. })
  78. -- By hand: 6 leaves --> 1 oil
  79. minetest.register_craft({
  80. type = "shapeless",
  81. output = "plastic:oil_extract 1",
  82. recipe = {
  83. "group:leaves",
  84. "group:leaves",
  85. "group:leaves",
  86. "group:leaves",
  87. "group:leaves",
  88. "group:leaves",
  89. },
  90. })
  91. -- With pestle: 4 leaves --> 1 oil
  92. minetest.register_craft({
  93. type = "shapeless",
  94. output = "plastic:oil_extract 1",
  95. recipe = {
  96. "group:leaves", "group:leaves", "group:leaves", "group:leaves",
  97. "farming:mortar_pestle"
  98. },
  99. replacements = {{"farming:mortar_pestle", "farming:mortar_pestle"}},
  100. })
  101. minetest.register_craft({
  102. type = "cooking",
  103. output = "plastic:raw_paraffin",
  104. recipe = "plastic:oil_extract",
  105. })
  106. minetest.register_craft({
  107. type = "cooking",
  108. output = "plastic:plastic_sheeting",
  109. recipe = "plastic:raw_paraffin",
  110. })
  111. minetest.register_craft({
  112. type = "fuel",
  113. recipe = "plastic:oil_extract",
  114. burntime = 20,
  115. })
  116. minetest.register_craft({
  117. type = "coalfuel",
  118. recipe = "plastic:oil_extract",
  119. burntime = 20,
  120. })
  121. minetest.register_craft({
  122. type = "fuel",
  123. recipe = "plastic:raw_paraffin",
  124. burntime = 20,
  125. })
  126. minetest.register_craft({
  127. type = "fuel",
  128. recipe = "plastic:plastic_sheeting",
  129. burntime = 20,
  130. })
  131. local c = "plastic:core"
  132. local f = plastic.modpath .. "/init.lua"
  133. reload.register_file(c, f, false)
  134. plastic.registered = true
  135. end