Skip to content

Wireless Minecraft Train Control

Kenny Mensah edited this page May 19, 2020 · 16 revisions

Wireless Minecraft Train Control

Wireless Minecraft Train Control (or W-MTC for short) is like it's standard MTC counterpart, only that information is transmitted wirelessly from a computer. It has the same features as MTC, as well as some added features.

Requirements

ComputerCraft. You can get the latest 1.7.10 version here.

(or) OpenComputers. You can download it here.

Basic Lua Skills: You can learn how to do it here.

A way to parse JSON in ComputerCraft or OpenComputers: For transmiJSON API v2.0.1 for ComputerCraft

Operation

Depending on the train, W-MTC support will be already avaliable, however if not there is a craftable item so that it can be used with the W-MTC system. Place the Wireless Transmitter item into the first slot of the train's inventory and it will make it have support.

W-MTC supported trains:

  • SD-40
  • BP-4
  • Class 66
  • BR 185
  • CD 151
  • DD35A
  • ICE 1
  • High Speed Train
  • E 103
  • V60
  • CD 742
  • VL10
  • Tram
  • IC4
  • SD70

The W-MTC system uses signal blocks for identifying where the train is, and the system uses a UUID system for transmitting between trains and radios. First, the train goes over a block that sends the server UUID to the train. It will first send an attemptconnection request to the server, as well as it's train level, and ID.

{"funct":"attemptconnection","trainType":"1"}

The connection request to the server in JSON.

[top, qgfe1, 47ba5d8c-a9af-420d-8dfc-2021d0833363, {"funct":"attemptconnection","trainType":"1"}, 0]

An example connection request in it's CC event form. (in order: side, trainid, thisuuid, message, system) (system not used)

The funct at the start defines what the function is. The ones that the train use are: startlevel2, attemptconnection, and update. Once it is connected successfully, a startlevel2 function should be sent to the train, as well as including the speed limit (speedLimit), the next speed limit (nextSpeedLimit) , if there is a stop point ahead (endsoon, boolean), if there is a speed change ahead (speedChange, boolean), if there is a station stop ahead (stationStopSoon), and finally, the MTC Status.

Please note that if speedChange, endSoon, or stationStopSoon is true, the X, Y, and Z coordinates MUST be specified or else you might get a ComputerCraft side error. (fixed in latest version)

  • speedChange: nextSpeedLimitChangeX, nextSpeedLimitChangeY, nextSpeedLimitChangeZ`
  • endSoon: xStopPoint, yStopPoint, zStopPoint
  • stationStopSoon: xStationStop, yStationStop, zStationStop
{"funct":"startlevel2","nextSpeedLimit":0,"endSoon":false,"speedChange":false,"stationStopSoon":false,"mtcStatus":1,"speedLimit":90}

An example startlevel2 response to the train.

Periodically, the train will send updates to the server letting it know what signal block it is in, the destination, and the train's level.

{"funct":"update","signalBlock":"TLS1","destination":"","trainLevel":"1"}

The update from the train in JSON.

{"xStationStop":"-354.50000","funct":"response","nextSpeedLimit":90,"speedChange":true,"endSoon":false,"stationStopSoon":true,"nextSpeedLimitChangeZ":"2163.80000","nextSpeedLimitChangeX":"-351.50000","mtcStatus":1,"nextSpeedLimitChangeY":"4.280","speedLimit":160,"yStationStop":"4.280","zStationStop":"1894.800000"}

An example response from the server. In this example, it says that there is a station stop ahead, and a speed change ahead, as well as the X, Y, and Z coordinates for them.

When the train is broke, or it exits a W-MTC area ( the mtcStatus being set to 0), the train sends a disconnect message to the server, letting it know that it has disconnected from that server.

{"funct":"disconnect"}

This is the disconnect message being sent from the train.

Implementation

Just like standard MTC, to use the system, ComputerCraft must be installed, or else the blocks won't show up in the creative menu or can't be crafted.

W-MTC Wireless Radio (known internally as pdmInstructionBlock. wirelessMTCRadio in version 021+)

.activate() Activates the radio.

radio.activate()

.deactivate() Deactivates the radio.

radio.deactivate()

.getSelfUUID() Gets the UUID of the radio. This is randomly generated when the block is placed. It can be long at times, so in the log of the game it is posted there as well.

print(radio.getSelfUUID())

.sendMessage(UUIDTo, message) Sends a message to the specified UUID.

radio.sendMessage("someUUID", "hi!!")

pdm_message ( radio_message in 021) Event, triggered when it gets a message from a train or another radio. (in order) side, train's id, this UUID, message, system (system not used)

[top, qgfe1, 47ba5d8c-a9af-420d-8dfc-2021d0833363, {"funct":"update","signalBlock":"TLS1","destina
tion":"","trainLevel":"1"}, 1]

Example.

Automatic Train Operation

Depending on the train, ATO or Automatic Train Control can be enabled and the train can drive itself. It abides by stop points, station stops, speed changes, and speed limits. ATO can be toggled with a keybind in the settings. It can be enforced for trains (if the train allows it), by adding {"atoStatus" : "1"} to your W-MTC responses.

ATO Supported Trains:

  • High Speed Locomotive
  • Kawaski PA4
  • ICE1
  • IC4

startrun

startrun can be added to funct to start a train after it has been stopped at a station, allowing for automation. recycled from the previous one lul

{"funct":"startrun","nextSpeedLimit":0,"endSoon":false,"speedChange":false,"stationStopSoon":false,"mtcStatus":1,"speedLimit":90}

message

message can be used to send a simple message to the person that is riding the train (if they are).

{"funct":"message", "themessage" : "Bruh"}

Need further help?

If you are confused, try asking in the Traincraft Discord server. Someone or most likely me will be happy to answer. Happy coding 😄