Added documentation for train station peripherals and train schedules

- Added in depth documentation for working with train stations and train schedules in Lua
- Fixed small formatting issues in Lua-Rotation-Speed-Controller.md and Lua-Sequenced-Gearshift.md
This commit is contained in:
caelwarner 2023-03-13 16:31:16 -07:00
parent 7f3ca1cfa0
commit 952941e5fc
No known key found for this signature in database
GPG key ID: 514BEF5EADE889FF
4 changed files with 381 additions and 10 deletions

View file

@ -1,7 +1,7 @@
| Method | Description |
|:-----------------------------------------------:|----------------------------------------|
| [`setTargetSpeed(speed)`](#setTargetSpeedspeed) | Sets the target rotation speed |
| [`getTargetSpeed()`](#getTargetSpeed) | Gets the current target rotation speed |
| Method | Description |
|--------------------------------------------------|----------------------------------------|
| [`setTargetSpeed(speed)`](#setTargetSpeedspeed) | Sets the target rotation speed |
| [`getTargetSpeed()`](#getTargetSpeed) | Gets the current target rotation speed |
---
### `setTargetSpeed(speed)`

View file

@ -1,12 +1,11 @@
| Method | Description |
|------------------------------------------------------|--------------------------------------------------------------|
| [`rotate(angle, [modifier])`](#rotateangle-modifier) | Rotates shaft by a set angle |
| [`move(distance, [modifier])`](#moveangle-modifier) | Rotates shaft to move Piston/Pulley/Gantry by a set distance |
| [`isRunning()`](#isRunning) | Checks if the gearshift is spinning |
| Method | Description |
|--------------------------------------------------------|--------------------------------------------------------------|
| [`rotate(angle, [modifier])`](#rotateangle-modifier) | Rotates shaft by a set angle |
| [`move(distance, [modifier])`](#movedistance-modifier) | Rotates shaft to move Piston/Pulley/Gantry by a set distance |
| [`isRunning()`](#isRunning) | Checks if the gearshift is spinning |
---
### `rotate(angle, [modifier])`
Rotates connected components by a set angle.
**Parameters**

193
wiki/Lua-Train-Schedule.md Normal file
View file

@ -0,0 +1,193 @@
Train schedules are represented by a table in Lua. The table contains a list of entries where each entry has a single instruction and multiple conditions. Each instruction and condition has a `data` table that stores specific data about the instruction or condition.
```lua
schedule = {
cyclic = true, -- Does the schedule repeat itself after the end has been reached?
entries = { -- List of entries, each entry contains a single instruction and multiple conditions.
{
instruction = {
id = "create:destination", -- The different instructions are described below.
data = { -- Data that is stored about the instruction. Different for each instruction type.
text = "Station 1",
},
},
conditions = { -- List of lists of conditions. The outer list is the "OR" list
{ -- and the inner lists are "AND" lists.
{
id = "create:delay", -- The different conditions are described below.
data = { -- Data that is stored about the condition. Different for each condition type.
value = 5,
time_unit = 1,
},
},
{
id = "create:powered",
data = {},
},
},
{
{
id = "create:time_of_day",
data = {
rotation = 0,
hour = 14,
minute = 0,
},
},
},
},
},
},
}
```
---
## Instructions
| ID | Description |
|----------------------------------------------|---------------------------------|
| [`"create:destination"`](#createdestination) | Move to a certain train station |
| [`"create:rename"`](#createrename) | Change the schedule title |
| [`"create:throttle"`](#createthrottle) | Change the train's throttle |
---
### `"create:destination"`
Moves the train to the chosen train station. This instruction must have at least one condition.
**Data**
- _text:_ `string` The name of the station to travel to.
---
### `"create:rename"`
Renames the schedule. This name shows up on display link targets. This instruction cannot have conditions.
**Data**
- _text:_ `string` The name to rename the schedule to.
---
### `"create:throttle"`
Changes the throttle of the train. This instruction cannot have conditions.
**Data**
- _value:_ `number` The throttle to set the train to. Must be an integer with in the range of [5..100].
---
## Conditions
Conditions are stored in a list of lists of conditions. The inner lists contain conditions that get `AND`'d together. They must all be met for that group to be true. The outer list contains the `AND`'d groups of conditions that get `OR`'d together. Only one of the groups needs to be true for the schedule to move onto the next instruction.
| ID | Description |
|-----------------------------------------------------|-----------------------------------------------------|
| [`"create:delay"`](#createdelay) | Wait for a certain delay |
| [`"create:time_of_day"`](#createtimeofday) | Wait for a specific time of day |
| [`"create:fluid_threshold"`](#createfluidthreshold) | Wait for a certain amount of fluid to be on board |
| [`"create:item_threshold"`](#createitemthreshold) | Wait for a certain amount of items to be on board |
| [`"create:redstone_link"`](#createredstonelink) | Wait for a redstone link to be powered |
| [`"create:player_count"`](#createplayercount) | Wait for a certain amount of players to be on board |
| [`"create:idle"`](#createidle) | Wait for cargo loading inactivity |
| [`"create:unloaded"`](#createunloaded) | Wait for the current chunk to be unloaded |
| [`"create:powered"`](#createpowered) | Wait for the station to be powered |
---
### `"create:delay"`
Wait for a set delay. Can be measured in ticks, seconds or minutes.
**Data**
- _value:_ `number` The amount of time to wait for.
- _time_unit:_ `number` The unit of time. 0 for ticks, 1 for seconds and 2 for minutes.
---
### `"create:time_of_day"`
Wait for a time of day, then repeat at a specified interval.
**Data**
- _hour:_ `number` The hour of the day to wait for in a 24-hour format. Must be an integer within the range of [0..23].
- _minute:_ `number` The minute of the hour to wait for. Must be an integer within the range of [0..59].
- _rotation:_ `number` The interval to repeat at after the time of day has been met. Check the rotation table below for valid values. Must be an integer within the range of [0..9].
**Rotation**
| Rotation | Time Interval |
|----------|------------------|
| 0 | Every Day |
| 1 | Every 12 hours |
| 2 | Every 6 hours |
| 3 | Every 4 hours |
| 4 | Every 3 hours |
| 5 | Every 2 hours |
| 6 | Every hour |
| 7 | Every 45 minutes |
| 8 | Every 30 minutes |
| 9 | Every 15 minutes |
---
### `"create:fluid_threshold"`
Wait for a certain amount of a specific fluid to be loaded onto the train.
**Data**
- _bucket:_ `table` The bucket item of the fluid.
- _threshold:_ `number` The threshold in number of buckets of fluid. Must be a positive integer.
- _operator:_ `number` Whether the condition should wait for the train to be loaded above the threshold, below the threshold or exactly at the threshold. 0 for greater than, 1 for less than, 2 for equal to.
- _measure:_ `number` The unit to measure the fluid in. This condition supports buckets as the only unit. Set to 0.
**See also**
- [Items](#items) How items are represented in Lua
---
### `"create:item_threshold"`
Wait for a certain amount of a specific item to be loaded onto the train.
**Data**
- _item:_ `table` The item.
- _threshold:_ `number` The threshold of items. Must be a positive integer.
- _operator:_ `number` Whether the condition should wait for the train to be loaded above the threshold, below the threshold or exactly at the threshold. 0 for greater than, 1 for less than, 2 for equal to.
- _measure:_ `number` The unit to measure the items in. 0 for items. 1 for stacks of items.
**See also**
- [Items](#items) How items are represented in Lua
---
### `"create:redstone_link"`
Wait for a redstone link to be powered.
**Data**
- _frequency:_ `{ table... }` A list of the two items making up the redstone link frequency.
- _inverted:_ `number` Whether the redstone link should be powered or not to meet the condition. 0 for powered. 1 for not powered.
**See also**
- [Items](#items) How items are represented in Lua
---
### `"create:player_count"`
Wait for a certain amount of players to be seated on the train.
**Data**
- _count:_ `number` The number of players to be seated on the train. Must be a positive integer.
- _exact:_ `number` Whether the seated player count has to be exact to meet the condition. 0 for the exact amount of players seated, 1 for a greater than or equal amount of seated players.
---
### `"create:idle"`
Wait for a period of inactivity in loading or unloading the train. Can be measured in ticks, seconds or minutes.
**Data**
- _value:_ `number` The amount of idle time to meet the condition. Must be a positive integer.
- _time_unit:_ `number` The unit of time. 0 for ticks, 1 for seconds and 2 for minutes.
---
### `"create:unloaded"`
Wait for the chunk the train is in to be unloaded.
---
### `"create:powered"`
Wait for the station to be powered with a redstone signal.
---
## Items
In Lua, items are represented with an ID and a count.
```lua
item = {
id = "minecraft:stone",
count = 1,
}
```
- _id:_ `string` The ID of the item.
- _count:_ `number` The amount of items in the stack. For the purposes of working with train schedules the count should always be 1. Must be an integer.

179
wiki/Lua-Train-Station.md Normal file
View file

@ -0,0 +1,179 @@
| Method | Description |
|---------------------------------------------------------------|----------------------------------------------------|
| [`assemble()`](#assemble) | Assembles a new train at the station |
| [`disassemble()`](#disassemble) | Disassembles the currently present train |
| [`setAssemblyMode(assemblyMode)`](#setAssemblyModeassemblyMode) | Sets the station's assembly mode |
| [`isInAssemblyMode()`](#isInAssemblyMode) | Whether the station is in assembly mode |
| [`getStationName()`](#getStationName) | Gets the station's current name |
| [`setStationName(name)`](#setStationNamename) | Sets the station's name |
| [`isTrainPresent()`](#isTrainPresent) | Whether a train is present at the station |
| [`isTrainImminent()`](#isTrainImminent) | Whether a train is imminent to the station |
| [`isTrainEnroute()`](#isTrainEnroute) | Whether a train is enroute to the station |
| [`getTrainName()`](#getTrainName) | Gets the currently present train's name |
| [`setTrainName(name)`](#setTrainNamename) | Sets the currently present train's name |
| [`hasSchedule()`](#hasSchedule) | Whether the currently present train has a schedule |
| [`getSchedule()`](#getSchedule) | Gets the currently present train's schedule |
| [`setSchedule(schedule)`](#setScheduleschedule) | Sets the currently present train's schedule |
---
### `assemble()`
Assembles a new train at the station. The station must be in assembly mode prior to calling this function.
This function also causes the station to exit assembly mode after the train is done assembing.
**Throws**
- If the station is not in assembly mode.
- If the station is not connected to a track.
- If the train failed to assemble.
- If the station failed to exit assembly mode.
**See also**
- [`setAssemblyMode(assemblyMode)`](#setAssemblyModeassemblyMode) To set the assembly mode of the station.
---
### `disassemble()`
Disassembles the station's currently present train. The station must not be in assembly mode.
**Throws**
- If the station is in assembly mode.
- If the station is not connected to a track.
- If there is no currently present train at the station.
- If the train failed to disassemble.
**See also**
- [`setAssemblyMode(assemblyMode)`](#setAssemblyModeassemblyMode) To set the assembly mode of the station.
---
### `setAssemblyMode(assemblyMode)`
Sets the station's assembly mode.
**Parameters**
- _assemblyMode:_ `boolean` Whether the station should enter or exit assembly mode.
**Throws**
- If the station fails to enter or exit assembly mode.
- If the station is not connected to a track.
---
### `isInAssemblyMode()`
Checks whether the station is in assembly mode.
**Returns**
- `boolean` Whether the station is in assembly mode.
---
### `getStationName()`
Gets the station's current name.
**Returns**
- `string` The station's current name.
**Throws**
- If the station is not connected to a track.
---
### `setStationName(name)`
Sets the station's name.
**Parameters**
- _name:_ `string` The name to set the station to.
**Throws**
- If the station name fails to be set.
- If the station is not connected to a track.
---
### `isTrainPresent()`
Checks whether a train is currently present at the station.
**Returns**
- Whether a train is present at the station.
**Throws**
- If the station is not connected to a track.
---
### `isTrainImminent()`
Checks whether a train is imminently arriving at the station.
Imminent is defined as being within 30 meters of the station.
This will not be true if the train has arrived and stopped at the station.
**Returns**
- Whether a train is imminent to the station.
**Throws**
- If the station is not connected to a track.
**See also**
- [`isTrainPresent()`](#isTrainPresent) To check if a train is present at the station.
---
### `isTrainEnroute()`
Checks whether a train is enroute and navigating to the station.
**Returns**
- `boolean` Whether a train is enroute to the station.
**Throws**
- If the station is not connected to a track.
---
### `getTrainName()`
Gets the currently present train's name.
**Returns**
- `string` The currently present train's name.
**Throws**
- If the station is not connected to a track.
- If there is no currently present train at the station.
---
### `setTrainName(name)`
Sets the currently present train's name.
**Parameters**
- _name:_ `string` The name to set the currently present train to.
**Throws**
- If the station is not connected to a track.
- If there is no currently present train at the station.
---
### `hasSchedule()`
Checks whether the currently present train has a schedule.
**Returns**
- `boolean` Whether the currently present train has a schedule.
**Throws**
- If the station is not connected to a track.
- If there is no currently present train at the station.
---
### `getSchedule()`
Gets the currently present train's schedule.
**Returns**
- `table` The train's schedule
**Throws**
- If the station is not connected to a track.
- If there is no currently present train at the station.
- If the present train doesn't have a schedule.
**See also**
- [Lua Train Schedules](#Lua-Train-Schedules) How train schedules are represented in Lua.
---
### `setSchedule(schedule)`
Sets the currently present train's schedule. This will overwrite the currently set schedule.
**Parameters**
- _schedule:_ `table` The schedule to set the present train to.
**Throws**
- If the station is not connected to a track.
- If there is no currently present train at the station.
**See also**
- [Lua Train Schedules](#Lua-Train-Schedules) How train schedules are represented in Lua.