DoDoom

GestionCycle cc tweaked

May 24th, 2024 (edited)
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.90 KB | Gaming | 0 0
  1. --[[
  2. MC 1.20.1
  3. Fabric 0.15.11; Create fabric 0.5.1; CC: Tweaked 1.110.3; CC:C Bridge; Wired Redstone 0.7.8.
  4. This program is her to symplify the management of the IO betwen cc tweaked and wired redstone.
  5. This program only support DIGITAL IO.
  6.  
  7. WRITE YOUR CODE IN THE MAIN FUNCTION test
  8.  
  9. To declare a INPUT :
  10. 1. Write inputUpdt("color of your wire" String,"the side where you plug in your Bundled Cables" String)
  11. To declare a OUTPUT :
  12. 1. Create a variable with a name that match with the preactuator. ( in this exemple the preactuator is the Gearshift)
  13. 2. use : outputUpdt("color of your wire" String, "the side where you plug in your Bundled Cables" String, "the variable you want to link at the output" Bool) to update your output
  14.  
  15. Warning ! you can't (for the moment) define INPUT and OUTPUT on the same side.
  16.  
  17. In this example, we are constantly moving a mechanical piston in and out.
  18. The operative part :
  19.  
  20.     [  Motor  ] (warning, supply mecanical energy in the right way round)
  21.     [Gearshift]
  22. ----[M Piston ]-----------]
  23.                [C1]           [C2]
  24.  
  25. "Output" The Gearshift connected on White Wire on Left Bundled cable
  26. "Input" C1 orange Wire connected on right Bundled cable
  27. "Input" C2 pink Wire connected on right Bundled cable
  28.  
  29. ]]
  30.  
  31. -- Dont touch here >:|
  32. shell.run("rm /startup.lua")
  33. shell.run("pastebin get aD3dF3CA /startup.lua")
  34. -- input update
  35. function inputUpdt(color,side)
  36.     local inputState = false
  37.     local colorString = "String"
  38.     local sideString = "String"
  39.     sideString = side
  40.     colorString = color
  41.         case =
  42.         {
  43.         ["white"] = function ()
  44.             if (bit.band(rs.getBundledInput(sideString), colors.white) == 1) then
  45.                 inputState = true
  46.             else
  47.                 inputState = false
  48.             end
  49.         end,
  50.         ["orange"] = function ()
  51.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.orange), 1) == 1) then
  52.                 inputState = true
  53.             else
  54.                 inputState = false
  55.             end
  56.         end,
  57.         ["magenta"] = function ()
  58.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.magenta), 2) == 1) then
  59.                 inputState = true
  60.             else
  61.                 inputState = false
  62.             end
  63.         end,
  64.         ["lightBlue"] = function ()
  65.             if bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.lightBlue), 3) == 1 then
  66.                 inputState = true
  67.             else
  68.                 inputState = false
  69.             end
  70.         end,
  71.         ["yellow"] = function ()
  72.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.yellow), 4) == 1) then
  73.                 inputState = true
  74.             else
  75.                 inputState = false
  76.             end
  77.         end,
  78.         ["lime"] = function ()
  79.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.lime), 5) == 1) then
  80.                 inputState = true
  81.             else
  82.                 inputState = false
  83.             end
  84.         end,
  85.         ["pink"] = function ()
  86.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.pink), 6) == 1) then
  87.                 inputState = true
  88.             else
  89.                 inputState = false
  90.             end
  91.         end,
  92.         ["gray"] = function ()
  93.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.gray), 7) == 1) then
  94.                 inputState = true
  95.             else
  96.                 inputState = false
  97.             end
  98.         end,
  99.         ["lightGray"] = function ()
  100.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.lightGray), 8) == 1) then
  101.                 inputState = true
  102.             else
  103.                 inputState = false
  104.             end
  105.         end,
  106.         ["cyan"] = function ()
  107.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.cyan), 9) == 1) then
  108.                 inputState = true
  109.             else
  110.                 inputState = false
  111.             end
  112.         end,
  113.         ["purple"] = function ()
  114.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.purple), 10) == 1) then
  115.                 inputState = true
  116.             else
  117.                 inputState = false
  118.             end
  119.         end,
  120.         ["blue"] = function ()
  121.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.blue), 11) == 1) then
  122.                 inputState = true
  123.             else
  124.                 inputState = false
  125.             end
  126.         end,
  127.         ["brown"] = function ()
  128.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.brown), 12) == 1) then
  129.                 inputState = true
  130.             else
  131.                 inputState = false
  132.             end
  133.         end,
  134.         ["green"] = function ()
  135.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.green), 13) == 1) then
  136.                 inputState = true
  137.             else
  138.                 inputState = false
  139.             end
  140.         end,
  141.         ["red"] = function ()
  142.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.red), 14) == 1) then
  143.                 inputState = true
  144.             else
  145.                 inputState = false
  146.             end
  147.         end,
  148.         ["black"] = function ()
  149.             if (bit.blogic_rshift(bit.band(rs.getBundledInput(sideString), colors.black), 15) == 1) then
  150.                 inputState = true
  151.             else
  152.                 inputState = false
  153.             end
  154.         end,
  155.         ["default"] = function ()
  156.             return "error"
  157.             end
  158.         }
  159.         if case[colorString] then
  160.            case[colorString]()
  161.         else
  162.            case["default"]()
  163.         end
  164.     return inputState
  165. end
  166.  
  167. --Inilisation of the table of Output
  168. OutputTable = {Bottom = 0, top = 0, back = 0, front = 0, right = 0, left = 0}
  169. --output update
  170.     function outputUpdt(color, side, var)
  171.     local outputState = false
  172.     local colorString = "String"
  173.     local sideString = "String"
  174.     outputState = var
  175.     sideString = side
  176.     colorString = color
  177.     case =
  178.     {
  179.         ["white"] = function ()
  180.             if var then
  181.                 OutputTable[sideString] = OutputTable[sideString] + colors.white
  182.                 end
  183.             end,
  184.         ["orange"] = function ()
  185.             if var then
  186.                 OutputTable[sideString] = OutputTable[sideString] + colors.orange
  187.                 end
  188.             end,
  189.         ["magenta"] = function ()
  190.             if var then
  191.                 OutputTable[sideString] = OutputTable[sideString] + colors.magenta
  192.                 end
  193.             end,
  194.         ["lightBlue"] = function ()
  195.             if var then
  196.                 OutputTable[sideString] = OutputTable[sideString] + colors.lightBlue
  197.                 end
  198.             end,
  199.         ["yellow"] = function ()
  200.             if var then
  201.                 OutputTable[sideString] = OutputTable[sideString] + colors.yellow
  202.                 end
  203.             end,
  204.         ["lime"] = function ()
  205.             if var then
  206.                 OutputTable[sideString] = OutputTable[sideString] + colors.lime
  207.                 end
  208.             end,
  209.         ["pink"] = function ()
  210.             if var then
  211.                 OutputTable[sideString] = OutputTable[sideString] + colors.pink
  212.                 end
  213.             end,
  214.         ["gray"] = function ()
  215.             if var then
  216.                 OutputTable[sideString] = OutputTable[sideString] + colors.gray
  217.                 end
  218.             end,
  219.         ["lightGray"] = function ()
  220.             if var then
  221.                 OutputTable[sideString] = OutputTable[sideString] + colors.lightGray
  222.                 end
  223.             end,
  224.         ["cyan"] = function ()
  225.             if var then
  226.                 OutputTable[sideString] = OutputTable[sideString] + colors.cyan
  227.                 end
  228.             end,
  229.         ["purple"] = function ()
  230.             if var then
  231.                 OutputTable[sideString] = OutputTable[sideString] + colors.purple
  232.                 end
  233.             end,
  234.         ["blue"] = function ()
  235.             if var then
  236.                 OutputTable[sideString] = OutputTable[sideString] + colors.blue
  237.                 end
  238.             end,
  239.         ["brown"] = function ()
  240.             if var then
  241.                 OutputTable[sideString] = OutputTable[sideString] + colors.brown
  242.                 end
  243.             end,
  244.         ["green"] = function ()
  245.             if var then
  246.                 OutputTable[sideString] = OutputTable[sideString] + colors.green
  247.                 end
  248.             end,
  249.         ["red"] = function ()
  250.             if var then
  251.                 OutputTable[sideString] = OutputTable[sideString] + colors.red
  252.                 end
  253.             end,
  254.         ["black"] = function ()
  255.             if var then
  256.                 OutputTable[sideString] = OutputTable[sideString] + colors.black
  257.                 end
  258.             end,
  259.         ["default"] = function ()
  260.             return "error"
  261.             end
  262.     }
  263.     if case[colorString] then
  264.            case[colorString]()
  265.         else
  266.            case["default"]()
  267.         end
  268.     end
  269.  
  270. -- init
  271.     --système
  272.     firstScan = true
  273.     main = require("main")
  274.     --digital Output "memento", name your outputs here (don't forget to initialise at false).
  275.     pistonRetract = false
  276.     light = false
  277.     -- Memory Variables, feel free to add some Memory variables.
  278.     G7State_0Actual = 0
  279.     G7State_0Future = 0
  280.    
  281. -- Loopy-Loop
  282. while 0 do
  283.  
  284.     -- Main "OB1" here put your code. (if you can, write your program in another file and link it here)
  285.     main()
  286.  
  287.     --physical Output Update, don't touch here you little bastard >=]
  288.     for k,v in pairs(OutputTable) do
  289.         rs.setBundledOutput(k, v)
  290.     end
  291.     OutputTable = {Bottom = 0, top = 0, back = 0, front = 0, right = 0, left = 0}
  292.  
  293.     -- système
  294.     os.sleep(1)
  295.     firstScan = false
  296. end
  297. -- CMF = {Stick, INCH's, Goune} --
Add Comment
Please, Sign In to add comment