Advertisement
LoaderB0T

CC: Wither Status

Apr 28th, 2025 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. -- ComputerCraft
  2. -- Writes text to a minecraft create display based on redstone inputs
  3. print("Starting Display")
  4.  
  5. -- Set up the display
  6. local display = peripheral.wrap("top") -- Wrap the display on top of the computer
  7. if not display then
  8.     print("No display found")
  9.     return
  10. end
  11.  
  12. display.clear() -- Clear the display
  13. display.setCursorPos(1, 1) -- Set the cursor position to the top left corner
  14. display.write("Display ready!") -- Write a message to the display
  15. display.update() -- Update the display to show the message
  16.  
  17. -- Wait for 4 seconds before clearing the display
  18. os.sleep(4)
  19. display.clear() -- Clear the display
  20. display.update() -- Update the display to show the cleared screen
  21.  
  22. local previous_state = nil -- Variable to store the previous state
  23.  
  24. while true do
  25.     local active_hostile = redstone.getInput("back")
  26.     local active_neutral = redstone.getInput("front")
  27.     local active_spawnDelay = redstone.getInput("right")
  28.     local active_chicken = redstone.getInput("bottom")
  29.     local active_missing = redstone.getInput("left")
  30.  
  31.     -- log the states to the console
  32.  
  33.     print("Hostile: " .. tostring(active_hostile))
  34.     print("Neutral: " .. tostring(active_neutral))
  35.     print("Spawn Delay: " .. tostring(active_spawnDelay))
  36.     print("Chicken: " .. tostring(active_chicken))
  37.     print("Missing: " .. tostring(active_missing))
  38.  
  39.     local state_spawning = active_spawnDelay
  40.     local state_chicken = active_chicken
  41.     local state_killing = active_hostile and not active_spawnDelay and not active_chicken
  42.     local state_clearing = active_neutral and not state_killing and not state_chicken
  43.     local state_missing = active_missing
  44.     local state_idle = not state_spawning and not state_killing and not state_clearing and not state_missing and
  45.                            not state_chicken
  46.  
  47.     local current_state = nil -- Variable to store the current state
  48.     if state_spawning then
  49.         current_state = "Spawning Wither"
  50.     elseif state_killing then
  51.         current_state = "Killing Wither"
  52.     elseif state_chicken then
  53.         current_state = "Deploying Chicken"
  54.     elseif state_clearing then
  55.         current_state = "Clearing Chamber"
  56.     elseif state_missing then
  57.         current_state = "Missing Resources"
  58.     elseif state_idle then
  59.         current_state = "Idle..."
  60.     end
  61.  
  62.     if current_state == previous_state then
  63.         -- If the state hasn't changed, skip the display update
  64.         print("State hasn't changed, skipping display update")
  65.         os.sleep(1) -- Sleep for 1 second before checking the states again
  66.         goto continue -- Skip to the next iteration of the loop
  67.     end
  68.     previous_state = current_state -- Update the previous state
  69.     print("State changed to: " .. current_state) -- Log the state change to the console
  70.  
  71.     -- Display the states on the screen
  72.     display.clear() -- Clear the display
  73.     display.setCursorPos(1, 1) -- Set the cursor position to the top left corner
  74.     display.write("State:") -- Write a message to the display
  75.     display.setCursorPos(1, 2) -- Move the cursor to the next line
  76.     display.write(current_state) -- Write the current state to the display
  77.     display.update() -- Update the display to show the current state
  78.  
  79.     -- Sleep for 1 second before checking the states again
  80.     os.sleep(1)
  81.  
  82.     ::continue:: -- Label to skip to the next iteration of the loop
  83. end
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement