· 6 years ago · Apr 12, 2020, 12:00 AM
1--Darknifes Spawner controller
2
3
4--# load the touchpoint API
5os.loadAPI("touchpoint")
6
7--# intialize a new button set on the top monitor
8local MonSide = "left"
9local t = touchpoint.new(MonSide)
10local m = peripheral.wrap(MonSide)
11for i,v in ipairs(redstone.getSides()) do redstone.setBundledOutput(v,0) end
12m.setTextScale(1)
13local MonX, MonY = m.getSize()
14------------------------------------------------------------------------------------------------
15---------------------------- CONFIGS ---------------------------------------------------
16------------------------------------------------------------------------------------------------
17--Spawner Buttons
18
19-- Example entry for buttons --
20
21-- MobName = {"CableSide","RedstoneColour",initialstate,isInverted}
22
23--Edit this table to add mobs
24local Mobs = {
25 Enderman ={"right","white",false,false},
26 Ghast = {"right","orange",false,false},
27 Cow = {"right","magenta",false,false},
28 Chicken = {"right","lightBlue",true,false},
29 Skeleton = {"right","yellow",false,false},
30
31}
32--Controls for machines
33local Controls = {
34 Crushers = {"bottom","lightBlue",true,true},
35 Lights = {"bottom","white",true,false},
36 Spikes = {"bottom","magenta",true,false}
37}
38
39
40
41local MobTitle = "Spawner Control"
42local ControlTitle = "Machine Control"
43
44
45-- all arrays in format [x,y]
46local MobGap = {2,2}
47local MobMin ={2,4}
48local MobMax = {MonX-2,18}
49
50local CtrlGap = {2,2}
51local CtrlMin ={2,22}
52local CtrlMax = {MonX-2,22}
53
54
55local ButtonSize={12,2}
56
57
58------------------------------------------------------------------------------------------------
59------------------------------------------------------------------------------------------------
60
61--Make Mob buttons
62local CurrentCoord = {MobMin[1],MobMin[2]}
63for key, value in pairs(Mobs) do
64
65
66
67
68 if CurrentCoord[1] > MobMax[1] then
69 CurrentCoord[2] = CurrentCoord[2]+ButtonSize[2]+MobGap[2]
70 CurrentCoord[1] = MobMin[1]
71
72 end
73 if CurrentCoord[2] > MobMax[2] then
74 error("Too Many Buttons for Specified Dimentions")
75 end
76 t:add(key, nil, CurrentCoord[1], CurrentCoord[2], CurrentCoord[1]+ButtonSize[1], CurrentCoord[2]+ButtonSize[2], colors.red, colors.lime)
77 CurrentCoord[1] = CurrentCoord[1]+ButtonSize[1]+MobGap[1]
78
79 RedstoneCol = 0
80 if value[3] and (value[4] == false) then
81 RedstoneCol = colors.combine(redstone.getBundledInput(value[1]),colors[value[2]])
82 redstone.setBundledOutput(value[1],RedstoneCol)
83 t:toggleButton(key)
84 os.sleep(0.15)
85 end
86end
87
88
89--Make Ctrl buttons
90local CurrentCoord = {CtrlMin[1],CtrlMin[2]}
91for key, value in pairs(Controls) do
92
93
94 if CurrentCoord[1] > CtrlMax[1] then
95 CurrentCoord[2] = CurrentCoord[2]+ButtonSize[2]+CtrlGap[2]
96 CurrentCoord[1] = CtrlMin[1]
97 end
98 if CurrentCoord[2] > CtrlMax[2] then
99 error("Too Many Buttons for Specified Dimentions")
100 end
101 t:add(key, nil, CurrentCoord[1], CurrentCoord[2], CurrentCoord[1]+ButtonSize[1], CurrentCoord[2]+ButtonSize[2], colors.red, colors.lime)
102 CurrentCoord[1] = CurrentCoord[1]+ButtonSize[1]+CtrlGap[1]
103
104 RedstoneCol = 0
105 if value[3] and (value[4] == false) then
106 RedstoneCol = colors.combine(redstone.getBundledInput(value[1]),colors[value[2]])
107 redstone.setBundledOutput(value[1],RedstoneCol)
108 t:toggleButton(key)
109 else if value[4] then
110 t:toggleButton(key)
111 end
112 os.sleep(0.15)
113 end
114
115
116end
117
118
119
120--Fake buttons used as headers
121t:add(MobTitle, nil, 1, 1, MonX, 3, colors.black, colors.black)
122t:add(ControlTitle, nil, 1, 19, MonX, 21, colors.black, colors.black)
123
124--# draw the buttons
125t:draw()
126
127
128
129while true do
130 --# handleEvents will convert monitor_touch events to button_click if it was on a button
131 local event, p1 = t:handleEvents(os.pullEvent())
132 if event == "button_click" then
133 if Mobs[p1] or Controls[p1] then-- is a real button
134
135 if Mobs[p1] then --If its a mob
136 RSSide = Mobs[p1][1]
137 RSCol = Mobs[p1][2]
138 RSInv = Mobs[p1][4]
139 elseif Controls[p1] then --If its a control
140 RSSide = Controls[p1][1]
141 RSCol = Controls[p1][2]
142 RSInv = Controls[p1][4]
143 end
144 if (t.buttonList[p1].active and (RSInv == false)) or ((t.buttonList[p1].active == false) and RSInv) then
145 RedstoneCol = colors.subtract(redstone.getBundledInput(RSSide),colors[RSCol])
146 redstone.setBundledOutput(RSSide,RedstoneCol)
147 else
148 RedstoneCol = colors.combine(redstone.getBundledInput(RSSide),colors[RSCol])
149 redstone.setBundledOutput(RSSide,RedstoneCol)
150 end
151 t:toggleButton(p1)
152 end
153 end
154 end