Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Consts
- local BTN_PADDING = 5
- local REDSTONE_SIDE = 'front'
- local ARMOR_REGULAR_SIDE = 'top'
- local ARMOR_SPACE_SIDE = 'right'
- local MAX_OXYGEN = 48000
- -- Data
- local rocketReady = false
- local spacesuiteEquipped = false
- local oxygenLevel = 100
- -- Peripherals
- local monitor = peripheral.find('monitor')
- local inventoryManager = peripheral.find('inventoryManager')
- if monitor == nil then
- print('Error: You need to connect a monitor!')
- return
- end
- if inventoryManager == nil then
- print('Error: You need to connect an inventory manager!')
- return
- end
- -- Cached properties
- local monitorWidth, monitorHeight = monitor.getSize()
- -- Generic methods
- function resetMonitor()
- monitor.clear()
- monitor.setCursorPos(0, 0)
- end
- function drawButton(label, y, color, parent)
- local parentWidth = parent.getSize()
- local button = window.create(parent, BTN_PADDING, y, parentWidth - BTN_PADDING * 2, 3)
- button.setBackgroundColor(color)
- button.clear()
- local btnWidth = parentWidth - 10;
- button.setCursorPos(1, 2)
- local remainingWidth = btnWidth - label:len()
- button.write(string.rep(' ', remainingWidth / 2) .. label .. string.rep(' ', remainingWidth / 2))
- button.redraw();
- end
- -- Main logic
- function drawLoop()
- resetMonitor()
- -- Generate status string --
- local statusLabel = 'Rocket inactive'
- local statusColor = colors.red
- if rocketReady == true then
- statusLabel = 'Rocket ready'
- statusColor = colors.green
- end
- --
- -- Top -> General information about rocket
- --
- monitor.setTextColor(statusColor)
- monitor.setCursorPos(
- monitorWidth / 2 - statusLabel:len() / 2,
- 3
- )
- monitor.write(statusLabel)
- if rocketReady == true and spacesuiteEquipped == false then
- -- Draw a button to equip the spacesuite
- drawButton('Equip spacesuite', 10, colors.green, monitor)
- elseif rocketReady == false and spacesuiteEquipped == true then
- -- Draw a button to equip regular armor
- drawButton('Equip regular armor', 10, colors.green, monitor)
- end
- if rocketReady == true and spacesuiteEquipped == true then
- -- Draw oxygen level
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(3, monitorHeight - 2)
- local oxygenLabel = 'Oxygen Level: ' .. oxygenLevel .. '%'
- monitor.write(oxygenLabel)
- if spacesuiteEquipped == true then
- local equippedLabel = 'Spacesuite equipped!'
- monitor.setCursorPos(monitorWidth - 3 - equippedLabel:len(), monitorHeight - 2)
- monitor.write(equippedLabel)
- end
- end
- end
- function checkClick(x, y)
- -- Check if the click is the start / stop load test button
- if x >= BTN_PADDING and x < BTN_PADDING + monitorWidth - BTN_PADDING * 2
- and y >= 10 and y < 13
- then
- if rocketReady == true and spacesuiteEquipped == false then
- -- Equip space suite
- -- First fetch the current armor
- inventoryManager.removeItemFromPlayer(ARMOR_REGULAR_SIDE, 1, 39) -- Helmet
- inventoryManager.removeItemFromPlayer(ARMOR_REGULAR_SIDE, 1, 38) -- Breastplate
- inventoryManager.removeItemFromPlayer(ARMOR_REGULAR_SIDE, 1, 37) -- Pants
- inventoryManager.removeItemFromPlayer(ARMOR_REGULAR_SIDE, 1, 36) -- Boots
- -- Then give the space suite
- inventoryManager.addItemToPlayer(ARMOR_SPACE_SIDE, 1, 39) -- Helmet
- inventoryManager.addItemToPlayer(ARMOR_SPACE_SIDE, 1, 38) -- Breastplate
- inventoryManager.addItemToPlayer(ARMOR_SPACE_SIDE, 1, 37) -- Pants
- inventoryManager.addItemToPlayer(ARMOR_SPACE_SIDE, 1, 36) -- Boots
- elseif rocketReady == false and spacesuiteEquipped == true then
- -- Equip regular armor
- -- First fetch the current space armor
- inventoryManager.removeItemFromPlayer(ARMOR_SPACE_SIDE, 1, 39) -- Helmet
- inventoryManager.removeItemFromPlayer(ARMOR_SPACE_SIDE, 1, 38) -- Breastplate
- inventoryManager.removeItemFromPlayer(ARMOR_SPACE_SIDE, 1, 37) -- Pants
- inventoryManager.removeItemFromPlayer(ARMOR_SPACE_SIDE, 1, 36) -- Boots
- -- Then give the regular armor
- inventoryManager.addItemToPlayer(ARMOR_REGULAR_SIDE, 1, 39) -- Helmet
- inventoryManager.addItemToPlayer(ARMOR_REGULAR_SIDE, 1, 38) -- Breastplate
- inventoryManager.addItemToPlayer(ARMOR_REGULAR_SIDE, 1, 37) -- Pants
- inventoryManager.addItemToPlayer(ARMOR_REGULAR_SIDE, 1, 36) -- Boots
- end
- elseif x <= 2 and y <= 2 then
- print("Dong")
- end
- fetchData()
- end
- function fetchData()
- rocketReady = redstone.getInput(REDSTONE_SIDE)
- -- Check if the player is currently wearing the spacesuite
- local armorPlate = inventoryManager.getArmor()[102]
- spacesuiteEquipped = false
- if armorPlate.name == 'beyond_earth:netherite_space_suit' then
- spacesuiteEquipped = true
- oxygenLevel = math.floor((armorPlate.nbt['Energy']/MAX_OXYGEN)*100)
- end
- end
- fetchData()
- while true do
- drawLoop()
- local event, _, x, y = os.pullEvent()
- if event == 'monitor_touch' then
- print('Clicked monitor')
- checkClick(x, y)
- elseif event == 'redstone' then
- print('Changed redstone signal')
- rocketReady = redstone.getInput(REDSTONE_SIDE)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement