-- ComputerCraft
-- Writes text to a minecraft create display based on redstone inputs
print("Starting Display")
-- Set up the display
local display = peripheral.wrap("top") -- Wrap the display on top of the computer
if not display then
print("No display found")
return
end
display.clear() -- Clear the display
display.setCursorPos(1, 1) -- Set the cursor position to the top left corner
display.write("Display ready!") -- Write a message to the display
display.update() -- Update the display to show the message
-- Wait for 4 seconds before clearing the display
os.sleep(4)
display.clear() -- Clear the display
display.update() -- Update the display to show the cleared screen
local previous_state = nil -- Variable to store the previous state
while true do
local active_hostile = redstone.getInput("back")
local active_neutral = redstone.getInput("front")
local active_spawnDelay = redstone.getInput("right")
local active_chicken = redstone.getInput("bottom")
local active_missing = redstone.getInput("left")
-- log the states to the console
print("Hostile: " .. tostring(active_hostile))
print("Neutral: " .. tostring(active_neutral))
print("Spawn Delay: " .. tostring(active_spawnDelay))
print("Chicken: " .. tostring(active_chicken))
print("Missing: " .. tostring(active_missing))
local state_spawning = active_spawnDelay
local state_chicken = active_chicken
local state_killing = active_hostile and not active_spawnDelay and not active_chicken
local state_clearing = active_neutral and not state_killing and not state_chicken
local state_missing = active_missing
local state_idle = not state_spawning and not state_killing and not state_clearing and not state_missing and
not state_chicken
local current_state = nil -- Variable to store the current state
if state_spawning then
current_state = "Spawning Wither"
elseif state_killing then
current_state = "Killing Wither"
elseif state_chicken then
current_state = "Deploying Chicken"
elseif state_clearing then
current_state = "Clearing Chamber"
elseif state_missing then
current_state = "Missing Resources"
elseif state_idle then
current_state = "Idle..."
end
if current_state == previous_state then
-- If the state hasn't changed, skip the display update
print("State hasn't changed, skipping display update")
os.sleep(1) -- Sleep for 1 second before checking the states again
goto continue -- Skip to the next iteration of the loop
end
previous_state = current_state -- Update the previous state
print("State changed to: " .. current_state) -- Log the state change to the console
-- Display the states on the screen
display.clear() -- Clear the display
display.setCursorPos(1, 1) -- Set the cursor position to the top left corner
display.write("State:") -- Write a message to the display
display.setCursorPos(1, 2) -- Move the cursor to the next line
display.write(current_state) -- Write the current state to the display
display.update() -- Update the display to show the current state
-- Sleep for 1 second before checking the states again
os.sleep(1)
::continue:: -- Label to skip to the next iteration of the loop
end
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎