Computer

Computers come in 5 different tiers, namely Wood, Iron, Diamond, Netherite and finally Creative, though that tier is not available in survival. These tiers only differ in the amount of inventory slots and computer speed. In the future, tiers will also impact the amount of usable memory.

The computer is what provides most of the core Lua components and is where you place item-components, such as Hard Disk Drives or Floppy Disks. You can start the computer by pressing the power button shown in the gui-image. Similarly, to forcefully stop a computer you can press the same button. Both actions can also be performed by shift-right-clicking the computer with an empty hand, which then either starts or stops it, depending on the current state.
The lit indicator on the front of the computer indicates the run-state. A computer can be in one of the following states:
| Color | State |
|---|---|
| Red - On | Stopped |
| Red - Blinking | Crashed |
| Green - On | Running |
| Green - Blinking | Currently unimplemented, but will indicate Working in the future |
Provided component
The computer block provides access to the computer component.
This component includes the following properties:
| Name | Type | Read/Write | Description |
|---|---|---|---|
uefi |
UefiUD |
READ | Provides access to the UEFI located on the Mainboard installed in the current computer's inventory. |
nvram |
NvramUD |
READ | Provides access to the NVRAM located on the Mainboard installed in the current computer's inventory. This can be used to store data that persists across reboots and does not require a filesystem. See NVRAM for more information. |
tpm |
not yet implemented | READ | In the future will provide access to the Trusted Platform Module. |
| Name | Returns | Description |
|---|---|---|
:beep(freq:number, duration:number) |
void |
Plays a hearable sound with frequency freq and duration duration, hearable near the computer block.
|
:getMachineEvent() |
any[] |
Dequeues and returns the next item in the computer's event queue. Example return values are {"keyPressed", "\n", 257, 28, 0} when pressing the ENTER key in a gui or {nil} when there is no queued event. All possible events are listed in section #Machine events.
|
:getEpoch() |
number |
Returns the number of real-world seconds since 1st of January 1970. |
:getEpochMs() |
integer |
Returns the number of real-world milliseconds since 1st of January 1970. |
:getDate() |
string |
Returns an ISO date string representing the current date and time on the host. The date is followed according to this format yyyy-MM-dd'T'HH:mm:ssXX.
|
:getUptime() |
number |
Returns the number of real-world seconds since the computer was started. |
Machine events
The following table shows all currently implemented machine events. Addon-mods may add their own events which will not be listed here. All the arguments in the Argument column are simply packed sequentially into a table and returned in the :getMachineEvent() call. No event being available is a special case and will return a table of length 1, with a single value nil.
| Event name | Arguments | Fired when |
|---|---|---|
componentAdded |
componentType:string, componentUD:userdata |
a new component is added to the computer's inventory or via a device cable. The second argument is the userdata instance which you would normally get via the Component Registry's components:getFirst(<component name>) call. |
componentRemoved
|
componentUD:userdata
|
a component is removed. |
keyPressed
|
stringRepresentation:string, keyCode:int, scanCode:int, modifiers:int
|
a connected screen has received a button press/release. The modifiers are represented as a bit-field, so 1=shift, 2=ctrl, 4=alt. Ctrl+alt would then, for instance be represented by 2+4=6. These modifiers are captured when the key is pressed/released. |
keyReleased
| ||
charTyped
|
typedChracter:string
|
a connected screen has received a button press that corresponds to printable text. |
textPasted
|
pastedText:string
|
a player has pressed middle-mouse-button and thus pasted their clipboard contents. |