detector.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. local mesecons_rules = mesecon.rules.flat
  2. function boost_cart:turnoff_detector_rail(pos)
  3. local node = minetest.get_node(pos)
  4. if minetest.get_item_group(node.name, "detector_rail") == 1 then
  5. if node.name == "boost_cart:detectorrail_on" then --has not been dug
  6. minetest.swap_node(pos, {name = "boost_cart:detectorrail", param2=node.param2})
  7. end
  8. mesecon.receptor_off(pos, mesecons_rules)
  9. end
  10. end
  11. function boost_cart:signal_detector_rail(pos)
  12. local node = minetest.get_node(pos)
  13. if minetest.get_item_group(node.name, "detector_rail") ~= 1 then
  14. return
  15. end
  16. if node.name == "boost_cart:detectorrail" then
  17. minetest.swap_node(pos, {name = "boost_cart:detectorrail_on", param2=node.param2})
  18. end
  19. mesecon.receptor_on(pos, mesecons_rules)
  20. minetest.after(0.5, boost_cart.turnoff_detector_rail, boost_cart, pos)
  21. end
  22. boost_cart:register_rail("boost_cart:detectorrail", {
  23. description = "Detector rail",
  24. tiles = {
  25. "carts_rail_straight_dtc.png", "carts_rail_curved_dtc.png",
  26. "carts_rail_t_junction_dtc.png", "carts_rail_crossing_dtc.png"
  27. },
  28. groups = boost_cart:get_rail_groups({detector_rail = 1}),
  29. mesecons = {receptor = {state = "off", rules = mesecons_rules}},
  30. })
  31. boost_cart:register_rail("boost_cart:detectorrail_on", {
  32. description = "Detector rail ON (you hacker you)",
  33. tiles = {
  34. "carts_rail_straight_dtc_on.png", "carts_rail_curved_dtc_on.png",
  35. "carts_rail_t_junction_dtc_on.png", "carts_rail_crossing_dtc_on.png"
  36. },
  37. groups = boost_cart:get_rail_groups({
  38. detector_rail = 1, not_in_creative_inventory = 1
  39. }),
  40. drop = "boost_cart:detectorrail",
  41. mesecons = {receptor = {state = "on", rules = mesecons_rules}},
  42. })
  43. minetest.register_craft({
  44. output = "boost_cart:detectorrail 12",
  45. recipe = {
  46. {"default:steel_ingot", "group:stick", "default:steel_ingot"},
  47. {"default:steel_ingot", "mesecons:wire_00000000_off", "default:steel_ingot"},
  48. {"default:steel_ingot", "group:stick", "default:steel_ingot"},
  49. },
  50. })