longsofas.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. local S = minetest.get_translator("homedecor_seating")
  2. local longsofa_cbox = {
  3. type = "wallmounted",
  4. wall_side = {-0.5, -0.5, -0.5, 0.5, 0.5, 2.5},
  5. }
  6. minetest.register_node(":lrfurn:longsofa", {
  7. description = S("Long Sofa"),
  8. drawtype = "mesh",
  9. mesh = "lrfurn_sofa_long.obj",
  10. tiles = {
  11. "lrfurn_upholstery.png",
  12. { name = "lrfurn_sofa_bottom.png", color = 0xffffffff }
  13. },
  14. paramtype = "light",
  15. paramtype2 = "colorwallmounted",
  16. palette = "unifieddyes_palette_colorwallmounted.png",
  17. inventory_image = "lrfurn_longsofa_inv.png",
  18. wield_scale = { x = 0.6, y = 0.6, z = 0.6 },
  19. groups = {snappy=3, ud_param2_colorable = 1},
  20. sounds = default.node_sound_wood_defaults(),
  21. selection_box = longsofa_cbox,
  22. node_box = longsofa_cbox,
  23. on_rotate = minetest.get_modpath("screwdriver") and screwdriver.disallow or nil,
  24. after_place_node = function(pos, placer, itemstack, pointed_thing)
  25. lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing)
  26. local playername = placer:get_player_name()
  27. if minetest.is_protected(pos, placer:get_player_name()) then return true end
  28. local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false)
  29. if lrfurn.check_right(pos, fdir, true, placer) then
  30. if not creative.is_enabled_for(playername) then
  31. itemstack:take_item()
  32. end
  33. else
  34. minetest.chat_send_player(placer:get_player_name(), S("No room to place the sofa!"))
  35. minetest.set_node(pos, { name = "air" })
  36. end
  37. return itemstack
  38. end,
  39. on_dig = unifieddyes.on_dig,
  40. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  41. if not clicker:is_player() then
  42. return itemstack
  43. end
  44. pos.y = pos.y-0.5
  45. clicker:setpos(pos)
  46. clicker:set_hp(20)
  47. return itemstack
  48. end
  49. })
  50. minetest.register_craft({
  51. output = "lrfurn:longsofa",
  52. recipe = {
  53. {"wool:white", "wool:white", "wool:white", },
  54. {"stairs:slab_wood", "stairs:slab_wood", "stairs:slab_wood", },
  55. {"group:stick", "group:stick", "group:stick", }
  56. }
  57. })
  58. minetest.register_craft({
  59. output = "lrfurn:longsofa",
  60. recipe = {
  61. {"wool:white", "wool:white", "wool:white", },
  62. {"moreblocks:slab_wood", "moreblocks:slab_wood", "moreblocks:slab_wood", },
  63. {"group:stick", "group:stick", "group:stick", }
  64. }
  65. })
  66. unifieddyes.register_color_craft({
  67. output = "lrfurn:longsofa",
  68. palette = "wallmounted",
  69. type = "shapeless",
  70. neutral_node = "lrfurn:longsofa",
  71. recipe = {
  72. "NEUTRAL_NODE",
  73. "MAIN_DYE"
  74. }
  75. })
  76. -- convert old static nodes to param2 colorization
  77. lrfurn.old_static_longsofas = {}
  78. for _, color in ipairs(lrfurn.colors) do
  79. table.insert(lrfurn.old_static_longsofas, "lrfurn:longsofa_"..color)
  80. end
  81. minetest.register_lbm({
  82. name = ":lrfurn:convert_longsofas",
  83. label = "Convert lrfurn long sofas to use param2 color",
  84. run_at_every_load = false,
  85. nodenames = lrfurn.old_static_longsofas,
  86. action = function(pos, node)
  87. local name = node.name
  88. local color = string.sub(name, string.find(name, "_")+1)
  89. if color == "red" then
  90. color = "medium_red"
  91. elseif color == "dark_green" then
  92. color = "medium_green"
  93. elseif color == "magenta" then
  94. color = "medium_magenta"
  95. elseif color == "cyan" then
  96. color = "medium_cyan"
  97. end
  98. local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, "wallmounted")
  99. local old_fdir = math.floor(node.param2 % 32)
  100. local new_fdir = 3
  101. if old_fdir == 0 then
  102. new_fdir = 3
  103. elseif old_fdir == 1 then
  104. new_fdir = 4
  105. elseif old_fdir == 2 then
  106. new_fdir = 2
  107. elseif old_fdir == 3 then
  108. new_fdir = 5
  109. end
  110. local param2 = paletteidx + new_fdir
  111. minetest.set_node(pos, { name = "lrfurn:longsofa", param2 = param2 })
  112. local meta = minetest.get_meta(pos)
  113. meta:set_string("dye", "unifieddyes:"..color)
  114. end
  115. })
  116. if minetest.settings:get("log_mods") then
  117. minetest.log("action", "[lrfurn/longsofas] Loaded!")
  118. end