[docs] MkDocs-based documentation for ReadTheDocs.

master
Quentin Bazin 2020-03-10 23:50:41 +01:00
parent 1606d9a300
commit 4a954b7d11
7 changed files with 309 additions and 0 deletions

View File

@ -1,6 +1,7 @@
# OpenMiner
[![Build Status](https://travis-ci.com/Unarelith/OpenMiner.svg?branch=master)](https://travis-ci.com/Unarelith/OpenMiner)
[![Documentation Status](https://readthedocs.org/projects/openminer/badge/?version=latest)](https://openminer.readthedocs.io/en/latest/?badge=latest)
[![Documentation](https://codedocs.xyz/Quent42340/OpenMiner.svg)](https://codedocs.xyz/Quent42340/OpenMiner/)
[![License](https://img.shields.io/badge/license-LGPLv2.1%2B-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html)
[![Discord](https://img.shields.io/discord/527527086756200458.svg?style=popout)](https://discord.gg/eN8k8wt)

20
docs/index.md Normal file
View File

@ -0,0 +1,20 @@
# Welcome to the OpenMiner wiki!
## Compilation
- [Compiling on Windows with MinGW-w64](https://github.com/Unarelith/OpenMiner/wiki/Compiling-on-Windows-with-MinGW-w64)
- [Compiling on Windows with Visual Studio 2017](https://github.com/Unarelith/OpenMiner/wiki/Compiling-on-Windows-with-Visual-Studio-2017)
## Documentation
- [Getting Started](https://github.com/Unarelith/OpenMiner/wiki/Getting-Started)
- [Contributing](https://github.com/Unarelith/OpenMiner/blob/master/CONTRIBUTING.md)
- [Coding Style](https://github.com/Unarelith/OpenMiner/wiki/Coding-Style)
- [Lua API](lua-api-overview.md)
- [Blocks](lua-api-blocks.md)
- [Network Protocol](https://github.com/Unarelith/OpenMiner/wiki/Network-Protocol)
## Other
- [History of OpenMiner](https://github.com/Unarelith/OpenMiner/wiki/History-of-OpenMiner)

80
docs/lua-api-blocks.md Normal file
View File

@ -0,0 +1,80 @@
# Lua API: Blocks
- [Attributes](#attributes)
- [Data types](#data-types)
- [Draw types](#draw-types)
- [Functions](#functions)
- [on_block_placed](#on_block_placed)
- [on_block_activatd](#on_block_activated)
- [on_tick](#on_tick)
## Attributes
Blocks can have the following attributes:
| Attribute | Type | Description |
| -------------------- | ------------- | ---------------------------------------------------- |
| id* | string | ID of the block without the "mod:" prefix |
| label* | string | Label of the block |
| on_block_placed | function | Called when the block is placed |
| on_block_activated | function | Called when a player right-click the block |
| on_tick | function | Called every tick |
| harvest_requirements | u8 | Set which tools are more effective |
| hardness | float | Hardness of the block, affects mining speed |
| is_opaque | bool | Whether or not the block let light pass |
| is_light_source | bool | Whether or not the block is a light source |
| is_rotatable | bool | Whether or not the block is rotatable |
| bounding_box | float[6] | Bounding box of the block {x,y,z,w,d,h} |
| draw_type | string | Draw type of the block (see [Draw types](#draw-types)) |
| item_drop | ItemStack | Item stack that is dropped when the block is broken |
| color_multiplier | u8[4] | Only grayscale colors are affected by this attribute |
NB: Attributes with a `*` means they're mandatory
### Data types
`ItemStack` is a table composed of:
- `id` (`string`): item id with the "mod:" prefix
- `amount` (`u16`): amount in the stack
### Draw types
The currently allowed draw type values are:
- `solid`
- `xshape`
- `leaves`
- `liquid`
- `glass`
## Functions
### on_block_placed
Parameters:
- `pos` (`vec3`): position of the block
- `world` (`World`): instance of `ServerWorld`
### on_block_activated
Parameters:
- `pos` (`vec3`): position of the block
- `player` (`Player`): current player
- `world` (`World`): instance of the `ServerWorld`
- `client` (`Client`): client that activated the block
- `screen_width` (`u16`): width of the screen
- `screen_height` (`u16`): height of the screen
- `gui_scale` (`u8`): current scaling setting
### on_tick
Parameters:
- `pos` (`vec3`): position of the block
- `player` (`Player`): current player
- `chunk` (`Chunk`): current chunk
- `world` (`World`): instance of the `ServerWorld`

192
docs/lua-api-overview.md Normal file
View File

@ -0,0 +1,192 @@
# Lua API: Overview
## Table of contents
- [Lua API](#lua-api)
- [Core API](#core-api)
- [Mod API](#mod-api)
- [Custom GUI](#custom-gui)
- [Button](#button)
- [Inventory](#inventory)
- [Crafting table](#crafting-table)
- [Image](#image)
- [C++ classes in Lua](#c-classes-in-lua)
- [Registry](#registry)
- [World](#world)
- [Chunk](#chunk)
- [BlockData](#blockdata)
- [Player](#player)
- [Inventory](#inventory-1)
- [Recipe](#recipe)
- [ItemStack](#itemstack)
- [Item](#item)
## Lua API
### Core API
- `Registry *openminer:registry()`
- `openminer:add_listener(event_type, listener)`
### Mod API
Here is an example:
```lua
local mod = LuaMod.new("mymod")
mod:block {
id = "myblock",
name = "My Block",
tiles = "myblock.png",
hardness = 3,
harvest_requirements = 1,
on_tick = function(pos, player, chunk, world) end,
on_block_activated = function(pos, player, world, client) end,
}
mod:item {
id = "mymod:myitem",
name = "My Item",
tiles = "myitem.png",
}
mod:crafting_recipe {
result = {
id = "mymod:myblock",
amount = 1
},
pattern = {
"###",
"# #",
"###"
},
keys = {["#"] = "default:cobblestone"}
}
mod:smelting_recipe {
input = {id = "mymod:myblock", amount = 1},
output = {id = "default:ingot_iron", amount = 1}
}
```
I'll describe all the possible options later.
### Custom GUI
You can create a new GUI with:
```lua
local gui = LuaGUI.new()
```
To show the custom GUI use:
```lua
gui:show(client)
```
#### Button
```lua
gui:button {
name = "btn_test",
pos = {x = 0, y = 0},
text = "Test button",
on_click = function(self)
print("Test button pressed")
end,
}
```
#### Inventory
```lua
gui:inventory {
name = "inv_main",
pos = {x = gui_pos.x + 7, y = gui_pos.y + 83},
player = "player",
inventory = "main",
size = {x = 9, y = 3},
offset = 9,
count = 9 * 3,
}
```
#### Crafting table
```lua
gui:crafting {
name = "inv_crafting",
pos = {x = gui_pos.x, y = gui_pos.y},
block = {x = pos.x, y = pos.y, z = pos.z},
offset = 0,
}
```
#### Image
```lua
gui:image {
name = "img_background",
pos = gui_pos,
texture = "texture-workbench",
clip = {x = 0, y = 0, width = 176, height = 166},
}
```
## C++ classes in Lua
### Registry
- `Recipe get_recipe(Inventory crafting_inventory)`
### World
- `u16 get_block(int x, int y, int z)`
- `u16 get_data(int x, int y, int z)`
- `void set_data(int x, int y, int z, u16 data)`
- `BlockData *get_block_data(int x, int y, int z)`
### Chunk
- `u16 get_block(int x, int y, int z)`
- `u16 get_data(int x, int y, int z)`
- `BlockData *get_block_data(int x, int y, int z)`
### BlockData
- `Inventory *inventory()`
- `u32 data()`
### Player
- `Inventory *inventory()`
### Inventory
- `void add_stack(string name, u16 amount)`
- `ItemStack get_stack(u16 x, u16 y)`
- `void set_stack(u16 x, u16 y, string name, u16 amount)`
### Recipe
- `string type()`
- `ItemStack result()`
### ItemStack
- `u16 amount()`
- `Item item()`
### Item
- `u16 id()`
- `string name()`
- `u16 burn_time()`

15
mkdocs.yml Normal file
View File

@ -0,0 +1,15 @@
site_name: OpenMiner
nav:
- 'Home': 'index.md'
- 'Lua API':
- 'Overview': 'lua-api-overview.md'
- 'Blocks': 'lua-api-blocks.md'
theme:
name: readthedocs
highlightjs: true
hljs_languages:
- yaml
- rust

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
mkdocs==1.1