init.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. minetest.register_node("mesecons_dispenser:dispenser", {
  2. description = "Dispenser",
  3. tiles = {"mesecons_dispenser_top.png" , "mesecons_dispenser_bottom.png",
  4. "mesecons_dispenser_side.png", "mesecons_dispenser_side.png" ,
  5. "mesecons_dispenser_side.png", "mesecons_dispenser_front.png"},
  6. paramtype2 = "facedir",
  7. groups = {cracky=2},
  8. sounds = default.node_sound_stone_defaults(),
  9. on_construct = function(pos)
  10. local meta = minetest.env:get_meta(pos)
  11. meta:set_string("formspec",
  12. "size[8,7]"..
  13. "list[current_name;main;2.5,0;3,3;]"..
  14. "list[current_player;main;0,3;8,4;]")
  15. local inv = meta:get_inventory()
  16. inv:set_size("main", 3*3)
  17. end,
  18. mesecons = {effector={
  19. action_on = function (pos, node)
  20. local dir = {{x=1, y=0, z=0}}
  21. for _ = 0, node.param2 do
  22. dir = mesecon:rotate_rules_left(dir)
  23. end
  24. dir = dir[1]
  25. local objpos = mesecon:addPosRule(pos, {x=dir.x/2, y=dir.y/2, z=dir.z/2})
  26. --minetest.env:add_node(mesecon:addPosRule(pos, dir[1]), {name="default:wood"})
  27. local inv = minetest.env:get_meta(pos):get_inventory()
  28. local stacks = {}
  29. for j = 1, 9 do
  30. local ts = inv:get_stack("main", j)
  31. if not ts:is_empty() then
  32. table.insert(stacks, {stack = ts, id = j})
  33. end
  34. end
  35. print(dump(stacks))
  36. if #stacks > 0 then
  37. local sn = math.random(1, #stacks)
  38. local takenitem = stacks[sn].stack:take_item()
  39. inv:set_stack("main", stacks[sn].id, stacks[sn].stack)
  40. print(dump(takenitem:to_table()))
  41. local obj = minetest.env:add_item(objpos, takenitem:to_table())
  42. obj:setvelocity({ x=dir.x*5+math.random(1, 100)/50-0.5,
  43. y=dir.y*5+math.random(1, 100)/50-0.5,
  44. z=dir.z*5+math.random(1, 100)/50-0.5})
  45. end
  46. end
  47. }},
  48. })
  49. minetest.register_craft({
  50. output = 'mesecons_dispenser:dispenser',
  51. recipe = {
  52. {"default:cobble", "default:cobble", "default:cobble"},
  53. {"default:cobble", "mesecons_materials:fiber", "default:cobble"},
  54. {"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
  55. }
  56. })