SHOW:
|
|
- or go back to the newest paste.
1 | -- takes about 56 seconds for a DM Generation loop to complete | |
2 | -- if you build a bigger one, increase TimeForParticleToReachFinalBend. | |
3 | -- ColliderActivationDuration should be fine. | |
4 | -- if you build a smaller one, experiment how long it takes the particle to | |
5 | -- reach the final bend, then add 2 seconds onto it (or dont... just experiment and | |
6 | -- see what works for you :]] ) | |
7 | ||
8 | -- Mine is 78x78 and this code works perfectly for it. (78 as in 78 electromagnets on the bottom of each side) | |
9 | PACounter = 0 | |
10 | CollisionPACounter = 0 | |
11 | - | TimeForParticleToReachFinalBend = 47 |
11 | + | TimeForParticleToReachFinalBend = 48 |
12 | - | ColliderActivationDuration = 9 |
12 | + | ColliderActivationDuration = 3 |
13 | ActivationDirection = "top" | |
14 | SignalingDirection = "bottom" | |
15 | -- a little less than 1 second due to code execution | |
16 | -- taking a tiny bit of extra time. | |
17 | PACounterSleepDuration = 0.95 | |
18 | ||
19 | function PrintTerminal(text, posX, posY) | |
20 | term.setCursorPos(posX, posY) | |
21 | term.write(text) | |
22 | end | |
23 | ||
24 | function IsActivated() | |
25 | return redstone.getInput(ActivationDirection) | |
26 | end | |
27 | ||
28 | function ResetCounters() | |
29 | PACounter = 0 | |
30 | CollisionPACounter = 0 | |
31 | end | |
32 | ||
33 | function ActivatePA(paDirection, isActivate) | |
34 | redstone.setOutput(paDirection, isActivate) | |
35 | sleep(0.2) | |
36 | end | |
37 | ||
38 | function SetNotifyerSignalOutput(isActive) | |
39 | redstone.setOutput(SignalingDirection, isActive) | |
40 | end | |
41 | ||
42 | function ManualDeactivate() | |
43 | term.clear() | |
44 | PrintTerminal("Manually Deactivating Dark Matter Generator.", 1, 0) | |
45 | ActivatePA("right", false) | |
46 | ActivatePA("left", false) | |
47 | ResetCounters() | |
48 | sleep(1) | |
49 | end | |
50 | ||
51 | function PAGeneratorLoop() | |
52 | while (true) do | |
53 | ActivatePA("right", false) | |
54 | ActivatePA("left", false) | |
55 | ResetCounters() | |
56 | term.clear() | |
57 | term.setCursorPos(0,0) | |
58 | ||
59 | if (IsActivated()) then | |
60 | SetNotifyerSignalOutput(true) | |
61 | PrintTerminal("Dark Matter generator ONLINE", 1, 1) | |
62 | PrintTerminal("Turning on Main Particle Accelerator...", 1, 2) | |
63 | ActivatePA("right", true) | |
64 | PrintTerminal("Waiting for particle to reach the final bend", 1, 3) | |
65 | ||
66 | while (PACounter < TimeForParticleToReachFinalBend) do | |
67 | if (IsActivated() == false) then | |
68 | ManualDeactivate() | |
69 | return | |
70 | else | |
71 | PACounter = PACounter + 1 | |
72 | term.setCursorPos(1, 4) | |
73 | term.write(PACounter .. " / " .. TimeForParticleToReachFinalBend) | |
74 | sleep(PACounterSleepDuration) | |
75 | end | |
76 | end | |
77 | ||
78 | PrintTerminal("Particle has reached final bend", 1, 4) | |
79 | PrintTerminal("Activating collision PA", 1, 5) | |
80 | ActivatePA("left", true) | |
81 | ||
82 | while (CollisionPACounter < ColliderActivationDuration) do | |
83 | if (IsActivated() == false) then | |
84 | ManualDeactivate() | |
85 | return | |
86 | else | |
87 | CollisionPACounter = CollisionPACounter + 1 | |
88 | term.setCursorPos(1, 6) | |
89 | term.write(CollisionPACounter .. " / " .. ColliderActivationDuration) | |
90 | sleep(PACounterSleepDuration) | |
91 | end | |
92 | end | |
93 | ||
94 | PrintTerminal("Particles collided in the past ".. ColliderActivationDuration.. " secs.", 1, 7) | |
95 | PrintTerminal("Deactivating both PAs", 1, 8) | |
96 | ActivatePA("right", false) | |
97 | ActivatePA("left", false) | |
98 | ResetCounters() | |
99 | sleep(1) | |
100 | else | |
101 | SetNotifyerSignalOutput(false) | |
102 | term.clear() | |
103 | PrintTerminal("Dark Matter generator offline.", 1, 1) | |
104 | sleep(1) | |
105 | end | |
106 | end | |
107 | end | |
108 | ||
109 | function MainProgram() | |
110 | while true do | |
111 | PAGeneratorLoop() | |
112 | end | |
113 | end | |
114 | ||
115 | MainProgram() |