Compare commits
79 Commits
shitcode
...
7ec4f906c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ec4f906c8 | |||
| 39dbf29ff6 | |||
| a4b1ff2ee5 | |||
| 0c5f508152 | |||
| 50dd702e6e | |||
| 426fea3691 | |||
| 299dad5e11 | |||
| 0e8edc4f05 | |||
| f13a0b1273 | |||
| 57de1f4b42 | |||
| d0eba35e8d | |||
| 8640e55415 | |||
| 84295c56c4 | |||
| eaf350e9ce | |||
| dfd8021808 | |||
| d9f9bd7a6c | |||
|
|
0ff45e4da1 | ||
| 395f45aeb9 | |||
| d9aa50fc91 | |||
| 876b24e1fe | |||
| 37ad60d348 | |||
| bc50096293 | |||
| 1c5038ff14 | |||
| 562ff7d24c | |||
| a08934c6e4 | |||
| 6236a12ca9 | |||
| f7ec69bd54 | |||
| bf107cb167 | |||
| cb49582a19 | |||
| cf4ca6f8dc | |||
| 2032082ba8 | |||
| 9557642805 | |||
| 6db2e9f77a | |||
| 275f54c7b7 | |||
| 47dc024b6c | |||
| efeb5c75cd | |||
| c0575e2c82 | |||
| 4e823bfee6 | |||
| 44ba5c7cfa | |||
| 475b199ddb | |||
| 96b51caaaf | |||
| 514e676e9a | |||
| 7773e25a81 | |||
| 96289375b1 | |||
| 40c1d34124 | |||
| 2655127a22 | |||
| b1c3e50445 | |||
| 9c919343cf | |||
| 13391b085e | |||
| 27004ebf45 | |||
| 7b951b64ac | |||
| c57a7ceadd | |||
| 95084d5daf | |||
| 3e9996e6a0 | |||
| 3646ec78cd | |||
| cf141f9797 | |||
| 475b5fab0c | |||
| 6f742e7291 | |||
| b5994d7383 | |||
| c5a71d5bdc | |||
| 1ac87b464a | |||
| 5b22c900d5 | |||
| 0b749564af | |||
| a699367bf4 | |||
| 720b7edcdb | |||
| bbd5c781e4 | |||
| 0870ce37e9 | |||
| a5c8846130 | |||
| 745fdb8dd3 | |||
| a0a1db6179 | |||
| 1d576dcaf5 | |||
| 414d5008d3 | |||
| 7908f5fc9f | |||
| af87c2912c | |||
| e44420d0ab | |||
| ace217832b | |||
| f9eccced09 | |||
| d07b7c811f | |||
| f556e4349e |
@@ -24,7 +24,9 @@
|
|||||||
"enables": [],
|
"enables": [],
|
||||||
"globals": [
|
"globals": [
|
||||||
"core",
|
"core",
|
||||||
|
"Smc",
|
||||||
"table",
|
"table",
|
||||||
|
"Events",
|
||||||
"VoxelArea",
|
"VoxelArea",
|
||||||
"VoxelManip",
|
"VoxelManip",
|
||||||
"vector",
|
"vector",
|
||||||
|
|||||||
52
.gitea/issue_template/bug.yaml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
name: Сообщение об ошибке
|
||||||
|
about: Сообщить о недоработке игры, которую необходимо исправить.
|
||||||
|
title: "[Bug]: "
|
||||||
|
labels:
|
||||||
|
- bug/need confirmed
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: bug-desc
|
||||||
|
attributes:
|
||||||
|
label: Описание ошибки
|
||||||
|
description: Опишите, что произошло, в чем по вашему мнению заключается ошибка и какое поведение игры вы ожидали.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: playback-order
|
||||||
|
attributes:
|
||||||
|
label: Как воспроизвести баг?
|
||||||
|
description: Опишите порядок действий, как воспроизвести описываемую ошибку.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: dropdown
|
||||||
|
id: game-version
|
||||||
|
attributes:
|
||||||
|
label: Версия игры
|
||||||
|
description: Сообщите на каких версиях клиента игры была замечена ошибка.
|
||||||
|
multiple: true
|
||||||
|
options:
|
||||||
|
- "5.15"
|
||||||
|
- "5.14"
|
||||||
|
- "5.13"
|
||||||
|
- "5.12"
|
||||||
|
- "5.11"
|
||||||
|
- "5.10"
|
||||||
|
- "< 5.10"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: bug-server
|
||||||
|
attributes:
|
||||||
|
label: Где была замечена ошибка?
|
||||||
|
description: Сообщите, где была замечена ошибка.
|
||||||
|
multiple: true
|
||||||
|
options:
|
||||||
|
- Игровой сервер
|
||||||
|
- Локальный мир
|
||||||
|
- Тестовый сервер
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Спасибо, что уделили время и заполнили этот отчет об ошибке!
|
||||||
19
.gitea/issue_template/idea.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name: Предложение
|
||||||
|
about: Описать предложение для рассмотрения мейнтейнерами проекта.
|
||||||
|
labels:
|
||||||
|
- idea/need a maintainer
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: task-desc
|
||||||
|
attributes:
|
||||||
|
label: Описание
|
||||||
|
description: Подробно опишите в чем заключается ваша идея, а так же объясните необходимость её реализации.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: task-additions
|
||||||
|
attributes:
|
||||||
|
label: Дополнения
|
||||||
|
description: Приложите дополнительные сведенья, файлы или изображения.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
19
.gitea/issue_template/task.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name: Задача
|
||||||
|
about: Сформировать и описать задачу, которую должен будет выполнить разработчик. Этот шаблон предназначен для мейнтейнеров проекта.
|
||||||
|
labels:
|
||||||
|
- task/need developer
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: task-desc
|
||||||
|
attributes:
|
||||||
|
label: Описание задачи
|
||||||
|
description: Подробно опишите в чем заключается задача для разработчика.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: task-additions
|
||||||
|
attributes:
|
||||||
|
label: Дополнения
|
||||||
|
description: Приложите дополнительные сведенья, файлы или изображения необходимые для выполнения задачи.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
35
.gitea/pull_request_template.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: Сообщение об ошибке
|
||||||
|
about: Сообщить о недоработке игры, которую необходимо исправить.
|
||||||
|
labels:
|
||||||
|
- pr/wait review
|
||||||
|
- review/need a maintainer
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: pr-desc
|
||||||
|
attributes:
|
||||||
|
label: Описание изменений
|
||||||
|
description: Опишите, что было изменено в запросе на слияние и по какой причине.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: testing
|
||||||
|
attributes:
|
||||||
|
label: Тестирование
|
||||||
|
description: Опишите, в наличии каких объектов или в работоспособности каких систем необходимо убедиться.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: checkboxes
|
||||||
|
id: terms
|
||||||
|
attributes:
|
||||||
|
label: Требования
|
||||||
|
options:
|
||||||
|
- label: Я запускал игру и убедился в том, что она работает.
|
||||||
|
required: true
|
||||||
|
- label: Я ознакомлен с соглашением по разработке и мои изменения следуют принятым стандартам.
|
||||||
|
required: true
|
||||||
|
- label: Я указал в описании запроса метки (label) с префиксом `Edit:` в соответствии с теми изменениями, которые сделал.
|
||||||
|
required: true
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Спасибо, что прислали это запрос на слияние и помогли нам в разработке игры!
|
||||||
7
.gitmodules
vendored
@@ -1,7 +1,6 @@
|
|||||||
[submodule "mods/API/Utf8"]
|
|
||||||
path = mods/API/Utf8
|
|
||||||
url = https://github.com/ApancoreStudio/utf8_api.git
|
|
||||||
branch = main
|
|
||||||
[submodule "util/ide-helper"]
|
[submodule "util/ide-helper"]
|
||||||
path = util/ide-helper
|
path = util/ide-helper
|
||||||
url = https://github.com/Voxrame/luanti-ide-helper.git
|
url = https://github.com/Voxrame/luanti-ide-helper.git
|
||||||
|
[submodule "mods/SYSTEM/Utf8"]
|
||||||
|
path = mods/SYSTEM/Utf8
|
||||||
|
url = https://git.apancore.ru/Apancore.Studio/utf8_api.git
|
||||||
|
|||||||
13
README.md
@@ -1,3 +1,12 @@
|
|||||||
Simple Makes Complex is a Luanti engine-based game focused on the multiplayer gameplay
|

|
||||||
|
|
||||||

|
# Simple Makes Complex
|
||||||
|
Simple Makes Complex is a Luanti engine-based game focused on the multiplayer gameplay.
|
||||||
|
|
||||||
|
# Licensing
|
||||||
|
- The project's core code is licensed under [MIT](/LICENSE).
|
||||||
|
- Submodules may contain their own license.
|
||||||
|
- Media assets are used and distributed under [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/).
|
||||||
|
|
||||||
|
# Assets used
|
||||||
|
- Font used in the `/menu/last_header.png`: https://fontstruct.com/fontstructions/show/2722233/gbjve (danil_2461, [CC0](http://creativecommons.org/publicdomain/zero/1.0/))
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
title = SMC
|
title = SMC
|
||||||
|
|
||||||
|
allowed_mapgens = singlenode
|
||||||
|
default_mapgen = singlenode
|
||||||
BIN
menu/background.png
Normal file
|
After Width: | Height: | Size: 2.1 MiB |
BIN
menu/header.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
menu/header_scale.png
Normal file
|
After Width: | Height: | Size: 770 KiB |
BIN
menu/icon.png
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 1.2 KiB |
BIN
menu/last_header.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
@@ -1,91 +0,0 @@
|
|||||||
Api = {}
|
|
||||||
|
|
||||||
---@alias Domain table<string,Mod|SubDomain> Global table for accessing public classes provided by mods.
|
|
||||||
---@alias SubDomain table<string,Mod>
|
|
||||||
|
|
||||||
---@type Domain
|
|
||||||
Core = {}
|
|
||||||
|
|
||||||
---@type Domain
|
|
||||||
Environment = {}
|
|
||||||
|
|
||||||
---@type Domain
|
|
||||||
Game = {}
|
|
||||||
|
|
||||||
---@type SubDomain
|
|
||||||
Game.Items = {}
|
|
||||||
|
|
||||||
---@type SubDomain
|
|
||||||
Game.Mobs = {}
|
|
||||||
|
|
||||||
---@type SubDomain
|
|
||||||
Game.Structures = {}
|
|
||||||
Ui = {}
|
|
||||||
|
|
||||||
local allowedDomains = {
|
|
||||||
Api = true,
|
|
||||||
Core = true,
|
|
||||||
Environment = true,
|
|
||||||
Game = true,
|
|
||||||
Ui = true
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Adds a mod to the global space under specified domain structure
|
|
||||||
---@param mod Mod The mod table containing functionality to expose
|
|
||||||
---@param location string Dot-separated path within domain structure (e.g. "Items.Log")
|
|
||||||
---@param force boolean? Whether to overwrite the target location.
|
|
||||||
Api.addModToGlobalSpace = function(mod, location, force)
|
|
||||||
-- Ensure `mod` type and that it's not empty
|
|
||||||
Ensure.argType(mod, 'table', 1, 'Api.addModToGlobalSpace')
|
|
||||||
|
|
||||||
-- Ensure `location` type and that it's not empty
|
|
||||||
Ensure.argType(location, 'string', 2, 'Api.addModToGlobalSpace')
|
|
||||||
Ensure.stringArgNotEmpty(location, 2, 'Api.addModToGlobalSpace')
|
|
||||||
|
|
||||||
-- Ensure `location` matches this format: 'field.subfield.subsubfield.<...>'
|
|
||||||
-- TODO: баг: ликвидные имена не определяются шаблоном
|
|
||||||
--[[if not location:match('^[%a_][%w_]*([%.][%a_][%w_]*)*$') then
|
|
||||||
error('bad argument #2 to \'Api.addModToGlobalSpace\' (invalid format)')
|
|
||||||
end--]]
|
|
||||||
|
|
||||||
-- Split `location` into fields -- TODO: !!!Make a String function!!!
|
|
||||||
local fields = {}
|
|
||||||
local domain = nil
|
|
||||||
for field in string.gmatch(location, '[^.]+') do
|
|
||||||
if domain ~= nil then
|
|
||||||
table.insert(fields, field)
|
|
||||||
else
|
|
||||||
domain = field
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Ensure the domain is allowed
|
|
||||||
Ensure.argIsAllowed(domain, allowedDomains , 2, 'Api.addModToGlobalSpace')
|
|
||||||
|
|
||||||
-- Handle case where we're modifying the domain root directly
|
|
||||||
if #fields == 0 then
|
|
||||||
error('Not allowed to directly write into the \''.. domain ..'\' domain')
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Start traversing from the domain's table
|
|
||||||
local current = _G[domain]
|
|
||||||
assert(type(current) == 'table', 'The global domain is not a table')
|
|
||||||
|
|
||||||
-- Traverse each field of the location
|
|
||||||
local num_fields = #fields
|
|
||||||
for i = 1, num_fields - 1 do
|
|
||||||
local field = fields[i]
|
|
||||||
if current[field] == nil then
|
|
||||||
current[field] = {}
|
|
||||||
end
|
|
||||||
current = current[field]
|
|
||||||
assert(type(current) == 'table', 'intermediate field is not a table')
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Assign mod to the final field
|
|
||||||
local last_field = fields[num_fields]
|
|
||||||
if force and current[last_field] ~= nil then
|
|
||||||
error(string.format('field \'%s\' already exists in \'%s\'', last_field, location))
|
|
||||||
end
|
|
||||||
current[last_field] = mod
|
|
||||||
end
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
name = smc__api__api_loader
|
|
||||||
description = Include this mod in your `depends` to ensure all necessary APIs are loaded for your mod
|
|
||||||
depends = smc__api__ensure, smc__api__math, smc__api__mod, smc__api__require, smc__api__table, smc__api__string, smc__api__utf8,
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__api__ensure
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__api__logger
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
local math = math
|
|
||||||
|
|
||||||
math.lerp = function (a, b, t)
|
|
||||||
return a + (b - a) * t
|
|
||||||
end
|
|
||||||
|
|
||||||
math.clamp = function(value, min, max)
|
|
||||||
return math.min(math.max(value, min), max)
|
|
||||||
end
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__api__math
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__api__mod
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__api__require
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
name = smc__api__string
|
|
||||||
depends = smc__api__ensure
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
name = smc__api__table
|
|
||||||
depends = smc__api__ensure
|
|
||||||
0
mods/API/Utf8/init.lua
Normal file
@@ -1 +0,0 @@
|
|||||||
name = smc__api
|
|
||||||
4
mods/CORE/Control/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__control')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Control')
|
||||||
2
mods/CORE/Control/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__control
|
||||||
|
depends = smc__system__system_loader
|
||||||
140
mods/CORE/Control/src/Control.lua
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
---@class Events.Control
|
||||||
|
local Control = {}
|
||||||
|
|
||||||
|
-- control.on_press
|
||||||
|
Events.registerEvent('control.on_press')
|
||||||
|
|
||||||
|
---@param callbackFunc fun(player:Player, controlName:string)
|
||||||
|
function Control.subcribeOnPress(callbackFunc)
|
||||||
|
Events.subscribe('control.on_press', callbackFunc)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- control.on_release
|
||||||
|
Events.registerEvent('control.on_release')
|
||||||
|
|
||||||
|
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number)
|
||||||
|
function Control.subcribeOnRelease(callbackFunc)
|
||||||
|
Events.subscribe('control.on_release', callbackFunc)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- control.on_hold
|
||||||
|
Events.registerEvent('control.on_hold')
|
||||||
|
|
||||||
|
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number, dtime:number)
|
||||||
|
function Control.subcribeOnHold(callbackFunc)
|
||||||
|
Events.subscribe('control.on_hold', callbackFunc)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- control.on_wield_change
|
||||||
|
Events.registerEvent('control.on_wield_change')
|
||||||
|
|
||||||
|
---@param callbackFunc fun(player:Player, player_wield_index:number, player_last_wield_index:number)
|
||||||
|
function Control.subcribeOnWieldChange(callbackFunc)
|
||||||
|
Events.subscribe('control.on_wield_change', callbackFunc)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- --- Call events ---
|
||||||
|
|
||||||
|
local ControlPressKeys = {
|
||||||
|
'up', 'down', 'left', 'right', 'jump', 'aux1', 'sneak', 'dig', 'place', 'zoom'
|
||||||
|
}
|
||||||
|
|
||||||
|
local ControlMovementKeys = {
|
||||||
|
'movement_x', 'movement_y'
|
||||||
|
}
|
||||||
|
|
||||||
|
local playersLastControl = {}
|
||||||
|
local playersControlTimer = {}
|
||||||
|
|
||||||
|
core.register_on_joinplayer(function(player, last_login)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
if playerName == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local nowControl = player:get_player_control()
|
||||||
|
if nowControl == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local controlTimer = {}
|
||||||
|
for _, key in ipairs(ControlPressKeys) do
|
||||||
|
controlTimer[key] = 0.0
|
||||||
|
end
|
||||||
|
|
||||||
|
playersLastControl[playerName] = nowControl
|
||||||
|
playersControlTimer[playerName] = controlTimer
|
||||||
|
end)
|
||||||
|
|
||||||
|
core.register_on_leaveplayer(function(player, timed_out)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
if playerName == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
playersLastControl[playerName] = nil
|
||||||
|
playersControlTimer[playerName] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
Smc.registerGlobalStepForEachPlayer(0, function(deltaTime, player)
|
||||||
|
if player == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
if playerName == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local lastControl = playersLastControl[playerName]
|
||||||
|
if lastControl == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local controlTimer = playersControlTimer[playerName]
|
||||||
|
if controlTimer == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local nowControl = player:get_player_control()
|
||||||
|
if nowControl == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, key in ipairs(ControlPressKeys) do
|
||||||
|
local lastPressed = lastControl[key]
|
||||||
|
local nowPressed = nowControl[key]
|
||||||
|
|
||||||
|
-- on_press
|
||||||
|
if not lastPressed and nowPressed then
|
||||||
|
Events.call('control.on_press', key)
|
||||||
|
|
||||||
|
controlTimer[key] = 0
|
||||||
|
|
||||||
|
-- on_release
|
||||||
|
elseif lastPressed and not nowPressed then
|
||||||
|
Events.call('control.on_release', key, controlTimer[key])
|
||||||
|
|
||||||
|
controlTimer[key] = 0
|
||||||
|
|
||||||
|
-- on_hold
|
||||||
|
elseif lastPressed and nowPressed then
|
||||||
|
Events.call('control.on_hold', key, controlTimer[key], deltaTime)
|
||||||
|
|
||||||
|
controlTimer[key] = controlTimer[key] + deltaTime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--TODO: add player movement callbacks
|
||||||
|
|
||||||
|
--TODO: add mouse movement callbacks on dir
|
||||||
|
|
||||||
|
playersLastControl[playerName] = nowControl
|
||||||
|
playersControlTimer[playerName] = controlTimer
|
||||||
|
end)
|
||||||
|
|
||||||
|
return Control
|
||||||
4
mods/CORE/CraftSystem/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('CraftSystem')
|
||||||
2
mods/CORE/CraftSystem/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__craft_system
|
||||||
|
depends = smc__system__system_loader
|
||||||
117
mods/CORE/CraftSystem/src/CraftSystem.lua
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
local HASH_SPLITTER = '&'
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__craft_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@alias CraftSystem.shapelessCraftsList table<CraftSystem.Craft.Group, table<string, CraftSystem.ShapelessCraft[]>>
|
||||||
|
---@alias CraftSystem.processualCraftsList table<CraftSystem.Craft.Group, table<string, CraftSystem.ProcessualCraft[]>>
|
||||||
|
|
||||||
|
---@class CraftSystem
|
||||||
|
---@field shapelessCraftsList CraftSystem.shapelessCraftsList
|
||||||
|
---@field processualCraftsList CraftSystem.processualCraftsList
|
||||||
|
local CraftSystem = {
|
||||||
|
shapelessCraftsList = {},
|
||||||
|
processualCraftsList = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
---@alias CraftSystem.Craft.Type
|
||||||
|
---|'shapeless'
|
||||||
|
---|'processual'
|
||||||
|
---@alias CraftSystem.Craft.Group string
|
||||||
|
---@alias CraftSystem.Craft.Recipe string[]
|
||||||
|
|
||||||
|
---@alias shapelessCraftFunc fun(self:CraftSystem.ShapelessCraft, input:ItemStack[], workbenchMeta:NodeMetaRef?):boolean
|
||||||
|
---@alias processualCraftFunc fun(self:CraftSystem.ProcessualCraft, input:ItemStack[], workbenchMeta:NodeMetaRef?, processTime:number):boolean
|
||||||
|
|
||||||
|
---@class CraftSystem.BaseCraft
|
||||||
|
---@field type CraftSystem.Craft.Type
|
||||||
|
---@field group CraftSystem.Craft.Group
|
||||||
|
---@field output string
|
||||||
|
---@field recipe CraftSystem.Craft.Recipe
|
||||||
|
---@field return table? TODO: доделать тут тип
|
||||||
|
---@field craftFunc (fun(self, ...):boolean)?
|
||||||
|
|
||||||
|
---@class CraftSystem.ShapelessCraft : CraftSystem.BaseCraft
|
||||||
|
---@field craftFunc shapelessCraftFunc?
|
||||||
|
|
||||||
|
---@class CraftSystem.ProcessualCraft : CraftSystem.BaseCraft
|
||||||
|
---@field processTime number
|
||||||
|
---@field craftFunc processualCraftFunc?
|
||||||
|
|
||||||
|
---@param type CraftSystem.Craft.Type
|
||||||
|
---@return CraftSystem.shapelessCraftsList|CraftSystem.processualCraftsList
|
||||||
|
local function getCraftList(type)
|
||||||
|
local craftList
|
||||||
|
|
||||||
|
if type == 'shapeless' then
|
||||||
|
craftList = CraftSystem.shapelessCraftsList
|
||||||
|
elseif type == 'processual' then
|
||||||
|
craftList = CraftSystem.processualCraftsList
|
||||||
|
else
|
||||||
|
error(string.format('Craft type `%s` does not exist.', type))
|
||||||
|
end
|
||||||
|
|
||||||
|
return craftList
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param type CraftSystem.Craft.Type
|
||||||
|
---@param group CraftSystem.Craft.Group
|
||||||
|
---@return table<string, table>
|
||||||
|
local function getCraftGroup(type, group)
|
||||||
|
local craftList = getCraftList(type)
|
||||||
|
|
||||||
|
---@type table<string, table>?
|
||||||
|
local craftGroup = craftList[group]
|
||||||
|
|
||||||
|
assert(craftGroup ~= nil, string.format('Craft group `%s` does not exist.', type))
|
||||||
|
|
||||||
|
return craftGroup
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param type CraftSystem.Craft.Type
|
||||||
|
---@param group CraftSystem.Craft.Group
|
||||||
|
function CraftSystem.registerCraftGroup(type, group)
|
||||||
|
local craftList = getCraftList(type)
|
||||||
|
|
||||||
|
assert(craftList[group] == nil, string.format('Craft group `%s` is already registered.', type))
|
||||||
|
|
||||||
|
craftList[group] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param recipe CraftSystem.Craft.Recipe
|
||||||
|
---@return string
|
||||||
|
function CraftSystem.getCraftHash(recipe)
|
||||||
|
table.sort(recipe)
|
||||||
|
|
||||||
|
local hash = ''
|
||||||
|
|
||||||
|
for i = 0, #recipe-1 do
|
||||||
|
hash = hash..recipe[i]..HASH_SPLITTER
|
||||||
|
end
|
||||||
|
|
||||||
|
return hash..recipe[#recipe]
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param craftDef CraftSystem.ShapelessCraft|CraftSystem.ProcessualCraft
|
||||||
|
function CraftSystem.registerCraft(craftDef)
|
||||||
|
local craftGroup = getCraftGroup(craftDef.type, craftDef.group)
|
||||||
|
|
||||||
|
local hash = CraftSystem.getCraftHash(craftDef.recipe)
|
||||||
|
|
||||||
|
table.insert(craftGroup[hash], craftDef)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param type CraftSystem.Craft.Type
|
||||||
|
---@param group CraftSystem.Craft.Group
|
||||||
|
---@return CraftSystem.ShapelessCraft[] |
|
||||||
|
--- CraftSystem.processualCraftsList[] |
|
||||||
|
--- nil
|
||||||
|
function CraftSystem.getCraftResults(type, group, recipe)
|
||||||
|
local craftGroup = getCraftGroup(type, group)
|
||||||
|
|
||||||
|
local hash = CraftSystem.getCraftHash(recipe)
|
||||||
|
|
||||||
|
return craftGroup[hash]
|
||||||
|
end
|
||||||
|
|
||||||
|
return CraftSystem
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
local Enum = Mod:new()
|
|
||||||
|
|
||||||
Enum.Class = Enum.require('Enum')
|
|
||||||
|
|
||||||
Api.addModToGlobalSpace(Enum, 'Core.Enum')
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
name = smc__core__enum
|
|
||||||
depends = smc__api__api_loader
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
---Abstract class implementing enumeration. It is a table<ENUM_KEY, ENUM_KEY>. Read-only table!
|
|
||||||
---@abstract
|
|
||||||
---@class Enum
|
|
||||||
local Enum = {}
|
|
||||||
|
|
||||||
---@param enum table[]
|
|
||||||
---@return Enum
|
|
||||||
function Enum:new(enum)
|
|
||||||
local metaEnum = {}
|
|
||||||
|
|
||||||
-- Create table<ENUM_KEY, ENUM_KEY>
|
|
||||||
for _, v in ipairs(enum) do
|
|
||||||
metaEnum[v] = v
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type Enum
|
|
||||||
local instance = setmetatable({}, {
|
|
||||||
__index = metaEnum,
|
|
||||||
__newindex = function()
|
|
||||||
error('The Enum table is read only!')
|
|
||||||
end,
|
|
||||||
__metatable = false
|
|
||||||
})
|
|
||||||
|
|
||||||
return instance
|
|
||||||
end
|
|
||||||
|
|
||||||
---@alias Enum.EnumKey string Key from enumeration
|
|
||||||
|
|
||||||
return Enum
|
|
||||||
4
mods/CORE/Formspec/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__formspec')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Formspec')
|
||||||
2
mods/CORE/Formspec/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__formspec
|
||||||
|
depends = smc__system__system_loader
|
||||||
502
mods/CORE/Formspec/src/Formspec.lua
Normal file
@@ -0,0 +1,502 @@
|
|||||||
|
---@class Formspec
|
||||||
|
---@field params string
|
||||||
|
---@field elements string
|
||||||
|
local Formspec = {
|
||||||
|
elements = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
---@class FormspecDef
|
||||||
|
---Set the formspec version to a certain number. If not specified, version `10` is assumed.
|
||||||
|
---@field version? number
|
||||||
|
---Define the size of the menu in inventory slots. `fixed_size` is optional, default `true`
|
||||||
|
---@field size {x:number, y:number, fixed_size:boolean?}
|
||||||
|
---Defines the position on the game window of the formspec's anchor point.
|
||||||
|
---@field position? {x:number, y:number}
|
||||||
|
---Defines the location of the anchor point within the formspec.
|
||||||
|
---@field anchor? {x:number, y:number}
|
||||||
|
---Defines how much space is padded around the formspec if the formspec tries to increase
|
||||||
|
---past the size of the screen and coordinates have to be shrunk.
|
||||||
|
---@field padding? {x:number, y:number}
|
||||||
|
---Disables player:set_formspec_prepend() from applying to this formspec.
|
||||||
|
---@field noPrepend? boolean
|
||||||
|
---When set to true, all following formspec elements will use the new coordinate system.
|
||||||
|
---@field realCoordinates? boolean
|
||||||
|
---When set to false, the formspec will not close when the user tries to close
|
||||||
|
---it with the Escape key or similar. Default true.
|
||||||
|
---@field allowClose? boolean
|
||||||
|
|
||||||
|
---@param def FormspecDef?
|
||||||
|
---@return Formspec
|
||||||
|
function Formspec:new(def)
|
||||||
|
if def == nil then
|
||||||
|
local instance = setmetatable({}, {__index = self})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
local version = ('formspec_version[%s]'):format( def.version or 10) -- formspec version 10 (5.13.0)
|
||||||
|
|
||||||
|
local size = ('size[%s,%s,%s]'):format(def.size.x, def.size.y, def.size.fixed_size or true)
|
||||||
|
|
||||||
|
local position
|
||||||
|
if def.position ~= nil then
|
||||||
|
position = ('position[%s,%s]'):format(def.position.x or 0.5, def.position.y or 0.5)
|
||||||
|
else
|
||||||
|
position = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local anchor
|
||||||
|
if def.anchor ~= nil then
|
||||||
|
anchor = ('anchor[%s,%s]'):format(def.anchor.x, def.anchor.y)
|
||||||
|
else
|
||||||
|
anchor = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local padding
|
||||||
|
if def.padding ~= nil then
|
||||||
|
padding = ('padding[%s,%s]'):format(def.padding.x, def.padding.y)
|
||||||
|
else
|
||||||
|
padding = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local noPrepend
|
||||||
|
if def.noPrepend == true then
|
||||||
|
noPrepend = 'no_prepend[]'
|
||||||
|
else
|
||||||
|
noPrepend = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local realCoordinates
|
||||||
|
if def.realCoordinates ~= nil then
|
||||||
|
noPrepend = ('real_coordinates[%s]'):format(def.realCoordinates)
|
||||||
|
|
||||||
|
else
|
||||||
|
realCoordinates = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local allowClose = ('allow_close[%s]'):format(def.allowClose or true)
|
||||||
|
|
||||||
|
---@type Formspec
|
||||||
|
local instance = setmetatable({
|
||||||
|
params = version..size..position..anchor..padding..noPrepend..realCoordinates..allowClose,
|
||||||
|
}, {__index = self})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO: описание
|
||||||
|
---@return string
|
||||||
|
function Formspec:getParams()
|
||||||
|
return self.params
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO: описание
|
||||||
|
---@return string
|
||||||
|
function Formspec:getElements()
|
||||||
|
return self.elements
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO: описание
|
||||||
|
---@return string
|
||||||
|
function Formspec:toString()
|
||||||
|
return self:getParams()..self:getElements()
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO: описание
|
||||||
|
---@param element string
|
||||||
|
function Formspec:addElement(element)
|
||||||
|
self.elements = self.elements..element
|
||||||
|
end
|
||||||
|
|
||||||
|
---Start of a container block, moves all physical elements in the container by (X, Y).
|
||||||
|
---Containers can be nested, in which case the offsets are added (child containers are relative to parent containers).
|
||||||
|
---@param container Formspec
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
function Formspec:container(container, x, y)
|
||||||
|
local element = ('container[%s,%s]'):format(x, y)..container:getElements()..'container_end[]'
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Start of a scroll_container block. All contained elements will
|
||||||
|
---take the scroll_container coordinate as position origin,
|
||||||
|
---be additionally moved by the current value of the scrollbar with
|
||||||
|
---the name `scrollbar name` times `scroll factor` along the orientation `orientation` and
|
||||||
|
---be clipped to the rectangle defined by `X`, `Y`, `W` and `H`.
|
||||||
|
---@param container Formspec
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param scrollbarName string
|
||||||
|
---@param orientation 'vertical'|'horizontal'
|
||||||
|
---@param scrollFactor number? Defaults to 0.1.
|
||||||
|
---@param contentPadding string? TODO: разобраться, что тут
|
||||||
|
function Formspec:scrollContainer(container, x, y, w, h, scrollbarName, orientation, scrollFactor, contentPadding)
|
||||||
|
local element = ('scroll_container[%s,%s;%s,%s;%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, scrollbarName, orientation, scrollFactor or '', contentPadding or '')..
|
||||||
|
container:getElements()..'scroll_container_end[]'
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@alias Formspec.ListDef {inventoryLocation:string, listName:string, x:number, y:number, w:number, h:number,startingItemIndex:number}
|
||||||
|
|
||||||
|
---@param inventoryLocation string
|
||||||
|
---@param listName string
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number Are in inventory slots, not in coordinates.
|
||||||
|
---@param h number Are in inventory slots, not in coordinates.
|
||||||
|
---@param startingItemIndex number?
|
||||||
|
function Formspec:list(inventoryLocation, listName, x, y, w, h,startingItemIndex)
|
||||||
|
if startingItemIndex == nil then
|
||||||
|
startingItemIndex = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local element = ('list[%s;%s;%s,%s;%s,%s;%s]'):format(
|
||||||
|
inventoryLocation, listName, x, y, w, h,startingItemIndex)
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO: немного отличается от листринга луанти, так что надо дописать подробности
|
||||||
|
---@param lists [string, string][]? List of looping lists in the format `[inventory location, list name]`
|
||||||
|
function Formspec:listring(lists)
|
||||||
|
if lists == nil then
|
||||||
|
self:addElement('listring[]')
|
||||||
|
end
|
||||||
|
|
||||||
|
local element = ''
|
||||||
|
|
||||||
|
for list in lists do
|
||||||
|
element = element..('listring[%s;%s]'):format(list[1], list[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---The following descriptions are allowed:
|
||||||
|
--- * `listcolors[<slot_bg_normal>;<slot_bg_hover>]`
|
||||||
|
--- * `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>]`
|
||||||
|
--- * `listcolors[<slot_bg_normal>;<slot_bg_hover>;<slot_border>;<tooltip_bgcolor>;<tooltip_fontcolor>]`
|
||||||
|
---@param slotBackgroundNormal ColorString
|
||||||
|
---@param slotBackgroundHover ColorString
|
||||||
|
---@param slotBorder ColorString?
|
||||||
|
---@param tooltipBgcolor ColorString?
|
||||||
|
---@param tooltipFontcolor ColorString?
|
||||||
|
function Formspec:listColors(slotBackgroundNormal, slotBackgroundHover, slotBorder, tooltipBgcolor, tooltipFontcolor)
|
||||||
|
local element
|
||||||
|
|
||||||
|
if tooltipBgcolor ~= nil and tooltipFontcolor ~= nil then
|
||||||
|
element = ('listcolors[%s;%s;%s;%s;%s]'):format(
|
||||||
|
slotBackgroundNormal, slotBackgroundHover, slotBorder, tooltipBgcolor, tooltipFontcolor)
|
||||||
|
elseif slotBorder ~= nil then
|
||||||
|
element = ('listcolors[%s;%s;%s]'):format(
|
||||||
|
slotBackgroundNormal, slotBackgroundHover, slotBorder)
|
||||||
|
else
|
||||||
|
element = ('listcolors[%s;%s]'):format(
|
||||||
|
slotBackgroundNormal, slotBackgroundHover)
|
||||||
|
end
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Adds tooltip for an element.
|
||||||
|
---@param elementName string
|
||||||
|
---@param tooltipText string
|
||||||
|
---@param bgcolor ColorString?
|
||||||
|
---@param fontcolor ColorString?
|
||||||
|
function Formspec:tooltipForElement(elementName, tooltipText, bgcolor, fontcolor)
|
||||||
|
local element = ('tooltip[%s;%s;%s;%s]'):format(
|
||||||
|
elementName, tooltipText, bgcolor or '', fontcolor or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Adds tooltip for an area. Other tooltips will take priority when present.
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param tooltipText string
|
||||||
|
---@param bgcolor ColorString?
|
||||||
|
---@param fontcolor ColorString?
|
||||||
|
function Formspec:tooltipForArea(x, y, w, h, tooltipText, bgcolor, fontcolor)
|
||||||
|
local element = ('tooltip[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, tooltipText, bgcolor or '', fontcolor or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Show an image.
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param textureName string
|
||||||
|
---@param middle boolean? Makes the image render in 9-sliced mode and defines the middle rect.
|
||||||
|
function Formspec:image(x, y, w, h, textureName, middle)
|
||||||
|
local element = ('image[%s,%s;%s,%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, textureName, middle or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Show an animated image. The image is drawn like a "vertical_frames" tile animation
|
||||||
|
---(See Tile animation definition), but uses a frame count/duration for simplicity.
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param textureName string
|
||||||
|
---@param frameCount number
|
||||||
|
---@param frameDuration number
|
||||||
|
---@param frameStart number
|
||||||
|
---@param middle boolean? Makes the image render in 9-sliced mode and defines the middle rect.
|
||||||
|
function Formspec:animatedImage(x, y, w, h, textureName, frameCount, frameDuration, frameStart, middle)
|
||||||
|
if middle == nil then
|
||||||
|
middle = false
|
||||||
|
end
|
||||||
|
|
||||||
|
local element = ('animated_image[%s,%s;%s,%s;%s;%s;%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, textureName, frameCount, frameDuration, frameStart, middle)
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Show a mesh model.
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param name string Element name that can be used for styling
|
||||||
|
---@param mesh string The mesh model to use.
|
||||||
|
---@param textures string The mesh textures to use according to the mesh materials. Texture names must be separated by commas.
|
||||||
|
---@param rotation number? Initial rotation of the camera, format x,y. The axes are euler angles in degrees.
|
||||||
|
---@param continuous boolean? Whether the rotation is continuous. Default `false`.
|
||||||
|
---@param mouseControl boolean? Whether the model can be controlled with the mouse. Default `true`.
|
||||||
|
---@param frameLoopRange string? Range of the animation frames. Defaults to the full range of all available frames. Syntax: `<begin>,<end>`.
|
||||||
|
---@param animationSpeed number? Sets the animation speed. Default 0 FPS.
|
||||||
|
function Formspec:model(x, y, w, h, name, mesh, textures, rotation, continuous, mouseControl, frameLoopRange, animationSpeed)
|
||||||
|
local element = ('model[%s,%s;%s,%s;%s;%s;%s;%s;%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, name, mesh, textures, rotation or '', continuous or '', mouseControl or '', frameLoopRange or '', animationSpeed or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Show an inventory image of registered item/node.
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param itemName string
|
||||||
|
function Formspec:itemImage(x, y, w, h, itemName)
|
||||||
|
local element = ('item_image[%s,%s;%s,%s;%s]'):format(
|
||||||
|
x, y, w, h, itemName)
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Sets background color of formspec.
|
||||||
|
---
|
||||||
|
---`fullscreen`:
|
||||||
|
--- * `false`: Only the non-fullscreen background color is drawn. (default)
|
||||||
|
--- * `true`: Only the fullscreen background color is drawn.
|
||||||
|
--- * `both`: The non-fullscreen and the fullscreen background color are drawn.
|
||||||
|
--- * `neither`: No background color is drawn.
|
||||||
|
---@param bgcolor ColorString Define the color of the non-fullscreen and the fullscreen background.
|
||||||
|
---@param fullscreen 'false'|'true'|'both'|'neither'
|
||||||
|
---@param fbgcolor ColorString? Define the color of the non-fullscreen and the fullscreen background.
|
||||||
|
function Formspec:bgcolor(bgcolor, fullscreen, fbgcolor)
|
||||||
|
local element = ('bgcolor[%s;%s;%s]'):format(
|
||||||
|
bgcolor, fullscreen or '', fbgcolor or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Example for formspec 8x4 in 16x resolution: image shall be sized 8 times 16px times 4 times 16px.
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param textureName string
|
||||||
|
---@param autoClip boolean? If is `true`, the background is clipped
|
||||||
|
---to the formspec size (x and y are used as offset values, w and h are ignored)
|
||||||
|
function Formspec:background(x, y, w, h, textureName, autoClip)
|
||||||
|
local element
|
||||||
|
|
||||||
|
if autoClip ~= nil then
|
||||||
|
element = ('background[%s,%s;%s,%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, textureName, autoClip)
|
||||||
|
else
|
||||||
|
element = ('background[%s,%s;%s,%s;%s]'):format(
|
||||||
|
x, y, w, h, textureName)
|
||||||
|
end
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:background9()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:pwdfield()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:field()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:fieldCloseOnEnter()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:textArea()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:label()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:hypertext()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:vertlabel()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:button()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:buttonUrl()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:imageButton()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param itemName string
|
||||||
|
---@param name string
|
||||||
|
---@param label string?
|
||||||
|
function Formspec:itemImageButton(x, y, w, h, itemName, name, label)
|
||||||
|
local element = ('item_image_button[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, itemName, name, label or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:buttonExit()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:buttonUrlExit()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:imageButtonExit()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:textlist()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:tabheader()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:box()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:dropdown()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:checkbox()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---Show a scrollbar using options defined by the previous `scrollbaroptions[]`
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param orientation 'vertical'|'horizontal'
|
||||||
|
---@param name string
|
||||||
|
---@param value number?
|
||||||
|
function Formspec:scrollbar(x, y, w, h, orientation, name, value)
|
||||||
|
local element = ('scrollbar[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||||
|
x, y, w, h, orientation, name, value or '')
|
||||||
|
|
||||||
|
self:addElement(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:scrollbarOptions()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:table()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:tableOptions()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:tablecolumns()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:style()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:style_type()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
---TODO
|
||||||
|
function Formspec:set_focus()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return Formspec
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
local Item = Mod:new()
|
local modInfo = Mod.getInfo('smc__core__item')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
Item.Class = Item.require('Item')
|
return require('Item')
|
||||||
|
|
||||||
Api.addModToGlobalSpace(Item, 'Core.Item')
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__item
|
name = smc__core__item
|
||||||
depends = smc__api__api_loader, smc__core__enum, smc__core__item_factory
|
depends = smc__system__system_loader, smc__core__item_factory
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
local modInfo = Mod.getInfo()
|
local modInfo = Mod.getInfo('smc__core__item')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
local VisualEnum = require('Item.VisualEnum')
|
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||||
|
|
||||||
---@class Item
|
---@class Item
|
||||||
---@field itemDef Item.ItemDefinition
|
---@field itemDef Item.ItemDefinition
|
||||||
---@field luantiDef table
|
---@field luantiDef table
|
||||||
---@field getVisual fun(): string
|
---@field getVisual fun(): string
|
||||||
---@field defaultDef Item.ItemDefinition
|
---@field defaultDef Item.ItemDefinition
|
||||||
local Item = {
|
local Item = {
|
||||||
defaultDef = {
|
defaultDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = "",
|
name = '',
|
||||||
title = "",
|
title = '',
|
||||||
description = "",
|
description = '',
|
||||||
|
titleColor = '#FFFFFF',
|
||||||
|
descriptionColor = '#C0C0C0',
|
||||||
|
addModName = true,
|
||||||
},
|
},
|
||||||
callbacks = {}
|
callbacks = {}
|
||||||
}
|
}
|
||||||
@@ -25,13 +28,38 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition
|
||||||
---@return NodeDefinition|ItemDefinition
|
---@return NodeDefinition|ItemDefinition
|
||||||
local function itemDefToLuantiDef(itemDef)
|
local function itemDefToLuantiDef(itemDef)
|
||||||
|
local modName = Mod.getInfo().shortName
|
||||||
|
local S = core.get_translator(modName)
|
||||||
|
|
||||||
itemDef = table.copy(itemDef)
|
itemDef = table.copy(itemDef)
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
local c = itemDef.callbacks
|
local c = itemDef.callbacks
|
||||||
local description = s.title .. "\n" .. s.description
|
|
||||||
|
if s.addModName then
|
||||||
|
s.name = modName .. ':' .. s.name
|
||||||
|
end
|
||||||
|
|
||||||
|
local title = s.title
|
||||||
|
local description = s.description
|
||||||
|
|
||||||
|
if title == nil or title == '' then
|
||||||
|
title = string.match(s.name, '%S:(%S+)')..'-title'
|
||||||
|
end
|
||||||
|
|
||||||
|
if description == nil or description == '' then
|
||||||
|
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||||
|
end
|
||||||
|
|
||||||
|
if s.titleColor ~= nil and s.descriptionColor ~= nil then
|
||||||
|
description = core.colorize(s.titleColor ,S(title))..'\n'..
|
||||||
|
core.colorize(s.descriptionColor, S(description))
|
||||||
|
else
|
||||||
|
error('Item description color parameters cannot be empty.')
|
||||||
|
end
|
||||||
|
|
||||||
s.title, s.description = nil, description
|
s.title, s.description = nil, description
|
||||||
|
|
||||||
local luantiDef = defMerge(s, c)
|
local luantiDef = defMerge(s, c)
|
||||||
@@ -61,8 +89,8 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition|Node.NodeDefinition
|
||||||
---@return Item
|
---@return Item
|
||||||
function Item:new(itemDef)
|
function Item:new(itemDef)
|
||||||
---Adding default parameters
|
---Adding default parameters
|
||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||||
@@ -74,15 +102,15 @@ function Item:new(itemDef)
|
|||||||
local visual = itemDef.settings.visual
|
local visual = itemDef.settings.visual
|
||||||
|
|
||||||
if visual == nil then
|
if visual == nil then
|
||||||
visual = VisualEnum.ITEM_2D
|
visual = 'item_2d'
|
||||||
end
|
end
|
||||||
|
|
||||||
itemDef.settings.visual = nil
|
itemDef.settings.visual = nil
|
||||||
|
|
||||||
if visual == VisualEnum.ITEM_3D then
|
if visual == 'item_3d' then
|
||||||
register3dItem(luantiDef)
|
register3dItem(luantiDef)
|
||||||
else
|
else
|
||||||
visual = VisualEnum.ITEM_2D
|
visual = 'item_2d'
|
||||||
registerFlatItem(luantiDef)
|
registerFlatItem(luantiDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -103,7 +131,7 @@ end
|
|||||||
---@return Item
|
---@return Item
|
||||||
function Item:getExtended(defaultDef)
|
function Item:getExtended(defaultDef)
|
||||||
---@type Item
|
---@type Item
|
||||||
local ChildClass = Mod:getClassExtended(self, {
|
local ChildClass = Class.extend(self, {
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -119,7 +147,7 @@ function Item:getFactory(defaultDef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@type ItemFactory
|
---@type ItemFactory
|
||||||
local instance = Core.ItemFactory():new(self, defaultDef)
|
local instance = ItemFactory:new(self, defaultDef)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
---@class Item.Callbacks
|
---@class Item.Callbacks
|
||||||
local Callbacks = {}
|
local Callbacks = {}
|
||||||
|
|
||||||
-- TODO: Разобраться с дубликатами аннотаций полей. Приоритетно брать аннотации из util/ide-helper
|
|
||||||
|
|
||||||
---Called when the 'place' key was pressed with the item in hand
|
---Called when the 'place' key was pressed with the item in hand
|
||||||
---and pointing at a node.
|
---and pointing at a node.
|
||||||
---Shall place item and return the leftover itemstack
|
---Shall place item and return the leftover itemstack
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ local Settings = {}
|
|||||||
|
|
||||||
---Technical name of the item. Must be unique and have the format `mod_name:item_name`
|
---Technical name of the item. Must be unique and have the format `mod_name:item_name`
|
||||||
---@type string
|
---@type string
|
||||||
Settings.name = ""
|
Settings.name = ''
|
||||||
|
|
||||||
|
---Whether to add the mod name to the settings.name. Default: `true`
|
||||||
|
---@type boolean?
|
||||||
|
Settings.addModName = nil
|
||||||
|
|
||||||
---Item description. 1st line of item description.
|
---Item description. 1st line of item description.
|
||||||
---@type string?
|
---@type string?
|
||||||
@@ -13,10 +17,25 @@ Settings.title = nil
|
|||||||
---@type string?
|
---@type string?
|
||||||
Settings.description = nil
|
Settings.description = nil
|
||||||
|
|
||||||
|
---Item title color in description.
|
||||||
|
---
|
||||||
|
---Default: `#FFFFFF`
|
||||||
|
---@type ColorString?
|
||||||
|
Settings.titleColor = nil
|
||||||
|
|
||||||
|
---Item description color in description.
|
||||||
|
---
|
||||||
|
---Default: `#C0C0C0`
|
||||||
|
---@type ColorString?
|
||||||
|
Settings.descriptionColor = nil
|
||||||
|
|
||||||
|
---@alias Item.Visual
|
||||||
|
---'item_2d'|
|
||||||
|
---'item_3d'
|
||||||
|
|
||||||
---Visual node type.
|
---Visual node type.
|
||||||
---Values are specified via an enumeration `Item.VisualEnum`.
|
---@type Item.Visual?
|
||||||
---@type Enum.EnumKey?
|
Settings.visual = nil
|
||||||
Settings.visual = ""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
---@class Item.VisualEnum : Enum
|
|
||||||
---@field ITEM_2D Enum.EnumKey
|
|
||||||
---@field ITEM_3D Enum.EnumKey
|
|
||||||
local VisualEnum = Core.Enum:getModClassInstance({
|
|
||||||
'ITEM_2D',
|
|
||||||
'ITEM_3D',
|
|
||||||
})
|
|
||||||
|
|
||||||
return VisualEnum
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
local ItemFactory = Mod:new()
|
local modInfo = Mod.getInfo('smc__core__item_factory')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
ItemFactory.Class = ItemFactory.require('ItemFactory')
|
return require('ItemFactory')
|
||||||
|
|
||||||
Api.addModToGlobalSpace(ItemFactory, 'Core.ItemFactory')
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__item_factory
|
name = smc__core__item_factory
|
||||||
depends = smc__api__api_loader
|
depends = smc__system__system_loader
|
||||||
|
|||||||
@@ -22,23 +22,12 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDefs Item.ItemDefinition[]|Node.NodeDefinition[] List of nodes with parameters unique to them.
|
---@param itemDefs Item.ItemDefinition[]|Node.NodeDefinition[] List of nodes with parameters unique to them.
|
||||||
---@param addModName boolean? Whether to add the mod name to the settings.name. Default: `true`
|
function ItemFactory:registerItems(itemDefs)
|
||||||
function ItemFactory:registerItems(itemDefs, addModName)
|
|
||||||
if addModName == nil then
|
|
||||||
addModName = true
|
|
||||||
end
|
|
||||||
|
|
||||||
local modName = Mod.getInfo().shortName
|
|
||||||
|
|
||||||
---@param nodeDef Item.ItemDefinition | Node.NodeDefinition
|
---@param nodeDef Item.ItemDefinition | Node.NodeDefinition
|
||||||
for _, itemDef in ipairs(itemDefs) do
|
for _, itemDef in ipairs(itemDefs) do
|
||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||||
|
|
||||||
if addModName then
|
|
||||||
itemDef.settings.name = modName .. ':' .. itemDef.settings.name
|
|
||||||
end
|
|
||||||
|
|
||||||
self.itemClass:new(itemDef)
|
self.itemClass:new(itemDef)
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -50,34 +39,20 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param shortNodeDefs table Table of the form `{ {name, title, description, tiles}, {name, title, description, tiles}, ...}`
|
---@param shortNodeDefs [string, (string[]|TileDefinition[])?][] Format list {{name, tiles}, {name, tiles}, ...}
|
||||||
---@param addModName boolean? Whether to add the mod name to the settings.name. Default: `true`
|
function ItemFactory:registerNodesByShortDef(shortNodeDefs)
|
||||||
function ItemFactory:registerNodesByShortDef(shortNodeDefs, addModName)
|
|
||||||
if addModName == nil then
|
|
||||||
addModName = true
|
|
||||||
end
|
|
||||||
|
|
||||||
local modName = Mod.getInfo().shortName
|
|
||||||
|
|
||||||
for _, shortNodeDef in ipairs(shortNodeDefs) do
|
for _, shortNodeDef in ipairs(shortNodeDefs) do
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
local nodeDef = {
|
local nodeDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = shortNodeDef[1],
|
name = shortNodeDef[1],
|
||||||
title = shortNodeDef[2],
|
tiles = shortNodeDef[2]
|
||||||
description = shortNodeDef[3],
|
|
||||||
tiles = shortNodeDef[4]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
||||||
|
|
||||||
if addModName then
|
|
||||||
nodeDef.settings.name = modName .. ':' .. nodeDef.settings.name
|
|
||||||
end
|
|
||||||
|
|
||||||
self.itemClass:new(nodeDef)
|
self.itemClass:new(nodeDef)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
local MapGen = Mod:new()
|
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
MapGen.Class = MapGen.require('MapGen')
|
return require('MapGen')
|
||||||
|
|
||||||
Api.addModToGlobalSpace(MapGen, 'Core.MapGen')
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__map_gen
|
name = smc__core__map_gen
|
||||||
depends = smc__api__api_loader, smc__game__items__rocks, smc__game__items__liquids
|
depends = smc__system__system_loader
|
||||||
@@ -1,21 +1,23 @@
|
|||||||
local mathAbs, mathRound, mathMin, mathMax
|
local mathAbs, mathRound, mathMin, mathMax, id
|
||||||
= math.abs, math.round, math.min, math.max
|
= math.abs, math.round, math.min, math.max, core.get_content_id
|
||||||
|
|
||||||
local pastNoise2DCalc = {
|
---@class MapGen.PastCalcNoiseValue
|
||||||
|
local pastCalcNoiseValue = {
|
||||||
---@type MapGen.Triangle?
|
---@type MapGen.Triangle?
|
||||||
triangle = nil,
|
triangle = nil,
|
||||||
---@type number?
|
---@type number?
|
||||||
x = nil,
|
x = nil,
|
||||||
---@type number?
|
---@type number?
|
||||||
y = nil,
|
z = nil,
|
||||||
noiseValues = {
|
---@type number?
|
||||||
---@type number?
|
noiseValue = nil,
|
||||||
height = nil,
|
}
|
||||||
---@type number?
|
|
||||||
humidity = nil,
|
---@type table<MapGen.Layer.Category, MapGen.PastCalcNoiseValue>
|
||||||
---@type number?
|
local pastNoise2DCalc = {
|
||||||
temp = nil,
|
landscape = pastCalcNoiseValue,
|
||||||
}
|
temp = pastCalcNoiseValue,
|
||||||
|
humidity = pastCalcNoiseValue
|
||||||
}
|
}
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||||
@@ -24,6 +26,9 @@ local require = modInfo.require
|
|||||||
---@type MapGen.Layer
|
---@type MapGen.Layer
|
||||||
local Layer = require('MapGen.Layer')
|
local Layer = require('MapGen.Layer')
|
||||||
|
|
||||||
|
---@type MapGen.StaticLayer
|
||||||
|
local StaticLayer = require('MapGen.StaticLayer')
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local Peak = require('MapGen.Peak')
|
local Peak = require('MapGen.Peak')
|
||||||
|
|
||||||
@@ -36,30 +41,46 @@ local Triangulation = require('MapGen.Triangulation')
|
|||||||
---@type MapGen.Cavern
|
---@type MapGen.Cavern
|
||||||
local Cavern = require('MapGen.Cavern')
|
local Cavern = require('MapGen.Cavern')
|
||||||
|
|
||||||
|
local ff2luat = require('MapGen.ff2luat')
|
||||||
|
|
||||||
---@class MapGen
|
---@class MapGen
|
||||||
---@field layersByName table<string, MapGen.Layer>
|
---@field layersByName table<string, MapGen.Layer>
|
||||||
---@field layersList MapGen.Layer[]
|
---@field layersList MapGen.Layer[]
|
||||||
---@field peaksMultinoiseInitialized boolean Is the fractal noise of the peaks initialized? This is necessary for a one-time noise initialization.
|
---@field staticsByName table<string, MapGen.StaticLayer>
|
||||||
---@field cavernsNoiseInitialized boolean TODO: описание
|
---@field staticsList MapGen.StaticLayer[]
|
||||||
|
---@field layersNoisesInitialized boolean Is the fractal noise of the layer initialized? This is necessary for a one-time noise initialization.
|
||||||
|
---@field cavernsNoiseInitialized boolean Is the fractal noise of the caverns initialized? This is necessary for a one-time noise initialization.
|
||||||
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
||||||
---@field nodeIDs table<string, number>
|
---@field nodeIDs table<string, number>
|
||||||
---@field waterLevel number
|
|
||||||
local MapGen = {
|
local MapGen = {
|
||||||
layersByName = {},
|
layersByName = {},
|
||||||
layersList = {},
|
layersList = {},
|
||||||
peaksMultinoiseInitialized = false,
|
staticsByName = {},
|
||||||
|
staticsList = {},
|
||||||
|
layersNoisesInitialized = false,
|
||||||
cavernsNoiseInitialized = false,
|
cavernsNoiseInitialized = false,
|
||||||
isRunning = false,
|
isRunning = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param nodeIDs table<string, number>
|
---Definition table for the `MapGen`.
|
||||||
---@param waterLevel number
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class MapGenDef
|
||||||
|
---@field nodes table<string, string>
|
||||||
|
|
||||||
|
---@param def MapGenDef
|
||||||
---@return MapGen
|
---@return MapGen
|
||||||
function MapGen:new(nodeIDs, waterLevel)
|
function MapGen:new(def)
|
||||||
|
local nodesIDs = {}
|
||||||
|
-- Converting node names to IDs
|
||||||
|
for k, v in pairs(def.nodes) do
|
||||||
|
nodesIDs[k] = id(v)
|
||||||
|
end
|
||||||
|
|
||||||
---@type MapGen
|
---@type MapGen
|
||||||
local instance = setmetatable({
|
local instance = setmetatable({
|
||||||
nodeIDs = nodeIDs,
|
nodes = def.nodes,
|
||||||
waterLevel = waterLevel or 0,
|
nodeIDs = nodesIDs,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
@@ -84,6 +105,25 @@ function MapGen:getLayerByHeight(yPos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Determines which statics layer a node belongs to based on its height coordinate.
|
||||||
|
---@param yPos number
|
||||||
|
---@return MapGen.StaticLayer?
|
||||||
|
function MapGen:getStaticByHeight(yPos)
|
||||||
|
--- TODO: возможно здесь получится сделать более оптимизированный алгоритм
|
||||||
|
--- учитывая тот факт, что эта функция вызывается для каждой ноды в on_generated
|
||||||
|
--- и может быть даже не один раз
|
||||||
|
--- Можно подумать над тем, чтобы использовать сортированный список
|
||||||
|
|
||||||
|
---@param static MapGen.StaticLayer
|
||||||
|
for _, static in ipairs(self.staticsList) do
|
||||||
|
|
||||||
|
if yPos >= static.minY and yPos <= static.maxY then
|
||||||
|
return static
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- --- REGISTRATION METHODS ---
|
-- --- REGISTRATION METHODS ---
|
||||||
@@ -91,85 +131,144 @@ end
|
|||||||
---Mark the world area between two heights as a `MapGen.Layer`.
|
---Mark the world area between two heights as a `MapGen.Layer`.
|
||||||
---
|
---
|
||||||
---Note: layers must not overlap.
|
---Note: layers must not overlap.
|
||||||
---@param name string The name that will be assigned to the layer. The name must be unique for each layer.
|
---@param name string The name that will be assigned to the layer. The name must be unique for each layer.
|
||||||
---@param minY number Minimum layer generation height.
|
---@param def MapGen.LayerDef Layer description table, see details `MapGen.LayerDef`.
|
||||||
---@param maxY number Maximum layer generation height.
|
function MapGen:registerLayer(name, def)
|
||||||
function MapGen:RegisterLayer(name, minY, maxY)
|
|
||||||
-- Layers with the same name cannot exist.
|
-- Layers with the same name cannot exist.
|
||||||
assert(self.layersByName[name] == nil, ('A layer named `%s` is already registered.'):format(name))
|
assert(self.layersByName[name] == nil, ('A layer named `%s` is already registered.'):format(name))
|
||||||
|
|
||||||
-- Layers cannot overlap.
|
-- Layers cannot overlap.
|
||||||
assert(self:getLayerByHeight(minY) == nil and self:getLayerByHeight(maxY) == nil, 'Registered layers must not overlap!')
|
assert(self:getLayerByHeight(def.minY) == nil and self:getLayerByHeight(def.maxY) == nil, 'Registered layers must not overlap!')
|
||||||
|
|
||||||
---@type MapGen.Layer
|
---@type MapGen.Layer
|
||||||
local layer = Layer:new(name, minY, maxY)
|
local layer = Layer:new(name, def)
|
||||||
|
|
||||||
self.layersByName[name] = layer
|
self.layersByName[name] = layer
|
||||||
table.insert(self.layersList, layer)
|
table.insert(self.layersList, layer)
|
||||||
|
|
||||||
-- Sort layers by maxY descending for processing priority
|
-- Sort layers by maxY descending for processing priority.
|
||||||
table.sort(self.layersList, function(a, b)
|
table.sort(self.layersList, function(a, b)
|
||||||
return a.maxY > b.maxY
|
return a.maxY > b.maxY
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Mark a world point as `MapGen.Peak` and assign it a specific noise that will affect the generation.
|
---Register the color and the noise parameters that correspond to it.
|
||||||
---
|
---@param layerName string The name of the layer for which the color will be registered.
|
||||||
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
---@param category MapGen.Layer.Category Category indicating what will be generated by noise.
|
||||||
---@param layerName string The name of the layer in which the new peak will be included.
|
---@param color ColorString Noise color. Must be unique.
|
||||||
---@param peakPos vector The coordinate where the peak will be placed.
|
---@param noiseParams NoiseParams Fractal noise parameters.
|
||||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation
|
function MapGen:registerLayerNoiseColor(layerName, category, color, noiseParams)
|
||||||
---@param groups table<string, number>? Peak groups that may affect processing.
|
|
||||||
function MapGen:registerPeak(layerName, peakPos, multinoise, groups)
|
|
||||||
---@type MapGen.Layer
|
---@type MapGen.Layer
|
||||||
local layer = self.layersByName[layerName]
|
local layer = self.layersByName[layerName]
|
||||||
|
|
||||||
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
||||||
|
|
||||||
if not layer then
|
layer:addNoiseParamsColor(category, color, noiseParams)
|
||||||
error('Invalid layer: ' .. layerName)
|
end
|
||||||
end
|
|
||||||
|
---Mark the world area between two heights as a `MapGen.StaticLayer`.
|
||||||
|
---
|
||||||
|
---Note: layers must not overlap.
|
||||||
|
---@param name string The name that will be assigned to the static layer. The name must be unique for each layer.
|
||||||
|
---@param def MapGen.StaticLayerDef Static layer description table, see details `MapGen.StaticLayerDef`.
|
||||||
|
function MapGen:registerStaticLayer(name, def)
|
||||||
|
-- Static layer with the same name cannot exist.
|
||||||
|
assert(self.staticsByName[name] == nil, ('A static layer named `%s` is already registered.'):format(name))
|
||||||
|
|
||||||
|
-- Static layers cannot overlap.
|
||||||
|
assert(self:getStaticByHeight(def.minY) == nil and self:getLayerByHeight(def.maxY) == nil, 'Registered static layers must not overlap!')
|
||||||
|
|
||||||
|
---@type MapGen.StaticLayer
|
||||||
|
local static = StaticLayer:new(name, def)
|
||||||
|
|
||||||
|
self.staticsByName[name] = static
|
||||||
|
table.insert(self.staticsList, static)
|
||||||
|
|
||||||
|
-- Sort srtatics by maxY descending for processing priority.
|
||||||
|
table.sort(self.staticsList, function(a, b)
|
||||||
|
return a.maxY > b.maxY
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
|
||||||
|
---
|
||||||
|
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
||||||
|
---@param layerName string The name of the layer in which the new peak will be included.
|
||||||
|
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
|
||||||
|
---@param def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
|
||||||
|
function MapGen:registerPeak(layerName, category, def)
|
||||||
|
---@type MapGen.Layer
|
||||||
|
local layer = self.layersByName[layerName]
|
||||||
|
|
||||||
|
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
||||||
|
|
||||||
--TODO: добавить проверку, что координата пиков не совпадают
|
--TODO: добавить проверку, что координата пиков не совпадают
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local peak = Peak:new(peakPos, multinoise, groups)
|
local peak = Peak:new(def)
|
||||||
|
|
||||||
layer:addPeak(peak)
|
layer:addPeak(category, peak)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Mark a world point as `MapGen.Peak` and assign it a specific noise that will affect the generation.
|
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
|
||||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
||||||
---
|
---
|
||||||
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
||||||
---@param layerName string The name of the layer in which the new peak will be included.
|
---@param layerName string The name of the layer in which the new peak will be included.
|
||||||
---@param peakPos vector The coordinate where the peak will be placed.
|
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
|
||||||
---@param multinoise MapGen.Peak.MultinoiseParams Noise that will be assigned to the peak and that will influence map generation.
|
---@param def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
|
||||||
---@param groups table<string, number>? Peak groups that may affect processing.
|
function MapGen:register2DPeak(layerName, category, def)
|
||||||
function MapGen:register2DPeak(layerName, peakPos, multinoise, groups)
|
def = table.copy_with_metatables(def)
|
||||||
local _peakPos = table.copy_with_metatables(peakPos)
|
|
||||||
_peakPos.y = 0
|
|
||||||
|
|
||||||
if groups == nil then
|
def.pos.y = 0
|
||||||
groups = {is2d = 1}
|
|
||||||
|
if def.groups == nil then
|
||||||
|
def.groups = {is2d = 1}
|
||||||
else
|
else
|
||||||
groups.is2d = 1
|
def.groups.is2d = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self:registerPeak(layerName, _peakPos, multinoise, groups)
|
self:registerPeak(layerName, category, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Mark the world points as `MapGen.Peak` and assign them all a specific noise that will affect generation.
|
---Mark the world points as `MapGen.Peak` and assign them all a specific noise that will affect generation.
|
||||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
||||||
---
|
---
|
||||||
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
---Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
|
||||||
---@param layerName string The name of the layer in which the new peaks will be included.
|
---@param layerName string The name of the layer in which the new peaks will be included.
|
||||||
---@param multinoise MapGen.Peak.MultinoiseParams The noise that will be assigned to each peak and will affect the map generation.
|
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
|
||||||
---@param peakPoses vector[] Set the coordinates where the peaks will be placed.
|
---@param defs MapGen.PeakDef[] Peaks description table, see details `MapGen.PeakDef`.
|
||||||
---@param groups table<string, number>? Peak groups that may affect processing.
|
function MapGen:register2DPeaks(layerName,category, defs)
|
||||||
function MapGen:register2DPeaks(layerName, multinoise, peakPoses, groups)
|
for _, def in ipairs(defs) do
|
||||||
for _, peakPos in ipairs(peakPoses) do
|
self:register2DPeak(layerName, category, def)
|
||||||
self:register2DPeak(layerName, peakPos, multinoise, groups)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Extract the `MapGen.Peak` from the image and assign them all a specific color that will affect the generation.
|
||||||
|
---@param layerName string The name of the layer in which the new peaks will be included.
|
||||||
|
---@param map string The name of the image from which the peaks will be extracted. It should be located in the `<mod_name>/textures/maps` folder and have the following format `<image_name>.ff`
|
||||||
|
---@param scale number Multiplier of how many blocks (nodes) will be between image pixels. It is not recommended to set the value below 50 for performance reasons.
|
||||||
|
---@param zeroPos Position2d The position in pixels where the zero world coordinate will be in the image.
|
||||||
|
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
|
||||||
|
---@param groups? table<string, number> Groups that will be added to all peaks.
|
||||||
|
function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, groups)
|
||||||
|
local modPath = core.get_modpath(core.get_current_modname())
|
||||||
|
local peaks = ff2luat(modPath .. '/textures/maps/' .. map)
|
||||||
|
|
||||||
|
local mapSize = peaks.size
|
||||||
|
peaks.size = nil
|
||||||
|
|
||||||
|
for color, peaksPos in pairs(peaks) do
|
||||||
|
for _, peakPos in ipairs(peaksPos) do
|
||||||
|
---@type MapGen.PeakDef
|
||||||
|
local def = {
|
||||||
|
pos = vector.new((peakPos.x - zeroPos.x) * scale, 0, (peakPos.y - zeroPos.y) * scale),
|
||||||
|
color = color,
|
||||||
|
groups = groups,
|
||||||
|
}
|
||||||
|
|
||||||
|
self:register2DPeak(layerName, category, def)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -209,8 +308,19 @@ end
|
|||||||
function MapGen:initLayersTriangultaion()
|
function MapGen:initLayersTriangultaion()
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
for _, layer in ipairs(self.layersList) do
|
for _, layer in ipairs(self.layersList) do
|
||||||
layer.trianglesList = Triangulation.triangulate(layer.peaksList)
|
for category, peaks in pairs(layer.peaksList) do
|
||||||
-- layer.tetrahedronsList = Triangulation.tetrahedralize(layer.peaksList)
|
|
||||||
|
layer.trianglesList[category] = Triangulation.triangulate(peaks)
|
||||||
|
-- layer.tetrahedronsList = Triangulation.tetrahedralize(layer.peaksList) -- 3D not supported
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Initialize all layer noises. This should be called after the map object is loaded.
|
||||||
|
function MapGen:initLayersNoises()
|
||||||
|
---@param layer MapGen.Layer
|
||||||
|
for _, layer in ipairs(self.layersList) do
|
||||||
|
layer:initNoises()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -222,22 +332,6 @@ function MapGen:initBiomesDiagram()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---Initialize peak's noises. This should be called after the map object is loaded.
|
|
||||||
function MapGen:initPeaksMultinoise()
|
|
||||||
---@param layer MapGen.Layer
|
|
||||||
for _, layer in ipairs(self.layersList) do
|
|
||||||
|
|
||||||
---@param peak MapGen.Peak
|
|
||||||
for _, peak in ipairs(layer.peaksList) do
|
|
||||||
peak:initMultinoise()
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
self.peaksMultinoiseInitialized = true
|
|
||||||
end
|
|
||||||
|
|
||||||
---Initialize caverns's noises. This should be called after the map object is loaded.
|
---Initialize caverns's noises. This should be called after the map object is loaded.
|
||||||
function MapGen:initCavernsNoise()
|
function MapGen:initCavernsNoise()
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
@@ -287,30 +381,79 @@ end
|
|||||||
---@param z number
|
---@param z number
|
||||||
local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z)
|
local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z)
|
||||||
local ids = mapGenerator.nodeIDs
|
local ids = mapGenerator.nodeIDs
|
||||||
local waterLevel = mapGenerator.waterLevel
|
local waterLevel = layer.waterLevel
|
||||||
|
|
||||||
local m = math.random(-5, 5)
|
-- Creating a rougher biome boundary.
|
||||||
|
local scatteringGorizontal = layer.biomesGorizontalScattering or 0
|
||||||
|
local scatteringVertical = layer.biomesVerticalScattering or 0
|
||||||
|
local scattTemp = temp
|
||||||
|
local scattHumidity = humidity
|
||||||
|
local scattHeight = y
|
||||||
|
|
||||||
temp = mathMin(100, mathMax(0, temp + m))
|
if scatteringGorizontal ~= 0 then
|
||||||
humidity = mathMin(100, mathMax(0, humidity + m))
|
---@diagnostic disable-next-line: param-type-not-match
|
||||||
--_height = mathMin(layer.maxY, mathMax(layer.minY, y + m))
|
scattTemp = scattTemp + math.random(scatteringGorizontal * -1, scatteringGorizontal)
|
||||||
|
---@diagnostic disable-next-line: param-type-not-match
|
||||||
|
scattHumidity = scattHumidity + math.random(scatteringGorizontal * -1, scatteringGorizontal)
|
||||||
|
end
|
||||||
|
|
||||||
|
if scatteringVertical ~= 0 then
|
||||||
|
---@diagnostic disable-next-line: param-type-not-match
|
||||||
|
scattHeight = scattHeight + math.random(scatteringVertical * -1, scatteringVertical)
|
||||||
|
end
|
||||||
|
|
||||||
|
scattTemp = math.clamp(scattTemp, layer.minTemp, layer.maxTemp)
|
||||||
|
scattHumidity = math.clamp(scattHumidity, layer.minHumidity, layer.maxHumidity)
|
||||||
|
scattHeight = math.clamp(scattHeight, layer.minY, layer.maxY)
|
||||||
|
|
||||||
|
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
|
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
|
|
||||||
---@type MapGen.Biome
|
---@type MapGen.Biome
|
||||||
local biome = layer.biomesDiagram[y][mathRound(temp)][mathRound(humidity)]
|
local biome = layer.biomesDiagram[scattHeight][scattTemp][scattHumidity]
|
||||||
|
|
||||||
|
-- If the block is above surface height and above water level...
|
||||||
if y > height and y > waterLevel then
|
if y > height and y > waterLevel then
|
||||||
data[index] = ids.air
|
-- ... then airspace is generated.
|
||||||
|
biome:generateAir(mapGenerator, data, index, x, y, z)
|
||||||
|
|
||||||
|
-- If the block is above the surface height BUT below the water level...
|
||||||
elseif y > height and y <= waterLevel then
|
elseif y > height and y <= waterLevel then
|
||||||
data[index] = ids.water
|
-- ... then underwater space is generated.
|
||||||
|
biome:generateWater(mapGenerator, data, index, x, y, z)
|
||||||
|
|
||||||
|
-- If the block is below the surface height...
|
||||||
elseif y <= height then
|
elseif y <= height then
|
||||||
|
-- ... and a cavern is generated in the block...
|
||||||
if isCavern(layer, x, y, z) then
|
if isCavern(layer, x, y, z) then
|
||||||
data[index] = ids.air
|
-- ... then airspace is generated.
|
||||||
elseif y == height and y >= waterLevel then
|
biome:generateCavernAir(mapGenerator, data, index, x, y, z)
|
||||||
biome.generateSoil(mapGenerator, biome, data, index, x, y, z)
|
|
||||||
elseif y == height and y < waterLevel then
|
-- ... or if the surface height is above the water level...
|
||||||
biome.generateBottom(mapGenerator, biome, data, index, x, y, z)
|
elseif height > waterLevel then
|
||||||
else
|
--- ... and the height of the block is equal to the height of the surface...
|
||||||
biome.generateRock(mapGenerator, biome, data, index, x, y, z)
|
if y == height then
|
||||||
|
-- ... then turf is generated.
|
||||||
|
biome:generateTurf(mapGenerator, data, index, x, y, z)
|
||||||
|
-- ... or if the height of the block falls within the thickness of the soil layer...
|
||||||
|
elseif y > height - biome.soilHeight then
|
||||||
|
-- ... then soil is generated.
|
||||||
|
biome:generateSoil(mapGenerator, data, index, x, y, z)
|
||||||
|
else
|
||||||
|
-- ... else e a stone is generated.
|
||||||
|
biome:generateRock(mapGenerator, data, index, x, y, z)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ... or if the surface height is below the water level...
|
||||||
|
elseif height <= waterLevel then
|
||||||
|
-- ... and if the height of the block falls within the thickness of the soil layer...
|
||||||
|
if y > height - biome.soilHeight then
|
||||||
|
-- ... then the river/ocean bottom is generated.
|
||||||
|
biome:generateBottom(mapGenerator, data, index, x, y, z)
|
||||||
|
else
|
||||||
|
-- ... else a stone is generated.
|
||||||
|
biome:generateRock(mapGenerator, data, index, x, y, z)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
data[index] = ids.air
|
data[index] = ids.air
|
||||||
@@ -374,20 +517,24 @@ local function pointInTriangle(px, pz, triangle)
|
|||||||
return (u >= 0) and (v >= 0) and (u + v <= 1)
|
return (u >= 0) and (v >= 0) and (u + v <= 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns the weighted values of 2d noises.
|
---Returns the weighted values of 2d noise.
|
||||||
|
---@param category MapGen.Layer.Category
|
||||||
|
---@param layer MapGen.Layer
|
||||||
---@param triangle MapGen.Triangle
|
---@param triangle MapGen.Triangle
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param z number
|
---@param z number
|
||||||
---@return number, number, number
|
---@return number
|
||||||
local function calcNoises2dValues(triangle, x, y, z)
|
local function calcNoise2dValue(category, layer, triangle, x, y, z)
|
||||||
local peak1 = triangle.p1
|
local peak1 = triangle.p1
|
||||||
local peak2 = triangle.p2
|
local peak2 = triangle.p2
|
||||||
local peak3 = triangle.p3
|
local peak3 = triangle.p3
|
||||||
|
|
||||||
local noiseHeightValue = 0.0
|
local noise1 = layer:getNoiseByColor(category, peak1:getColor())
|
||||||
local noiseTempValue = 0.0
|
local noise2 = layer:getNoiseByColor(category, peak2:getColor())
|
||||||
local noiseHumidityValue = 0.0
|
local noise3 = layer:getNoiseByColor(category, peak3:getColor())
|
||||||
|
|
||||||
|
local noiseValue = 0.0
|
||||||
|
|
||||||
local totalWeight = 0.0
|
local totalWeight = 0.0
|
||||||
|
|
||||||
@@ -395,68 +542,58 @@ local function calcNoises2dValues(triangle, x, y, z)
|
|||||||
-- ( peak1 * weight1 + peak2 * weight2 + peak3 * weight3) / totalWeight, when
|
-- ( peak1 * weight1 + peak2 * weight2 + peak3 * weight3) / totalWeight, when
|
||||||
-- totalWeight = weight1 + weight2 + weight3
|
-- totalWeight = weight1 + weight2 + weight3
|
||||||
local weight = calcWeight(triangle.h1, x, y, z)
|
local weight = calcWeight(triangle.h1, x, y, z)
|
||||||
noiseHeightValue = noiseHeightValue + peak1:getMultinoise().landscapeNoise:get_2d({x = x, y = z}) * weight
|
noiseValue = noiseValue + noise1:get_2d({x = x, y = z}) * weight
|
||||||
noiseTempValue = noiseTempValue + peak1:getMultinoise().tempNoise:get_2d({x = x, y = z}) * weight
|
|
||||||
noiseHumidityValue = noiseHumidityValue + peak1:getMultinoise().humidityNoise:get_2d({x = x, y = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
totalWeight = totalWeight + weight
|
||||||
|
|
||||||
weight = calcWeight(triangle.h2, x, y, z)
|
weight = calcWeight(triangle.h2, x, y, z)
|
||||||
noiseHeightValue = noiseHeightValue + peak2:getMultinoise().landscapeNoise:get_2d({x = x, y = z}) * weight
|
noiseValue = noiseValue + noise2:get_2d({x = x, y = z}) * weight
|
||||||
noiseTempValue = noiseTempValue + peak2:getMultinoise().tempNoise:get_2d({x = x, y = z}) * weight
|
|
||||||
noiseHumidityValue = noiseHumidityValue + peak2:getMultinoise().humidityNoise:get_2d({x = x, y = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
totalWeight = totalWeight + weight
|
||||||
|
|
||||||
weight = calcWeight(triangle.h3, x, y, z)
|
weight = calcWeight(triangle.h3, x, y, z)
|
||||||
noiseHeightValue = noiseHeightValue + peak3:getMultinoise().landscapeNoise:get_2d({x = x, y = z}) * weight
|
noiseValue = noiseValue + noise3:get_2d({x = x, y = z}) * weight
|
||||||
noiseTempValue = noiseTempValue + peak3:getMultinoise().tempNoise:get_2d({x = x, y = z}) * weight
|
|
||||||
noiseHumidityValue = noiseHumidityValue + peak3:getMultinoise().humidityNoise:get_2d({x = x, y = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
totalWeight = totalWeight + weight
|
||||||
|
|
||||||
return mathRound(noiseHeightValue / totalWeight), mathRound(noiseTempValue / totalWeight), mathRound(noiseHumidityValue / totalWeight)
|
return (noiseValue / totalWeight)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Calculates a smoothed 2D noise value based on a preliminary space partitioning.
|
---Calculates a smoothed 2D noise value based on a preliminary space partitioning.
|
||||||
---
|
---
|
||||||
---Returns `nil` if the point is not included in any triangle.
|
---Returns `nil` if the point is not included in any triangle.
|
||||||
---@param layer MapGen.Layer
|
---@param category MapGen.Layer.Category
|
||||||
---@param x number
|
---@param layer MapGen.Layer
|
||||||
---@param y number
|
---@param x number
|
||||||
---@param z number
|
---@param y number
|
||||||
---@return number?, number?, number?
|
---@param z number
|
||||||
function MapGen:getNoises2dValues(layer, x, y, z)
|
---@return number?
|
||||||
if (pastNoise2DCalc.x ~= nil and pastNoise2DCalc.z ~= nil) and (x == pastNoise2DCalc.x and z == pastNoise2DCalc.z) then
|
function MapGen:getNoises2dValue(category, layer, x, y, z)
|
||||||
return pastNoise2DCalc.noiseValues.height, pastNoise2DCalc.noiseValues.temp, pastNoise2DCalc.noiseValues.humidity
|
---@type MapGen.PastCalcNoiseValue
|
||||||
|
local pastCalc = pastNoise2DCalc[category]
|
||||||
|
|
||||||
|
if (pastCalc.x ~= nil and pastCalc.z ~= nil) and (x == pastCalc.x and z == pastCalc.z) then
|
||||||
|
return pastCalc.noiseValue
|
||||||
end
|
end
|
||||||
|
|
||||||
if pastNoise2DCalc.triangle ~= nil and pointInTriangle(x, z, pastNoise2DCalc.triangle) then
|
if pastCalc.triangle ~= nil and pointInTriangle(x, z, pastCalc.triangle) then
|
||||||
local noiseHeightValue, noiseTempValue, noiseHumidityValue = calcNoises2dValues(pastNoise2DCalc.triangle, x, y, z)
|
local noiseValue = calcNoise2dValue(category, layer, pastCalc.triangle, x, y, z)
|
||||||
|
|
||||||
pastNoise2DCalc.x = x
|
pastCalc.x = x
|
||||||
pastNoise2DCalc.z = z
|
pastCalc.z = z
|
||||||
pastNoise2DCalc.noiseValues = {
|
pastCalc.noiseValue = noiseValue
|
||||||
height = noiseHeightValue,
|
|
||||||
temp = noiseTempValue,
|
|
||||||
humidity = noiseHumidityValue,
|
|
||||||
}
|
|
||||||
|
|
||||||
return noiseHeightValue, noiseTempValue, noiseHumidityValue
|
return noiseValue
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param triangle MapGen.Triangle
|
---@param triangle MapGen.Triangle
|
||||||
for _, triangle in ipairs(layer.trianglesList) do
|
for _, triangle in ipairs(layer.trianglesList[category]) do
|
||||||
if pointInTriangle(x, z,triangle) then
|
if pointInTriangle(x, z,triangle) then
|
||||||
local noiseHeightValue, noiseTempValue, noiseHumidityValue = calcNoises2dValues(triangle, x, y, z)
|
local noiseValue = calcNoise2dValue(category, layer, triangle, x, y, z)
|
||||||
|
|
||||||
pastNoise2DCalc.triangle = triangle
|
pastCalc.triangle = triangle
|
||||||
pastNoise2DCalc.x = x
|
pastCalc.x = x
|
||||||
pastNoise2DCalc.z = z
|
pastCalc.z = z
|
||||||
pastNoise2DCalc.noiseValues = {
|
pastCalc.noiseValue = noiseValue
|
||||||
height = noiseHeightValue,
|
|
||||||
temp = noiseTempValue,
|
|
||||||
humidity = noiseHumidityValue,
|
|
||||||
}
|
|
||||||
|
|
||||||
return noiseHeightValue, noiseTempValue, noiseHumidityValue
|
return noiseValue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -563,6 +700,14 @@ end
|
|||||||
---@param y number
|
---@param y number
|
||||||
---@param z number
|
---@param z number
|
||||||
local function generatorHandler(mapGenerator, data, index, x, y, z)
|
local function generatorHandler(mapGenerator, data, index, x, y, z)
|
||||||
|
-- If the node belongs to a static layer, then a static node is generated.
|
||||||
|
local static = mapGenerator:getStaticByHeight(y)
|
||||||
|
if static ~= nil then
|
||||||
|
static:generateStaticNode(mapGenerator, data, index, x, y, z)
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- If generation occurs outside the layers, then a void is generated.
|
-- If generation occurs outside the layers, then a void is generated.
|
||||||
local layer = mapGenerator:getLayerByHeight(y)
|
local layer = mapGenerator:getLayerByHeight(y)
|
||||||
if layer == nil then
|
if layer == nil then
|
||||||
@@ -572,17 +717,16 @@ local function generatorHandler(mapGenerator, data, index, x, y, z)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Calculating landscape height
|
-- Calculating landscape height
|
||||||
local noiseHeightValue, noiseTempValue, noiseHumidityValue = mapGenerator:getNoises2dValues(layer, x, y, z)
|
-- If the value of the noise is `nil`,
|
||||||
|
|
||||||
-- If the height of the landscape is zero,
|
|
||||||
-- then the point does not fall within any of the triangles.
|
-- then the point does not fall within any of the triangles.
|
||||||
if noiseHeightValue == nil then
|
local noiseHeightValue = mapGenerator:getNoises2dValue('landscape', layer, x, y, z) or 0.0
|
||||||
noiseHeightValue = 0.0
|
local noiseTempValue = mapGenerator:getNoises2dValue('temp', layer, x, y, z) or 0.0
|
||||||
noiseTempValue = 0.0
|
local noiseHumidityValue = mapGenerator:getNoises2dValue('humidity', layer, x, y, z) or 0.0
|
||||||
noiseHumidityValue = 0.0
|
|
||||||
end
|
-- We recalculate the climate based on altitude.
|
||||||
|
noiseTempValue = layer:calcTemp(noiseTempValue, y)
|
||||||
|
noiseHumidityValue = layer:calcHumidity(noiseHumidityValue, y)
|
||||||
|
|
||||||
---@diagnostic disable-next-line: param-type-not-match
|
|
||||||
generateNode(mapGenerator, layer, noiseHeightValue, noiseTempValue, noiseHumidityValue, data, index, x, y, z)
|
generateNode(mapGenerator, layer, noiseHeightValue, noiseTempValue, noiseHumidityValue, data, index, x, y, z)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -597,8 +741,8 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
|
|
||||||
local eMin, eMax = voxelManip:get_emerged_area()
|
local eMin, eMax = voxelManip:get_emerged_area()
|
||||||
|
|
||||||
if not self.peaksMultinoiseInitialized then
|
if not self.layersNoisesInitialized then
|
||||||
self:initPeaksMultinoise()
|
self:initLayersNoises()
|
||||||
end
|
end
|
||||||
|
|
||||||
if not self.cavernsNoiseInitialized then
|
if not self.cavernsNoiseInitialized then
|
||||||
@@ -609,8 +753,6 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
-- local param2_data = voxelManip:get_param2_data()
|
-- local param2_data = voxelManip:get_param2_data()
|
||||||
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
||||||
|
|
||||||
data[area:index(0,50,0)] = core.get_content_id('rocks:malachite')
|
|
||||||
|
|
||||||
local index
|
local index
|
||||||
-- Initial generation: landscape
|
-- Initial generation: landscape
|
||||||
for z = minPos.z, maxPos.z do
|
for z = minPos.z, maxPos.z do
|
||||||
@@ -627,14 +769,15 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
|
|
||||||
-- We make changes back to LVM and recalculate light & liquids
|
-- We make changes back to LVM and recalculate light & liquids
|
||||||
voxelManip:set_data(data)
|
voxelManip:set_data(data)
|
||||||
|
|
||||||
|
core.generate_ores(voxelManip, minPos, maxPos)
|
||||||
|
core.generate_decorations(voxelManip, minPos, maxPos)
|
||||||
|
|
||||||
--voxelManip:set_param2_data()
|
--voxelManip:set_param2_data()
|
||||||
voxelManip:set_lighting({ day = 14, night = 0})
|
voxelManip:set_lighting({ day = 14, night = 0})
|
||||||
voxelManip:calc_lighting()
|
voxelManip:calc_lighting()
|
||||||
voxelManip:update_liquids()
|
voxelManip:update_liquids()
|
||||||
|
|
||||||
core.generate_ores(voxelManip, minPos, maxPos)
|
|
||||||
core.generate_decorations(voxelManip, minPos, maxPos)
|
|
||||||
|
|
||||||
--voxelManip:write_to_map() -- Async edit
|
--voxelManip:write_to_map() -- Async edit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +1,121 @@
|
|||||||
|
local id = core.get_content_id
|
||||||
|
|
||||||
---@class MapGen.Biome
|
---@class MapGen.Biome
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field tempPoint number
|
---@field tempPoint number
|
||||||
---@field humidityPoint number
|
---@field humidityPoint number
|
||||||
---@field minY number
|
---@field minY number
|
||||||
---@field maxY number
|
---@field maxY number
|
||||||
---@field groundNodes MapGen.Biome.GroundNodes
|
---@field groundNodes MapGen.Biome.GroundNodes
|
||||||
---@field soilHeight number
|
---@field groundNodesIDs MapGen.Biome.GroundNodesIDs
|
||||||
---@field generateRock fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)
|
---@field soilHeight number
|
||||||
---@field generateSoil fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)
|
---@field generateAir generateFunc
|
||||||
---@field generateBottom fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)
|
---@field generateCavernAir generateFunc
|
||||||
|
---@field generateWater generateFunc
|
||||||
|
---@field generateRock generateFunc
|
||||||
|
---@field generateTurf generateFunc
|
||||||
|
---@field generateSoil generateFunc
|
||||||
|
---@field generateBottom generateFunc
|
||||||
local Biome = {}
|
local Biome = {}
|
||||||
|
|
||||||
|
---@alias generateFunc fun(self, mapGenerator:MapGen, data:number[], index:number, x:number, y:number, z:number)
|
||||||
|
|
||||||
---Definition table for the `MapGen.Biome`.
|
---Definition table for the `MapGen.Biome`.
|
||||||
---
|
---
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class MapGen.BiomeDef
|
---@class MapGen.BiomeDef
|
||||||
---@field tempPoint number
|
---@field tempPoint number
|
||||||
---@field humidityPoint number
|
---@field humidityPoint number
|
||||||
---@field minY number
|
---@field minY number
|
||||||
---@field maxY number
|
---@field maxY number
|
||||||
---@field groundNodes MapGen.Biome.GroundNodes
|
---@field groundNodes MapGen.Biome.GroundNodes
|
||||||
---@field soilHeight number
|
---@field soilHeight number
|
||||||
---@field generateRock fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
---@field generateAir generateFunc?
|
||||||
---@field generateSoil fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
---@field generateCavernAir generateFunc?
|
||||||
---@field generateBottom fun(mapGenerator:MapGen, biome:MapGen.Biome, data:number[], index:number, x:number, y:number, z:number)?
|
---@field generateWater generateFunc?
|
||||||
|
---@field generateRock generateFunc?
|
||||||
|
---@field generateTurf generateFunc?
|
||||||
|
---@field generateSoil generateFunc?
|
||||||
|
---@field generateBottom generateFunc?
|
||||||
|
|
||||||
|
|
||||||
-- Default generate functions
|
-- Default generate functions
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
---@param mapGenerator MapGen
|
---@param mapGenerator MapGen
|
||||||
---@param biome MapGen.Biome
|
|
||||||
---@param data number[]
|
---@param data number[]
|
||||||
---@param index number
|
---@param index number
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param z number
|
---@param z number
|
||||||
local defaultGenerateRock = function(mapGenerator, biome, data, index, x, y, z)
|
local defaultGenerateAir = function(self, mapGenerator, data, index, x, y, z)
|
||||||
--TODO: минимальную логику генерации прописать
|
data[index] = mapGenerator.nodeIDs.air
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
---@param mapGenerator MapGen
|
---@param mapGenerator MapGen
|
||||||
---@param biome MapGen.Biome
|
|
||||||
---@param data number[]
|
---@param data number[]
|
||||||
---@param index number
|
---@param index number
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param z number
|
---@param z number
|
||||||
local defaultGenerateSoil = function(mapGenerator, biome, data, index, x, y, z)
|
local defaultGenerateCavernAir = function(self, mapGenerator, data, index, x, y, z)
|
||||||
--TODO: минимальную логику генерации прописать
|
self:generateAir(mapGenerator, data, index, x, y, z)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
---@param mapGenerator MapGen
|
---@param mapGenerator MapGen
|
||||||
---@param biome MapGen.Biome
|
|
||||||
---@param data number[]
|
---@param data number[]
|
||||||
---@param index number
|
---@param index number
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param z number
|
---@param z number
|
||||||
local defaultGenerateBottom = function(mapGenerator, biome, data, index, x, y, z)
|
local defaultGenerateWater = function(self, mapGenerator, data, index, x, y, z)
|
||||||
--TODO: минимальную логику генерации прописать
|
data[index] = mapGenerator.nodeIDs.water
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
|
---@param mapGenerator MapGen
|
||||||
|
---@param data number[]
|
||||||
|
---@param index number
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param z number
|
||||||
|
local defaultGenerateRock = function(self, mapGenerator, data, index, x, y, z)
|
||||||
|
data[index] = self.groundNodesIDs.rock
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
|
---@param mapGenerator MapGen
|
||||||
|
---@param data number[]
|
||||||
|
---@param index number
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param z number
|
||||||
|
local defaultGenerateTurf = function(self, mapGenerator, data, index, x, y, z)
|
||||||
|
data[index] = self.groundNodesIDs.turf
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
|
---@param mapGenerator MapGen
|
||||||
|
---@param data number[]
|
||||||
|
---@param index number
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param z number
|
||||||
|
local defaultGenerateSoil = function(self, mapGenerator,data, index, x, y, z)
|
||||||
|
data[index] = self.groundNodesIDs.soil
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param self MapGen.Biome
|
||||||
|
---@param mapGenerator MapGen
|
||||||
|
---@param data number[]
|
||||||
|
---@param index number
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param z number
|
||||||
|
local defaultGenerateBottom = function(self, mapGenerator, data, index, x, y, z)
|
||||||
|
data[index] = self.groundNodesIDs.bottom
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -66,33 +123,64 @@ end
|
|||||||
---@param def MapGen.BiomeDef
|
---@param def MapGen.BiomeDef
|
||||||
---@return MapGen.Biome
|
---@return MapGen.Biome
|
||||||
function Biome:new(name, def)
|
function Biome:new(name, def)
|
||||||
|
if def.generateAir == nil then
|
||||||
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateAir()` function. The default function is used.', name)
|
||||||
|
def.generateAir = defaultGenerateAir
|
||||||
|
end
|
||||||
|
|
||||||
|
if def.generateCavernAir == nil then
|
||||||
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateCavernAir()` function. The default function is used.', name)
|
||||||
|
def.generateCavernAir = defaultGenerateCavernAir
|
||||||
|
end
|
||||||
|
|
||||||
|
if def.generateWater == nil then
|
||||||
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateWater()` function. The default function is used.', name)
|
||||||
|
def.generateWater = defaultGenerateWater
|
||||||
|
end
|
||||||
|
|
||||||
if def.generateRock == nil then
|
if def.generateRock == nil then
|
||||||
Logger.warningLog('MapGen.Biome: The `%s` biome does not have a specified `generateRock()` function. The default function is used.', name)
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateRock()` function. The default function is used.', name)
|
||||||
def.generateRock = defaultGenerateRock
|
def.generateRock = defaultGenerateRock
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if def.generateTurf == nil then
|
||||||
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateTurf()` function. The default function is used.', name)
|
||||||
|
def.generateTurf = defaultGenerateTurf
|
||||||
|
end
|
||||||
|
|
||||||
if def.generateSoil == nil then
|
if def.generateSoil == nil then
|
||||||
Logger.warningLog('MapGen.Biome: The `%s` biome does not have a specified `generateSoil()` function. The default function is used.', name)
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateSoil()` function. The default function is used.', name)
|
||||||
def.generateSoil = defaultGenerateSoil
|
def.generateSoil = defaultGenerateSoil
|
||||||
end
|
end
|
||||||
|
|
||||||
if def.generateBottom == nil then
|
if def.generateBottom == nil then
|
||||||
Logger.warningLog('MapGen.Biome: The `%s` biome does not have a specified `generateBottom()` function. The default function is used.', name)
|
Logger.infoLog('MapGen.Biome: The `%s` biome does not have a specified `generateBottom()` function. The default function is used.', name)
|
||||||
def.generateBottom = defaultGenerateBottom
|
def.generateBottom = defaultGenerateBottom
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local groundNodesIDs = {}
|
||||||
|
-- Converting node names to IDs
|
||||||
|
for k, v in pairs(def.groundNodes) do
|
||||||
|
groundNodesIDs[k] = id(v)
|
||||||
|
end
|
||||||
|
|
||||||
---@type MapGen.Biome
|
---@type MapGen.Biome
|
||||||
local instance = setmetatable({
|
local instance = setmetatable({
|
||||||
name = name,
|
name = name,
|
||||||
tempPoint = def.tempPoint,
|
tempPoint = def.tempPoint,
|
||||||
humidityPoint = def.humidityPoint,
|
humidityPoint = def.humidityPoint,
|
||||||
minY = def.minY,
|
minY = def.minY,
|
||||||
maxY = def.maxY,
|
maxY = def.maxY,
|
||||||
groundNodes = def.groundNodes,
|
groundNodes = def.groundNodes,
|
||||||
soilHeight = def.soilHeight,
|
groundNodesIDs = groundNodesIDs,
|
||||||
generateRock = def.generateRock or defaultGenerateRock,
|
soilHeight = def.soilHeight,
|
||||||
generateSoil = def.generateSoil or defaultGenerateSoil,
|
generateAir = def.generateAir,
|
||||||
generateBottom = def.generateBottom or defaultGenerateBottom,
|
generateCavernAir = def.generateCavernAir,
|
||||||
|
generateWater = def.generateWater,
|
||||||
|
generateRock = def.generateRock,
|
||||||
|
generateSoil = def.generateSoil,
|
||||||
|
generateTurf = def.generateTurf,
|
||||||
|
generateBottom = def.generateBottom,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class MapGen.Biome.GroundNodes
|
---@class MapGen.Biome.GroundNodes
|
||||||
---@field turf string The soil covering the surface of the biome
|
---@field turf string The soil covering the surface of the biome
|
||||||
---@field soil string The soil beneath the turf. The height of this layer depends on `Biome.soilHeight`
|
---@field soil string The soil beneath the turf. The height of this layer depends on `Biome.soilHeight`
|
||||||
|
---@field rock string The rock found beneath the soil of a biome.
|
||||||
|
---@field bottom string Covering the bottom of reservoirs.
|
||||||
local GroundNodes = {}
|
local GroundNodes = {}
|
||||||
|
|
||||||
return GroundNodes
|
return GroundNodes
|
||||||
|
|||||||
11
mods/CORE/MapGen/src/MapGen/Biome/GroundNodesIds.lua
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
--- Only for EmmyLua
|
||||||
|
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class MapGen.Biome.GroundNodesIDs
|
||||||
|
---@field turf number The soil covering the surface of the biome
|
||||||
|
---@field soil number The soil beneath the turf. The height of this layer depends on `Biome.soilHeight`
|
||||||
|
---@field rock number The rock found beneath the soil of a biome.
|
||||||
|
---@field bottom number Covering the bottom of reservoirs.
|
||||||
|
local GroundNodes = {}
|
||||||
|
|
||||||
|
return GroundNodes
|
||||||
@@ -1,45 +1,174 @@
|
|||||||
---@class MapGen.Layer
|
---@class MapGen.Layer
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field minY number
|
---@field minY number
|
||||||
---@field maxY number
|
---@field maxY number
|
||||||
---@field peaksList MapGen.Peak[]
|
---@field minTemp number
|
||||||
---@field biomesByName table<string, MapGen.Biome>
|
---@field maxTemp number
|
||||||
---@field biomesList MapGen.Biome[]
|
---@field minHumidity number
|
||||||
---@field biomesDiagram table
|
---@field maxHumidity number
|
||||||
---@field cavernsByName table<string, MapGen.Cavern>
|
---@field waterLevel number
|
||||||
---@field cavernsList MapGen.Cavern[]
|
---@field calcTemp fun(self:MapGen.Layer, value:number, height:number):number
|
||||||
---@field trianglesList MapGen.Triangle[]
|
---@field calcHumidity fun(self:MapGen.Layer, value:number, height:number):number
|
||||||
---@field tetrahedronsList MapGen.Tetrahedron[]
|
---@field peaksList {['landscape']:MapGen.Peak[],['temp']:MapGen.Peak[],['humidity']:MapGen.Peak[]}
|
||||||
|
---@field noisesByColor {['landscape']:table<ColorString, ValueNoise>,['temp']:table<ColorString, ValueNoise>,['humidity']:table<ColorString, ValueNoise>}
|
||||||
|
---@field noisesParamsByColor {['landscape']:table<ColorString, NoiseParams>,['temp']:table<ColorString, NoiseParams>,['humidity']:table<ColorString, NoiseParams>}
|
||||||
|
---@field biomesByName table<string, MapGen.Biome>
|
||||||
|
---@field biomesList MapGen.Biome[]
|
||||||
|
---@field biomesDiagram table
|
||||||
|
---@field biomesGorizontalScattering number
|
||||||
|
---@field biomesVerticalScattering number
|
||||||
|
---@field cavernsByName table<string, MapGen.Cavern>
|
||||||
|
---@field cavernsList MapGen.Cavern[]
|
||||||
|
---@field trianglesList {['landscape']:MapGen.Triangle[],['temp']:MapGen.Triangle[],['humidity']:MapGen.Triangle[]}
|
||||||
|
---@field tetrahedronsList MapGen.Tetrahedron[] **Not supported**
|
||||||
local Layer = {
|
local Layer = {
|
||||||
peaksList = {},
|
peaksList = {
|
||||||
|
landscape = {},
|
||||||
|
temp = {},
|
||||||
|
humidity = {},
|
||||||
|
},
|
||||||
|
noisesByColor = {
|
||||||
|
landscape = {},
|
||||||
|
temp = {},
|
||||||
|
humidity = {},
|
||||||
|
},
|
||||||
|
noisesParamsByColor = {
|
||||||
|
landscape = {},
|
||||||
|
temp = {},
|
||||||
|
humidity = {},
|
||||||
|
},
|
||||||
biomesByName = {},
|
biomesByName = {},
|
||||||
biomesList = {},
|
biomesList = {},
|
||||||
biomesDiagram = {},
|
biomesDiagram = {},
|
||||||
cavernsByName = {},
|
cavernsByName = {},
|
||||||
cavernsList = {},
|
cavernsList = {},
|
||||||
trianglesList = {},
|
trianglesList = {
|
||||||
|
landscape = {},
|
||||||
|
temp = {},
|
||||||
|
humidity = {},
|
||||||
|
},
|
||||||
tetrahedronsList = {},
|
tetrahedronsList = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---Definition table for the `MapGen.Layer`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class MapGen.LayerDef
|
||||||
|
---@field minY number
|
||||||
|
---@field maxY number
|
||||||
|
---@field minTemp number
|
||||||
|
---@field maxTemp number
|
||||||
|
---@field minHumidity number
|
||||||
|
---@field maxHumidity number
|
||||||
|
---@field waterLevel? number
|
||||||
|
---@field calcTemp (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||||
|
---@field calcHumidity (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||||
|
---@field biomesGorizontalScattering number?
|
||||||
|
---@field biomesVerticalScattering number?
|
||||||
|
|
||||||
|
---@param self MapGen.Layer
|
||||||
|
---@param value number
|
||||||
|
---@param height number
|
||||||
|
---@return number
|
||||||
|
local function defaultCalcFunc(self, value, height)
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param minY number
|
---@param def MapGen.LayerDef
|
||||||
---@param maxY number
|
|
||||||
---@return MapGen.Layer
|
---@return MapGen.Layer
|
||||||
function Layer:new(name, minY, maxY)
|
function Layer:new(name, def)
|
||||||
|
if def.calcTemp == nil then
|
||||||
|
Logger.infoLog('MapGen.Layer: The `%s` layer does not have a specified `calcTemp()` function. The default function is used.', name)
|
||||||
|
def.calcTemp = defaultCalcFunc
|
||||||
|
end
|
||||||
|
|
||||||
|
if def.calcHumidity == nil then
|
||||||
|
Logger.infoLog('MapGen.Layer: The `%s` layer does not have a specified `calcHumidity()` function. The default function is used.', name)
|
||||||
|
def.calcHumidity = defaultCalcFunc
|
||||||
|
end
|
||||||
|
|
||||||
---@type MapGen.Layer
|
---@type MapGen.Layer
|
||||||
local instance = setmetatable({
|
local instance = setmetatable({
|
||||||
name = name,
|
name = name,
|
||||||
minY = minY,
|
minY = def.minY,
|
||||||
maxY = maxY,
|
maxY = def.maxY,
|
||||||
|
minTemp = def.minTemp,
|
||||||
|
maxTemp = def.maxTemp,
|
||||||
|
minHumidity = def.minHumidity,
|
||||||
|
maxHumidity = def.maxHumidity,
|
||||||
|
waterLevel = def.waterLevel or 0,
|
||||||
|
calcTemp = def.calcTemp,
|
||||||
|
calcHumidity = def.calcHumidity,
|
||||||
|
biomesGorizontalScattering = def.biomesGorizontalScattering or 0,
|
||||||
|
biomesVerticalScattering = def.biomesVerticalScattering or 0,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---A category of noise that affects specific map generation objects.
|
||||||
|
---@alias MapGen.Layer.Category 'landscape'|'temp'|'humidity'
|
||||||
|
|
||||||
---Adds a peak to the `Layer.peaksList`
|
---Adds a peak to the `Layer.peaksList`
|
||||||
---@param peak MapGen.Peak
|
---@param category MapGen.Layer.Category
|
||||||
function Layer:addPeak(peak)
|
---@param peak MapGen.Peak
|
||||||
table.insert(self.peaksList, peak)
|
function Layer:addPeak(category, peak)
|
||||||
|
if category == 'landscape' then
|
||||||
|
table.insert(self.peaksList.landscape, peak)
|
||||||
|
elseif category == 'temp' then
|
||||||
|
table.insert(self.peaksList.temp, peak)
|
||||||
|
elseif category == 'humidity' then
|
||||||
|
table.insert(self.peaksList.humidity, peak)
|
||||||
|
else
|
||||||
|
error(('There is no peak category named %s.'):format(category))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Adds a NoiseParams color to the `Layer.noisesParamsByColor`
|
||||||
|
---@param category MapGen.Layer.Category
|
||||||
|
---@param color ColorString
|
||||||
|
---@param noiseParams NoiseParams
|
||||||
|
function Layer:addNoiseParamsColor(category, color, noiseParams)
|
||||||
|
color = core.colorspec_to_colorstring(core.colorspec_to_table(color))
|
||||||
|
|
||||||
|
local noisesParams = self.noisesParamsByColor
|
||||||
|
|
||||||
|
if category == 'landscape' then
|
||||||
|
assert(noisesParams.landscape[color] == nil, ('The color `%s` already exists.'):format(color))
|
||||||
|
noisesParams.landscape[color] = noiseParams
|
||||||
|
elseif category == 'temp' then
|
||||||
|
assert(noisesParams.temp[color] == nil, ('The color `%s` already exists.'):format(color))
|
||||||
|
noisesParams.temp[color] = noiseParams
|
||||||
|
elseif category == 'humidity' then
|
||||||
|
assert(noisesParams.humidity[color] == nil, ('The color `%s` already exists.'):format(color))
|
||||||
|
noisesParams.humidity[color] = noiseParams
|
||||||
|
else
|
||||||
|
error(('There is no color category named `%s`.'):format(category))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Returns noise corresponding to a color.
|
||||||
|
---@param category MapGen.Layer.Category
|
||||||
|
---@param color ColorString
|
||||||
|
---@return ValueNoise
|
||||||
|
function Layer:getNoiseByColor(category, color)
|
||||||
|
color = core.colorspec_to_colorstring(core.colorspec_to_table(color))
|
||||||
|
|
||||||
|
local noises = self.noisesByColor
|
||||||
|
|
||||||
|
if category == 'landscape' then
|
||||||
|
assert(noises.landscape[color] ~= nil, ('`%s` color does not exist.'):format(color))
|
||||||
|
return noises.landscape[color]
|
||||||
|
elseif category == 'temp' then
|
||||||
|
assert(noises.temp[color] ~= nil, ('`%s` color does not exist.'):format(color))
|
||||||
|
return noises.temp[color]
|
||||||
|
elseif category == 'humidity' then
|
||||||
|
assert(noises.humidity[color] ~= nil, ('`%s` color does not exist.'):format(color))
|
||||||
|
return noises.humidity[color]
|
||||||
|
else
|
||||||
|
error(('There is no color category named `%s`.'):format(category))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Adds a biome to the `Layer.biomesByName` & `Layer.biomesList`
|
---Adds a biome to the `Layer.biomesByName` & `Layer.biomesList`
|
||||||
@@ -77,6 +206,19 @@ local function getBiomesNamesByHeight(height, biomesList)
|
|||||||
return biomesNames, biomes
|
return biomesNames, biomes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Initializes noise for generation.
|
||||||
|
---
|
||||||
|
---Should only be called after the mapgen object has been loaded.
|
||||||
|
function Layer:initNoises()
|
||||||
|
local noises = self.noisesByColor
|
||||||
|
|
||||||
|
for category, noisesParams in pairs(self.noisesParamsByColor) do
|
||||||
|
for color, noiseParams in pairs(noisesParams) do
|
||||||
|
noises[category][color] = core.get_value_noise(noiseParams)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---Initialization of the biome diagram using the Voronoi method.
|
---Initialization of the biome diagram using the Voronoi method.
|
||||||
function Layer:initBiomesDiagram()
|
function Layer:initBiomesDiagram()
|
||||||
local diagram = self.biomesDiagram
|
local diagram = self.biomesDiagram
|
||||||
@@ -98,10 +240,10 @@ function Layer:initBiomesDiagram()
|
|||||||
end
|
end
|
||||||
|
|
||||||
pastBiomesNames = newBiomesNames
|
pastBiomesNames = newBiomesNames
|
||||||
for temp = 0, 100 do
|
for temp = self.minTemp, self.maxTemp do
|
||||||
diagram[height][temp] = {}
|
diagram[height][temp] = {}
|
||||||
|
|
||||||
for humidity = 0, 100 do
|
for humidity = self.minHumidity, self.maxHumidity do
|
||||||
local minDistance = math.huge
|
local minDistance = math.huge
|
||||||
local closestBiome = nil
|
local closestBiome = nil
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,35 @@
|
|||||||
---@class MapGen.Peak
|
---@class MapGen.Peak
|
||||||
---@field id number
|
---@field id number
|
||||||
---@field getPeakPos fun():vector
|
---@field getPeakPos fun():vector
|
||||||
---@field getMultinoiseParams fun():MapGen.Peak.MultinoiseParams
|
---@field getColor fun():ColorString
|
||||||
---@field getMultinoise fun():MapGen.Peak.Multinoise
|
|
||||||
---@field initMultinoise fun()
|
|
||||||
---@field getGroups fun():table<string, number>
|
---@field getGroups fun():table<string, number>
|
||||||
local Peak = {
|
local Peak = {
|
||||||
id = 0,
|
id = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- --- Helpers functions ---
|
|
||||||
|
|
||||||
---@param multinoiseParams MapGen.Peak.MultinoiseParams
|
|
||||||
---@return MapGen.Peak.Multinoise
|
|
||||||
local function multinoiseParamsToMultinoise(multinoiseParams)
|
|
||||||
---@diagnostic disable-next-line: missing-fields
|
|
||||||
---@type MapGen.Peak.Multinoise
|
|
||||||
local multinoise = {}
|
|
||||||
|
|
||||||
for noiseName, noiseParams in pairs(multinoiseParams) do
|
|
||||||
multinoise[noiseName] = core.get_value_noise(noiseParams)
|
|
||||||
end
|
|
||||||
|
|
||||||
return multinoise
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- --- Class registration ---
|
-- --- Class registration ---
|
||||||
|
|
||||||
---@param peakPos vector
|
---Definition table for the `MapGen.Peak`.
|
||||||
---@param multinoiseParams MapGen.Peak.MultinoiseParams
|
---
|
||||||
---@param groups? table<string, number>
|
---**Only for EmmyLua.**
|
||||||
---@return MapGen.Peak
|
---@class MapGen.PeakDef
|
||||||
function Peak:new(peakPos, multinoiseParams, groups)
|
---@field pos vector
|
||||||
---@type vector
|
---@field color ColorString
|
||||||
local _peakPos = peakPos
|
---@field groups? table<string, number>
|
||||||
---@type MapGen.Peak.MultinoiseParams
|
|
||||||
local _multinoiseParams = multinoiseParams
|
|
||||||
|
|
||||||
|
---@param def MapGen.PeakDef
|
||||||
|
---@return MapGen.Peak
|
||||||
|
function Peak:new(def)
|
||||||
|
local _pos = def.pos
|
||||||
|
local _color = def.color
|
||||||
local _groups
|
local _groups
|
||||||
|
|
||||||
if groups == nil then
|
if def.groups == nil then
|
||||||
_groups = {}
|
_groups = {}
|
||||||
else
|
else
|
||||||
_groups = groups
|
_groups = def.groups
|
||||||
end
|
end
|
||||||
|
|
||||||
---@diagnostic disable-next-line: missing-fields
|
|
||||||
---@type MapGen.Peak.Multinoise
|
|
||||||
local _multinoise = {} -- note: must be empty until luanti mapgen objects are loaded.
|
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local instance = setmetatable({},
|
local instance = setmetatable({},
|
||||||
{
|
{
|
||||||
@@ -60,35 +39,15 @@ function Peak:new(peakPos, multinoiseParams, groups)
|
|||||||
})
|
})
|
||||||
|
|
||||||
function instance:getPeakPos()
|
function instance:getPeakPos()
|
||||||
return vector.new(_peakPos.x, _peakPos.y, _peakPos.z)
|
return _pos:copy()
|
||||||
end
|
end
|
||||||
|
|
||||||
function instance:getMultinoiseParams()
|
function instance:getColor()
|
||||||
return _multinoiseParams
|
return _color
|
||||||
end
|
|
||||||
|
|
||||||
function instance:getMultinoise()
|
|
||||||
if table.is_empty(_multinoise) then
|
|
||||||
error('Attempt to get `MapGen.Triangulation.FakePeak` noise (empty noise).')
|
|
||||||
end
|
|
||||||
|
|
||||||
return _multinoise
|
|
||||||
end
|
|
||||||
|
|
||||||
function instance:initMultinoise()
|
|
||||||
if not table.is_empty(_multinoise) then
|
|
||||||
Logger.warningLog('Multinoise has already been initialized. Re-initialization is not recommended.')
|
|
||||||
end
|
|
||||||
|
|
||||||
if table.is_empty(_multinoiseParams) then
|
|
||||||
error('Attempt to initialize `MapGen.Triangulation.FakePeak` noise (noise parameter empty).')
|
|
||||||
end
|
|
||||||
|
|
||||||
_multinoise = multinoiseParamsToMultinoise(_multinoiseParams)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function instance:getGroups()
|
function instance:getGroups()
|
||||||
return _groups
|
return table.copy_with_metatables(_groups)
|
||||||
end
|
end
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
---For EmmyLua only
|
|
||||||
|
|
||||||
---**For EmmyLua only**
|
|
||||||
---@class MapGen.Peak.Multinoise
|
|
||||||
---@field landscapeNoise ValueNoise
|
|
||||||
---@field tempNoise ValueNoise
|
|
||||||
---@field humidityNoise ValueNoise
|
|
||||||
local Multinoise = {}
|
|
||||||
|
|
||||||
return Multinoise
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
---For EmmyLua only
|
|
||||||
|
|
||||||
---**For EmmyLua only**
|
|
||||||
---@class MapGen.Peak.MultinoiseParams
|
|
||||||
---@field landscapeNoise NoiseParams
|
|
||||||
---@field tempNoise NoiseParams
|
|
||||||
---@field humidityNoise NoiseParams
|
|
||||||
local MultinoiseParams = {}
|
|
||||||
|
|
||||||
return MultinoiseParams
|
|
||||||
58
mods/CORE/MapGen/src/MapGen/StaticLayer.lua
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
local id = core.get_content_id
|
||||||
|
|
||||||
|
---@class MapGen.StaticLayer
|
||||||
|
---@field name string
|
||||||
|
---@field minY number
|
||||||
|
---@field maxY number
|
||||||
|
---@field staticNode string
|
||||||
|
---@field staticNodeID number
|
||||||
|
---@field generateStaticNode generateFunc
|
||||||
|
local StaticLayer = {}
|
||||||
|
|
||||||
|
---Definition table for the `MapGen.StaticLayer`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class MapGen.StaticLayerDef
|
||||||
|
---@field minY number
|
||||||
|
---@field maxY number
|
||||||
|
---@field staticNode string
|
||||||
|
---@field generateStaticNode generateFunc
|
||||||
|
|
||||||
|
---@param self MapGen.StaticLayer
|
||||||
|
---@param mapGenerator MapGen
|
||||||
|
---@param data number[]
|
||||||
|
---@param index number
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param z number
|
||||||
|
local defaultGenerateStaticNode = function(self, mapGenerator, data, index, x, y, z)
|
||||||
|
data[index] = self.staticNodeID
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param def MapGen.StaticLayerDef
|
||||||
|
---@return MapGen.StaticLayer
|
||||||
|
function StaticLayer:new(name, def)
|
||||||
|
assert(def.maxY > def.minY, 'maxY there should be more minY')
|
||||||
|
|
||||||
|
if def.generateStaticNode == nil then
|
||||||
|
Logger.infoLog('MapGen.StaticLayer: The `%s` static layer does not have a specified `generateStaticNode()` function. The default function is used.', name)
|
||||||
|
def.generateStaticNode = defaultGenerateStaticNode
|
||||||
|
end
|
||||||
|
|
||||||
|
local staticNodeID = id(def.staticNode)
|
||||||
|
|
||||||
|
---@type MapGen.StaticLayer
|
||||||
|
local instance = setmetatable({
|
||||||
|
name = name,
|
||||||
|
minY = def.minY,
|
||||||
|
maxY = def.maxY,
|
||||||
|
staticNode = def.staticNode,
|
||||||
|
staticNodeID = staticNodeID,
|
||||||
|
generateStaticNode = def.generateStaticNode
|
||||||
|
}, {__index = self})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
return StaticLayer
|
||||||
@@ -10,15 +10,14 @@ local Peak = require('MapGen.Peak')
|
|||||||
---@class MapGen.Triangulation.FakePeak : MapGen.Peak
|
---@class MapGen.Triangulation.FakePeak : MapGen.Peak
|
||||||
---@field id number
|
---@field id number
|
||||||
---@field getPeakPos fun():vector
|
---@field getPeakPos fun():vector
|
||||||
local FakePeak = Mod:getClassExtended(Peak, {})
|
local FakePeak = Class.extend(Peak, {})
|
||||||
|
|
||||||
---Returns a fake `MapGen.Peak` that has no noise parameters.
|
---Returns a fake `MapGen.Peak` that has no noise parameters.
|
||||||
---Note that the initialized peak should not be used in generation.
|
---Note that the initialized peak should not be used in generation.
|
||||||
---@param peakPos vector
|
---@param peakPos vector
|
||||||
---@return MapGen.Peak
|
---@return MapGen.Peak
|
||||||
function FakePeak:new(peakPos)
|
function FakePeak:new(peakPos)
|
||||||
---@diagnostic disable-next-line: missing-fields, param-type-not-match
|
local instance = Peak:new({pos = peakPos, color = '#000000'})
|
||||||
local instance = Peak:new(peakPos, {}, 1)
|
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
101
mods/CORE/MapGen/src/MapGen/ff2luat.lua
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
-- A method for converting an image with colored dots (pixels) into a Lua table grouped by color.
|
||||||
|
-- Author: @ssdaniel24 (github)
|
||||||
|
|
||||||
|
---Table with color as key and value is table with coordinates of dots. Note: coords begin from 1,1 (not 0,0).
|
||||||
|
---Example of table:
|
||||||
|
---```lua
|
||||||
|
---{
|
||||||
|
--- 'size': { h=256, w=256 },
|
||||||
|
--- '#fff': { {x=1,y=1}, {x=2,y=2}, ... },
|
||||||
|
--- '#ff0': { {x=3,y=3}, {x=4,y=4}, ... },
|
||||||
|
--- ...
|
||||||
|
---}
|
||||||
|
---```
|
||||||
|
---@alias ColoredDotsTable table<string,table>
|
||||||
|
|
||||||
|
---@param uintb string unsigned int bytes
|
||||||
|
---@return number
|
||||||
|
local function uintb2num(uintb)
|
||||||
|
local num = 0
|
||||||
|
local len = string.len(uintb)
|
||||||
|
|
||||||
|
for i = 1,len do
|
||||||
|
num = num*256 + string.byte(uintb, i)
|
||||||
|
end
|
||||||
|
|
||||||
|
return num
|
||||||
|
end
|
||||||
|
|
||||||
|
---Converts (scaling) 16-bit unsigned integer to 8-bit unsigned integer.
|
||||||
|
---Why? Because hex codes of colors are 8-bit: #ffffff -> ff = 256 (8 bit). Not 65536 (16 bit).
|
||||||
|
---@param num number 16-bit number
|
||||||
|
---@return number 8-bit number
|
||||||
|
local function uint16ToUint8(num)
|
||||||
|
return math.floor(num / 256)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Converts given farbfeld image to ColoredDotsTable.
|
||||||
|
---Farbfeld format:
|
||||||
|
---```
|
||||||
|
---╔════════╤═════════════════════════════════════════════════════════╗
|
||||||
|
---║ Bytes │ Description ║
|
||||||
|
---╠════════╪═════════════════════════════════════════════════════════╣
|
||||||
|
---║ 8 │ 'farbfeld' magic value ║
|
||||||
|
---╟────────┼─────────────────────────────────────────────────────────╢
|
||||||
|
---║ 4 │ 32-Bit BE unsigned integer (width) ║
|
||||||
|
---╟────────┼─────────────────────────────────────────────────────────╢
|
||||||
|
---║ 4 │ 32-Bit BE unsigned integer (height) ║
|
||||||
|
---╟────────┼─────────────────────────────────────────────────────────╢
|
||||||
|
---║ [2222] │ 4x16-Bit BE unsigned integers [RGBA] / pixel, row-major ║
|
||||||
|
---╚════════╧═════════════════════════════════════════════════════════╝
|
||||||
|
---```
|
||||||
|
---[tools/farbfeld | suckless.org software that sucks less](https://tools.suckless.org/farbfeld/)
|
||||||
|
---@param filepath string image in farbfeld format
|
||||||
|
---@param backgroundColor string? ColorString, will be ignored while processing image. Default: `#000000FF`
|
||||||
|
---@return ColoredDotsTable
|
||||||
|
local function ff2luat(filepath, backgroundColor)
|
||||||
|
local file = io.open(filepath, 'rb')
|
||||||
|
if not file then error('Can\'t open farbfeld image: ' .. dump(filepath)) end
|
||||||
|
local ff = file:read('*a') -- binary!
|
||||||
|
file:close()
|
||||||
|
-- TODO: make it decompressing gzip format -> https://en.wikipedia.org/wiki/Gzip
|
||||||
|
-- I should skip 10 bytes in a beginning, read how many extra fields after it, skip them too, and skip last 8 bytes
|
||||||
|
-- (read wiki for information).
|
||||||
|
-- if filepath:sub(-3) == '.gz' then ff = core.decompress(ff, 'deflate') end
|
||||||
|
if not ff:sub(1,8) == 'farbfeld' then error('Not farbfeld image: ' .. dump(filepath)) end
|
||||||
|
|
||||||
|
if not backgroundColor then backgroundColor = '#000000FF' end
|
||||||
|
--HACK: normalizing colorstring for future string comparison ('#000' -> '#000000FF')
|
||||||
|
backgroundColor = core.colorspec_to_colorstring(core.colorspec_to_table(backgroundColor))
|
||||||
|
|
||||||
|
---@type ColoredDotsTable
|
||||||
|
local dots = { size = { w = uintb2num(ff:sub(9,12)), h = uintb2num(ff:sub(13,16)) } }
|
||||||
|
|
||||||
|
local cursor
|
||||||
|
for i = 1,dots.size.h do
|
||||||
|
for j = 1,dots.size.w do
|
||||||
|
cursor = 16 + ((i-1)*dots.size.w + j-1)*8 + 1
|
||||||
|
local colorT = {
|
||||||
|
r = uint16ToUint8(uintb2num(ff:sub(cursor, cursor+1))),
|
||||||
|
g = uint16ToUint8(uintb2num(ff:sub(cursor+2,cursor+3))),
|
||||||
|
b = uint16ToUint8(uintb2num(ff:sub(cursor+4,cursor+5))),
|
||||||
|
a = uint16ToUint8(uintb2num(ff:sub(cursor+6,cursor+7)))
|
||||||
|
}
|
||||||
|
|
||||||
|
---@type string @ColorString
|
||||||
|
local color = core.colorspec_to_colorstring(colorT)
|
||||||
|
|
||||||
|
if color ~= backgroundColor then
|
||||||
|
if not dots[color] then
|
||||||
|
dots[color] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(dots[color], { x=j, y=i })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return dots
|
||||||
|
end
|
||||||
|
|
||||||
|
return ff2luat
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
local Node = Mod:new()
|
local modInfo = Mod.getInfo('smc__core__node')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
Node.Class = Node.require('Node')
|
return require('Node')
|
||||||
|
|
||||||
Api.addModToGlobalSpace(Node, 'Core.Node')
|
|
||||||
@@ -1,18 +1,31 @@
|
|||||||
---@type Item.VisualEnum
|
local itemRequire = Mod.getInfo('smc__core__item').require
|
||||||
local VisualEnum = Core.Item.require('Item.VisualEnum')
|
|
||||||
|
---@type Item
|
||||||
|
local Item = itemRequire('Item')
|
||||||
|
|
||||||
|
---@type ItemFactory
|
||||||
|
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||||
|
|
||||||
---@class Node : Item
|
---@class Node : Item
|
||||||
---@field defaultDef Node.NodeDefinition
|
---@field defaultDef Node.NodeDefinition
|
||||||
local Node = Core.Item:getModClassExtended({})
|
local Node = Class.extend(Item, {})
|
||||||
|
|
||||||
---@param nodeDef Node.NodeDefinition
|
---The alias `table.merge` for EmmyLua
|
||||||
---@return Node
|
---@type fun(...):(Node.NodeDefinition)
|
||||||
|
local defMerge = function(...)
|
||||||
|
return table.merge(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param nodeDef Node.NodeDefinition
|
||||||
|
---@return Node
|
||||||
function Node:new(nodeDef)
|
function Node:new(nodeDef)
|
||||||
nodeDef.settings.visual = VisualEnum.ITEM_3D
|
---Adding default parameters
|
||||||
|
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
||||||
|
|
||||||
|
nodeDef.settings.visual = 'item_3d'
|
||||||
|
|
||||||
---@type Node
|
---@type Node
|
||||||
local instance = Core.Item:getModClassInstance(nodeDef)
|
local instance = Item:new(nodeDef)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,7 +36,7 @@ end
|
|||||||
---@return Node
|
---@return Node
|
||||||
function Node:getExtended(defaultDef)
|
function Node:getExtended(defaultDef)
|
||||||
---@type Node
|
---@type Node
|
||||||
local ChildClass = Mod:getClassExtended(self, {
|
local ChildClass = Class.extend(self, {
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -39,7 +52,7 @@ function Node:getFactory(defaultDef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@type ItemFactory
|
---@type ItemFactory
|
||||||
local instance = Core.ItemFactory:getModClassInstance(self, defaultDef)
|
local instance = ItemFactory:new(self, defaultDef)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
---@type Item.Callbacks
|
---@type Item.Callbacks
|
||||||
local ItemCallbacks = Core.Item.require('Item.Callbacks')
|
local ItemCallbacks = Mod.getInfo('smc__core__item').require('Item.Callbacks')
|
||||||
|
|
||||||
---@class Node.Callbacks : Item.Callbacks
|
---@class Node.Callbacks : Item.Callbacks
|
||||||
local Callbacks = Mod:getClassExtended(ItemCallbacks, {})
|
local Callbacks = Class.extend(ItemCallbacks, {})
|
||||||
|
|
||||||
---Node constructor; called after adding node.
|
---Node constructor; called after adding node.
|
||||||
---Can set up metadata and stuff like that.
|
---Can set up metadata and stuff like that.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
---@type Item.Settings
|
---@type Item.Settings
|
||||||
local ItemSettings = Core.Item.require('Item.Settings')
|
local ItemSettings = Mod.getInfo('smc__core__item').require('Item.Settings')
|
||||||
|
|
||||||
---@class Node.Settings : Item.Settings
|
---@class Node.Settings : Item.Settings
|
||||||
local Settings = Mod:getClassExtended(ItemSettings, {})
|
local Settings = Class.extend(ItemSettings, {})
|
||||||
|
|
||||||
---See "Node drawtypes"
|
---See "Node drawtypes"
|
||||||
---@type string?
|
---@type string?
|
||||||
|
|||||||
4
mods/CORE/Plant/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__plant')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Plant')
|
||||||
2
mods/CORE/Plant/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__plant
|
||||||
|
depends = smc__core__node
|
||||||
27
mods/CORE/Plant/src/Plant.lua
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
local nodeRequire = Mod.getInfo('smc__core__node').require
|
||||||
|
|
||||||
|
---@type Node
|
||||||
|
local Node = nodeRequire('Node')
|
||||||
|
|
||||||
|
-- -@type ItemFactory
|
||||||
|
---local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
||||||
|
|
||||||
|
---@class Plant : Node
|
||||||
|
local Plant = Node:getExtended({
|
||||||
|
settings = {
|
||||||
|
name = 'smc__core__plant:abstract_plant',
|
||||||
|
drawtype = "plantlike",
|
||||||
|
sunlight_propagates = true,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "meshoptions",
|
||||||
|
walkable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
groups = {dig_immediate = 3},
|
||||||
|
selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {-0.25, -0.5, -0.25, 0.25, 0.5, 0.25},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return Plant
|
||||||
4
mods/CORE/Player/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__player')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Player')
|
||||||
2
mods/CORE/Player/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__player
|
||||||
|
depends = smc__system__system_loader
|
||||||
4
mods/CORE/Player/src/Player.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---@class Player
|
||||||
|
local Player = {}
|
||||||
|
|
||||||
|
return Player
|
||||||
4
mods/CORE/Player/src/Player/GUI.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---@class Player.GUI
|
||||||
|
local GUI = {}
|
||||||
|
|
||||||
|
return GUI
|
||||||
4
mods/CORE/Player/src/Player/HUD.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---@class Player.HUD
|
||||||
|
local HUD = {}
|
||||||
|
|
||||||
|
return HUD
|
||||||
4
mods/CORE/Sound/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__sound')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Sound')
|
||||||
2
mods/CORE/Sound/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__sound
|
||||||
|
depends = smc__system__system_loader
|
||||||
4
mods/CORE/Sound/src/Sound.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---@class Sound
|
||||||
|
local Sound = {}
|
||||||
|
|
||||||
|
return Sound
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
local TileSheet = Mod:new()
|
local modInfo = Mod.getInfo('smc__core__tilesheet')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
TileSheet.Class = TileSheet.require('TileSheet')
|
return require('TileSheet')
|
||||||
|
|
||||||
Api.addModToGlobalSpace(TileSheet, 'Core.TileSheet')
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__tilesheet
|
name = smc__core__tilesheet
|
||||||
depends = smc__api__api_loader
|
depends = smc__system__system_loader
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ end
|
|||||||
---@param y number
|
---@param y number
|
||||||
---@return string
|
---@return string
|
||||||
function TileSheet:getTextureName(x, y)
|
function TileSheet:getTextureName(x, y)
|
||||||
local textureName = self.image .. '^[sheet:'.. self.width .. 'x' .. self.height .. ':' .. x .. ',' .. y
|
local textureName = '('..self.image .. '^[sheet:'.. self.width .. 'x' .. self.height .. ':' .. x .. ',' .. y..')'
|
||||||
|
|
||||||
return textureName
|
return textureName
|
||||||
end
|
end
|
||||||
|
|||||||
71
mods/CORE/adminCommands/init.lua
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__formspec')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type Formspec
|
||||||
|
local Formspec = require('Formspec')
|
||||||
|
|
||||||
|
local listForm = Formspec:new({
|
||||||
|
size = {x=21, y=12},
|
||||||
|
})
|
||||||
|
|
||||||
|
listForm:list('current_player', 'main', 10.5, 6.5, 8, 4)
|
||||||
|
|
||||||
|
local listFormItems = Formspec:new()
|
||||||
|
|
||||||
|
local items = core.registered_nodes
|
||||||
|
|
||||||
|
local w, h = 0, 0
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param def NodeDefinition
|
||||||
|
for name, def in pairs(items) do
|
||||||
|
listFormItems:itemImageButton(w, h, 1, 1, name, name..'::item_button')
|
||||||
|
|
||||||
|
w = w + 1
|
||||||
|
|
||||||
|
if w > 9 then
|
||||||
|
w = 0
|
||||||
|
h = h + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--listFormItems:list('current_player', 'main', 0, 0, 1, 32)
|
||||||
|
|
||||||
|
listForm:scrollContainer(listFormItems, 0.5, 0.5, 9, 11, 'admin_commands:list_items', 'vertical')
|
||||||
|
listForm:scrollbar(10, 0.5, 0.25, 10, 'vertical', 'admin_commands:list_items')
|
||||||
|
|
||||||
|
core.log(listForm:toString())
|
||||||
|
|
||||||
|
core.register_chatcommand('list', {
|
||||||
|
privs = {server = true},
|
||||||
|
|
||||||
|
func = function(name, param)
|
||||||
|
local player = core.get_player_by_name(name)
|
||||||
|
|
||||||
|
core.show_formspec(name, 'admin_commands:list_form', listForm:toString())
|
||||||
|
|
||||||
|
return true, ''
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname ~= 'admin_commands:list_form' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for key, value in pairs(fields) do
|
||||||
|
if string.ends_with(key, '::item_button') then
|
||||||
|
---@type ItemStackString
|
||||||
|
local stack = string.match(key, '(%S+)::item_button')
|
||||||
|
|
||||||
|
core.log(tostring(stack))
|
||||||
|
|
||||||
|
---@type InvRef
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
|
if inv:room_for_item("main", stack) then
|
||||||
|
inv:add_item("main", stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
2
mods/CORE/adminCommands/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__admin_commands
|
||||||
|
depends = smc__system__system_loader, smc__core__formspec, smc__core__item
|
||||||
@@ -1,243 +0,0 @@
|
|||||||
-- MAPGEN ENVIROMENT ONLY
|
|
||||||
-- https://api.luanti.org/core-namespace-reference/#mapgen-environment
|
|
||||||
|
|
||||||
-- This environment is isolated from the main environment,
|
|
||||||
-- so global tables need to be preloaded manually.
|
|
||||||
|
|
||||||
-- --- Global APIs load --
|
|
||||||
-- Ensure
|
|
||||||
dofile(core.get_modpath('smc__api__ensure')..'/init.lua')
|
|
||||||
|
|
||||||
-- Logger
|
|
||||||
dofile(core.get_modpath('smc__api__logger')..'/init.lua')
|
|
||||||
|
|
||||||
-- Math
|
|
||||||
dofile(core.get_modpath('smc__api__math')..'/init.lua')
|
|
||||||
|
|
||||||
-- Require
|
|
||||||
dofile(core.get_modpath('smc__api__require')..'/init.lua')
|
|
||||||
|
|
||||||
-- Mod
|
|
||||||
dofile(core.get_modpath('smc__api__mod')..'/init.lua')
|
|
||||||
|
|
||||||
-- TODO: исправить загрузку строковых библиотек (хотя они пока что не юзаются в мапгене)
|
|
||||||
-- Они не работают из-за get_current_modname внутри utf8
|
|
||||||
-- UTF-8
|
|
||||||
-- dofile(core.get_modpath('smc__api__utf8')..'/init.lua')
|
|
||||||
|
|
||||||
-- String
|
|
||||||
-- dofile(core.get_modpath('smc__api__string')..'/init.lua')
|
|
||||||
|
|
||||||
-- Table
|
|
||||||
dofile(core.get_modpath('smc__api__table')..'/init.lua')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- --- MapGen definiton ---
|
|
||||||
local id = core.get_content_id
|
|
||||||
|
|
||||||
local mathRound = math.round
|
|
||||||
|
|
||||||
local mapGenRequire = Mod.getInfo('smc__core__map_gen').require
|
|
||||||
|
|
||||||
---@type MapGen
|
|
||||||
local MapGen = mapGenRequire('MapGen')
|
|
||||||
|
|
||||||
---@type MapGen
|
|
||||||
local mapGenerator = MapGen:new({
|
|
||||||
-- Special nodes
|
|
||||||
air = id("air"),
|
|
||||||
|
|
||||||
-- Rocks
|
|
||||||
sylite = id("rocks:sylite"),
|
|
||||||
tauitite = id("rocks:tauitite"),
|
|
||||||
iyellite = id("rocks:iyellite"),
|
|
||||||
falmyte = id("rocks:falmyte"),
|
|
||||||
hapcoryte = id("rocks:hapcoryte"),
|
|
||||||
burcite = id("rocks:burcite"),
|
|
||||||
felhor = id("rocks:felhor"),
|
|
||||||
malachite = id("rocks:malachite"),
|
|
||||||
|
|
||||||
-- Liquids
|
|
||||||
water = id("liquids:water_source"),
|
|
||||||
}, 10
|
|
||||||
)
|
|
||||||
|
|
||||||
mapGenerator:RegisterLayer("world", -1000, 500)
|
|
||||||
|
|
||||||
local land1 = {
|
|
||||||
offset = -20,
|
|
||||||
scale = 5,
|
|
||||||
spread = {x = 10, y = 10, z = 10},
|
|
||||||
seed = 47,
|
|
||||||
octaves = 3,
|
|
||||||
persistence = 0.4,
|
|
||||||
lacunarity = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
local land2 = {
|
|
||||||
offset = 20,
|
|
||||||
scale = 5,
|
|
||||||
spread = {x = 10, y = 10, z = 10},
|
|
||||||
seed = 47,
|
|
||||||
octaves = 3,
|
|
||||||
persistence = 0.4,
|
|
||||||
lacunarity = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
local climat1 = {
|
|
||||||
offset = 80,
|
|
||||||
scale = 10,
|
|
||||||
spread = {x = 10, y = 10, z = 10},
|
|
||||||
seed = 47,
|
|
||||||
octaves = 8,
|
|
||||||
persistence = 0.6,
|
|
||||||
lacunarity = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
local climat2 = {
|
|
||||||
offset = 30,
|
|
||||||
scale = 10,
|
|
||||||
spread = {x = 10, y = 10, z = 10},
|
|
||||||
seed = 47,
|
|
||||||
octaves = 8,
|
|
||||||
persistence = 0.6,
|
|
||||||
lacunarity = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
local climat0 = {
|
|
||||||
offset = 50,
|
|
||||||
scale = 0,
|
|
||||||
spread = {x = 10, y = 10, z = 10},
|
|
||||||
seed = 47,
|
|
||||||
octaves = 8,
|
|
||||||
persistence = 0.4,
|
|
||||||
lacunarity = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
local v = vector.new
|
|
||||||
|
|
||||||
mapGenerator:register2DPeaks("world",
|
|
||||||
{
|
|
||||||
landscapeNoise = land1,
|
|
||||||
tempNoise = climat2,
|
|
||||||
humidityNoise = climat2,
|
|
||||||
},{
|
|
||||||
v(500, 0, 500),
|
|
||||||
v(-500, 0, -500),
|
|
||||||
v(-500, 0, 500),
|
|
||||||
v(500, 0, -500),
|
|
||||||
})
|
|
||||||
|
|
||||||
mapGenerator:register2DPeaks("world",
|
|
||||||
{
|
|
||||||
landscapeNoise = land2,
|
|
||||||
tempNoise = climat1,
|
|
||||||
humidityNoise = climat1,
|
|
||||||
},{
|
|
||||||
v(-300, 0, 300),
|
|
||||||
v(200, 0, -400),
|
|
||||||
})
|
|
||||||
|
|
||||||
mapGenerator:register2DPeaks("world",
|
|
||||||
{
|
|
||||||
landscapeNoise = land2,
|
|
||||||
tempNoise = climat2,
|
|
||||||
humidityNoise = climat2,
|
|
||||||
},{
|
|
||||||
v(200, 0, 100),
|
|
||||||
v(-300, 0, -200),
|
|
||||||
})
|
|
||||||
|
|
||||||
mapGenerator:registerCavern('world', 'cavern1', {
|
|
||||||
minY = -100,
|
|
||||||
maxY = -10,
|
|
||||||
smoothDistance = 20,
|
|
||||||
threshold = 0.3,
|
|
||||||
noiseParams ={
|
|
||||||
offset = 0,
|
|
||||||
scale = 1,
|
|
||||||
spread = {x = 25, y = 25, z = 25},
|
|
||||||
seed = 5934,
|
|
||||||
octaves = 3,
|
|
||||||
persistence = 0.5,
|
|
||||||
lacunarity = 2.0
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
-- --- Biomes ---
|
|
||||||
|
|
||||||
---@type ValueNoise
|
|
||||||
local rocksNoise
|
|
||||||
|
|
||||||
---@type NoiseParams
|
|
||||||
local rocksNoiseParams ={
|
|
||||||
offset = 4,
|
|
||||||
scale = 2,
|
|
||||||
spread = {x = 30, y = 30, z = 30},
|
|
||||||
seed = 47,
|
|
||||||
octaves = 3,
|
|
||||||
persistence = 0.5,
|
|
||||||
lacunarity = 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
local function generateRock(mapGenerator, biome, data, index, x, y, z)
|
|
||||||
local ids = mapGenerator.nodeIDs --TODO перенести камни в Biome
|
|
||||||
|
|
||||||
if rocksNoise == nil then
|
|
||||||
rocksNoise = core.get_value_noise(rocksNoiseParams)
|
|
||||||
end
|
|
||||||
|
|
||||||
local noiseRocksValue = mathRound(rocksNoise:get_3d({x = x, y = y, z = z}))
|
|
||||||
if noiseRocksValue == 1 then
|
|
||||||
data[index] = ids.malachite
|
|
||||||
elseif noiseRocksValue == 2 then
|
|
||||||
data[index] = ids.hapcoryte
|
|
||||||
elseif noiseRocksValue == 3 then
|
|
||||||
data[index] = ids.iyellite
|
|
||||||
elseif noiseRocksValue == 4 then
|
|
||||||
data[index] = ids.sylite
|
|
||||||
elseif noiseRocksValue == 5 then
|
|
||||||
data[index] = ids.tauitite
|
|
||||||
elseif noiseRocksValue == 6 then
|
|
||||||
data[index] = ids.falmyte
|
|
||||||
elseif noiseRocksValue == 7 then
|
|
||||||
data[index] = ids.burcite
|
|
||||||
elseif noiseRocksValue == 8 then
|
|
||||||
data[index] = ids.felhor
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function generateSoil(mapGenerator, biome, data, index, x, y, z)
|
|
||||||
data[index] = core.get_content_id(biome.groundNodes.turf) -- TODO: убрать тут get_content_id(), переместить его куда-то "выше"
|
|
||||||
end
|
|
||||||
|
|
||||||
mapGenerator:registerBiome('world', "biome1", {
|
|
||||||
tempPoint = 0,
|
|
||||||
humidityPoint = 0,
|
|
||||||
minY = -10000,
|
|
||||||
maxY = 1000,
|
|
||||||
groundNodes = {
|
|
||||||
soil = "soils:clay_soil_baren",
|
|
||||||
turf = "soils:clay_soil_baren",
|
|
||||||
},
|
|
||||||
soilHeight = 1,
|
|
||||||
generateRock = generateRock,
|
|
||||||
generateSoil = generateSoil,
|
|
||||||
})
|
|
||||||
|
|
||||||
mapGenerator:registerBiome('world', "biome2", {
|
|
||||||
tempPoint = 100,
|
|
||||||
humidityPoint = 100,
|
|
||||||
minY = -1000,
|
|
||||||
maxY = 1000,
|
|
||||||
groundNodes = {
|
|
||||||
soil = "soils:rocky_soil_baren",
|
|
||||||
turf = "soils:rocky_soil_baren",
|
|
||||||
},
|
|
||||||
soilHeight = 1,
|
|
||||||
generateRock = generateRock,
|
|
||||||
generateSoil = generateSoil,
|
|
||||||
})
|
|
||||||
|
|
||||||
mapGenerator:run()
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
-- World generation runs in the mapgen environment (separate thread)
|
|
||||||
-- The Mapgen environment is isolated from the main enviroment.
|
|
||||||
|
|
||||||
core.register_mapgen_script(core.get_modpath(core.get_current_modname())..'/MapGenerator.lua')
|
|
||||||
|
|
||||||
core.register_ore({
|
|
||||||
ore_type = "scatter",
|
|
||||||
ore = "soils:rocky_soil_baren",
|
|
||||||
wherein = "rocks:sylite",
|
|
||||||
clust_scarcity = 8*8*8,
|
|
||||||
clust_num_ores = 8,
|
|
||||||
clust_size = 3,
|
|
||||||
y_min = -31000,
|
|
||||||
y_max = 64,
|
|
||||||
})
|
|
||||||
|
|
||||||
core.register_decoration({
|
|
||||||
deco_type = "simple",
|
|
||||||
place_on = "soils:clay_soil_baren",
|
|
||||||
sidelen = 8,
|
|
||||||
fill_ratio = 0.1,
|
|
||||||
decoration = "plants:plants",
|
|
||||||
})
|
|
||||||
52
mods/ENVIRONMENT/mapGenerator/init.lua
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
-- World generation occurs in a separate thread (MapGen Environment).
|
||||||
|
-- But for the main thread, the mapgenerator object is also initialized.
|
||||||
|
|
||||||
|
local mapGeneneratorRequire = Mod.getInfo('smc__core__map_generator').require
|
||||||
|
|
||||||
|
-- Main env init
|
||||||
|
local mapGenerator = mapGeneneratorRequire('mapGenerator')
|
||||||
|
|
||||||
|
-- Async env init
|
||||||
|
core.register_mapgen_script(core.get_modpath('smc__core__map_generator')..'/src/asyncInit.lua')
|
||||||
|
|
||||||
|
|
||||||
|
-- --- Register vanilla ores & decorations ---
|
||||||
|
-- For now, the generation does not have its own support
|
||||||
|
-- for the generation of ores and decorations, so vanilla ones are used.
|
||||||
|
|
||||||
|
core.register_ore({
|
||||||
|
ore_type = "scatter",
|
||||||
|
ore = "soils:rocky_soil_baren",
|
||||||
|
wherein = "rocks:sylite",
|
||||||
|
clust_scarcity = 8*8*8,
|
||||||
|
clust_num_ores = 8,
|
||||||
|
clust_size = 3,
|
||||||
|
y_min = -31000,
|
||||||
|
y_max = 64,
|
||||||
|
})
|
||||||
|
|
||||||
|
core.register_decoration({
|
||||||
|
deco_type = "simple",
|
||||||
|
place_on = "soils:turf_swamp",
|
||||||
|
sidelen = 8,
|
||||||
|
fill_ratio = 0.4,
|
||||||
|
decoration = "plants:plants",
|
||||||
|
})
|
||||||
|
|
||||||
|
core.register_decoration({
|
||||||
|
deco_type = "simple",
|
||||||
|
place_on = "soils:turf_swamp",
|
||||||
|
sidelen = 8,
|
||||||
|
fill_ratio = 0.05,
|
||||||
|
decoration = "plants:plant0",
|
||||||
|
})
|
||||||
|
|
||||||
|
core.register_decoration({
|
||||||
|
deco_type = "simple",
|
||||||
|
place_on = "soils:turf_swamp",
|
||||||
|
sidelen = 8,
|
||||||
|
fill_ratio = 0.01,
|
||||||
|
decoration = "plants:plant2",
|
||||||
|
})
|
||||||
|
|
||||||
|
return mapGenerator
|
||||||
44
mods/ENVIRONMENT/mapGenerator/src/asyncInit.lua
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
-- MAPGEN ENVIROMENT ONLY
|
||||||
|
-- https://api.luanti.org/core-namespace-reference/#mapgen-environment
|
||||||
|
|
||||||
|
-- This environment is isolated from the main environment,
|
||||||
|
-- so global tables need to be preloaded manually.
|
||||||
|
|
||||||
|
-- --- Global APIs load --
|
||||||
|
-- Class
|
||||||
|
dofile(core.get_modpath('smc__system__class')..'/init.lua')
|
||||||
|
|
||||||
|
-- Ensure
|
||||||
|
dofile(core.get_modpath('smc__system__ensure')..'/init.lua')
|
||||||
|
|
||||||
|
-- Logger
|
||||||
|
dofile(core.get_modpath('smc__system__logger')..'/init.lua')
|
||||||
|
|
||||||
|
-- Math
|
||||||
|
dofile(core.get_modpath('smc__system__math')..'/init.lua')
|
||||||
|
|
||||||
|
-- Require
|
||||||
|
dofile(core.get_modpath('smc__system__require')..'/init.lua')
|
||||||
|
|
||||||
|
-- Mod
|
||||||
|
dofile(core.get_modpath('smc__system__mod')..'/init.lua')
|
||||||
|
|
||||||
|
-- TODO: исправить загрузку строковых библиотек (хотя они пока что не юзаются в мапгене)
|
||||||
|
-- Они не работают из-за get_current_modname внутри utf8
|
||||||
|
-- UTF-8
|
||||||
|
-- dofile(core.get_modpath('smc__system__utf8')..'/init.lua')
|
||||||
|
|
||||||
|
-- String
|
||||||
|
-- dofile(core.get_modpath('smc__system__string')..'/init.lua')
|
||||||
|
|
||||||
|
-- Table
|
||||||
|
dofile(core.get_modpath('smc__system__table')..'/init.lua')
|
||||||
|
|
||||||
|
-- TODO: пока что закоментировано, поскольку вызывает ошибку из-за global_step
|
||||||
|
-- Smc lib loader
|
||||||
|
-- dofile(core.get_modpath('smc__system__helper_lib')..'/init.lua')
|
||||||
|
|
||||||
|
---@type MapGen
|
||||||
|
local mapGenerator = dofile(core.get_modpath('smc__core__map_generator')..'/src/mapGenerator.lua')
|
||||||
|
|
||||||
|
mapGenerator:run()
|
||||||
255
mods/ENVIRONMENT/mapGenerator/src/mapGenerator.lua
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
-- --- MapGen definiton ---
|
||||||
|
local id = core.get_content_id
|
||||||
|
|
||||||
|
local mathRound = math.round
|
||||||
|
|
||||||
|
local mapGenRequire = Mod.getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
|
---@type MapGen
|
||||||
|
local MapGen = mapGenRequire('MapGen')
|
||||||
|
|
||||||
|
---@type MapGen
|
||||||
|
local mapGenerator = MapGen:new({
|
||||||
|
nodes = {
|
||||||
|
-- Special nodes
|
||||||
|
air = 'air',
|
||||||
|
|
||||||
|
-- Rocks
|
||||||
|
sylite = 'rocks:sylite',
|
||||||
|
tauitite = 'rocks:tauitite',
|
||||||
|
iyellite = 'rocks:iyellite',
|
||||||
|
falmyte = 'rocks:falmyte',
|
||||||
|
hapcoryte = 'rocks:hapcoryte',
|
||||||
|
burcite = 'rocks:burcite',
|
||||||
|
felhor = 'rocks:felhor',
|
||||||
|
malachite = 'rocks:malachite',
|
||||||
|
|
||||||
|
-- Liquids
|
||||||
|
water = 'liquids:water_source',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
local function calcTemp(layer, value, height)
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
|
local function calcHumidity(layer, value, height)
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
|
mapGenerator:registerLayer('midgard', {
|
||||||
|
minY = -256,
|
||||||
|
maxY = 256,
|
||||||
|
minTemp = -100,
|
||||||
|
maxTemp = 100,
|
||||||
|
minHumidity = 0,
|
||||||
|
maxHumidity = 100,
|
||||||
|
calcTemp = calcTemp,
|
||||||
|
calcHumidity = calcHumidity,
|
||||||
|
biomesVerticalScattering = 5,
|
||||||
|
biomesGorizontalScattering = 5
|
||||||
|
})
|
||||||
|
|
||||||
|
local land1 = {
|
||||||
|
offset = -20,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
local land2 = {
|
||||||
|
offset = 10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 30, y = 30, z = 30},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
local climat1 = {
|
||||||
|
offset = 80,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 8,
|
||||||
|
persistence = 0.6,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
local climat2 = {
|
||||||
|
offset = 30,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 8,
|
||||||
|
persistence = 0.6,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
local climat0 = {
|
||||||
|
offset = 50,
|
||||||
|
scale = 0,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 8,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
local v = vector.new
|
||||||
|
--[[
|
||||||
|
mapGenerator:register2DPeaks('midgard',
|
||||||
|
{
|
||||||
|
landscapeNoise = land1,
|
||||||
|
tempNoise = climat2,
|
||||||
|
humidityNoise = climat2,
|
||||||
|
},{
|
||||||
|
v(500, 0, 500),
|
||||||
|
v(-500, 0, -500),
|
||||||
|
v(-500, 0, 500),
|
||||||
|
v(500, 0, -500),
|
||||||
|
})
|
||||||
|
|
||||||
|
mapGenerator:register2DPeaks('midgard',
|
||||||
|
{
|
||||||
|
landscapeNoise = land2,
|
||||||
|
tempNoise = climat1,
|
||||||
|
humidityNoise = climat1,
|
||||||
|
},{
|
||||||
|
v(-300, 0, 300),
|
||||||
|
v(200, 0, -400),
|
||||||
|
})
|
||||||
|
|
||||||
|
mapGenerator:register2DPeaks('midgard',
|
||||||
|
{
|
||||||
|
landscapeNoise = land2,
|
||||||
|
tempNoise = climat2,
|
||||||
|
humidityNoise = climat2,
|
||||||
|
},{
|
||||||
|
v(200, 0, 100),
|
||||||
|
v(-300, 0, -200),
|
||||||
|
})--]]
|
||||||
|
|
||||||
|
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#4978c6', land1)
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#77ea72', land2)
|
||||||
|
end
|
||||||
|
|
||||||
|
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 64,{x=8, y=8}, 'landscape')
|
||||||
|
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 100,{x=8, y=8}, 'temp')
|
||||||
|
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 100,{x=8, y=8}, 'humidity')
|
||||||
|
|
||||||
|
--[[
|
||||||
|
mapGenerator:registerCavern('midgard', 'cavern1', {
|
||||||
|
minY = -48,
|
||||||
|
maxY = 0,
|
||||||
|
smoothDistance = 20,
|
||||||
|
threshold = 0.3,
|
||||||
|
noiseParams ={
|
||||||
|
offset = 0,
|
||||||
|
scale = 1,
|
||||||
|
spread = {x = 25, y = 25, z = 25},
|
||||||
|
seed = 5934,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 2.0
|
||||||
|
},
|
||||||
|
})--]]
|
||||||
|
|
||||||
|
-- --- Biomes ---
|
||||||
|
|
||||||
|
---@type ValueNoise
|
||||||
|
local rocksNoise
|
||||||
|
|
||||||
|
---@type NoiseParams
|
||||||
|
local rocksNoiseParams ={
|
||||||
|
offset = 4,
|
||||||
|
scale = 2,
|
||||||
|
spread = {x = 30, y = 30, z = 30},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function generateRock(biome, mapGenerator, data, index, x, y, z)
|
||||||
|
local ids = mapGenerator.nodeIDs
|
||||||
|
|
||||||
|
if rocksNoise == nil then
|
||||||
|
rocksNoise = core.get_value_noise(rocksNoiseParams)
|
||||||
|
end
|
||||||
|
|
||||||
|
local noiseRocksValue = mathRound(rocksNoise:get_3d({x = x, y = y, z = z}))
|
||||||
|
if noiseRocksValue == 1 then
|
||||||
|
data[index] = ids.malachite
|
||||||
|
elseif noiseRocksValue == 2 then
|
||||||
|
data[index] = ids.hapcoryte
|
||||||
|
elseif noiseRocksValue == 3 then
|
||||||
|
data[index] = ids.iyellite
|
||||||
|
elseif noiseRocksValue == 4 then
|
||||||
|
data[index] = ids.sylite
|
||||||
|
elseif noiseRocksValue == 5 then
|
||||||
|
data[index] = ids.tauitite
|
||||||
|
elseif noiseRocksValue == 6 then
|
||||||
|
data[index] = ids.falmyte
|
||||||
|
elseif noiseRocksValue == 7 then
|
||||||
|
data[index] = ids.burcite
|
||||||
|
elseif noiseRocksValue == 8 then
|
||||||
|
data[index] = ids.felhor
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param biome MapGen.Biome
|
||||||
|
local function generateSoil(biome, mapGenerator, data, index, x, y, z)
|
||||||
|
local ids = mapGenerator.nodeIDs
|
||||||
|
if rocksNoise == nil then
|
||||||
|
rocksNoise = core.get_value_noise(rocksNoiseParams)
|
||||||
|
end
|
||||||
|
|
||||||
|
local noiseRocksValue = mathRound(rocksNoise:get_3d({x = x, y = y, z = z}))
|
||||||
|
|
||||||
|
if noiseRocksValue > 4 then
|
||||||
|
data[index] = ids.sylite
|
||||||
|
else
|
||||||
|
data[index] = biome.groundNodesIDs.soil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param biome MapGen.Biome
|
||||||
|
local function generateTurf(biome, mapGenerator, data, index, x, y, z)
|
||||||
|
local ids = mapGenerator.nodeIDs
|
||||||
|
if rocksNoise == nil then
|
||||||
|
rocksNoise = core.get_value_noise(rocksNoiseParams)
|
||||||
|
end
|
||||||
|
|
||||||
|
local noiseRocksValue = mathRound(rocksNoise:get_3d({x = x, y = y, z = z}))
|
||||||
|
|
||||||
|
if noiseRocksValue > 4 then
|
||||||
|
data[index] = ids.sylite
|
||||||
|
else
|
||||||
|
data[index] = biome.groundNodesIDs.turf
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
mapGenerator:registerBiome('midgard', 'swamp', {
|
||||||
|
tempPoint = 0,
|
||||||
|
humidityPoint = 80,
|
||||||
|
minY = 100,
|
||||||
|
maxY = 0,
|
||||||
|
groundNodes = {
|
||||||
|
soil = 'soils:rocky_soil_baren',
|
||||||
|
turf = 'soils:turf_swamp',
|
||||||
|
rock = 'rocks:sylite',
|
||||||
|
bottom = 'soils:rocky_soil_baren',
|
||||||
|
},
|
||||||
|
soilHeight = 3,
|
||||||
|
generateRock = generateRock,
|
||||||
|
generateTurf = generateTurf,
|
||||||
|
generateSoil = generateSoil,
|
||||||
|
})
|
||||||
|
|
||||||
|
return mapGenerator
|
||||||
BIN
mods/ENVIRONMENT/mapGenerator/textures/maps/map.ff
Normal file
@@ -1 +1,2 @@
|
|||||||
name = smc__environment
|
name = smc__environment
|
||||||
|
depends = smc__core__map_gen, smc__game__items__rocks, smc__game__items__liquids
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
name = smc__game__items__items_loader
|
name = smc__game__items__items_loader
|
||||||
description = Include this mod in your `depends` to ensure all items are registered
|
description = Include this mod in your `depends` to ensure all items are registered
|
||||||
depends = smc__game__items__rocks, smc__game__items__log, smc__game__items__soils, smc__game__items__liquids
|
depends = smc__game__items__rocks, smc__game__items__wood, smc__game__items__soils, smc__game__items__liquids
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
print(":)")
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
name = smc__game__items__log
|
|
||||||
depends = smc__core__node
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
core.register_node(":plants:plants", {
|
|
||||||
description = 'Plant',
|
|
||||||
drawtype = "plantlike",
|
|
||||||
tiles = { "test_plant.png" },
|
|
||||||
sunlight_propagates = true,
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "meshoptions",
|
|
||||||
place_param2 = 3,
|
|
||||||
waving = 1,
|
|
||||||
walkable = false,
|
|
||||||
buildable_to = true,
|
|
||||||
groups = {dig_immediate = 2},
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 },
|
|
||||||
},
|
|
||||||
on_construct = function(pos)
|
|
||||||
local node = core.get_node(pos)
|
|
||||||
|
|
||||||
node.param2 = 3
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -1,7 +1,11 @@
|
|||||||
|
---@type Node
|
||||||
|
local Node = Mod.getInfo('smc__core__node').require('Node')
|
||||||
|
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
local defaultLiquidDef = {
|
local defaultLiquidDef = {
|
||||||
settings = {
|
settings = {
|
||||||
name = '',
|
name = '',
|
||||||
|
addModName = false,
|
||||||
tiles = {},
|
tiles = {},
|
||||||
waving = 3,
|
waving = 3,
|
||||||
use_texture_alpha = "blend",
|
use_texture_alpha = "blend",
|
||||||
@@ -19,7 +23,7 @@ local defaultLiquidDef = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
---@type Node
|
---@type Node
|
||||||
local defaultLiquid = Core.Node.Class:getExtended(defaultLiquidDef)
|
local defaultLiquid = Node:getExtended(defaultLiquidDef)
|
||||||
|
|
||||||
local liquidFactory = defaultLiquid:getFactory()
|
local liquidFactory = defaultLiquid:getFactory()
|
||||||
|
|
||||||
@@ -91,4 +95,4 @@ liquidFactory:registerItems({
|
|||||||
paramtype2 = "flowingliquid",
|
paramtype2 = "flowingliquid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, false)
|
})
|
||||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
29
mods/GAME/ITEMS/plants/init.lua
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__plant')
|
||||||
|
|
||||||
|
---@type TileSheet
|
||||||
|
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
|
||||||
|
|
||||||
|
---@type Plant
|
||||||
|
local Plant = modInfo.require('Plant')
|
||||||
|
|
||||||
|
Plant:new({
|
||||||
|
settings = {
|
||||||
|
name = 'plants',
|
||||||
|
tiles = { "test_plant.png" },
|
||||||
|
place_param2 = 3,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
local ts = TileSheet:new('plants_test_sheet.png', 16, 16)
|
||||||
|
|
||||||
|
|
||||||
|
for i=0, 3 do
|
||||||
|
Plant:new({
|
||||||
|
settings = {
|
||||||
|
name = 'plant'..tostring(i),
|
||||||
|
title = 'Plant',
|
||||||
|
tiles = { ts:t(i,0) },
|
||||||
|
place_param2 = 3,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
BIN
mods/GAME/ITEMS/plants/textures/sheets/plants_test_sheet.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
mods/GAME/ITEMS/plants/textures/test_plant.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |