ComputerCraft modems#

ComputerCraft adds three different kinds of modems:

  • wired modems, which allows a computer to be connected to another through wires.

  • wireless modems, which allows a computer to be connected to others without wires with a limited range depending on the weather.

  • ender modems are similar to wireless modems (in fact, ComputerCraft recognizes them as “advanced” wireless modems), except that for a given channel, they can communicate with all wireless and ender modems in all dimensions, and listen to all communications from wireless and ender modems from all dimensions; see WirelessNetwork.tryTransmit (where interdimensional is set for packets sent by ender modems, and receiver.isInterdimensional is true if the receiver is an ender modem).

Note that what ComputerCraft wiki calls dimensions corresponds to what Mojang mappings calls worlds (hence the technical name net.minecraft.world.World).

All modems work the same: datagrams are sent on ports whose numbers vary between 0 and 65535 (see modem.open). Through such a modem, computers can send a message from any arbitrary port, and receive messages on up to 128 simultaneously opened ports at once.

Note

The opened port limit can be pushed further by using several modems on a computer; e.g. up to 256 ports can be opened when two wireless modems are connected.

Messages are Lua strings, numbers, or tables; metatables are not transmitted along the way, a byproduct of using the @LuaFunction decorator from ComputerCraft.

Any message on the given modems also send along the pipe the “reply channel”, which for Rednet-enabled devices corresponds to the source channel. Note that this can be set by the user program when sending a message and does not correspond to a MAC address or anything, therefore cannot be used as a reliable source port (see Rednet).

When receiving a message, in the produced modem_message event in CraftOS, wireless and ender modems within the same dimensions include the distance from the emitting device; this specificity is used on some protocols, such as the GPS one (see GPS protocol). Note that the distance is calculated not using the position of the modem themselves, but:

  • When the modem is plugged on the side bus (see ComputerCraft side bus), the position of the center of the computer directly.

  • When the modem is plugged on the wired bus (see ComputerCraft wired bus), the position of the center of the wired modem that is directly aside the modem receiving the message.

The distance itself is calculated:

  • On wireless modems, the distance between the two positions determined using the method described above.

  • On wired modems, the number of cables and wired modems (including those used to send and receive the message on both sides) traversed by the message.

Warning

If you’re running a version of ComputerCraft before 1.53, tables are not supported as valid message types.

Note

Although modem as blocks use integer coordinates, even turtles when they move (positions update immediately to the new block position), some modems can have decimal positions, most importantly pocket computers, linked to the player’s coordinates.

Classic GPS hosts round the coordinates with a .01 precision.

Basic wireless modems have a limit on how far they can send modem messages. The formula for determining this limit, named \(D_{max}\) and represented in blocks, is the following:

\[\begin{split}\begin{cases} D_{max} = R_{low} + (y - 96) * ((R_{high} - R_{low}) / (Y_{max} - 1 - 96) \text{ if $y > 96$} \\ D_{max} = R_{low} \text{ if $y <= 96$} \end{cases}\end{split}\]

Where the variables are the following:

  • \(y\) is the modem’s y coordinate.

  • \(Y_{max}\) is the maximum Y coordinate, equal to 256 in Minecraft 1.16.

  • \(R_{low}\) represents the range of wireless modems at “low altitude”, i.e. at \(y = 96\) and below; it is configurable, but is of 64 in both clear weather and storm.

  • \(R_{high}\) represents the range of wireless modems at “high altitude”, i.e. at \(y = Y_{max}\); it is configurable, but is of 384 in both clear weather and storm.

Note

In legacy ComputerCraft, the values were the following:

Weather

Range at low alt.

Range at high alt.

Clear

64

384

Storm

16

96

Wireless range evolution.

A vizualization of the range depending on the current y coordinate, with \(Y_{max}\) being defined to 256, its current value. The values taken for clear and stormy weathers are those of legacy ComputerCraft.

See WirelessModemPeripheral.getRange, Config.Config and ComputerCraft.modemRange for reference.

In versions of ComputerCraft prior to 1.80pr1.3, wired modems/network cables have a limit of 256 cables.