Jump to content

Computer: Difference between revisions

From Advanced Computers Wiki
No edit summary
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 23: Line 23:
{{Note|Keep in mind that starting the computer initially may take some time; give it a few seconds. This is because the JLuaVM is warming up and will be fixed in future. Successive runs are much faster as the Lua code is already compiled and loaded from one of the two compilation caches (the second one even persists across world reload).}}
{{Note|Keep in mind that starting the computer initially may take some time; give it a few seconds. This is because the JLuaVM is warming up and will be fixed in future. Successive runs are much faster as the Lua code is already compiled and loaded from one of the two compilation caches (the second one even persists across world reload).}}


== Provided Component ==
== Provided component ==
The computer block provides access to the <code>computer</code> component.
The computer block provides access to the <code>computer</code> component.
This component includes the following properties:
This component includes the following properties:
Line 42: Line 42:
|+ ComputerUD component methods
|+ ComputerUD component methods
|-
|-
! Name !! Type !! Description
! Name !! Returns !! Description
|-
|-
| style="white-space: nowrap;" | <code>:beep(freq:number, duration:number)</code> || <code>void</code> || Plays a hearable sound with frequency <code>freq</code> and duration <code>duration</code>, hearable near the computer block.
| style="white-space: nowrap;" | <code>:beep(freq:number, duration:number)</code> || <code>void</code> || Plays a hearable sound with frequency <code>freq</code> and duration <code>duration</code>, hearable near the computer block.
|-
|-
| style="white-space: nowrap;" | <code>:getMachineEvent()</code> || <code>any[]</code> || Dequeues and returns the next item in the computer's event queue. Example return values are <code>{"keyPressed", "\n", 257, 28, 0}</code> when pressing the ENTER key in a gui or <code>{nil}</code> when there is no queued event. All possible events are listed in section [[#Machine Events]].
| style="white-space: nowrap;" | <code>:getMachineEvent()</code> || <code>any[]</code> || Dequeues and returns the next item in the computer's event queue. Example return values are <code>"keyPressed", "\n", 257, 28, 0</code> when pressing the ENTER key in a gui or <code>nil</code> when there is no queued event. All possible events are listed in section [[#Machine events]]. The result is a multi-return, not a table.
|-
|-
| style="white-space: nowrap;" | <code>:getEpoch()</code> || <code>number</code> || Returns the number of real-world seconds since 1st of January 1970.
| style="white-space: nowrap;" | <code>:getEpoch()</code> || <code>number</code> || Returns the number of real-world seconds since 1st of January 1970.
Line 52: Line 52:
| style="white-space: nowrap;" | <code>:getEpochMs()</code> || <code>integer</code> || Returns the number of real-world milliseconds since 1st of January 1970.
| style="white-space: nowrap;" | <code>:getEpochMs()</code> || <code>integer</code> || Returns the number of real-world milliseconds since 1st of January 1970.
|-
|-
| style="white-space: nowrap;" | <code>:getDate()</code> || <code>string</code> || Returns an ISO date string representing the current date and time on the host. The date is followed according to this format <code>yyyy-MM-dd'T'HH:mm:ssXX</code>
| style="white-space: nowrap;" | <code>:getDate()</code> || <code>string</code> || Returns an ISO date string representing the current date and time on the host. The date is followed according to this format <code>yyyy-MM-dd'T'HH:mm:ssXX</code>.
|-
|-
| style="white-space: nowrap;" | <code>:getUptime()</code> || <code>number</code> || Returns the number of real-world seconds since the computer was started.
| style="white-space: nowrap;" | <code>:getUptime()</code> || <code>number</code> || Returns the number of real-world seconds since the computer was started.
|}
|}


== Machine Events ==
== Machine events ==
content
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 returned as a multi-return value in the <code>:getMachineEvent()</code> call. No event being available is a special case and will return a single value <code>nil</code>.
{| class="wikitable"
! Event name !! Values !! Fired when
|-
| <code>componentAdded</code>|| <code>componentType:string, componentUD:userdata</code>|| 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.
|-
|<code>componentRemoved</code>
|<code>componentUD:userdata</code>
|a component is removed.
|-
|<code>keyPressed</code>
|rowspan="2"|<code>stringRepresentation:string, keyCode:int, scanCode:int, modifiers:int</code>
|rowspan="2"|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.
|-
|<code>keyReleased</code>
|-
|<code>charTyped</code>
|<code>typedChracter:string</code>
|a connected screen has received a button press that corresponds to printable text.
|-
|<code>textPasted</code>
|<code>pastedText:string</code>
|a player has pressed middle-mouse-button and thus pasted their clipboard contents.
|-
|<code>networkPacket</code>
|<code>message:string, port:int, sourceAcIp:string, side:string</code>
|a computer with the ingame IP address <code>sourceAcIp</code> has sent a network packet via the [[Network]] component to the current computer's local port <code>port</code>, arriving at side <code>side</code>. The content of the packet is a single string stored in <code>message</code>.
|}
 
{{Navbox content}}
{{Navbox content}}

Latest revision as of 23:58, 17 August 2026

All computer tiers ingame

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.

Netherite computer gui
Netherite computer gui

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:

Run states
Color State
Red - On Stopped
Red - Blinking Crashed
Green - On Running
Green - Blinking Currently unimplemented, but will indicate Working in the future
Keep in mind that starting the computer initially may take some time; give it a few seconds. This is because the JLuaVM is warming up and will be fixed in future. Successive runs are much faster as the Lua code is already compiled and loaded from one of the two compilation caches (the second one even persists across world reload).

Provided component

The computer block provides access to the computer component. This component includes the following properties:

ComputerUD component 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.


ComputerUD component methods
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. The result is a multi-return, not a table.
: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 returned as a multi-return value in the :getMachineEvent() call. No event being available is a special case and will return a single value nil.

Event name Values 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.
networkPacket message:string, port:int, sourceAcIp:string, side:string a computer with the ingame IP address sourceAcIp has sent a network packet via the Network component to the current computer's local port port, arriving at side side. The content of the packet is a single string stored in message.