Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define global variables
- VERSION_STR_ASTRAL_SORCERY = 'astralsorcery-1.16-1.16.5-1.13.12'
- NAME_ENVIRONMENT_DETECTOR = 'environmentDetector'
- NAME_CHAT_BOX = 'chatBox'
- NAME_AR_CONTROLLER = 'arController'
- CMD_DRAW = '!sky_draw'
- CMD_CLEAR = '!sky_clear'
- CMD_LOG = '!sky_log'
- TIME_MINECRAFT_DAY_TICK = 0
- TIME_MINECRAFT_NIGHT_TICK = 12000
- INTERVAL_MINECRAFT_DAY_TICK = 24000
- INTERVAL_SOLAR_ECLIPSE_DAY = 36
- INTERVAL_MAIN_LOOP_SLEEP_SECONDS = 1
- -- Construct constellation to moon id table
- CONSTELLATION_TABLE = {
- ['Discidia'] = { 0, 5, 6, 7 },
- ['Armara'] = { 2, 3, 4, 5, 6 },
- ['Vicio'] = { 3, 4, 5, 6, 7 },
- ['Aevitas'] = { 2, 3, 4, 5, 6 },
- ['Evorsio'] = { 2, 3, 4, 5, 6 },
- ['Lucerna'] = { 0, 4, 5, 6, 7 },
- ['Mineralis'] = { 0, 1, 2, 3, 7 },
- ['Octans'] = { 2, 3, 4, 5, 6 },
- ['Bootes'] = { 0, 1, 2, 3, 7 },
- ['Fornax'] = { 0, 4, 5, 6, 7 },
- ['Gelu'] = { 2, 3, 4 },
- ['Ulteria'] = { 0, 2, 7 },
- ['Alcara'] = { 0, 4 },
- ['Vorux'] = { 5, 6, 7 }
- }
- -- Construct moon id to constellation table
- INVERTED_CONSTELLATION_TABLE = { [0]={}, [1]={}, [2]={}, [3]={}, [4]={}, [5]={}, [6]={}, [7]={} }
- for constellation, moonIdTable in pairs( CONSTELLATION_TABLE ) do
- for _, moonId in pairs( moonIdTable ) do
- table.insert( INVERTED_CONSTELLATION_TABLE[ moonId ], constellation )
- end
- end
- SPECIAL_CONSTELLATION_TABLE = {
- 'Horologium',
- 'Pelotrio'
- }
- function logConstellationTable( peripheralChatBoxController )
- -- Display constellation table in chat message
- local logMessage = ''
- local availableConstellationStr
- for moonId, constallationTable in pairs( INVERTED_CONSTELLATION_TABLE ) do
- availableConstellationStr = table.concat( INVERTED_CONSTELLATION_TABLE[ moonId ], ', ' )
- logMessage = logMessage .. 'Moon (id) ' .. moonId .. ', Constellation : ' .. availableConstellationStr .. '\n'
- end
- peripheralChatBoxController.sendMessage( logMessage )
- end
- function draw( peripheralEnvironmentDetector, peripheralArController, firstSolarEclipseDate )
- -- Clear the ar screen
- peripheralArController.clear()
- -- Get today date
- local todayDate = math.floor( peripheralEnvironmentDetector.getTime() / INTERVAL_MINECRAFT_DAY_TICK )
- local currentTime = peripheralEnvironmentDetector.getTime() % INTERVAL_MINECRAFT_DAY_TICK
- -- Draw today date
- peripheralArController.drawItemIcon( 'minecraft:clock', 31, 1 )
- peripheralArController.drawRightboundString( 'Date (day) : ' .. todayDate, 31, 1, 0xFFFFFF )
- peripheralArController.drawRightboundString( 'Time (tick) : ' .. currentTime, 31, 2, 0xFFFFFF )
- -- Get weather
- local weather = 'Unknown'
- if peripheralEnvironmentDetector.isSunny() then
- weather = 'Clear'
- elseif peripheralEnvironmentDetector.isRaining() then
- weather = 'Rain'
- elseif peripheralEnvironmentDetector.isThunder() then
- weather = 'Storm'
- end
- -- Draw weather
- peripheralArController.drawItemIcon( 'minecraft:sunflower', 31, 3 )
- peripheralArController.drawRightboundString( 'Weather : ' .. weather, 31, 3, 0xFFFFFF )
- -- Get moon
- local moonId = peripheralEnvironmentDetector.getMoonId()
- local moonName = peripheralEnvironmentDetector.getMoonName()
- local availableConstellationStr = table.concat( INVERTED_CONSTELLATION_TABLE[ moonId ], ', ' )
- -- Draw moon and constellation
- peripheralArController.drawItemIcon( 'astralsorcery:constellation_paper', 31, 4 )
- peripheralArController.drawRightboundString( 'Moon (id/name) : ' .. moonId .. '/' .. moonName, 31, 4, 0xFFFFFF )
- peripheralArController.drawRightboundString( 'Constellation : ' .. availableConstellationStr, 31, 5, 0xFFFFFF )
- -- Get next solar eclipse day
- local nextSolarEclipseMessage = 'N/A'
- if firstSolarEclipseDate ~= nil then
- -- Compute next solar eclipse day
- local nextSolarEclipseDay = INTERVAL_SOLAR_ECLIPSE_DAY - ( ( todayDate - firstSolarEclipseDate ) % INTERVAL_SOLAR_ECLIPSE_DAY )
- -- Set the display message regarding to the next solar eclipse day
- if nextSolarEclipseDay == INTERVAL_SOLAR_ECLIPSE_DAY then
- nextSolarEclipseMessage = 'TODAY!!!'
- else
- local nextSolarEclipseDate = todayDate + nextSolarEclipseDay
- nextSolarEclipseMessage = 'Day ' .. nextSolarEclipseDate .. ' (' .. nextSolarEclipseDay .. ' day(s))'
- end
- end
- -- Draw next solar eclipse day
- peripheralArController.drawItemIcon( 'astralsorcery:observatory', 31, 6 )
- peripheralArController.drawRightboundString( 'Next solar eclipse : ' .. nextSolarEclipseMessage, 31, 6, 0xFFFFFF )
- end
- function main()
- -- Display program description and note messages
- print( 'This program visualizes the sky information including today date, ' ..
- 'current time, weather, moon phase and today available constallations via an AR Goggles.\n' ..
- '(Tested with ' .. VERSION_STR_ASTRAL_SORCERY .. ')' )
- -- Bind an environment detector peripheral
- local peripheralEnvironmentDetector = peripheral.find( NAME_ENVIRONMENT_DETECTOR )
- if peripheralEnvironmentDetector == nil then
- error( 'Cannot find ' .. NAME_ENVIRONMENT_DETECTOR .. '.' )
- do return end
- end
- -- Bind a chat box peripheral
- local peripheralChatBoxController = peripheral.find( NAME_CHAT_BOX )
- if peripheralChatBoxController == nil then
- error( 'Cannot find ' .. NAME_CHAT_BOX .. '.' )
- do return end
- end
- -- Bind an ar controller peripheral
- local peripheralArController = peripheral.find( NAME_AR_CONTROLLER )
- if peripheralArController == nil then
- error( 'Cannot find ' .. NAME_AR_CONTROLLER .. '.' )
- do return end
- end
- -- Disable relative mode
- peripheralArController.setRelativeMode( true, 64, 40 )
- -- Get the date of solar eclipse
- print( 'Please input the date of solar eclipse (input any string, if you don\'t know): ' )
- local firstSolarEclipseDate = tonumber(read())
- -- Validate given date
- if firstSolarEclipseDate ~= nil then
- -- Try convert to number
- if firstSolarEclipseDate < 0 then
- error( 'The date cannot be negative number.' )
- do return end
- end
- -- Find the first date of solar eclipse
- firstSolarEclipseDate = firstSolarEclipseDate % INTERVAL_SOLAR_ECLIPSE_DAY
- end
- print( 'To use this program, bind the AR Goggles to the AR Controller and type these commands in the chat box.\n' ..
- '1. !sky_draw : Redraw the sky information.\n' ..
- '2. !sky_clear : Clear the screen.\n' ..
- '3. !sky_log : Display constellation table in chat message.' )
- local event, username, message
- while true do
- event, username, message = os.pullEvent("chat")
- -- Parse chat message to command
- if message == CMD_CLEAR then
- print('User [' .. username .. '] called ' .. CMD_CLEAR .. '.')
- peripheralArController.clear()
- elseif message == CMD_DRAW then
- print('User [' .. username .. '] called ' .. CMD_DRAW .. '.')
- draw( peripheralEnvironmentDetector, peripheralArController, firstSolarEclipseDate )
- elseif message == CMD_LOG then
- print('User [' .. username .. '] called ' .. CMD_LOG .. '.')
- logConstellationTable( peripheralChatBoxController )
- end
- -- I still have a performance concern for this program, so a little sleep here
- sleep( INTERVAL_MAIN_LOOP_SLEEP_SECONDS )
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement