Skip to content

Commit 4434025

Browse files
authored
Update API documentation (#237)
* API documentation * Fix switching station description
1 parent ec3a52c commit 4434025

File tree

1 file changed

+82
-54
lines changed

1 file changed

+82
-54
lines changed

technic/doc/api.md

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
This file is fairly incomplete. Help is welcome.
1+
This file is fairly incomplete. Read the code if this is not enough. Help is welcome.
22

33
Tiers
44
-----
5-
The tier is a string, currently `"LV"`, `"MV"` and `"HV"` are supported.
5+
The tier is a string, currently `"LV"`, `"MV"` and `"HV"` are included with technic.
66

77
Network
88
-------
9-
The network is the cable with the connected machine nodes. Currently the
10-
switching station handles the network activity.
9+
The network is the cable with the connected machine nodes. The switching station activates network.
1110

1211
Helper functions
1312
----------------
@@ -24,14 +23,6 @@ Helper functions
2423
* `technic.get_or_load_node(pos)`
2524
* If the mapblock is loaded, it returns the node at pos,
2625
else it loads the chunk and returns `nil`.
27-
* `technic.set_RE_wear(itemstack, item_load, max_charge)`
28-
* If the `wear_represents` field in the item's nodedef is
29-
`"technic_RE_charge"`, this function does nothing.
30-
* `technic.refill_RE_charge(itemstack)`
31-
* This function fully recharges an RE chargeable item.
32-
* If `technic.power_tools[itemstack:get_name()]` is `nil` (or `false`), this
33-
function does nothing, else that value is the maximum charge.
34-
* The itemstack metadata is changed to contain the charge.
3526
* `technic.is_tier_cable(nodename, tier)`
3627
* Tells whether the node `nodename` is the cable of the tier `tier`.
3728
* `technic.get_cable_tier(nodename)`
@@ -43,34 +34,84 @@ Helper functions
4334
* `technic.trace_node_ray_fat(pos, dir, range)`
4435
* Like `technic.trace_node_ray` but includes extra positions near the ray.
4536
* The node ray functions are used for mining lasers.
46-
* `technic.config:get(name)`
47-
* Some configuration function
4837
* `technic.tube_inject_item(pos, start_pos, velocity, item)`
4938
* Same as `pipeworks.tube_inject_item`
5039

51-
Registration functions
40+
Configuration API
41+
----------------------
42+
* `technic.config` Settings object that contains Technic configuration.
43+
* Provides all methods that are provided by Minetest Settings object.
44+
* Uses `<world-path>/technic.conf` as configuration file.
45+
* If key is not present in configuration then returns default value for that key.
46+
* `:get_int(key)` Return number value for configuration key.
47+
48+
Power tool API
49+
----------------------
50+
51+
* `technic.register_power_tool(itemname, definition)`
52+
* Registers power tool adding required fields, otherwise same as `minetest.register_tool(itemname, definition)`.
53+
* For regular power tools you only want to change `max_charge` and leave other fields unset (defaults).
54+
* Special fields for `definition`:
55+
* `max_charge` Number, maximum charge for tool. Defaults to `10000` which is same as RE battery.
56+
* `on_refill` Function to refill charge completely. Default is to set maximum charge for tool.
57+
* `wear_represents` Customize wear indicator instead of using charge level. Default is `"technic_RE_charge"`.
58+
* `tool_capabilities` See Minetest documentation. Default is `{ punch_attack_uses = 0 }`.
59+
* `technic.get_RE_charge(itemstack)`
60+
* Returns current charge level of tool
61+
* `technic.set_RE_charge(itemstack, charge)`
62+
* Sets tool charge level.
63+
* `technic.use_RE_charge(itemstack, charge)`
64+
* Attempt to use charge and return `true`/`false` indicating success.
65+
* Always succeeds without checking charge level if creative is enabled.
66+
67+
Machine registration API
5268
----------------------
53-
* `technic.register_power_tool(itemname, max_charge)`
54-
* Same as `technic.power_tools[itemname] = max_charge`
55-
* This function makes the craftitem `itemname` chargeable.
5669
* `technic.register_machine(tier, nodename, machine_type)`
57-
* Same as `technic.machines[tier][nodename] = machine_type`
58-
* Currently this is requisite to make technic recognize your node.
70+
* Custom machine registration. Not needed when using builtin machine registration functions.
5971
* See also `Machine types`
6072
* `technic.register_tier(tier)`
61-
* Same as `technic.machines[tier] = {}`
73+
* Registers network tier.
6274
* See also `tiers`
75+
* `technic.register_base_machine(nodename, def)`
76+
* Register various types of basic factory processing machines.
77+
* `typename = "compressing"`
78+
* `description = S("%s Compressor")`
79+
* `tier = "HV"`
80+
* `demand = {1500, 1000, 750}`
81+
* `speed = 5`
82+
* `upgrade = 1`
83+
* `tube = 1`
84+
* TODO / TBD
85+
* `technic.register_solar_array(nodename, def)`
86+
* Registers solar array generator.
87+
* `tier = "HV"`
88+
* `power = 100`
89+
* TODO / TBD
90+
* `technic.register_battery_box(nodename, def)`
91+
* Registers battery box node used as energy storage.
92+
* TODO / TBD
93+
* `technic.register_cable(nodename, data)`
94+
* Registers technic network cables.
95+
* `tier = "HV"`
96+
* `size = 3/16`
97+
* `description = S("%s Digiline Cable"):format("HV")`
98+
* `digiline = { wire = { rules = technic.digilines.rules_allfaces } }`
99+
* `technic.register_cable_plate(nodename, data)`
100+
* Registers technic network cable plates. Results in multiple nodes registered with `_1` to `_6` appended to name.
101+
* See `technic.register_cable(nodename, data)`
102+
103+
Network control API
104+
----------------------
105+
* TBD, functions exported through technic namespace are currently considered to be internal use only.
63106

64107
### Specific machines
65-
* `technic.register_solar_array(data)`
66-
* data is a table
67108
* `technic.can_insert_unique_stack(pos, node, stack, direction)`
68109
* `technic.insert_object_unique_stack(pos, node, stack, direction)`
69110
* Functions for the parameters `can_insert` and `insert_object` to avoid
70-
filling multiple inventory slots with same type of item.
111+
filling multiple inventory slots with same type of item.
71112

72113
Used itemdef fields
73-
-------------------
114+
----------------------
74115
* groups:
75116
* `technic_<ltier> = 1` ltier is a tier in small letters; this group makes
76117
the node connect to the cable(s) of the right tier.
@@ -101,42 +142,29 @@ There are currently following types:
101142

102143
Switching Station
103144
-----------------
104-
The switching station is the center of all power distribution on an electric
105-
network.
145+
The switching station is required to start electric network and keep it running.
146+
Unlike in original mod this node does not handle power distribution logic but instead just resets network timeout.
147+
148+
Network logic
149+
-----------------
106150

107-
The station collects power from sources (PR), distributes it to sinks (RE),
151+
The network logic collects power from sources (PR), distributes it to sinks (RE),
108152
and uses the excess/shortfall to charge and discharge batteries (BA).
109153

110154
For now, all supply and demand values are expressed in kW.
111155

112-
It works like this:
113-
All PR,BA,RE nodes are indexed and tagged with the switching station.
114-
The tagging is a workaround to allow more stations to be built without allowing
115-
a cheat with duplicating power.
116-
All the RE nodes are queried for their current EU demand. Those which are off
117-
would require no or a small standby EU demand, while those which are on would
118-
require more.
119-
If the total demand is less than the available power they are all updated with
120-
the demand number.
121-
If any surplus exists from the PR nodes the batteries will be charged evenly
122-
with this.
123-
If the total demand requires draw on the batteries they will be discharged
124-
evenly.
125-
126-
If the total demand is more than the available power all RE nodes will be shut
127-
down. We have a brown-out situation.
128-
129-
Hence for now all the power distribution logic resides in this single node.
156+
All the RE nodes are queried for their current EU demand. Those which are off would
157+
require no or a small standby EU demand, while those which are on would require more.
158+
If total demand is less than the available power they are all updated with the demand number.
159+
If any surplus exists from the PR nodes the batteries will be charged evenly with excess power.
160+
If total demand exceeds generator supply then draw difference from batteries.
161+
If total demand is more than available power all RE nodes will be shut down.
130162

131163
### Node meta usage
132-
Nodes connected to the network will have one or more of these parameters as meta
133-
data:
134-
* `<LV|MV|HV>_EU_supply` : Exists for PR and BA node types.
135-
This is the EU value supplied by the node. Output
136-
* `<LV|MV|HV>_EU_demand` : Exists for RE and BA node types.
137-
This is the EU value the node requires to run. Output
138-
* `<LV|MV|HV>_EU_input` : Exists for RE and BA node types.
139-
This is the actual EU value the network can give the node. Input
164+
Nodes connected to the network will have one or more of these parameters as meta data:
165+
* `<LV|MV|HV>_EU_supply` : Exists for PR and BA node types. This is the EU value supplied by the node. Output
166+
* `<LV|MV|HV>_EU_demand` : Exists for RE and BA node types. This is the EU value the node requires to run. Output
167+
* `<LV|MV|HV>_EU_input` : Exists for RE and BA node types. This is the actual EU value the network can give the node. Input
140168

141169
The reason the LV|MV|HV type is prepended to meta data is because some machine
142170
could require several supplies to work.

0 commit comments

Comments
 (0)