Compare commits
71 Commits
d04f3407b4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c3defaaa15 | |||
| 7ccaea2ed0 | |||
| c96bb2c0bc | |||
| 9fa3a0aff7 | |||
| e540107876 | |||
| 1e91290b02 | |||
| 2243ed7532 | |||
| 20ebf5ad75 | |||
| 1fe3200692 | |||
| 24932b5d2e | |||
| af0b7c8beb | |||
| ba8dad4798 | |||
| c2e16834d8 | |||
| 2d3bdf4d02 | |||
| 841d269494 | |||
| ced1397c76 | |||
| 56a9388676 | |||
| 5d3e7b3620 | |||
| f995397f28 | |||
| 9566e0edde | |||
| 316d2cac3b | |||
| 3da8c3a27c | |||
| 266d44eca8 | |||
| d82cd28407 | |||
| 02f7ca2894 | |||
| 7ef96bd434 | |||
| 26a73117a9 | |||
| 87e5304acd | |||
| 600c83ea04 | |||
| e8f547e98b | |||
| c7d2b94603 | |||
| 934a8a8e83 | |||
| 50572e4c6b | |||
| b10f5c314a | |||
| a90c5a31d7 | |||
| f375e0aa19 | |||
| 8c482b9cac | |||
| 92516f7ec4 | |||
| a4249091e0 | |||
| 5a138cdf68 | |||
| bf4966afe4 | |||
| f586121b12 | |||
| 613e7a9c93 | |||
| 7a06e7fffb | |||
| 582658d437 | |||
| 4fcb15424e | |||
| 97711eccb8 | |||
| c380638166 | |||
| ccb89d2990 | |||
| fe8e72cdde | |||
| 87a68f056e | |||
| 6eac20e4f5 | |||
| 4210248343 | |||
| 441fbb8323 | |||
| 467d251681 | |||
| a9c5e54b00 | |||
| 6935673be7 | |||
| be2d28fc90 | |||
| 204cd9b1aa | |||
| aafb0a3600 | |||
| f5c9122560 | |||
| 118f27ae37 | |||
| 9e6bd5d952 | |||
| df5762abf6 | |||
| a504223240 | |||
| b40b8c97c0 | |||
| a41817cc3d | |||
| 6f35ca8d6f | |||
| 6c10201fa9 | |||
| c0fe6c683e | |||
| 80c0f45f34 |
@@ -21,9 +21,7 @@
|
|||||||
"diagnostics": {
|
"diagnostics": {
|
||||||
"libraryFiles": "Enable",
|
"libraryFiles": "Enable",
|
||||||
"workspaceDelay": 1,
|
"workspaceDelay": 1,
|
||||||
"disable": [
|
"disable": [],
|
||||||
"inject-field"
|
|
||||||
],
|
|
||||||
"globals": [
|
"globals": [
|
||||||
// Smc globals:
|
// Smc globals:
|
||||||
"Smc",
|
"Smc",
|
||||||
@@ -48,5 +46,6 @@
|
|||||||
"unbalanced": "Any"
|
"unbalanced": "Any"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"completion.callSnippet": "Both"
|
"completion.callSnippet": "Both",
|
||||||
|
"completion.workspaceWord":false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__base_processing_station')
|
local modInfo = Mod:getInfo('smc__core__base_processing_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('BaseProcessingStation')
|
return require('BaseProcessingStation')
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__base_processing_station
|
name = smc__core__base_processing_station
|
||||||
depends = smc__core__craft_system, smc__core__node
|
depends = smc__core__craft_system, smc__core__node, smc__ui__player_inventory
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__base_ui')
|
local modInfo = Mod:getInfo('smc__core__base_ui')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('BaseUI')
|
return require('BaseUI')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__controls')
|
local modInfo = Mod:getInfo('smc__core__controls')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Controls')
|
return require('Controls')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('CraftSystem')
|
return require('CraftSystem')
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__craft_system
|
name = smc__core__craft_system
|
||||||
depends = smc__system__system_loader, smc__core__creature
|
depends = smc__system__system_loader, smc__core__creature, smc__core__progression_system
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local tableJoin = table.join
|
local tableJoin = table.join
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.PrimitiveCraftHandler
|
---@type CraftSystem.PrimitiveCraftHandler
|
||||||
@@ -134,7 +134,7 @@ local function getMaterials(craft, recipeIndex, count)
|
|||||||
local materialStacks = {}
|
local materialStacks = {}
|
||||||
local materialGroups = {}
|
local materialGroups = {}
|
||||||
|
|
||||||
for _, itemName in ipairs(craft:getRecipe(recipeIndex)) do
|
for _, itemName in ipairs(craft.recipe) do
|
||||||
local group = itemName:match('group:(%S+)')
|
local group = itemName:match('group:(%S+)')
|
||||||
local materialCount = itemName:match('group:%S+ (%S+)') or 1
|
local materialCount = itemName:match('group:%S+ (%S+)') or 1
|
||||||
|
|
||||||
@@ -205,9 +205,19 @@ end
|
|||||||
---@return boolean check true if craft can be produced
|
---@return boolean check true if craft can be produced
|
||||||
---@return ItemStack[] materialStacks list of itemStacks for crafting
|
---@return ItemStack[] materialStacks list of itemStacks for crafting
|
||||||
function CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count)
|
function CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count)
|
||||||
|
local OutputStack = ItemStack(craft.output)
|
||||||
|
|
||||||
|
if count <= 0 then
|
||||||
|
Logger.warningLog('`CraftSystem:checkPossiblePlayerInventoryCrafting()`: param `count` <= 0. '..
|
||||||
|
'Was force-reset to `1`. '..
|
||||||
|
'Info: value: `%s`, player: `%s`, craft: `%s`',
|
||||||
|
count, player:get_player_name(), craft.name
|
||||||
|
)
|
||||||
|
count = 1
|
||||||
|
end
|
||||||
|
|
||||||
local inventory = player:get_inventory()
|
local inventory = player:get_inventory()
|
||||||
|
|
||||||
local OutputStack = ItemStack(craft.output)
|
|
||||||
OutputStack:set_count(OutputStack:get_count() * count)
|
OutputStack:set_count(OutputStack:get_count() * count)
|
||||||
|
|
||||||
local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count)
|
local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count)
|
||||||
|
|||||||
@@ -4,17 +4,20 @@ local CHECK = {YES = '[x]', NO = '[ ]', EMPTY = '-'}
|
|||||||
|
|
||||||
---@class CraftSystem.BaseCraft : Class
|
---@class CraftSystem.BaseCraft : Class
|
||||||
---@field name string
|
---@field name string
|
||||||
|
---@field hidden boolean?
|
||||||
---@field recipe ItemStackString[]
|
---@field recipe ItemStackString[]
|
||||||
---@field altRecipes CraftSystem.CraftRecipe[]
|
|
||||||
---@field output ItemStackString
|
---@field output ItemStackString
|
||||||
|
---@field age ProgressionSystem.Age.Name,
|
||||||
|
---@field milestone string?
|
||||||
---@field group CraftSystem.CraftGroup
|
---@field group CraftSystem.CraftGroup
|
||||||
local BaseCraft = Class:extend({})
|
local BaseCraft = Class:extend({})
|
||||||
|
|
||||||
---Definition table for the `CraftSystem.BaseCraft`.
|
---Definition table for the `CraftSystem.BaseCraft`.
|
||||||
---@class CraftSystem.BaseCraftDef
|
---@class CraftSystem.BaseCraftDef
|
||||||
---@field recipe ItemStackString[]
|
---@field recipe ItemStackString[]
|
||||||
---@field altRecipes CraftSystem.CraftRecipe[]?
|
|
||||||
---@field output ItemStackString
|
---@field output ItemStackString
|
||||||
|
---@field age ProgressionSystem.Age.Name?
|
||||||
|
---@field milestone string?
|
||||||
---@field group CraftSystem.CraftGroup?
|
---@field group CraftSystem.CraftGroup?
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
@@ -25,8 +28,9 @@ function BaseCraft:new(name, def)
|
|||||||
local instance = self:getInstance({})
|
local instance = self:getInstance({})
|
||||||
instance.name = name
|
instance.name = name
|
||||||
instance.recipe = def.recipe
|
instance.recipe = def.recipe
|
||||||
instance.altRecipes = def.altRecipes or {}
|
|
||||||
instance.output = def.output
|
instance.output = def.output
|
||||||
|
instance.age = def.age
|
||||||
|
instance.milestone = def.milestone
|
||||||
instance.group = def.group
|
instance.group = def.group
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
@@ -80,46 +84,11 @@ local function getCheckMaterialGroup(material, count, list)
|
|||||||
return CHECK.NO
|
return CHECK.NO
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns the crafting recipe corresponding to the index.
|
|
||||||
---@param index integer Recipe number. If `0` is specified,
|
|
||||||
--- the primary craft (`craft.recipe`) will be used;
|
|
||||||
--- if `1` or greater, the alternative craft
|
|
||||||
--- corresponding to the index will be used (`craft.altRecipes`).
|
|
||||||
---@return CraftSystem.CraftRecipe
|
|
||||||
function BaseCraft:getRecipe(index)
|
|
||||||
local recipe
|
|
||||||
if index == 0 or self.altRecipes == nil then
|
|
||||||
recipe = self.recipe
|
|
||||||
else
|
|
||||||
if index > #self.altRecipes then
|
|
||||||
recipe = self.altRecipes[#self.altRecipes]
|
|
||||||
else
|
|
||||||
recipe = self.altRecipes[index]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
assert(recipe ~= nil)
|
|
||||||
|
|
||||||
return recipe
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param recipeIndex integer?
|
|
||||||
---@param mainList ItemStack[]?
|
---@param mainList ItemStack[]?
|
||||||
---@return string
|
---@return string
|
||||||
function BaseCraft:recipeToString(recipeIndex, mainList)
|
function BaseCraft:recipeToString(mainList)
|
||||||
local recipe
|
|
||||||
if recipeIndex == nil or recipeIndex == 0 or self.altRecipes == nil then
|
|
||||||
recipe = self.recipe
|
|
||||||
else
|
|
||||||
if recipeIndex > #self.altRecipes then
|
|
||||||
recipe = self.altRecipes[#self.altRecipes]
|
|
||||||
else
|
|
||||||
recipe = self.altRecipes[recipeIndex]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
assert(recipe ~= nil)
|
|
||||||
|
|
||||||
local recipeDesc = ''
|
local recipeDesc = ''
|
||||||
for _, itemName in ipairs(recipe) do
|
for _, itemName in ipairs(self.recipe) do
|
||||||
local group, count = itemName:match('group:(%S+)'), itemName:match('group:%S+ (%S+)') or 1
|
local group, count = itemName:match('group:(%S+)'), itemName:match('group:%S+ (%S+)') or 1
|
||||||
|
|
||||||
if group == nil then
|
if group == nil then
|
||||||
@@ -139,16 +108,15 @@ function BaseCraft:recipeToString(recipeIndex, mainList)
|
|||||||
return recipeDesc
|
return recipeDesc
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param recipeIndex integer?
|
|
||||||
---@param mainList ItemStack[]?
|
---@param mainList ItemStack[]?
|
||||||
---@return string
|
---@return string
|
||||||
function BaseCraft:toString(recipeIndex, mainList)
|
function BaseCraft:toString(mainList)
|
||||||
local outputItem = ItemStack(self.output)
|
local outputItem = ItemStack(self.output)
|
||||||
local outputItemSettings = Smc.getItemDefinition(outputItem).settings
|
local outputItemSettings = Smc.getItemDefinition(outputItem).settings
|
||||||
|
|
||||||
local craftDesc = ('%s\n\nNeeded:\n%s'):format(
|
local craftDesc = ('%s\n\nNeeded:\n%s'):format(
|
||||||
outputItemSettings._title,
|
outputItemSettings._title,
|
||||||
self:recipeToString(recipeIndex, mainList))
|
self:recipeToString(mainList))
|
||||||
|
|
||||||
return craftDesc
|
return craftDesc
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
local tableInsert = table.insert
|
local assert, pairs, ipairs = assert, pairs, ipairs
|
||||||
local stringMatch = string.match
|
|
||||||
|
|
||||||
local PLAYERS_KNOW_ALL_RECIPES = true
|
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
||||||
|
local stringMatch, stringLower = string.match, string_utf8.lower
|
||||||
|
|
||||||
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
|
---@type CraftSystem.BaseCraftHandler.PlayerCraftsCache
|
||||||
|
local PlayerCraftsCache = require('CraftSystem.BaseCraftHandler.PlayerCraftsCache')
|
||||||
|
---@type CraftSystem.BaseCraftHandler.ProgressionCraftsCache
|
||||||
|
local ProgressionCraftsCache = require('CraftSystem.BaseCraftHandler.ProgressionCraftsCache')
|
||||||
|
|
||||||
|
local PLAYERS_KNOW_ALL_RECIPES = false
|
||||||
|
|
||||||
---Abstract class for handling crafting.
|
---Abstract class for handling crafting.
|
||||||
---@class CraftSystem.BaseCraftHandler : Class
|
---@class CraftSystem.BaseCraftHandler : Class
|
||||||
@@ -11,17 +20,25 @@ local PLAYERS_KNOW_ALL_RECIPES = true
|
|||||||
---
|
---
|
||||||
---@field craftsByName table<string, CraftSystem.BaseCraft>
|
---@field craftsByName table<string, CraftSystem.BaseCraft>
|
||||||
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.BaseCraft[]>
|
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.BaseCraft[]>
|
||||||
|
---@field craftsByOutput table<ItemStackString, CraftSystem.BaseCraft[]>
|
||||||
---@field craftsList CraftSystem.BaseCraft[]
|
---@field craftsList CraftSystem.BaseCraft[]
|
||||||
---@field groupedCrafts (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]
|
---@field groupedCrafts (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]
|
||||||
---@field learnedCrafts table<string, CraftSystem.BaseCraft[]>
|
---
|
||||||
---@field learnedGroupedCrafts table<string, (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]>
|
---@field playersCraftsCache table<string, CraftSystem.BaseCraftHandler.PlayerCraftsCache>
|
||||||
|
---
|
||||||
|
---@field agesCrafts table<ProgressionSystem.Age.Name, CraftSystem.BaseCraftHandler.ProgressionCraftsCache>
|
||||||
|
---@field milestonesCrafts table<ProgressionSystem.Age.Name, table<string, CraftSystem.BaseCraftHandler.ProgressionCraftsCache>>
|
||||||
local BaseCraftHandler = Class:extend({
|
local BaseCraftHandler = Class:extend({
|
||||||
craftsByName = {},
|
craftsByName = {},
|
||||||
craftsByGroup = {},
|
craftsByGroup = {},
|
||||||
|
craftsByOutput = {},
|
||||||
craftsList = {},
|
craftsList = {},
|
||||||
groupedCrafts = {},
|
groupedCrafts = {},
|
||||||
learnedCrafts = {},
|
|
||||||
learnedGroupedCrafts = {},
|
playersCraftsCache = {},
|
||||||
|
|
||||||
|
agesCrafts = {},
|
||||||
|
milestonesCrafts = {},
|
||||||
})
|
})
|
||||||
|
|
||||||
---@class CraftSystem.BaseCraftHandlerDef
|
---@class CraftSystem.BaseCraftHandlerDef
|
||||||
@@ -38,16 +55,111 @@ function BaseCraftHandler:new(baseType, type, def)
|
|||||||
instance.type = type
|
instance.type = type
|
||||||
instance.defaultCraftDef = def.defaultCraftDef or {}
|
instance.defaultCraftDef = def.defaultCraftDef or {}
|
||||||
|
|
||||||
|
-- Initializing the temporary crafting cache for players.
|
||||||
|
core.register_on_joinplayer(function (player, last_login)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
local cache = PlayerCraftsCache:new(playerName)
|
||||||
|
cache:update(instance.agesCrafts, instance.agesCrafts)
|
||||||
|
|
||||||
|
instance.playersCraftsCache[playerName] = cache
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Clearing the temporary crafting cache for players.
|
||||||
|
core.register_on_leaveplayer(function (player, timed_out)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
instance.playersCraftsCache[playerName] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Initializing the list of crafts by groups.
|
||||||
|
core.register_on_mods_loaded(function()
|
||||||
|
for groupName, crafts in pairs(instance.craftsByGroup) do
|
||||||
|
tableSort(crafts, function(a, b)
|
||||||
|
if a.output < b.output then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
if groupName ~= 'craft_group:UNDEFINED' then
|
||||||
|
tableInsert(instance.groupedCrafts, crafts)
|
||||||
|
else
|
||||||
|
instance.groupedCrafts = tableJoin(instance.groupedCrafts, crafts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tableSort(instance.groupedCrafts, function(a, b)
|
||||||
|
local outputA = (a[1] and a[1].output) or a.output
|
||||||
|
local outputB = (b[1] and b[1].output) or b.output
|
||||||
|
|
||||||
|
if outputA < outputB then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Adds craft to its corresponding progression caches.
|
||||||
|
---@param craft CraftSystem.BaseCraft
|
||||||
|
function BaseCraftHandler:addCraftToProgressionTable(craft)
|
||||||
|
local age = craft.age or 'zero'
|
||||||
|
local milestone = craft.milestone
|
||||||
|
|
||||||
|
if milestone ~= nil then
|
||||||
|
if self.milestonesCrafts[age] == nil then
|
||||||
|
self.milestonesCrafts[age] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.milestonesCrafts[age][milestone] == nil then
|
||||||
|
self.milestonesCrafts[age][milestone] = ProgressionCraftsCache:new()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.milestonesCrafts[age][milestone]:addCraft(craft)
|
||||||
|
else
|
||||||
|
if self.agesCrafts[age] == nil then
|
||||||
|
self.agesCrafts[age] = ProgressionCraftsCache:new()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.agesCrafts[age]:addCraft(craft)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Returns a temporary cache of the player's crafts.
|
||||||
|
---
|
||||||
|
---If the player is not online, an error will be raised.
|
||||||
|
---@param playerName string
|
||||||
|
---@return CraftSystem.BaseCraftHandler.PlayerCraftsCache
|
||||||
|
function BaseCraftHandler:getPlayerCraftsCache(playerName)
|
||||||
|
local cache = self.playersCraftsCache[playerName]
|
||||||
|
assert(cache ~= nil)
|
||||||
|
|
||||||
|
return cache
|
||||||
|
end
|
||||||
|
|
||||||
---@param craftName string
|
---@param craftName string
|
||||||
---@return CraftSystem.BaseCraft
|
---@return CraftSystem.BaseCraft
|
||||||
function BaseCraftHandler:getCraftByName(craftName)
|
function BaseCraftHandler:getCraftByName(craftName)
|
||||||
local craft = self.craftsByName[craftName]
|
local craft = self.craftsByName[craftName]
|
||||||
|
|
||||||
assert(craft ~= nil, ('A craft `%s` not exists.'):format(
|
assert(craft ~= nil, ('A craft `%s` not exists.'):format(craftName))
|
||||||
craftName))
|
|
||||||
|
return craft
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@return CraftSystem.BaseCraft?
|
||||||
|
function BaseCraftHandler:getLearnedCraftByName(playerName, craftName)
|
||||||
|
if PLAYERS_KNOW_ALL_RECIPES then
|
||||||
|
return self.craftsByName[craftName]
|
||||||
|
end
|
||||||
|
|
||||||
|
local cache = self:getPlayerCraftsCache(playerName)
|
||||||
|
local craft = cache.craftsByName[craftName]
|
||||||
|
|
||||||
return craft
|
return craft
|
||||||
end
|
end
|
||||||
@@ -57,25 +169,64 @@ end
|
|||||||
function BaseCraftHandler:getCraftsByGroup(craftGroup)
|
function BaseCraftHandler:getCraftsByGroup(craftGroup)
|
||||||
local crafts = self.craftsByGroup[craftGroup]
|
local crafts = self.craftsByGroup[craftGroup]
|
||||||
|
|
||||||
assert(crafts ~= nil, ('A craft with group `%s` not exists.'):format(
|
assert(crafts ~= nil, ('A craft with group `%s` not exists.'):format(craftGroup))
|
||||||
craftGroup))
|
|
||||||
|
return crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param craftGroup CraftSystem.CraftGroup
|
||||||
|
---@return CraftSystem.BaseCraft[]?
|
||||||
|
function BaseCraftHandler:getLearnedCraftsByGroup(playerName, craftGroup)
|
||||||
|
if PLAYERS_KNOW_ALL_RECIPES then
|
||||||
|
return self.craftsByGroup[craftGroup]
|
||||||
|
end
|
||||||
|
|
||||||
|
local cache = self:getPlayerCraftsCache(playerName)
|
||||||
|
local crafts = cache.craftsByGroup[craftGroup]
|
||||||
|
|
||||||
|
return crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]
|
||||||
|
function BaseCraftHandler:getGroupedCrafts()
|
||||||
|
return self.groupedCrafts
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param playerName string
|
||||||
|
---@return (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]
|
||||||
|
function BaseCraftHandler:getLearnedGroupedCrafts(playerName)
|
||||||
|
if PLAYERS_KNOW_ALL_RECIPES then
|
||||||
|
return self.groupedCrafts
|
||||||
|
end
|
||||||
|
|
||||||
|
local cache = self:getPlayerCraftsCache(playerName)
|
||||||
|
local crafts = cache.groupedCrafts
|
||||||
|
|
||||||
|
return crafts
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param output ItemStackString
|
||||||
|
---@return CraftSystem.BaseCraft[]?
|
||||||
|
function BaseCraftHandler:getCraftsByOutput(output)
|
||||||
|
output = ItemStack(output):get_name()
|
||||||
|
|
||||||
|
local crafts = self.craftsByOutput[output]
|
||||||
|
|
||||||
return crafts
|
return crafts
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param playerName string
|
---@param playerName string
|
||||||
---@return (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]
|
---@param output ItemStackString
|
||||||
function BaseCraftHandler:getLearnedCrafts(playerName)
|
---@return CraftSystem.BaseCraft[]?
|
||||||
|
function BaseCraftHandler:getLearnedCraftsByOutput(playerName, output)
|
||||||
|
output = ItemStack(output):get_name()
|
||||||
|
|
||||||
if PLAYERS_KNOW_ALL_RECIPES then
|
if PLAYERS_KNOW_ALL_RECIPES then
|
||||||
return self.groupedCrafts
|
return self.craftsByOutput[output]
|
||||||
end
|
end
|
||||||
|
|
||||||
local crafts = self.learnedGroupedCrafts[playerName]
|
local cache = self:getPlayerCraftsCache(playerName)
|
||||||
|
local crafts = cache.craftsByOutput[output]
|
||||||
if crafts == nil then
|
|
||||||
crafts = {}
|
|
||||||
self.learnedGroupedCrafts[playerName] = crafts
|
|
||||||
end
|
|
||||||
|
|
||||||
return crafts
|
return crafts
|
||||||
end
|
end
|
||||||
@@ -84,18 +235,11 @@ end
|
|||||||
---@param pattern string
|
---@param pattern string
|
||||||
---@return CraftSystem.BaseCraft[]
|
---@return CraftSystem.BaseCraft[]
|
||||||
local function getMathedCrafts(crafts, pattern)
|
local function getMathedCrafts(crafts, pattern)
|
||||||
local pattern = string_utf8.lower(pattern)
|
local pattern = stringLower(pattern)
|
||||||
local matchedCrafts = {}
|
local matchedCrafts = {}
|
||||||
|
|
||||||
for _, craft in ipairs(crafts) do
|
for _, craft in ipairs(crafts) do
|
||||||
local outputItem = ItemStack(craft.output)
|
if Smc.matchItemDescription(ItemStack(craft.output):get_name(), pattern) then
|
||||||
local itemSettings = Smc.getItemDefinition(outputItem).settings
|
|
||||||
local ruName = string_utf8.lower(core.get_translated_string('ru', itemSettings._title))
|
|
||||||
local enName = string_utf8.lower(core.get_translated_string('en', itemSettings._title))
|
|
||||||
|
|
||||||
if stringMatch(outputItem:get_name(), pattern) or
|
|
||||||
stringMatch(ruName, pattern) or
|
|
||||||
stringMatch(enName, pattern) then
|
|
||||||
tableInsert(matchedCrafts, craft)
|
tableInsert(matchedCrafts, craft)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -103,6 +247,12 @@ local function getMathedCrafts(crafts, pattern)
|
|||||||
return matchedCrafts
|
return matchedCrafts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param pattern string
|
||||||
|
---@return CraftSystem.BaseCraft[]
|
||||||
|
function BaseCraftHandler:getCraftsMatch(pattern)
|
||||||
|
return getMathedCrafts(self.craftsList, pattern)
|
||||||
|
end
|
||||||
|
|
||||||
---@param playerName string
|
---@param playerName string
|
||||||
---@param pattern string
|
---@param pattern string
|
||||||
---@return CraftSystem.BaseCraft[]
|
---@return CraftSystem.BaseCraft[]
|
||||||
@@ -111,16 +261,10 @@ function BaseCraftHandler:getLearnedCraftsMatch(playerName, pattern)
|
|||||||
return getMathedCrafts(self.craftsList, pattern)
|
return getMathedCrafts(self.craftsList, pattern)
|
||||||
end
|
end
|
||||||
|
|
||||||
local crafts = self.learnedCrafts[playerName]
|
local cache = self:getPlayerCraftsCache(playerName)
|
||||||
|
local crafts = getMathedCrafts(cache.craftsList, pattern)
|
||||||
if crafts == nil then
|
|
||||||
crafts = {}
|
|
||||||
self.learnedCrafts[playerName] = crafts
|
|
||||||
end
|
|
||||||
|
|
||||||
return crafts
|
return crafts
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO: сохранять выученные крафты игроков в сторадже
|
|
||||||
|
|
||||||
return BaseCraftHandler
|
return BaseCraftHandler
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
local assert, pairs = assert, pairs
|
||||||
|
|
||||||
|
local tableMerge, tableJoin, tableInsert, tableSort = table.merge, table.join, table.insert, table.sort
|
||||||
|
|
||||||
|
local ProgressionSystem = Smc.requireProgressionSystem()
|
||||||
|
|
||||||
|
---A player's temporary cache containing known crafts
|
||||||
|
---in the form of lists of various sorting types.
|
||||||
|
---
|
||||||
|
---Designed for quick access to the player's learned crafts.
|
||||||
|
---
|
||||||
|
---Initialized when a player joins the server and cleared when the player leaves the server.
|
||||||
|
---
|
||||||
|
---For more details see [BaseCraftHandler:new()](lua://CraftSystem.BaseCraftHandler)
|
||||||
|
---@class CraftSystem.BaseCraftHandler.PlayerCraftsCache : Class
|
||||||
|
---@field playerName string
|
||||||
|
---
|
||||||
|
---@field craftsByName table<string, CraftSystem.BaseCraft>
|
||||||
|
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.BaseCraft[]>
|
||||||
|
---@field craftsByOutput table<ItemStackString, CraftSystem.BaseCraft[]>
|
||||||
|
---@field craftsList CraftSystem.BaseCraft[]
|
||||||
|
---@field groupedCrafts (CraftSystem.BaseCraft[]|CraftSystem.BaseCraft)[]
|
||||||
|
local PlayerCraftsCache = Class:extend({
|
||||||
|
craftsByName = {},
|
||||||
|
craftsByGroup = {},
|
||||||
|
craftsByOutput = {},
|
||||||
|
craftsList = {},
|
||||||
|
groupedCrafts = {},
|
||||||
|
})
|
||||||
|
|
||||||
|
---@param playerName string
|
||||||
|
---@return CraftSystem.BaseCraftHandler.PlayerCraftsCache
|
||||||
|
function PlayerCraftsCache:new(playerName)
|
||||||
|
local instance = self:getInstance({})
|
||||||
|
instance.playerName = playerName
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---Adds all crafts from the passed cache to the player's cache.
|
||||||
|
---
|
||||||
|
---**Note**: Doesn't init (update) the list of grouped recipes (`self.groupedCrafts`).
|
||||||
|
---
|
||||||
|
---To initialize (update), use `self:initGroupedCrafts()`.
|
||||||
|
---@param cache CraftSystem.BaseCraftHandler.ProgressionCraftsCache
|
||||||
|
function PlayerCraftsCache:addCraftsByProgressionCache(cache)
|
||||||
|
self.craftsByName = tableMerge(self.craftsByName, cache.craftsByName, false)
|
||||||
|
for group, crafts in pairs(cache.craftsByGroup) do
|
||||||
|
local list = self.craftsByGroup[group]
|
||||||
|
if list == nil then
|
||||||
|
self.craftsByGroup[group] = crafts
|
||||||
|
else
|
||||||
|
self.craftsByGroup[group] = tableJoin(list, crafts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for output, crafts in pairs(cache.craftsByOutput) do
|
||||||
|
local list = self.craftsByOutput[output]
|
||||||
|
if list == nil then
|
||||||
|
self.craftsByOutput[output] = crafts
|
||||||
|
else
|
||||||
|
self.craftsByOutput[output] = tableJoin(list, crafts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.craftsList = tableJoin(self.craftsList, cache.craftsList)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Initializes a list of grouped crafts based
|
||||||
|
---on the crafts contained in the cache (uses `self.craftsByGroup`).
|
||||||
|
function PlayerCraftsCache:initGroupedCrafts()
|
||||||
|
for groupName, crafts in pairs(self.craftsByGroup) do
|
||||||
|
tableSort(crafts, function(a, b)
|
||||||
|
if a.output < b.output then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
if groupName ~= 'craft_group:UNDEFINED' then
|
||||||
|
tableInsert(self.groupedCrafts, crafts)
|
||||||
|
else
|
||||||
|
self.groupedCrafts = tableJoin(self.groupedCrafts, crafts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tableSort(self.groupedCrafts, function(a, b)
|
||||||
|
local outputA = (a[#a] and a[#a].output) or a.output
|
||||||
|
local outputB = (b[#b] and b[#b].output) or b.output
|
||||||
|
|
||||||
|
if outputA < outputB then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Overwrites the player's craft cache based on the passed global progression craft caches.
|
||||||
|
---@param agesCrafts table<ProgressionSystem.Age.Name, CraftSystem.BaseCraftHandler.ProgressionCraftsCache>
|
||||||
|
---@param milestonesCrafts table<ProgressionSystem.Age.Name, table<string, CraftSystem.BaseCraftHandler.ProgressionCraftsCache>>
|
||||||
|
function PlayerCraftsCache:update(agesCrafts, milestonesCrafts)
|
||||||
|
self.craftsByName = {}
|
||||||
|
self.craftsByGroup = {}
|
||||||
|
self.craftsByOutput = {}
|
||||||
|
self.craftsList = {}
|
||||||
|
self.groupedCrafts = {}
|
||||||
|
|
||||||
|
local player = core.get_player_by_name(self.playerName)
|
||||||
|
assert(player ~= nil)
|
||||||
|
|
||||||
|
local playerMeta = player:get_meta()
|
||||||
|
local ageID = ProgressionSystem:getPlayerAge(playerMeta)
|
||||||
|
local milestones = ProgressionSystem:getPlayerMilestones(playerMeta)
|
||||||
|
|
||||||
|
for i = 0, ageID do
|
||||||
|
local ageName = ProgressionSystem:getAgeByID(i).name
|
||||||
|
|
||||||
|
local ageCache = agesCrafts[ageName]
|
||||||
|
if ageCache ~= nil then
|
||||||
|
self:addCraftsByProgressionCache(ageCache)
|
||||||
|
end
|
||||||
|
|
||||||
|
local milestonesList = milestones[ageID] or {}
|
||||||
|
local milestoneCache
|
||||||
|
for milestoneName, _ in pairs(milestonesList) do
|
||||||
|
if milestonesCrafts[ageName] ~= nil then
|
||||||
|
milestoneCache = milestonesCrafts[ageName][milestoneName]
|
||||||
|
|
||||||
|
if milestoneCache ~= nil then
|
||||||
|
self:addCraftsByProgressionCache(milestoneCache)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self:initGroupedCrafts()
|
||||||
|
end
|
||||||
|
|
||||||
|
return PlayerCraftsCache
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
local tableInsert = table.insert
|
||||||
|
|
||||||
|
---Crafting cache for individual stages of global progression.
|
||||||
|
---
|
||||||
|
---Designed to store crafting associated with edges and milestones while the server is running,
|
||||||
|
---allowing for quick access to the crafting list.
|
||||||
|
---@class CraftSystem.BaseCraftHandler.ProgressionCraftsCache : Class
|
||||||
|
---@field craftsByName table<string, CraftSystem.BaseCraft>
|
||||||
|
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.BaseCraft[]>
|
||||||
|
---@field craftsByOutput table<ItemStackString, CraftSystem.BaseCraft[]>
|
||||||
|
---@field craftsList CraftSystem.BaseCraft[]
|
||||||
|
local ProgressionCraftsCache = Class:extend({
|
||||||
|
craftsByName = {},
|
||||||
|
craftsByGroup = {},
|
||||||
|
craftsByOutput = {},
|
||||||
|
craftsList = {},
|
||||||
|
})
|
||||||
|
|
||||||
|
---@return CraftSystem.BaseCraftHandler.ProgressionCraftsCache
|
||||||
|
function ProgressionCraftsCache:new()
|
||||||
|
local instance = self:getInstance({})
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---Adds a craft to the cache.
|
||||||
|
---
|
||||||
|
---**Note**: If `craft.hidden = true`, the craft will not be added to the list of crafts by group.
|
||||||
|
---@param craft CraftSystem.BaseCraft
|
||||||
|
function ProgressionCraftsCache:addCraft(craft)
|
||||||
|
local group = craft.group
|
||||||
|
if self.craftsByGroup[group] == nil and craft.hidden ~= true then
|
||||||
|
self.craftsByGroup[group] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local output = ItemStack(craft.output):get_name()
|
||||||
|
if self.craftsByOutput[output] == nil then
|
||||||
|
self.craftsByOutput[output] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local craftName = craft.name
|
||||||
|
self.craftsByName[craftName] = craft
|
||||||
|
if craft.hidden ~= true then
|
||||||
|
tableInsert(self.craftsByGroup[group], craft)
|
||||||
|
end
|
||||||
|
tableInsert(self.craftsByOutput[output], craft)
|
||||||
|
tableInsert(self.craftsList, craft)
|
||||||
|
end
|
||||||
|
|
||||||
|
return ProgressionCraftsCache
|
||||||
@@ -2,7 +2,7 @@ local v = vector.new
|
|||||||
local assert, ipairs, tostring = assert, ipairs, tostring
|
local assert, ipairs, tostring = assert, ipairs, tostring
|
||||||
local coreChatSendPlayer, coreItemDrop = core.chat_send_player, core.item_drop
|
local coreChatSendPlayer, coreItemDrop = core.chat_send_player, core.item_drop
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
||||||
|
|
||||||
@@ -83,6 +83,15 @@ end
|
|||||||
---@param amount integer
|
---@param amount integer
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function ImmersiveCraft:startCraft(pos, player, amount)
|
function ImmersiveCraft:startCraft(pos, player, amount)
|
||||||
|
if amount <= 0 then
|
||||||
|
Logger.warningLog('`ImmersiveCraft:startCraft()`: param `amount` <= 0. '..
|
||||||
|
'Was force-reset to `1`. '..
|
||||||
|
'Info: value: `%s`, player: `%s`, craft: `%s`',
|
||||||
|
amount, player:get_player_name(), self.name
|
||||||
|
)
|
||||||
|
amount = 1
|
||||||
|
end
|
||||||
|
|
||||||
local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]]
|
local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]]
|
||||||
assert(workStation ~= nil)
|
assert(workStation ~= nil)
|
||||||
|
|
||||||
@@ -124,7 +133,7 @@ function ImmersiveCraft:endCraft(pos, player)
|
|||||||
local playerName = meta:get_string('player_name')
|
local playerName = meta:get_string('player_name')
|
||||||
assert(playerName ~= '')
|
assert(playerName ~= '')
|
||||||
local amount = meta:get_float('craft_amount')
|
local amount = meta:get_float('craft_amount')
|
||||||
assert(amount ~= 0)
|
assert(amount > 0)
|
||||||
|
|
||||||
-- Drop the result of crafting.
|
-- Drop the result of crafting.
|
||||||
local dropPos = v(pos) + v(0, 0.9,0)
|
local dropPos = v(pos) + v(0, 0.9,0)
|
||||||
@@ -198,7 +207,7 @@ function ImmersiveCraft:toString(recipeIndex, mainList)
|
|||||||
|
|
||||||
local craftDesc = ('%s\n\nRecipe:\n%s\nActions:\n%s'):format(
|
local craftDesc = ('%s\n\nRecipe:\n%s\nActions:\n%s'):format(
|
||||||
outputItemSettings._title,
|
outputItemSettings._title,
|
||||||
BaseCraft.recipeToString(self, recipeIndex, mainList),
|
BaseCraft.recipeToString(self, mainList),
|
||||||
self:recipeToString(recipeIndex, mainList))
|
self:recipeToString(recipeIndex, mainList))
|
||||||
|
|
||||||
return craftDesc
|
return craftDesc
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
local assert = assert
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local tableInsert, tableMerge = table.insert, table.merge
|
||||||
|
|
||||||
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler
|
---@type CraftSystem.BaseCraftHandler
|
||||||
@@ -14,9 +16,6 @@ local ImmersiveCraft = require('CraftSystem.ImmersiveCraft')
|
|||||||
---@field defaultCraftDef CraftSystem.BaseCraftDef
|
---@field defaultCraftDef CraftSystem.BaseCraftDef
|
||||||
---
|
---
|
||||||
---@field new fun(self:CraftSystem.ImmersiveCraftHandler, baseType:CraftSystem.BaseCraftType, type:CraftSystem.ImmersiveCraftType, def:CraftSystem.ImmersiveCraftHandlerDef):CraftSystem.ImmersiveCraftHandler
|
---@field new fun(self:CraftSystem.ImmersiveCraftHandler, baseType:CraftSystem.BaseCraftType, type:CraftSystem.ImmersiveCraftType, def:CraftSystem.ImmersiveCraftHandlerDef):CraftSystem.ImmersiveCraftHandler
|
||||||
---@field getCraftByName fun(self, craftName:string):CraftSystem.ImmersiveCraft
|
|
||||||
---@field getCraftsByGroup fun(self, craftGroup):CraftSystem.ImmersiveCraft[]
|
|
||||||
---@field getLearnedCrafts fun(self, playerName):table<string, CraftSystem.ImmersiveCraft>
|
|
||||||
local ImmersiveCraftHandler = BaseCraftHandler:extend({})
|
local ImmersiveCraftHandler = BaseCraftHandler:extend({})
|
||||||
|
|
||||||
---@class CraftSystem.ImmersiveCraftHandlerDef : CraftSystem.BaseCraftHandlerDef
|
---@class CraftSystem.ImmersiveCraftHandlerDef : CraftSystem.BaseCraftHandlerDef
|
||||||
@@ -30,7 +29,7 @@ function ImmersiveCraftHandler:registerCraft(craftName, def)
|
|||||||
assert(self.craftsByName[craftName] == nil, ('A craft named `%s` already exists.'):format(
|
assert(self.craftsByName[craftName] == nil, ('A craft named `%s` already exists.'):format(
|
||||||
craftName))
|
craftName))
|
||||||
|
|
||||||
local def = table.merge(def, self.defaultCraftDef)
|
local def = tableMerge(def, self.defaultCraftDef)
|
||||||
|
|
||||||
local group = 'craft_group:' .. (def.group or 'UNDEFINED')
|
local group = 'craft_group:' .. (def.group or 'UNDEFINED')
|
||||||
def.group = group
|
def.group = group
|
||||||
@@ -44,37 +43,8 @@ function ImmersiveCraftHandler:registerCraft(craftName, def)
|
|||||||
self.craftsByName[craftName] = craft
|
self.craftsByName[craftName] = craft
|
||||||
tableInsert(self.craftsByGroup[group], craft)
|
tableInsert(self.craftsByGroup[group], craft)
|
||||||
tableInsert(self.craftsList, craft)
|
tableInsert(self.craftsList, craft)
|
||||||
|
|
||||||
|
self:addCraftToProgressionTable(craft)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sort the list of crafts in alphabetical order by product name and combine crafts into groups.
|
|
||||||
-- Provides a convenient list of crafting items in the player's inventory.
|
|
||||||
core.register_on_mods_loaded(function()
|
|
||||||
for groupName, crafts in pairs(ImmersiveCraftHandler.craftsByGroup) do
|
|
||||||
tableSort(crafts, function(a, b)
|
|
||||||
if a.output < b.output then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
if groupName ~= 'craft_group:UNDEFINED' then
|
|
||||||
tableInsert(ImmersiveCraftHandler.groupedCrafts, crafts)
|
|
||||||
else
|
|
||||||
ImmersiveCraftHandler.groupedCrafts = tableJoin(ImmersiveCraftHandler.groupedCrafts, crafts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tableSort(ImmersiveCraftHandler.groupedCrafts, function(a, b)
|
|
||||||
local outputA = (a[1] and a[1].output) or a.output
|
|
||||||
local outputB = (b[1] and b[1].output) or b.output
|
|
||||||
|
|
||||||
if outputA < outputB then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return ImmersiveCraftHandler
|
return ImmersiveCraftHandler
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@type Creature
|
---@type Creature
|
||||||
local Creature = Mod.getInfo('smc__core__creature').require('Creature')
|
local Creature = Mod:getInfo('smc__core__creature').require('Creature')
|
||||||
|
|
||||||
---The entity the player interacts with during immersive crafting.
|
---The entity the player interacts with during immersive crafting.
|
||||||
---@class CraftSystem.ImmersiveCraftNode : Creature
|
---@class CraftSystem.ImmersiveCraftNode : Creature
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local assert = assert
|
|||||||
local extend = Class.extend
|
local extend = Class.extend
|
||||||
local coreItemDrop = core.item_drop
|
local coreItemDrop = core.item_drop
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod:getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents') --[[@as Events.ImmersiveCraftEvents]]
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ function TappingStage:new(def)
|
|||||||
assert(stageData ~= nil)
|
assert(stageData ~= nil)
|
||||||
|
|
||||||
local amount = meta:get_float('craft_amount')
|
local amount = meta:get_float('craft_amount')
|
||||||
assert(amount ~= 0)
|
assert(amount > 0)
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
||||||
local stageData = stageData
|
local stageData = stageData
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local getInstance, extend = Class.getInstance, Class.extend
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraft
|
---@type CraftSystem.BaseCraft
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local extend = Class.extend
|
|||||||
|
|
||||||
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
local tableInsert, tableSort, tableJoin = table.insert, table.sort, table.join
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler
|
---@type CraftSystem.BaseCraftHandler
|
||||||
@@ -17,12 +17,10 @@ local PrimitiveCraft = require('CraftSystem.PrimitiveCraft')
|
|||||||
---@field defaultCraftDef CraftSystem.PrimitiveCraftDef
|
---@field defaultCraftDef CraftSystem.PrimitiveCraftDef
|
||||||
---
|
---
|
||||||
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.PrimitiveCraft[]>
|
---@field craftsByGroup table<CraftSystem.CraftGroup, CraftSystem.PrimitiveCraft[]>
|
||||||
|
---@field craftsByOutput table<ItemStackString, CraftSystem.BaseCraft[]>
|
||||||
---@field groupedCrafts (CraftSystem.PrimitiveCraft[]|CraftSystem.PrimitiveCraft)[]
|
---@field groupedCrafts (CraftSystem.PrimitiveCraft[]|CraftSystem.PrimitiveCraft)[]
|
||||||
---
|
---
|
||||||
---@field new fun(self:CraftSystem.PrimitiveCraftHandler, baseType:CraftSystem.BaseCraftType, type:CraftSystem.PrimitiveCraftType, def:CraftSystem.PrimitiveCraftHandlerDef):CraftSystem.PrimitiveCraftHandler
|
---@field new fun(self:CraftSystem.PrimitiveCraftHandler, baseType:CraftSystem.BaseCraftType, type:CraftSystem.PrimitiveCraftType, def:CraftSystem.PrimitiveCraftHandlerDef):CraftSystem.PrimitiveCraftHandler
|
||||||
---@field getCraftByName fun(self, craftName:string):CraftSystem.PrimitiveCraft
|
|
||||||
---@field getCraftsByGroup fun(self, craftGroup:string):CraftSystem.PrimitiveCraft[]
|
|
||||||
---@field getLearnedCrafts fun(self, playerName:string):(CraftSystem.PrimitiveCraft[]|CraftSystem.PrimitiveCraft)[]
|
|
||||||
local PrimitiveCraftHandler = BaseCraftHandler:extend({})
|
local PrimitiveCraftHandler = BaseCraftHandler:extend({})
|
||||||
|
|
||||||
---@class CraftSystem.PrimitiveCraftHandlerDef : CraftSystem.BaseCraftHandlerDef
|
---@class CraftSystem.PrimitiveCraftHandlerDef : CraftSystem.BaseCraftHandlerDef
|
||||||
@@ -46,51 +44,21 @@ function PrimitiveCraftHandler:registerCraft(craftName, def)
|
|||||||
self.craftsByGroup[group] = {}
|
self.craftsByGroup[group] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local output = ItemStack(craft.output):get_name()
|
||||||
|
if self.craftsByOutput[output] == nil then
|
||||||
|
self.craftsByOutput[output] = {}
|
||||||
|
elseif craft.hidden == nil then
|
||||||
|
craft.hidden = true
|
||||||
|
end
|
||||||
|
|
||||||
self.craftsByName[craftName] = craft
|
self.craftsByName[craftName] = craft
|
||||||
|
if craft.hidden ~= true then
|
||||||
tableInsert(self.craftsByGroup[group], craft)
|
tableInsert(self.craftsByGroup[group], craft)
|
||||||
|
end
|
||||||
|
tableInsert(self.craftsByOutput[output], craft)
|
||||||
tableInsert(self.craftsList, craft)
|
tableInsert(self.craftsList, craft)
|
||||||
|
|
||||||
|
self:addCraftToProgressionTable(craft)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Adds alternative recipes to the craft with the specified name.
|
|
||||||
---
|
|
||||||
---If a craft with the specified name does not exist, an error will call.
|
|
||||||
---@param craftName string
|
|
||||||
---@param recipes CraftSystem.CraftRecipe[]
|
|
||||||
function PrimitiveCraftHandler:registerAlternativeRecipes(craftName, recipes)
|
|
||||||
local craft = PrimitiveCraftHandler:getCraftByName(craftName)
|
|
||||||
|
|
||||||
craft.altRecipes = tableJoin(craft.altRecipes or {}, recipes)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Sort the list of crafts in alphabetical order by product name and combine crafts into groups.
|
|
||||||
-- Provides a convenient list of crafting items in the player's inventory.
|
|
||||||
core.register_on_mods_loaded(function()
|
|
||||||
for groupName, crafts in pairs(PrimitiveCraftHandler.craftsByGroup) do
|
|
||||||
tableSort(crafts, function(a, b)
|
|
||||||
if a.output < b.output then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
if groupName ~= 'craft_group:UNDEFINED' then
|
|
||||||
tableInsert(PrimitiveCraftHandler.groupedCrafts, crafts)
|
|
||||||
else
|
|
||||||
PrimitiveCraftHandler.groupedCrafts = tableJoin(PrimitiveCraftHandler.groupedCrafts, crafts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tableSort(PrimitiveCraftHandler.groupedCrafts, function(a, b)
|
|
||||||
local outputA = (a[1] and a[1].output) or a.output
|
|
||||||
local outputB = (b[1] and b[1].output) or b.output
|
|
||||||
|
|
||||||
if outputA < outputB then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return PrimitiveCraftHandler
|
return PrimitiveCraftHandler
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local getInstance, extend = Class.getInstance, Class.extend
|
local getInstance, extend = Class.getInstance, Class.extend
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraft
|
---@type CraftSystem.BaseCraft
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local HASH_SEPARATOR = ','
|
|||||||
|
|
||||||
local tableInsert, tableCopy, tableSort, tableConcat, tableIsEmpty = table.insert, table.copy, table.sort, table.concat, table.is_empty
|
local tableInsert, tableCopy, tableSort, tableConcat, tableIsEmpty = table.insert, table.copy, table.sort, table.concat, table.is_empty
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local modInfo = Mod:getInfo('smc__core__craft_system')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraftHandler
|
---@type CraftSystem.BaseCraftHandler
|
||||||
@@ -19,9 +19,6 @@ local ProcessingCraft = require('CraftSystem.ProcessingCraft')
|
|||||||
---@field craftsByHash table<string, CraftSystem.ProcessingCraft>
|
---@field craftsByHash table<string, CraftSystem.ProcessingCraft>
|
||||||
---
|
---
|
||||||
---@field new fun(self:CraftSystem.ProcessingCraftHandler, baseType:CraftSystem.BaseCraftType, type:CraftSystem.ProcessingCraftType, def:CraftSystem.ProcessingCraftHandlerDef):CraftSystem.ProcessingCraftHandler
|
---@field new fun(self:CraftSystem.ProcessingCraftHandler, baseType:CraftSystem.BaseCraftType, type:CraftSystem.ProcessingCraftType, def:CraftSystem.ProcessingCraftHandlerDef):CraftSystem.ProcessingCraftHandler
|
||||||
---@field getCraftByName fun(self, craftName:string):CraftSystem.ProcessingCraft
|
|
||||||
---@field getCraftsByGroup fun(self, craftGroup:string):CraftSystem.ProcessingCraft[]
|
|
||||||
---@field getLearnedCrafts fun(self, playerName:string):(CraftSystem.ProcessingCraft[]|CraftSystem.ProcessingCraft)[]
|
|
||||||
local ProcessingCraftHandler = BaseCraftHandler:extend({
|
local ProcessingCraftHandler = BaseCraftHandler:extend({
|
||||||
craftsByHash = {}
|
craftsByHash = {}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__creature')
|
local modInfo = Mod:getInfo('smc__core__creature')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Creature')
|
return require('Creature')
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
name = smc__core__creature
|
name = smc__core__creature
|
||||||
|
depends = smc__system__system_loader
|
||||||
@@ -48,7 +48,7 @@ function Creature:new(entityDef)
|
|||||||
|
|
||||||
-- Add the short mod name prefix to the entity name.
|
-- Add the short mod name prefix to the entity name.
|
||||||
if s._add_mod_name then
|
if s._add_mod_name then
|
||||||
s._name = Mod.getInfo().shortName .. ':' .. s._name
|
s._name = Mod:getInfo().shortName .. ':' .. s._name
|
||||||
end
|
end
|
||||||
|
|
||||||
local onActivate = c.on_activate or function() end
|
local onActivate = c.on_activate or function() end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
local modInfo = Mod:getInfo('smc__core__formspec')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Formspec')
|
return require('Formspec')
|
||||||
@@ -745,6 +745,41 @@ function Formspec:imageButton(x, y, w, h, textureName, name, label, pressedTextu
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@alias Formspec.ImageButtonRowElement {
|
||||||
|
--- [1] : string,
|
||||||
|
--- [2] : string,
|
||||||
|
--- [3] : string?,
|
||||||
|
--- [4] : string?,
|
||||||
|
--- [5] : boolean?,
|
||||||
|
--- [6] : boolean?,
|
||||||
|
--- }
|
||||||
|
|
||||||
|
---Creates a row of buttons, automatically calculating the coordinates of buttons based on the width.
|
||||||
|
---
|
||||||
|
---@see Formspec.imageButton
|
||||||
|
---@param x number
|
||||||
|
---@param y number
|
||||||
|
---@param w number
|
||||||
|
---@param h number
|
||||||
|
---@param imageButtonRow Formspec.ImageButtonRowElement[]
|
||||||
|
---@return Formspec
|
||||||
|
function Formspec:imageButtonRow(x, y, w, h, imageButtonRow)
|
||||||
|
---@param element Formspec.ImageButtonRowElement
|
||||||
|
for i, element in ipairs(imageButtonRow) do
|
||||||
|
local ex = x + ( ( i - 1 ) * w)
|
||||||
|
self:imageButton(ex, y, w, h,
|
||||||
|
element[1],
|
||||||
|
element[2],
|
||||||
|
element[3],
|
||||||
|
element[4],
|
||||||
|
element[5],
|
||||||
|
element[6]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
---Clickable item image button. When clicked, fields will be sent.
|
---Clickable item image button. When clicked, fields will be sent.
|
||||||
---
|
---
|
||||||
---**Element:** `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
|
---**Element:** `item_image_button[<X>,<Y>;<W>,<H>;<item name>;<name>;<label>]`
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__immersive_work_station')
|
local modInfo = Mod:getInfo('smc__core__immersive_work_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ImmersiveWorkStation')
|
return require('ImmersiveWorkStation')
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__immersive_work_station
|
name = smc__core__immersive_work_station
|
||||||
depends = smc__core__craft_system, smc__core__node, smc__ui__work_station
|
depends = smc__core__craft_system, smc__core__node, smc__ui__work_station, smc__ui__player_inventory
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ function ImmersiveWorkStation:abortCraft(pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local craft = self.handler:getCraftByName(craftName)
|
local craft = self.handler:getCraftByName(craftName) --[[@as CraftSystem.ImmersiveCraft]]
|
||||||
craft:abortCraft(pos)
|
craft:abortCraft(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ end
|
|||||||
|
|
||||||
local handler = CraftSystem:getImmersiveCraftHandler('workbench')
|
local handler = CraftSystem:getImmersiveCraftHandler('workbench')
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__ui__player_inventory').require
|
local require = Mod:getInfo('smc__ui__player_inventory').require
|
||||||
local baseGetCraftTab = require('PlayerInventoryUI.baseGetCraftTab')
|
local baseGetCraftTab = require('PlayerInventoryUI.baseGetCraftTab')
|
||||||
|
|
||||||
---@param self PlayerInventoryUI
|
---@param self PlayerInventoryUI
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__item')
|
local modInfo = Mod:getInfo('smc__core__item')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Item')
|
return require('Item')
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ end
|
|||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition
|
||||||
---@return ItemDefinition
|
---@return ItemDefinition
|
||||||
local function itemDefToLuantiDef(itemDef)
|
local function itemDefToLuantiDef(itemDef)
|
||||||
local modName = Mod.getInfo().shortName
|
local modName = Mod:getInfo().shortName
|
||||||
local S = core.get_translator(modName)
|
local S = core.get_translator(modName)
|
||||||
|
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
@@ -129,6 +129,7 @@ end
|
|||||||
---@param luantiDef NodeDefinition
|
---@param luantiDef NodeDefinition
|
||||||
local function registerNode(luantiDef)
|
local function registerNode(luantiDef)
|
||||||
local name = luantiDef.name
|
local name = luantiDef.name
|
||||||
|
---@diagnostic disable-next-line: inject-field
|
||||||
luantiDef.name = nil
|
luantiDef.name = nil
|
||||||
|
|
||||||
core.register_node(':'..name, luantiDef)
|
core.register_node(':'..name, luantiDef)
|
||||||
@@ -137,6 +138,7 @@ end
|
|||||||
---@param luantiDef ItemDefinition
|
---@param luantiDef ItemDefinition
|
||||||
local function registerCraftitem(luantiDef)
|
local function registerCraftitem(luantiDef)
|
||||||
local name = luantiDef.name
|
local name = luantiDef.name
|
||||||
|
---@diagnostic disable-next-line: inject-field
|
||||||
luantiDef.name = nil
|
luantiDef.name = nil
|
||||||
|
|
||||||
core.register_craftitem(':'..name, luantiDef)
|
core.register_craftitem(':'..name, luantiDef)
|
||||||
@@ -145,6 +147,7 @@ end
|
|||||||
---@param luantiDef ItemDefinition
|
---@param luantiDef ItemDefinition
|
||||||
local function registerTool(luantiDef)
|
local function registerTool(luantiDef)
|
||||||
local name = luantiDef.name
|
local name = luantiDef.name
|
||||||
|
---@diagnostic disable-next-line: inject-field
|
||||||
luantiDef.name = nil
|
luantiDef.name = nil
|
||||||
|
|
||||||
core.register_tool(':'..name, luantiDef)
|
core.register_tool(':'..name, luantiDef)
|
||||||
@@ -164,7 +167,7 @@ function Item:new(itemDef)
|
|||||||
itemDef = tableMerge(itemDef, self.defaultDef, true) --[[@as Item.ItemDefinition]]
|
itemDef = tableMerge(itemDef, self.defaultDef, true) --[[@as Item.ItemDefinition]]
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
|
|
||||||
local shortModName = Mod.getInfo().shortName
|
local shortModName = Mod:getInfo().shortName
|
||||||
|
|
||||||
if s._add_mod_name then
|
if s._add_mod_name then
|
||||||
s.name = shortModName .. ':' .. s.name
|
s.name = shortModName .. ':' .. s.name
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__item_factory')
|
local modInfo = Mod:getInfo('smc__core__item_factory')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ItemFactory')
|
return require('ItemFactory')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
local modInfo = Mod:getInfo('smc__core__map_gen')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('MapGen')
|
return require('MapGen')
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
local assert = assert
|
local assert = assert
|
||||||
local pairs, ipairs = pairs, ipairs
|
local pairs, ipairs = pairs, ipairs
|
||||||
|
|
||||||
local mathRound, mathRandom, mathClamp = math.round, math.random, math.clamp
|
local bitToBit, bitBxor, bitRshift, bitBand = bit.tobit, bit.bxor, bit.rshift, bit.band
|
||||||
|
local mathFloor, mathRound, mathRandom, mathClamp = math.floor, math.round, math.random, math.clamp
|
||||||
local tableInsert, tableSort = table.insert, table.sort
|
local tableInsert, tableSort = table.insert, table.sort
|
||||||
|
|
||||||
local v = vector.new
|
local v = vector.new
|
||||||
local id = core.get_content_id
|
local id = core.get_content_id
|
||||||
local AIR_ID = core.CONTENT_AIR
|
local AIR_ID = core.CONTENT_AIR
|
||||||
local corePosToString, coreGetUsTime = core.pos_to_string, core.get_us_time
|
local corePosToString, coreGetUsTime = core.pos_to_string, core.get_us_time
|
||||||
|
local PcgRandom = PcgRandom
|
||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
@@ -18,10 +20,10 @@ local function mglog(text, ...)
|
|||||||
core.log((text):format(...))
|
core.log((text):format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---Numeric values defining the surface height and climate for the node.
|
---Numeric values defining the surface height and climate for the node.
|
||||||
---@alias MapGen.Factors {height:number, temp:number, humidity:number}
|
---@alias MapGen.Factors {height:number, temp:number, humidity:number, weight:number}
|
||||||
|
|
||||||
---Table of all past generation factor calculations for nodes.
|
---Table of all past generation factor calculations for nodes.
|
||||||
---
|
---
|
||||||
@@ -209,6 +211,32 @@ function MapGen:getTree(name)
|
|||||||
return self.treesByName[name]
|
return self.treesByName[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Returns a pseudorandom number within
|
||||||
|
---a specified range based on coordinates.
|
||||||
|
---
|
||||||
|
---Use this to generate deterministic random
|
||||||
|
---numbers within node generation functions.
|
||||||
|
---@param x integer
|
||||||
|
---@param y integer
|
||||||
|
---@param z integer
|
||||||
|
---@param min integer
|
||||||
|
---@param max integer
|
||||||
|
---@return integer
|
||||||
|
function MapGen:random(x, y, z, min, max)
|
||||||
|
local n = bitToBit(bitBxor(x, 0xB57B6AE1) * 0x9E3779B9)
|
||||||
|
n = bitToBit(bitBxor(n, y) * 0x85EBCA6B)
|
||||||
|
n = bitToBit(bitBxor(n, z) * 0xC2B2AE35)
|
||||||
|
|
||||||
|
n = bitBxor(n, bit.rshift(n, 16))
|
||||||
|
n = bitToBit(n * 0x27D4EB2D)
|
||||||
|
n = bitBxor(n, bit.rshift(n, 15))
|
||||||
|
|
||||||
|
n = bitBand(n, 0x7FFFFFFF)
|
||||||
|
|
||||||
|
local range = max - min + 1
|
||||||
|
return min + mathFloor((n / 2147483648) * range)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- --- API METHODS: REGISTRATION ---
|
-- --- API METHODS: REGISTRATION ---
|
||||||
@@ -690,8 +718,10 @@ local function generateNode(mapGenerator, layer, factors, data, data2, index, x,
|
|||||||
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
|
|
||||||
|
local diagramPoint = layer.biomesDiagram[height][scattTemp][scattHumidity] -- TODO: разобраться со смещением по вертикали
|
||||||
---@type MapGen.Biome
|
---@type MapGen.Biome
|
||||||
local biome = layer.biomesDiagram[scattHeight][scattTemp][scattHumidity]
|
local biome = diagramPoint.biome
|
||||||
|
factors.weight = diagramPoint.weight
|
||||||
|
|
||||||
-- If the block is above surface height and above water level...
|
-- 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
|
||||||
@@ -714,7 +744,7 @@ local function generateNode(mapGenerator, layer, factors, data, data2, index, x,
|
|||||||
addPostProccessing(biome, mapGenerator, factors, index, x, y, z, 'CAVERN_AIR')
|
addPostProccessing(biome, mapGenerator, factors, index, x, y, z, 'CAVERN_AIR')
|
||||||
|
|
||||||
-- ... or if the surface height is above the water level...
|
-- ... or if the surface height is above the water level...
|
||||||
elseif height > waterLevel then
|
elseif height >= waterLevel then
|
||||||
--- ... and the height of the block is equal to the height of the surface...
|
--- ... and the height of the block is equal to the height of the surface...
|
||||||
if y == height then
|
if y == height then
|
||||||
-- ... then turf is generated.
|
-- ... then turf is generated.
|
||||||
@@ -732,7 +762,7 @@ local function generateNode(mapGenerator, layer, factors, data, data2, index, x,
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ... or if the surface height is below the water level...
|
-- ... or if the surface height is below the water level...
|
||||||
elseif height <= waterLevel then
|
elseif height < waterLevel then
|
||||||
-- ... and if the height of the block falls within the thickness of the soil layer...
|
-- ... and if the height of the block falls within the thickness of the soil layer...
|
||||||
if y > height - biome.soilHeight then
|
if y > height - biome.soilHeight then
|
||||||
-- ... then the river/ocean bottom is generated.
|
-- ... then the river/ocean bottom is generated.
|
||||||
@@ -800,7 +830,7 @@ local function calcNoise2dValue(category, layer, triangle, x, y, z)
|
|||||||
-- If the triangle is monochromatic (all peaks have the same color and,
|
-- If the triangle is monochromatic (all peaks have the same color and,
|
||||||
-- accordingly, the same noise), then there is no point in smoothing out the noise.
|
-- accordingly, the same noise), then there is no point in smoothing out the noise.
|
||||||
if triangleColor ~= nil then
|
if triangleColor ~= nil then
|
||||||
return layer:getNoiseByColor(category, triangleColor):get_2d({x = x, y = z})
|
return layer:getNoiseByColor(category, triangleColor):get_3d({x = x, y = 0, z = z})
|
||||||
end
|
end
|
||||||
|
|
||||||
local peak1 = triangle.p1
|
local peak1 = triangle.p1
|
||||||
@@ -819,15 +849,15 @@ local function calcNoise2dValue(category, layer, 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)
|
||||||
noiseValue = noiseValue + noise1:get_2d({x = x, y = z}) * weight
|
noiseValue = noiseValue + noise1:get_3d({x = x, y = 0, z = z}) * weight
|
||||||
totalWeight = totalWeight + weight
|
totalWeight = totalWeight + weight
|
||||||
|
|
||||||
weight = calcWeight(triangle.h2, x, y, z)
|
weight = calcWeight(triangle.h2, x, y, z)
|
||||||
noiseValue = noiseValue + noise2:get_2d({x = x, y = z}) * weight
|
noiseValue = noiseValue + noise2:get_3d({x = x, y = 0, z = z}) * weight
|
||||||
totalWeight = totalWeight + weight
|
totalWeight = totalWeight + weight
|
||||||
|
|
||||||
weight = calcWeight(triangle.h3, x, y, z)
|
weight = calcWeight(triangle.h3, x, y, z)
|
||||||
noiseValue = noiseValue + noise3:get_2d({x = x, y = z}) * weight
|
noiseValue = noiseValue + noise3:get_3d({x = x, y = 0, z = z}) * weight
|
||||||
totalWeight = totalWeight + weight
|
totalWeight = totalWeight + weight
|
||||||
|
|
||||||
return (noiseValue / totalWeight)
|
return (noiseValue / totalWeight)
|
||||||
@@ -926,6 +956,7 @@ local function generatorHandler(mapGenerator, layer, data, data2, index, x, y, z
|
|||||||
|
|
||||||
local endGetLayerTime = coreGetUsTime()
|
local endGetLayerTime = coreGetUsTime()
|
||||||
local startNoiseCalcTime = endGetLayerTime
|
local startNoiseCalcTime = endGetLayerTime
|
||||||
|
|
||||||
-- If the value of the noise is `nil`,
|
-- If the value of the noise is `nil`,
|
||||||
-- then the point does not fall within any of the triangles.
|
-- then the point does not fall within any of the triangles.
|
||||||
local height, temp, humidity = mapGenerator:getFactors(layer, x, y, z)
|
local height, temp, humidity = mapGenerator:getFactors(layer, x, y, z)
|
||||||
@@ -1036,6 +1067,9 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Clear post processing tables
|
||||||
|
dataPostProcessing, vmPostProcessing = {}, {}
|
||||||
|
|
||||||
core.generate_ores(voxelManip, minPos, maxPos)
|
core.generate_ores(voxelManip, minPos, maxPos)
|
||||||
core.generate_decorations(voxelManip, minPos, maxPos)
|
core.generate_decorations(voxelManip, minPos, maxPos)
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
local assert = assert
|
local assert = assert
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
|
|
||||||
local mathMin, mathAbs, mathClamp = math.min, math.abs, math.clamp
|
local mathFloor, mathMin, mathAbs, mathClamp, mathRound = math.floor, math.min, math.abs, math.clamp, math.round
|
||||||
|
|
||||||
local coreGetValueNoise = core.get_value_noise
|
local coreGetValueNoise, corePosToString = core.get_value_noise, core.pos_to_string
|
||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
---@alias MapGen.Cavern.Type 'cheesed'|'warped'
|
---@alias MapGen.Cavern.Type 'cheesy'|'warped'|'worm'
|
||||||
|
|
||||||
---@alias MapGen.Cavern.NoiseParams {baseNoise:NoiseParams, xNoise?:NoiseParams, yNoise?:NoiseParams, zNoise?:NoiseParams}
|
---@alias MapGen.Cavern.NoiseParams {baseNoise:NoiseParams, xNoise?:NoiseParams, yNoise?:NoiseParams, zNoise?:NoiseParams}
|
||||||
---@alias MapGen.Cavern.ValueNoise {baseNoise:ValueNoise, xNoise?:ValueNoise, yNoise?:ValueNoise, zNoise?:ValueNoise}
|
---@alias MapGen.Cavern.ValueNoise {baseNoise:ValueNoise, xNoise?:ValueNoise, yNoise?:ValueNoise, zNoise?:ValueNoise}
|
||||||
@@ -18,14 +18,29 @@ local getInstance = Class.getInstance
|
|||||||
---@field type MapGen.Cavern.Type
|
---@field type MapGen.Cavern.Type
|
||||||
---@field minY integer
|
---@field minY integer
|
||||||
---@field maxY integer
|
---@field maxY integer
|
||||||
---@field smoothDistance number
|
---@field smoothDistance number?
|
||||||
---@field threshold number
|
---@field threshold number?
|
||||||
---
|
---
|
||||||
---@field warpStrength number
|
---@field warpStrength number?
|
||||||
|
---
|
||||||
|
---@field regionSize integer?
|
||||||
|
---@field wormStep integer?
|
||||||
|
---@field lenght integer?
|
||||||
|
---@field maxRadius integer?
|
||||||
|
---@field minRadius integer?
|
||||||
|
---@field defaulDirection IntegerPosition?
|
||||||
|
---@field wormOffset IntegerPosition?
|
||||||
---
|
---
|
||||||
---@field getNoise fun(self:MapGen.Cavern):MapGen.Cavern.ValueNoise
|
---@field getNoise fun(self:MapGen.Cavern):MapGen.Cavern.ValueNoise
|
||||||
---@field initNoise fun(self:MapGen.Cavern)
|
---@field initNoise fun(self:MapGen.Cavern)
|
||||||
local Cavern = {}
|
---
|
||||||
|
---A table that stores pre-calculated coordinates of worm-type caves. Filled as needed
|
||||||
|
---
|
||||||
|
---TODO: It might be worth clearing the cache to save RAM.
|
||||||
|
---@field wormCache table<string, table<string, boolean>>
|
||||||
|
local Cavern = {
|
||||||
|
wormCache = {}
|
||||||
|
}
|
||||||
|
|
||||||
---Definition table for the `MapGen.Cavern`.
|
---Definition table for the `MapGen.Cavern`.
|
||||||
---
|
---
|
||||||
@@ -36,10 +51,18 @@ local Cavern = {}
|
|||||||
---@field minY integer
|
---@field minY integer
|
||||||
---@field maxY integer
|
---@field maxY integer
|
||||||
---@field noiseParams MapGen.Cavern.NoiseParams
|
---@field noiseParams MapGen.Cavern.NoiseParams
|
||||||
---@field smoothDistance number
|
---@field smoothDistance number?
|
||||||
---@field threshold number?
|
---@field threshold number?
|
||||||
---
|
---
|
||||||
---@field warpStrength number
|
---@field warpStrength number?
|
||||||
|
---
|
||||||
|
---@field regionSize integer?
|
||||||
|
---@field wormStep integer?
|
||||||
|
---@field lenght integer?
|
||||||
|
---@field maxRadius integer?
|
||||||
|
---@field minRadius integer?
|
||||||
|
---@field defaulDirection IntegerPosition?
|
||||||
|
---@field wormOffset IntegerPosition?
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param def MapGen.CavernDef
|
---@param def MapGen.CavernDef
|
||||||
@@ -56,6 +79,16 @@ function Cavern:new(name, def)
|
|||||||
assert(noises.zNoise ~= nil, 'The cavern cannot be `warped` but has no `zNoise`')
|
assert(noises.zNoise ~= nil, 'The cavern cannot be `warped` but has no `zNoise`')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if def.type == 'worm' then
|
||||||
|
local noises = def.noiseParams
|
||||||
|
assert(def.regionSize ~= nil, 'The cavern cannot be `worm` but has no `regionSize`')
|
||||||
|
assert(def.lenght ~= nil, 'The cavern cannot be `worm` but has no `lenght`')
|
||||||
|
assert(def.maxRadius ~= nil, 'The cavern cannot be `worm` but has no `maxRadius`')
|
||||||
|
assert(noises.xNoise ~= nil, 'The cavern cannot be `worm` but has no `xNoise`')
|
||||||
|
assert(noises.yNoise ~= nil, 'The cavern cannot be `worm` but has no `yNoise`')
|
||||||
|
assert(noises.zNoise ~= nil, 'The cavern cannot be `worm` but has no `zNoise`')
|
||||||
|
end
|
||||||
|
|
||||||
local _noiseParams = def.noiseParams
|
local _noiseParams = def.noiseParams
|
||||||
local _noise = {}
|
local _noise = {}
|
||||||
|
|
||||||
@@ -68,8 +101,17 @@ function Cavern:new(name, def)
|
|||||||
instance.maxY = def.maxY
|
instance.maxY = def.maxY
|
||||||
instance.smoothDistance = def.smoothDistance
|
instance.smoothDistance = def.smoothDistance
|
||||||
instance.threshold = def.threshold or 0.1
|
instance.threshold = def.threshold or 0.1
|
||||||
|
|
||||||
instance.warpStrength = def.warpStrength
|
instance.warpStrength = def.warpStrength
|
||||||
|
|
||||||
|
instance.wormStep = def.wormStep or 1
|
||||||
|
instance.regionSize = def.regionSize
|
||||||
|
instance.lenght = def.lenght
|
||||||
|
instance.maxRadius = def.maxRadius
|
||||||
|
instance.minRadius = def.minRadius or 0
|
||||||
|
instance.defaulDirection = def.defaulDirection or {x = 0, y = -1, z = 0}
|
||||||
|
instance.wormOffset = def.wormOffset or {x = 0, y = 0, z = 0}
|
||||||
|
|
||||||
function instance:getNoise()
|
function instance:getNoise()
|
||||||
return _noise
|
return _noise
|
||||||
end
|
end
|
||||||
@@ -123,7 +165,145 @@ function Cavern:isWarpedCavern(x, y, z, weight)
|
|||||||
return value * weight >= self.threshold
|
return value * weight >= self.threshold
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns `true` if there is a cavern at the specified coordinates.
|
---Calculates the worm offset for one coordinate.
|
||||||
|
---
|
||||||
|
---If the worm is closer to the boundary than the radius of its tunnel,
|
||||||
|
---it will be forced to turn in the opposite direction.
|
||||||
|
---@param x integer
|
||||||
|
---@param minX integer
|
||||||
|
---@param maxX integer
|
||||||
|
---@param noiseValue number
|
||||||
|
---@param radius integer
|
||||||
|
---@return integer
|
||||||
|
local function calcWormOffset(x, minX, maxX, noiseValue, radius)
|
||||||
|
local distance1 = x - minX
|
||||||
|
local distance2 = maxX - x
|
||||||
|
|
||||||
|
if distance1 <= radius then
|
||||||
|
return 1
|
||||||
|
elseif distance2 <= radius then
|
||||||
|
return -1
|
||||||
|
else
|
||||||
|
return mathRound(mathClamp(noiseValue, -1, 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function drawSphere(wx, wy, wz, radius, cache)
|
||||||
|
local radiusSqrt = (radius + 0.25) ^ 2 -- `+ 0.25` is needed to make the sphere appear more round.
|
||||||
|
|
||||||
|
for sx = -radius, radius do
|
||||||
|
local xSqrt = sx * sx
|
||||||
|
for sy = -radius, radius do
|
||||||
|
local xySqrt = xSqrt + sy * sy
|
||||||
|
|
||||||
|
if xySqrt <= radiusSqrt then
|
||||||
|
for sz = -radius, radius do
|
||||||
|
if xySqrt + (sz * sz) <= radiusSqrt then
|
||||||
|
local posString = corePosToString({x = wx+sx, y = wy+sy, z = wz+sz})
|
||||||
|
|
||||||
|
cache[posString] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Calculates a full cave for a given region and saves it to the cache.
|
||||||
|
---@param regionPos IntegerPosition
|
||||||
|
---@return table<string, boolean>
|
||||||
|
function Cavern:caclRegionWormCache(regionPos)
|
||||||
|
---@type IntegerPosition
|
||||||
|
local offset = self.wormOffset
|
||||||
|
---@type integer, integer
|
||||||
|
local maxRadius, minRadius = self.maxRadius, self.minRadius
|
||||||
|
local step, size = self.wormStep, self.regionSize
|
||||||
|
local noise = self:getNoise()
|
||||||
|
local cache = {}
|
||||||
|
|
||||||
|
local regionMin = {
|
||||||
|
x = regionPos.x * size + offset.x,
|
||||||
|
y = regionPos.y * size + offset.y,
|
||||||
|
z = regionPos.z * size + offset.z
|
||||||
|
}
|
||||||
|
|
||||||
|
local regionMax = {
|
||||||
|
x = regionMin.x + size,
|
||||||
|
y = regionMin.y + size,
|
||||||
|
z = regionMin.z + size
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Coordinates of the worm's head
|
||||||
|
local wx = regionMin.x + mathFloor(0.5 * size)
|
||||||
|
local wy = regionMin.y + mathFloor(0.5 * size)
|
||||||
|
local wz = regionMin.z + mathFloor(0.5 * size)
|
||||||
|
|
||||||
|
-- Direction vector of the worm's head movement
|
||||||
|
local wormDirection = {x = 0, y = - 1, z = 0}
|
||||||
|
|
||||||
|
for i=1, self.lenght do
|
||||||
|
-- Calculating the new direction of movement of the worm
|
||||||
|
wormDirection = {
|
||||||
|
x = mathClamp(wormDirection.x + calcWormOffset(wx, regionMin.x, regionMax.x, noise.xNoise:get_3d({x=wx, y=wy, z=wz}), maxRadius), -1, 1),
|
||||||
|
y = mathClamp(wormDirection.y + calcWormOffset(wy, regionMin.y, regionMax.y, noise.yNoise:get_3d({x=wx, y=wy, z=wz}), maxRadius), -1, 1),
|
||||||
|
z = mathClamp(wormDirection.z + calcWormOffset(wz, regionMin.z, regionMax.z, noise.zNoise:get_3d({x=wx, y=wy, z=wz}), maxRadius), -1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
-- To prevent the worm from getting stuck in place,
|
||||||
|
-- when receiving a zero motion vector, we reset the vector to the default
|
||||||
|
if wormDirection.x == 0 and wormDirection.y == 0 and wormDirection.z == 0 then
|
||||||
|
wormDirection = { x = 0, y = -1, z = 0}
|
||||||
|
end
|
||||||
|
|
||||||
|
wx = wx + wormDirection.x
|
||||||
|
wy = wy + wormDirection.y
|
||||||
|
wz = wz + wormDirection.z
|
||||||
|
|
||||||
|
local radius = mathFloor(noise.baseNoise:get_3d({x = wz, y = wy, z = wz}))
|
||||||
|
if radius > maxRadius then
|
||||||
|
radius = maxRadius
|
||||||
|
end
|
||||||
|
if radius < minRadius then
|
||||||
|
radius = minRadius
|
||||||
|
end
|
||||||
|
|
||||||
|
if i % step == 0 then
|
||||||
|
drawSphere(wx, wy, wz, radius, cache)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return cache
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param x integer
|
||||||
|
---@param y integer
|
||||||
|
---@param z integer
|
||||||
|
---@param weight number
|
||||||
|
---@return boolean
|
||||||
|
function Cavern:isWormCavern(x, y, z, weight)
|
||||||
|
---@type IntegerPosition
|
||||||
|
local offset = self.wormOffset
|
||||||
|
|
||||||
|
local regionPos = {
|
||||||
|
x = mathFloor((x - offset.x)/self.regionSize),
|
||||||
|
y = mathFloor((y - offset.y)/self.regionSize),
|
||||||
|
z = mathFloor((z - offset.z)/self.regionSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
local regionPosString = corePosToString(regionPos)
|
||||||
|
local posString = corePosToString({x = x, y = y, z = z})
|
||||||
|
|
||||||
|
local regionWormCache = self.wormCache[regionPosString]
|
||||||
|
|
||||||
|
if regionWormCache ~= nil then
|
||||||
|
return regionWormCache[posString] == true
|
||||||
|
else
|
||||||
|
local regionCache = self:caclRegionWormCache(regionPos)
|
||||||
|
self.wormCache[regionPosString] = regionCache
|
||||||
|
return regionCache[posString] == true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param x integer
|
---@param x integer
|
||||||
---@param y integer
|
---@param y integer
|
||||||
---@param z integer
|
---@param z integer
|
||||||
@@ -140,10 +320,12 @@ function Cavern:isCavern(x, y, z, distance)
|
|||||||
|
|
||||||
local weight = self:calcCavernWeight(distance)
|
local weight = self:calcCavernWeight(distance)
|
||||||
|
|
||||||
if self.type == 'warped' then
|
if self.type == 'cheesy' then
|
||||||
return self:isWarpedCavern(x, y, z, weight)
|
|
||||||
elseif self.type == 'cheesed' then
|
|
||||||
return self:isCheesedCavern(x, y, z, weight)
|
return self:isCheesedCavern(x, y, z, weight)
|
||||||
|
elseif self.type == 'warped' then
|
||||||
|
return self:isWarpedCavern(x, y, z, weight)
|
||||||
|
elseif self.type == 'worm' then
|
||||||
|
return self:isWormCavern(x, y, z, weight)
|
||||||
else
|
else
|
||||||
error(('unknown type of cave `%s`'):format(self.type))
|
error(('unknown type of cave `%s`'):format(self.type))
|
||||||
end
|
end
|
||||||
@@ -165,10 +347,12 @@ function Cavern:isLayeredCavern(x, y, z)
|
|||||||
|
|
||||||
local weight = self:calcCavernWeight(distance)
|
local weight = self:calcCavernWeight(distance)
|
||||||
|
|
||||||
if self.type == 'warped' then
|
if self.type == 'cheesy' then
|
||||||
return self:isWarpedCavern(x, y, z, weight)
|
|
||||||
elseif self.type == 'cheesed' then
|
|
||||||
return self:isCheesedCavern(x, y, z, weight)
|
return self:isCheesedCavern(x, y, z, weight)
|
||||||
|
elseif self.type == 'warped' then
|
||||||
|
return self:isWarpedCavern(x, y, z, weight)
|
||||||
|
elseif self.type == 'worm' then
|
||||||
|
return self:isWormCavern(x, y, z, weight)
|
||||||
else
|
else
|
||||||
error(('unknown type of cave `%s`'):format(self.type))
|
error(('unknown type of cave `%s`'):format(self.type))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local extend = Class.extend
|
local extend = Class.extend
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local Peak = require('MapGen.Peak')
|
local Peak = require('MapGen.Peak')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local assert, dump, type = assert, dump, type
|
local assert, dump, type = assert, dump, type
|
||||||
local pairs, ipairs = pairs, ipairs
|
local pairs, ipairs = pairs, ipairs
|
||||||
|
|
||||||
local mathHuge = math.huge
|
local mathHuge, mathClamp = math.huge, math.clamp
|
||||||
local tableInsert, tableSort = table.insert, table.sort
|
local tableInsert, tableSort = table.insert, table.sort
|
||||||
|
|
||||||
local id = core.get_content_id
|
local id = core.get_content_id
|
||||||
@@ -9,7 +9,7 @@ local corePosToString, coreGetValueNoise = core.pos_to_string, core.get_value_no
|
|||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen.Peak
|
---@type MapGen.Peak
|
||||||
local Peak = require('MapGen.Peak')
|
local Peak = require('MapGen.Peak')
|
||||||
@@ -39,7 +39,7 @@ local Triangle = require('MapGen.Triangle')
|
|||||||
---@field biomesVerticalScattering integer
|
---@field biomesVerticalScattering integer
|
||||||
---@field biomesByName table<string, MapGen.Biome>
|
---@field biomesByName table<string, MapGen.Biome>
|
||||||
---@field biomesList MapGen.Biome[]
|
---@field biomesList MapGen.Biome[]
|
||||||
---@field biomesDiagram table
|
---@field biomesDiagram table<integer, table<integer, table<integer, {biome:MapGen.Biome, weight:number}>>>
|
||||||
---
|
---
|
||||||
---@field cavernsByName table<string, MapGen.Cavern>
|
---@field cavernsByName table<string, MapGen.Cavern>
|
||||||
---@field cavernsList MapGen.Cavern[]
|
---@field cavernsList MapGen.Cavern[]
|
||||||
@@ -512,6 +512,7 @@ function Layer:initBiomesDiagram()
|
|||||||
|
|
||||||
for humidity = self.minHumidity, self.maxHumidity do
|
for humidity = self.minHumidity, self.maxHumidity do
|
||||||
local minDistance = mathHuge
|
local minDistance = mathHuge
|
||||||
|
local pastClosestBiome = nil
|
||||||
local closestBiome = nil
|
local closestBiome = nil
|
||||||
|
|
||||||
---@param biome MapGen.Biome
|
---@param biome MapGen.Biome
|
||||||
@@ -520,17 +521,28 @@ function Layer:initBiomesDiagram()
|
|||||||
|
|
||||||
if distance < minDistance then
|
if distance < minDistance then
|
||||||
minDistance = distance
|
minDistance = distance
|
||||||
|
pastClosestBiome = closestBiome
|
||||||
closestBiome = biome
|
closestBiome = biome
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If there is no nearby biome for this height...
|
|
||||||
if closestBiome == nil then
|
if closestBiome == nil then
|
||||||
-- ... then the first registered biome in the layer will be the default one.
|
closestBiome = self.biomesList[1]
|
||||||
diagram[height][temp][humidity] = self.biomesList[1]
|
|
||||||
else
|
|
||||||
diagram[height][temp][humidity] = closestBiome
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local weight
|
||||||
|
if pastClosestBiome ~= nil then
|
||||||
|
---Distances from the center of the nearest biome to the current point.
|
||||||
|
local distance1 = (temp - closestBiome.tempPoint)^2 + (humidity - closestBiome.humidityPoint)^2
|
||||||
|
---Half the distance between the centers of two nearest biomes (i.e. the distance to the biome boundary)
|
||||||
|
local distance2 = (pastClosestBiome.tempPoint - closestBiome.tempPoint)^2 + (pastClosestBiome.humidityPoint - closestBiome.humidityPoint) / 2
|
||||||
|
|
||||||
|
weight = 1 - mathClamp(distance1 / distance2, 0, 1)
|
||||||
|
else
|
||||||
|
weight = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
diagram[height][temp][humidity] = { biome = closestBiome, weight = weight}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local coreGetValueNoise = core.get_value_noise
|
|||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
---@alias MapGen.Ore.Type 'cheesed'|'custom'
|
---@alias MapGen.Ore.Type 'cheesy'|'custom'
|
||||||
---@alias MapGen.Ore.NoiseParams {baseNoise:NoiseParams, xNoise?:NoiseParams, yNoise?:NoiseParams, zNoise?:NoiseParams}
|
---@alias MapGen.Ore.NoiseParams {baseNoise:NoiseParams, xNoise?:NoiseParams, yNoise?:NoiseParams, zNoise?:NoiseParams}
|
||||||
---@alias MapGen.Ore.ValueNoise {baseNoise:ValueNoise, xNoise?:ValueNoise, yNoise?:ValueNoise, zNoise?:ValueNoise}
|
---@alias MapGen.Ore.ValueNoise {baseNoise:ValueNoise, xNoise?:ValueNoise, yNoise?:ValueNoise, zNoise?:ValueNoise}
|
||||||
|
|
||||||
@@ -38,6 +38,8 @@ local Ore = {}
|
|||||||
---
|
---
|
||||||
---If `nil`, ore will generate on the entire layer.
|
---If `nil`, ore will generate on the entire layer.
|
||||||
---@field biomes string[]?
|
---@field biomes string[]?
|
||||||
|
---@field minY integer
|
||||||
|
---@field maxY integer
|
||||||
---
|
---
|
||||||
---List of node names where ore will spawn.
|
---List of node names where ore will spawn.
|
||||||
---@field wherein string[]
|
---@field wherein string[]
|
||||||
@@ -66,6 +68,9 @@ function Ore:new(name, def)
|
|||||||
local instance = getInstance(self, {})
|
local instance = getInstance(self, {})
|
||||||
instance.name = name
|
instance.name = name
|
||||||
instance.type = def.type
|
instance.type = def.type
|
||||||
|
instance.biomes = def.biomes
|
||||||
|
instance.minY = def.minY
|
||||||
|
instance.maxY = def.maxY
|
||||||
instance.wherein = def.wherein
|
instance.wherein = def.wherein
|
||||||
instance.nodeName = def.nodeName
|
instance.nodeName = def.nodeName
|
||||||
instance.nodeParam2 = def.nodeParam2 or 0
|
instance.nodeParam2 = def.nodeParam2 or 0
|
||||||
@@ -144,7 +149,7 @@ function Ore:generate(factors, data, data2, index, x, y, z)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.type == 'cheesed' then
|
if self.type == 'cheesy' then
|
||||||
return self:generateCheesed(factors, data, data2, index, x, y, z)
|
return self:generateCheesed(factors, data, data2, index, x, y, z)
|
||||||
elseif self.type == 'custom' then
|
elseif self.type == 'custom' then
|
||||||
return self:oreFunc(factors, data, data2, index, x, y, z)
|
return self:oreFunc(factors, data, data2, index, x, y, z)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function Tree:new(name, def)
|
|||||||
local intance = getInstance(self, {})
|
local intance = getInstance(self, {})
|
||||||
intance.name = name
|
intance.name = name
|
||||||
intance.path = def.path
|
intance.path = def.path
|
||||||
intance.placerName = Mod.getInfo().shortName..':'..name..'_placer'
|
intance.placerName = Mod:getInfo().shortName..':'..name..'_placer'
|
||||||
|
|
||||||
intance:registerPlacer()
|
intance:registerPlacer()
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ function Tree:place(pos)
|
|||||||
local pos1, pos2 = pos - v(16, 0, 16), pos + v(16, 80, 16) --[[@as MapVector]]
|
local pos1, pos2 = pos - v(16, 0, 16), pos + v(16, 80, 16) --[[@as MapVector]]
|
||||||
|
|
||||||
if isAreaGenerated(pos1, pos2) then
|
if isAreaGenerated(pos1, pos2) then
|
||||||
corePlaceSchematic(pos, self.path, getRotation(pos), nil, nil, 'place_center_x, place_center_z')
|
corePlaceSchematic(pos, self.path, getRotation(pos), nil, false, 'place_center_x, place_center_z')
|
||||||
else
|
else
|
||||||
coreEmergeArea(pos1, pos2)
|
coreEmergeArea(pos1, pos2)
|
||||||
end
|
end
|
||||||
@@ -122,7 +122,7 @@ end
|
|||||||
---@param voxelManip VoxelManip
|
---@param voxelManip VoxelManip
|
||||||
---@param pos MapVector
|
---@param pos MapVector
|
||||||
function Tree:placeOnVM(voxelManip, pos)
|
function Tree:placeOnVM(voxelManip, pos)
|
||||||
local result = corePlaceSchematicOnVM(voxelManip, pos, self.path, getRotation(pos), nil, nil, 'place_center_x, place_center_z')
|
local result = corePlaceSchematicOnVM(voxelManip, pos, self.path, getRotation(pos), nil, false, 'place_center_x, place_center_z')
|
||||||
|
|
||||||
if not result then
|
if not result then
|
||||||
voxelManip:set_node_at(pos, {name = self.placerName, force_place = true})
|
voxelManip:set_node_at(pos, {name = self.placerName, force_place = true})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local v = vector.new
|
|||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__map_gen').require
|
local require = Mod:getInfo('smc__core__map_gen').require
|
||||||
|
|
||||||
---@type MapGen.Edge
|
---@type MapGen.Edge
|
||||||
local Edge = require('MapGen.Edge')
|
local Edge = require('MapGen.Edge')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__node')
|
local modInfo = Mod:getInfo('smc__core__node')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Node')
|
return require('Node')
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ local function registerSlab(nodeDef)
|
|||||||
settings.drawtype = 'nodebox'
|
settings.drawtype = 'nodebox'
|
||||||
settings.paramtype = 'light'
|
settings.paramtype = 'light'
|
||||||
settings.paramtype2 = 'facedir'
|
settings.paramtype2 = 'facedir'
|
||||||
settings.groups['segments'] = nil
|
settings.groups.segments = nil
|
||||||
settings.groups['slabs'] = 1
|
settings.groups.slabs = 1
|
||||||
if nodeDef.callbacks ~= nil then
|
if nodeDef.callbacks ~= nil then
|
||||||
nodeDef.callbacks.on_place = core.rotate_and_place
|
nodeDef.callbacks.on_place = core.rotate_and_place
|
||||||
else
|
else
|
||||||
@@ -52,8 +52,8 @@ local function registerStair(nodeDef)
|
|||||||
settings.drawtype = 'nodebox'
|
settings.drawtype = 'nodebox'
|
||||||
settings.paramtype = 'light'
|
settings.paramtype = 'light'
|
||||||
settings.paramtype2 = 'facedir'
|
settings.paramtype2 = 'facedir'
|
||||||
settings.groups['segments'] = nil
|
settings.groups.segments = nil
|
||||||
settings.groups['slabs'] = 1
|
settings.groups.stairs = 1
|
||||||
if nodeDef.callbacks ~= nil then
|
if nodeDef.callbacks ~= nil then
|
||||||
nodeDef.callbacks.on_place = core.rotate_and_place
|
nodeDef.callbacks.on_place = core.rotate_and_place
|
||||||
else
|
else
|
||||||
@@ -72,10 +72,12 @@ function Node:new(nodeDef)
|
|||||||
local settings = nodeDef.settings
|
local settings = nodeDef.settings
|
||||||
settings._type = 'node'
|
settings._type = 'node'
|
||||||
|
|
||||||
|
local instance = Item:new(nodeDef) --[[@as Node]]
|
||||||
|
|
||||||
-- Registration of segmented blocks.
|
-- Registration of segmented blocks.
|
||||||
-- If you specify a specific group with a specific index for a node,
|
-- If you specify a specific group with a specific index for a node,
|
||||||
-- the slabs and stairs will be registered automatically.
|
-- the slabs and stairs will be registered automatically.
|
||||||
local segmentsIndex = settings.groups and settings.groups['segments']
|
local segmentsIndex = settings.groups and settings.groups.segments
|
||||||
if segmentsIndex == 1 then
|
if segmentsIndex == 1 then
|
||||||
-- Only slabs
|
-- Only slabs
|
||||||
registerSlab(nodeDef)
|
registerSlab(nodeDef)
|
||||||
@@ -88,8 +90,6 @@ function Node:new(nodeDef)
|
|||||||
registerStair(nodeDef)
|
registerStair(nodeDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
local instance = Item:new(nodeDef) --[[@as Node]]
|
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
---@meta
|
---@meta
|
||||||
|
|
||||||
---@class Node.Settings : Item.Settings, NodeDefinition.Settings
|
---@class Node.Settings : NodeDefinition.Settings, Item.Settings
|
||||||
local Settings = {}
|
local Settings = {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__plant')
|
local modInfo = Mod:getInfo('smc__core__plant')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Plant')
|
return require('Plant')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__player')
|
local modInfo = Mod:getInfo('smc__core__player')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Player')
|
return require('Player')
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
local Player = {}
|
local Player = {}
|
||||||
|
|
||||||
---@type PlayerInventoryUI
|
---@type PlayerInventoryUI
|
||||||
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
local PlayerInventoryUI = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
core.register_on_joinplayer(function(player)
|
core.register_on_joinplayer(function(player)
|
||||||
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
||||||
@@ -29,7 +29,7 @@ core.register_chatcommand('show_inv',
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__player').require
|
local require = Mod:getInfo('smc__core__player').require
|
||||||
|
|
||||||
require('Player.inventory')
|
require('Player.inventory')
|
||||||
|
|
||||||
|
|||||||
19
mods/CORE/Player/src/Player/PlayerMetaRef.lua
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias PlayerMetaRef.IntKey
|
||||||
|
---| 'progression_system.player_age'
|
||||||
|
|
||||||
|
---@alias PlayerMetaRef.FloatKey string
|
||||||
|
|
||||||
|
---@alias PlayerMetaRef.StringKey string
|
||||||
|
---| 'progression_system.player_milestones'
|
||||||
|
|
||||||
|
-- Overriding PlayerMetaRef for annotations and metadata field hints.
|
||||||
|
|
||||||
|
---@class PlayerMetaRef : MetaDataRef
|
||||||
|
---@field get_int fun(self, key:PlayerMetaRef.IntKey):integer
|
||||||
|
---@field set_int fun(self, key:PlayerMetaRef.IntKey, value:integer)
|
||||||
|
---@field get_float fun(self, key:PlayerMetaRef.FloatKey, string):number
|
||||||
|
---@field set_float fun(self, key:PlayerMetaRef.FloatKey, string, value:number)
|
||||||
|
---@field get_string fun(self, key:PlayerMetaRef.StringKey):string
|
||||||
|
---@field set_string fun(self, key:PlayerMetaRef.StringKey, value:string)
|
||||||
@@ -1,6 +1,2 @@
|
|||||||
|
|
||||||
---@type PlayerInventoryUI
|
---@type PlayerInventoryUI
|
||||||
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
local PlayerInventoryUI = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
-- TODO: перенести обработки в PlayerUI
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__processing_container_station')
|
local modInfo = Mod:getInfo('smc__core__processing_container_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProcessingContainerStation')
|
return require('ProcessingContainerStation')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__processing_fuel_station')
|
local modInfo = Mod:getInfo('smc__core__processing_fuel_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProcessingFuelStation')
|
return require('ProcessingFuelStation')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__processing_station')
|
local modInfo = Mod:getInfo('smc__core__processing_station')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('ProcessingStation')
|
return require('ProcessingStation')
|
||||||
|
|||||||
4
mods/CORE/ProgressionSystem/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod:getInfo('smc__core__progression_system')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('ProgressionSystem')
|
||||||
2
mods/CORE/ProgressionSystem/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__progression_system
|
||||||
|
depends = smc__system__system_loader
|
||||||
122
mods/CORE/ProgressionSystem/src/ProgressionSystem.lua
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
local assert = assert
|
||||||
|
|
||||||
|
local require = Mod:getInfo('smc__core__progression_system').require
|
||||||
|
|
||||||
|
---@type ProgressionSystem.Age
|
||||||
|
local Age = require('ProgressionSystem.Age')
|
||||||
|
---@type ProgressionSystem.Milestone
|
||||||
|
local Milestone = require('ProgressionSystem.Milestone')
|
||||||
|
|
||||||
|
---The zeroth century, from which progression begins.
|
||||||
|
---
|
||||||
|
---It is not registered through the usual mechanism,
|
||||||
|
---but is integrated directly into the progression system.
|
||||||
|
local zeroAge = Age:new('zero', {})
|
||||||
|
zeroAge.id = 0
|
||||||
|
|
||||||
|
---@class ProgressionSystem
|
||||||
|
---@field agesByName table<ProgressionSystem.Age.Name, ProgressionSystem.Age>
|
||||||
|
---@field agesByID table<integer, ProgressionSystem.Age>
|
||||||
|
---
|
||||||
|
---The age ID currently reached by players in global progression.
|
||||||
|
---@field serverAge integer
|
||||||
|
local ProgressionSystem = {
|
||||||
|
agesByName = { ['zero'] = zeroAge, },
|
||||||
|
agesByID = { [0] = zeroAge },
|
||||||
|
serverAge = 10, -- DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param ageName ProgressionSystem.Age.Name
|
||||||
|
---@param def ProgressionSystem.AgeDef
|
||||||
|
function ProgressionSystem:registerAge(ageName, def)
|
||||||
|
assert(self.agesByName[ageName] == nil)
|
||||||
|
|
||||||
|
local age = Age:new(ageName, def)
|
||||||
|
self.agesByName[ageName] = age
|
||||||
|
|
||||||
|
age.id = #self.agesByID + 1
|
||||||
|
self.agesByID[age.id] = age
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ageName ProgressionSystem.Age.Name
|
||||||
|
---@return ProgressionSystem.Age
|
||||||
|
function ProgressionSystem:getAgeByName(ageName)
|
||||||
|
assert(self.agesByName[ageName] ~= nil)
|
||||||
|
|
||||||
|
return self.agesByName[ageName]
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param id integer
|
||||||
|
---@return ProgressionSystem.Age
|
||||||
|
function ProgressionSystem:getAgeByID(id)
|
||||||
|
assert(self.agesByID[id] ~= nil)
|
||||||
|
|
||||||
|
return self.agesByID[id]
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ageName ProgressionSystem.Age.Name
|
||||||
|
---@param milestoneName string
|
||||||
|
---@param def ProgressionSystem.MilestoneDef
|
||||||
|
function ProgressionSystem:registerMilestone(ageName, milestoneName, def)
|
||||||
|
local age = self:getAgeByName(ageName)
|
||||||
|
|
||||||
|
local milestone = Milestone:new(milestoneName, def)
|
||||||
|
|
||||||
|
age:addMilestone(milestoneName, milestone)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ageName ProgressionSystem.Age.Name
|
||||||
|
---@param milestoneName string
|
||||||
|
---@return ProgressionSystem.Milestone
|
||||||
|
function ProgressionSystem:getMilestoneByName(ageName, milestoneName)
|
||||||
|
local age = self:getAgeByName(ageName)
|
||||||
|
|
||||||
|
return age:getMilestoneByName(milestoneName)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ageID integer
|
||||||
|
function ProgressionSystem:setServerAge(ageID)
|
||||||
|
assert(ageID <= #self.agesByID)
|
||||||
|
|
||||||
|
self.serverAge = ageID
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return integer
|
||||||
|
function ProgressionSystem:getServerAge()
|
||||||
|
return self.serverAge
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param playerMeta PlayerMetaRef
|
||||||
|
---@return integer
|
||||||
|
function ProgressionSystem:getPlayerAge(playerMeta)
|
||||||
|
return playerMeta:get_int('progression_system.player_age')
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param playerMeta PlayerMetaRef
|
||||||
|
---@param ageID integer
|
||||||
|
function ProgressionSystem:setPlayerAge(playerMeta, ageID)
|
||||||
|
assert(ageID <= ProgressionSystem.serverAge, 'The players progress age cannot exceed the servers progress age.')
|
||||||
|
|
||||||
|
playerMeta:set_int('progression_system.player_age', ageID)
|
||||||
|
end
|
||||||
|
|
||||||
|
---The table of progression milestones, which is stored in the player's metadata.
|
||||||
|
---
|
||||||
|
---Milestones are divided into their Ages and are listed by name.
|
||||||
|
---@alias ProgressionSystem.PlayerMilestones table<integer, table<string, ProgressionSystem.Milestone>>
|
||||||
|
|
||||||
|
---@param playerMeta PlayerMetaRef
|
||||||
|
---@return ProgressionSystem.PlayerMilestones
|
||||||
|
function ProgressionSystem:getPlayerMilestones(playerMeta)
|
||||||
|
local milestones = core.deserialize(playerMeta:get_string('progression_system.player_milestones')) or {}
|
||||||
|
|
||||||
|
return milestones
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param playerMeta PlayerMetaRef
|
||||||
|
---@param milestones ProgressionSystem.PlayerMilestones
|
||||||
|
function ProgressionSystem:setPlayerMilestones(playerMeta, milestones)
|
||||||
|
playerMeta:set_string('progression_system.player_milestones', core.serialize(milestones))
|
||||||
|
end
|
||||||
|
|
||||||
|
return ProgressionSystem
|
||||||
47
mods/CORE/ProgressionSystem/src/ProgressionSystem/Age.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
local assert = assert
|
||||||
|
|
||||||
|
local tableInsert = table.insert
|
||||||
|
|
||||||
|
---@alias ProgressionSystem.Age.Name
|
||||||
|
---| 'zero'
|
||||||
|
|
||||||
|
---@class ProgressionSystem.Age : Class
|
||||||
|
---@field name ProgressionSystem.Age.Name
|
||||||
|
---@field id integer
|
||||||
|
---
|
||||||
|
---@field milestonesByName ProgressionSystem.Milestone[]
|
||||||
|
---@field milestonesList ProgressionSystem.Milestone[]
|
||||||
|
local Age = Class:extend({
|
||||||
|
milestonesByName = {},
|
||||||
|
milestonesList = {},
|
||||||
|
})
|
||||||
|
|
||||||
|
---@class ProgressionSystem.AgeDef
|
||||||
|
|
||||||
|
---@param name ProgressionSystem.Age.Name
|
||||||
|
---@param def ProgressionSystem.AgeDef
|
||||||
|
function Age:new(name, def)
|
||||||
|
local instance = self:getInstance({})
|
||||||
|
instance.name = name
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param milestoneName string
|
||||||
|
---@param milestone ProgressionSystem.Milestone
|
||||||
|
function Age:addMilestone(milestoneName, milestone)
|
||||||
|
assert(self.milestonesByName[milestoneName] == nil)
|
||||||
|
|
||||||
|
self.milestonesByName[milestoneName] = milestone
|
||||||
|
tableInsert(self.milestonesList, milestone)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param milestoneName string
|
||||||
|
---@return ProgressionSystem.Milestone
|
||||||
|
function Age:getMilestoneByName(milestoneName)
|
||||||
|
assert(self.milestonesByName[milestoneName] ~= nil)
|
||||||
|
|
||||||
|
return self.milestonesByName[milestoneName]
|
||||||
|
end
|
||||||
|
|
||||||
|
return Age
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---@class ProgressionSystem.Milestone : Class
|
||||||
|
---@field name string
|
||||||
|
local Milestone = Class:extend()
|
||||||
|
|
||||||
|
---@class ProgressionSystem.MilestoneDef
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param def ProgressionSystem.MilestoneDef
|
||||||
|
function Milestone:new(name, def)
|
||||||
|
local instance = self:getInstance({})
|
||||||
|
instance.name = name
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
return Milestone
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__sound')
|
local modInfo = Mod:getInfo('smc__core__sound')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Sound')
|
return require('Sound')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__tilesheet')
|
local modInfo = Mod:getInfo('smc__core__tilesheet')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('TileSheet')
|
return require('TileSheet')
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__tool')
|
local modInfo = Mod:getInfo('smc__core__tool')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Tool')
|
return require('Tool')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
--core.set_mapgen_setting('chunksize', '{x=2,y=10,z=2}', true)
|
--core.set_mapgen_setting('chunksize', '{x=2,y=10,z=2}', true)
|
||||||
|
|
||||||
local mapGeneneratorRequire = Mod.getInfo('smc__core__map_generator').require
|
local mapGeneneratorRequire = Mod:getInfo('smc__core__map_generator').require
|
||||||
|
|
||||||
-- Main env init
|
-- Main env init
|
||||||
local mapGenerator = mapGeneneratorRequire('mapGenerator')
|
local mapGenerator = mapGeneneratorRequire('mapGenerator')
|
||||||
|
|||||||
1
mods/ENVIRONMENT/mapGenerator/maps/origia.json
Normal file
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__map_generator
|
name = smc__core__map_generator
|
||||||
depends = smc__core__map_gen, smc__game__items__rocks, smc__game__items__liquids
|
depends = smc__core__map_gen, smc__game__items__rocks, smc__game__items__liquids, smc__game__items__soils, smc__game__items__clays, smc__game__items__sands, smc__game__items__plants
|
||||||
|
|||||||
BIN
mods/ENVIRONMENT/mapGenerator/schems/allwhere_tree_a.mts
Normal file
BIN
mods/ENVIRONMENT/mapGenerator/schems/marentine_tree_a.mts
Normal file
@@ -5,12 +5,16 @@
|
|||||||
-- so global tables need to be preloaded manually.
|
-- so global tables need to be preloaded manually.
|
||||||
|
|
||||||
-- --- Global APIs load --
|
-- --- Global APIs load --
|
||||||
-- Class
|
|
||||||
dofile(core.get_modpath('smc__system__class')..'/init.lua')
|
|
||||||
|
|
||||||
-- Ensure
|
-- Ensure
|
||||||
dofile(core.get_modpath('smc__system__ensure')..'/init.lua')
|
dofile(core.get_modpath('smc__system__ensure')..'/init.lua')
|
||||||
|
|
||||||
|
-- Table
|
||||||
|
dofile(core.get_modpath('smc__system__table')..'/init.lua')
|
||||||
|
|
||||||
|
-- Class
|
||||||
|
dofile(core.get_modpath('smc__system__class')..'/init.lua')
|
||||||
|
|
||||||
-- Logger
|
-- Logger
|
||||||
dofile(core.get_modpath('smc__system__logger')..'/init.lua')
|
dofile(core.get_modpath('smc__system__logger')..'/init.lua')
|
||||||
|
|
||||||
@@ -34,9 +38,6 @@ dofile(core.get_modpath('smc__system__mod')..'/init.lua')
|
|||||||
-- String
|
-- String
|
||||||
-- dofile(core.get_modpath('smc__system__string')..'/init.lua')
|
-- dofile(core.get_modpath('smc__system__string')..'/init.lua')
|
||||||
|
|
||||||
-- Table
|
|
||||||
dofile(core.get_modpath('smc__system__table')..'/init.lua')
|
|
||||||
|
|
||||||
-- TODO: пока что закоментировано, поскольку вызывает ошибку из-за global_step
|
-- TODO: пока что закоментировано, поскольку вызывает ошибку из-за global_step
|
||||||
-- Smc lib loader
|
-- Smc lib loader
|
||||||
-- dofile(core.get_modpath('smc__system__helper_lib')..'/init.lua')
|
-- dofile(core.get_modpath('smc__system__helper_lib')..'/init.lua')
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.2 KiB |
47
mods/GAME/ITEMS/clays/init.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
local Item, Node, TileSheet = Smc.requireItem(), Smc.requireNode(), Smc.requireTileSheet()
|
||||||
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|
||||||
|
-- local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
|
||||||
|
|
||||||
|
---@type TileSheet
|
||||||
|
local clayTileSheet = TileSheet:new('clays_sheet.png', 16, 16)
|
||||||
|
|
||||||
|
---@param type string
|
||||||
|
---@param y integer
|
||||||
|
local function registerSand(type, y)
|
||||||
|
Node:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_clay_block',
|
||||||
|
groups = { clay_block = 1, dig_immediate = 2 },
|
||||||
|
tiles = { clayTileSheet:t(0, y)}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_clay',
|
||||||
|
inventory_image = clayTileSheet:t(1, y),
|
||||||
|
groups = { clay = 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Node:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_clay_bricks',
|
||||||
|
tiles = { clayTileSheet:t(2, y)},
|
||||||
|
groups = { clay_bricks = 1, dig_immediate = 2 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_clay_brick',
|
||||||
|
inventory_image = clayTileSheet:t(3, y),
|
||||||
|
groups = { clay_brick = 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
registerSand('red', 0)
|
||||||
|
registerSand('white', 1)
|
||||||
|
registerSand('fireproof', 2)
|
||||||
2
mods/GAME/ITEMS/clays/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__game__items__clays
|
||||||
|
depends = smc__core__node, smc__core__tilesheet
|
||||||
BIN
mods/GAME/ITEMS/clays/textures/sheets/clays_sheet.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
67
mods/GAME/ITEMS/ores/init.lua
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
local Item, Node, TileSheet = Smc.requireItem(), Smc.requireNode(), Smc.requireTileSheet()
|
||||||
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|
||||||
|
-- local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
|
||||||
|
|
||||||
|
---@type TileSheet
|
||||||
|
local oreTileSheet = TileSheet:new('ores_sheet.png', 16, 16)
|
||||||
|
|
||||||
|
---@class OreDef
|
||||||
|
---@field rarity Item.Rarity?
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param y integer
|
||||||
|
---@param def OreDef?
|
||||||
|
local function registerOre(name, y, def)
|
||||||
|
if def == nil then
|
||||||
|
def = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = name,
|
||||||
|
rarity = def.rarity,
|
||||||
|
inventory_image = oreTileSheet:t(0, y),
|
||||||
|
groups = { ore = 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Ores Items --
|
||||||
|
-- Slag
|
||||||
|
registerOre('slag', 0, {})
|
||||||
|
|
||||||
|
-- Copper ores
|
||||||
|
registerOre('chalcopyrite', 1, {})
|
||||||
|
registerOre('malachite', 2, {})
|
||||||
|
registerOre('cuprite', 3, {})
|
||||||
|
registerOre('native_copper', 4, {})
|
||||||
|
|
||||||
|
-- Tin ores
|
||||||
|
registerOre('cassiterite', 5, {})
|
||||||
|
registerOre('stannite', 6, {})
|
||||||
|
|
||||||
|
-- Iron oresLimonite
|
||||||
|
registerOre('limonite', 7, {})
|
||||||
|
registerOre('hematite', 8, {})
|
||||||
|
registerOre('magnetite', 9, {})
|
||||||
|
registerOre('meteoric_iron', 10, {})
|
||||||
|
|
||||||
|
-- Ores blocks --
|
||||||
|
-- Slag
|
||||||
|
Node:new({
|
||||||
|
settings = {
|
||||||
|
name = 'slag_block',
|
||||||
|
tiles = { oreTileSheet:t(1, 0) },
|
||||||
|
groups = { ore = 1, dig_immediate = 2 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Malachite
|
||||||
|
Node:new({
|
||||||
|
settings = {
|
||||||
|
name = 'malachite_block',
|
||||||
|
tiles = { oreTileSheet:t(1, 2) },
|
||||||
|
groups = { ore = 1, dig_immediate = 2 }
|
||||||
|
}
|
||||||
|
})
|
||||||
2
mods/GAME/ITEMS/ores/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__game__items__ores
|
||||||
|
depends = smc__core__node, smc__core__tilesheet
|
||||||
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 66 KiB |
@@ -1,16 +1,40 @@
|
|||||||
local Plant, TileSheet = Smc.requirePlant(), Smc.requireTileSheet()
|
local Plant, TileSheet = Smc.requirePlant(), Smc.requireTileSheet()
|
||||||
|
|
||||||
Plant:new({
|
local placeParam2 = {
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
34,
|
||||||
|
35,
|
||||||
|
36
|
||||||
|
}
|
||||||
|
|
||||||
|
local function afterPlaceNode(pos, placer, itemstack, pointed_thing)
|
||||||
|
local node = core.get_node(pos)
|
||||||
|
node.param2 = 8 + placeParam2[math.random(#placeParam2)]
|
||||||
|
core.set_node(pos, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- --- Bog plants ---
|
||||||
|
local BogPlantsTileSheet = TileSheet:new('plants_bog_sheet.png', 16, 16)
|
||||||
|
|
||||||
|
for i=1, 3 do
|
||||||
|
Plant:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = 'plants',
|
name = 'bog_grass_'..tostring(i),
|
||||||
tiles = { "test_plant.png" },
|
tiles = { BogPlantsTileSheet:t(i-1, 0) },
|
||||||
place_param2 = 3,
|
place_param2 = 8,
|
||||||
},
|
},
|
||||||
})
|
callbacks = {
|
||||||
|
after_place_node = afterPlaceNode,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- DEBUG
|
||||||
|
|
||||||
local PlantsTileSheet = TileSheet:new('plants_test_sheet.png', 16, 16)
|
local PlantsTileSheet = TileSheet:new('plants_test_sheet.png', 16, 16)
|
||||||
|
|
||||||
|
|
||||||
for i=0, 3 do
|
for i=0, 3 do
|
||||||
Plant:new({
|
Plant:new({
|
||||||
settings = {
|
settings = {
|
||||||
@@ -53,6 +77,3 @@ Plant:new({
|
|||||||
place_param2 = 3,
|
place_param2 = 3,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
mods/GAME/ITEMS/plants/textures/sheets/plants_bog_sheet.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -4,7 +4,7 @@ local CraftSystem = Smc.requireCraftSystem()
|
|||||||
local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
|
local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
|
||||||
|
|
||||||
---@type TileSheet
|
---@type TileSheet
|
||||||
local rocksTileSheet = TileSheet:new("rocks_sheet.png", 16, 16)
|
local rocksTileSheet = TileSheet:new('rocks_sheet.png', 16, 16)
|
||||||
|
|
||||||
---@class RockDef
|
---@class RockDef
|
||||||
---@field rarity Item.Rarity?
|
---@field rarity Item.Rarity?
|
||||||
@@ -24,7 +24,7 @@ local function registerSegmentsCrafts(name, craftGroup)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param y number
|
---@param y integer
|
||||||
---@param def RockDef?
|
---@param def RockDef?
|
||||||
---@param staff {block:boolean?,bricks:boolean?,pillar:boolean?}
|
---@param staff {block:boolean?,bricks:boolean?,pillar:boolean?}
|
||||||
local function registerRock(name, y, def, staff)
|
local function registerRock(name, y, def, staff)
|
||||||
@@ -32,7 +32,7 @@ local function registerRock(name, y, def, staff)
|
|||||||
def = {}
|
def = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local modPrefix = Mod.getInfo().shortName..':'
|
local modPrefix = Mod:getInfo().shortName..':'
|
||||||
local craftGroup = 'rocks_'..name..'_staff'
|
local craftGroup = 'rocks_'..name..'_staff'
|
||||||
|
|
||||||
-- Default rock
|
-- Default rock
|
||||||
@@ -150,6 +150,7 @@ local function registerRock(name, y, def, staff)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
-- Sylite group
|
-- Sylite group
|
||||||
registerRock('sylite', 0, {}, {block = true, bricks = true, pillar = true})
|
registerRock('sylite', 0, {}, {block = true, bricks = true, pillar = true})
|
||||||
registerRock('sylite_gray', 1, {}, {block = true, bricks = true, pillar = true})
|
registerRock('sylite_gray', 1, {}, {block = true, bricks = true, pillar = true})
|
||||||
@@ -165,11 +166,10 @@ registerRock('falmyte_light', 6, {}, {block = true, bricks = true})
|
|||||||
registerRock('falmyte_yellow', 7, {}, {block = true, bricks = true})
|
registerRock('falmyte_yellow', 7, {}, {block = true, bricks = true})
|
||||||
registerRock('falmyte_red', 8, {}, {block = true, bricks = true})
|
registerRock('falmyte_red', 8, {}, {block = true, bricks = true})
|
||||||
registerRock('falmyte_dark', 9, {}, {block = true, bricks = true})
|
registerRock('falmyte_dark', 9, {}, {block = true, bricks = true})
|
||||||
|
--]]
|
||||||
|
|
||||||
|
registerRock('basalt', 0, {}, {block = true, bricks = true})
|
||||||
|
registerRock('granite_red', 1, {}, {block = true, bricks = true})
|
||||||
|
registerRock('limestone', 2, {}, {block = true, bricks = true})
|
||||||
|
registerRock('dolomit', 3, {}, {block = true, bricks = true})
|
||||||
|
|
||||||
-- TODO:
|
|
||||||
-- iyellite
|
|
||||||
-- falmyte
|
|
||||||
-- hapcoryte
|
|
||||||
-- burcite
|
|
||||||
-- felhor
|
|
||||||
-- malachite
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 5.0 KiB |
46
mods/GAME/ITEMS/sands/init.lua
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
local Item, Node, TileSheet = Smc.requireItem(), Smc.requireNode(), Smc.requireTileSheet()
|
||||||
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|
||||||
|
-- local InventoryCraftHandler = CraftSystem:getPrimitiveCraftHandler('inside_player_inventory')
|
||||||
|
|
||||||
|
---@type TileSheet
|
||||||
|
local sandTileSheet = TileSheet:new('sands_sheet.png', 16, 16)
|
||||||
|
|
||||||
|
---@param type string
|
||||||
|
---@param y integer
|
||||||
|
local function registerSand(type, y)
|
||||||
|
local defaultSandNode = Node:getExtended({
|
||||||
|
settings = {
|
||||||
|
name = '',
|
||||||
|
groups = { dig_immediate = 2 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
defaultSandNode:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_sand',
|
||||||
|
tiles = { sandTileSheet:t(0, y) },
|
||||||
|
groups = { sand = 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
defaultSandNode:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_sandstone',
|
||||||
|
tiles = { sandTileSheet:t(1, y) },
|
||||||
|
groups = { sandstone = 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
defaultSandNode:new({
|
||||||
|
settings = {
|
||||||
|
name = type..'_sandstone_chipped',
|
||||||
|
tiles = { sandTileSheet:t(2, y) },
|
||||||
|
groups = { sandstone = 1 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
registerSand('yellow', 0)
|
||||||
|
registerSand('red', 1)
|
||||||
|
registerSand('black', 2)
|
||||||
2
mods/GAME/ITEMS/sands/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__game__items__sands
|
||||||
|
depends = smc__core__node, smc__core__tilesheet
|
||||||
BIN
mods/GAME/ITEMS/sands/textures/sheets/sands_sheet.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
@@ -1,7 +1,9 @@
|
|||||||
local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
||||||
|
|
||||||
---@type TileSheet
|
---@type TileSheet
|
||||||
local soilTileSheet = TileSheet:new("soils_sheet.png", 16, 16)
|
local soilTileSheet = TileSheet:new('soils_sheet.png', 16, 16)
|
||||||
|
---@type TileSheet
|
||||||
|
local grassTileSheet = TileSheet:new('soils_grass_sheet.png', 16, 16)
|
||||||
|
|
||||||
---@class SoilDef
|
---@class SoilDef
|
||||||
---@field rarity Item.Rarity?
|
---@field rarity Item.Rarity?
|
||||||
@@ -28,7 +30,10 @@ local function registerSoil(name, x, def, turfs)
|
|||||||
defaultSoil:new({
|
defaultSoil:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name,
|
name = name,
|
||||||
tiles = {soilTexture}
|
tiles = { soilTexture },
|
||||||
|
paramtype2 ='color4dir',
|
||||||
|
palette = 'soils_grass_palette.png',
|
||||||
|
drop = 'soils:'..name,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -56,240 +61,35 @@ local function registerSoil(name, x, def, turfs)
|
|||||||
})
|
})
|
||||||
|
|
||||||
if turfs ~= nil then
|
if turfs ~= nil then
|
||||||
for turfName, turfX in pairs(turfs) do
|
for turfName, turfY in pairs(turfs) do
|
||||||
defaultSoil:new({
|
defaultSoil:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = turfName,
|
name = turfName,
|
||||||
tiles = {
|
tiles = {
|
||||||
soilTileSheet:t(turfX,2),
|
grassTileSheet:t(0, turfY),
|
||||||
soilTexture,
|
{name = soilTexture, color = 'white'},
|
||||||
soilTexture..'^'..soilTileSheet:t(turfX,3)
|
|
||||||
},
|
},
|
||||||
|
overlay_tiles = {
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
grassTileSheet:t(1, turfY),
|
||||||
|
grassTileSheet:t(2, turfY),
|
||||||
|
grassTileSheet:t(3, turfY),
|
||||||
|
grassTileSheet:t(4, turfY),
|
||||||
|
},
|
||||||
|
paramtype2 ='color4dir',
|
||||||
|
palette = 'soils_grass_palette.png',
|
||||||
|
drop = 'soils:'..turfName,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
registerSoil('mud', 0, {maxFertility = 20, rarity = 'common'}, {
|
||||||
local clayTiles = {
|
turf_bog = 0,
|
||||||
ts:t(0,0)
|
})
|
||||||
}
|
|
||||||
|
|
||||||
local sandyTiles = {
|
registerSoil('chernozem', 1, {maxFertility = 100, rarity = 'uncommon'}, {
|
||||||
ts:t(2,0)
|
turf_meadow = 0,
|
||||||
}
|
})
|
||||||
|
|
||||||
local mixedTiles = {
|
|
||||||
ts:t(4,0)
|
|
||||||
}
|
|
||||||
|
|
||||||
local rockyTiles = {
|
|
||||||
ts:t(6,0)
|
|
||||||
}
|
|
||||||
|
|
||||||
soilFactory:registerItems({
|
|
||||||
--- Clay soils
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "clay_soil_baren",
|
|
||||||
_title = "Barren Clay Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = clayTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "clay_soil_poor",
|
|
||||||
_title = "Poor Clay Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = clayTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "clay_soil_moderate",
|
|
||||||
_title = "Moderate Clay Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = clayTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "clay_soil_fertile",
|
|
||||||
_title = "Fertile Clay Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = clayTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "clay_soil_rich",
|
|
||||||
_title = "Rich Clay Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = clayTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Sandy soils
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "sandy_soil_baren",
|
|
||||||
_title = "Barren Sandy Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = sandyTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "sandy_soil_poor",
|
|
||||||
_title = "Poor Sandy Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = sandyTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "sandy_soil_moderate",
|
|
||||||
_title = "Moderate Sandy Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = sandyTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "sandy_soil_fertile",
|
|
||||||
_title = "Fertile Sandy Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = sandyTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "sandy_soil_rich",
|
|
||||||
_title = "Rich Sandy Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = sandyTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Mixed soils
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "mixed_soil_baren",
|
|
||||||
_title = "Barren Mixed Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = mixedTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "mixed_soil_poor",
|
|
||||||
_title = "Poor Mixed Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = mixedTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "mixed_soil_moderate",
|
|
||||||
_title = "Moderate Mixed Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = mixedTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "mixed_soil_fertile",
|
|
||||||
_title = "Fertile Mixed Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = mixedTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "mixed_soil_rich",
|
|
||||||
_title = "Rich Mixed Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = mixedTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Rocky soils
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "rocky_soil_baren",
|
|
||||||
_title = "Barren Rocky Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = rockyTiles,
|
|
||||||
rarity = 'uncommon'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "rocky_soil_poor",
|
|
||||||
_title = "Poor Rocky Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = rockyTiles,
|
|
||||||
rarity = 'distinguished'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "rocky_soil_moderate",
|
|
||||||
_title = "Moderate Rocky Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = rockyTiles,
|
|
||||||
rarity = 'eminent'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "rocky_soil_fertile",
|
|
||||||
_title = "Fertile Rocky Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = rockyTiles,
|
|
||||||
rarity = 'prime'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
---@type Node.NodeDefinition
|
|
||||||
{
|
|
||||||
settings = {
|
|
||||||
name = "rocky_soil_rich",
|
|
||||||
_title = "Rich Rocky Soil",
|
|
||||||
--description = "",
|
|
||||||
tiles = rockyTiles,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
})--]]
|
|
||||||
|
|
||||||
---@type TileSheet
|
|
||||||
local tsT = TileSheet:new("soils_turfs_sheet.png", 16, 16)
|
|
||||||
|
|
||||||
registerSoil('humus', 0, {maxFertility = 100, rarity = 'uncommon'}, {turf_meadow=0})
|
|
||||||
|
|||||||
BIN
mods/GAME/ITEMS/soils/textures/palettes/soils_grass_palette.png
Normal file
|
After Width: | Height: | Size: 438 B |
BIN
mods/GAME/ITEMS/soils/textures/sheets/soils_grass_sheet.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 22 KiB |
@@ -83,6 +83,7 @@ local function registerWood(name, x, def)
|
|||||||
def = {}
|
def = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Tree log with cut annual rings
|
||||||
defaultLog:new({
|
defaultLog:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_log',
|
name = name..'_log',
|
||||||
@@ -96,6 +97,7 @@ local function registerWood(name, x, def)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Stripped Log
|
||||||
defaultLog:new({
|
defaultLog:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_log_stripped',
|
name = name..'_log_stripped',
|
||||||
@@ -108,25 +110,11 @@ local function registerWood(name, x, def)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Tree trunk completely covered in bark
|
||||||
defaultLog:new({
|
defaultLog:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_timber',
|
name = name..'_trunk',
|
||||||
tiles = {
|
|
||||||
woodTileSheet:t(x, 8)..'^[transformR90', woodTileSheet:t(x, 8)..'^[transformR90',
|
|
||||||
woodTileSheet:t(x, 8), woodTileSheet:t(x, 8),
|
|
||||||
woodTileSheet:t(x, 7), woodTileSheet:t(x, 7)
|
|
||||||
},
|
|
||||||
paramtype2 = 'facedir',
|
|
||||||
_rarity = def.rarity,
|
|
||||||
groups = {segments = 1}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
defaultLog:new({
|
|
||||||
settings = {
|
|
||||||
name = name..'_trunk_6_sides',
|
|
||||||
tiles = {woodTileSheet:t(x, 3)},
|
tiles = {woodTileSheet:t(x, 3)},
|
||||||
inventory_overlay = 'wood_trunk_overlay.png',
|
|
||||||
drop = 'wood:'..name..'_log',
|
drop = 'wood:'..name..'_log',
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
_rarity = def.rarity,
|
_rarity = def.rarity,
|
||||||
@@ -136,24 +124,13 @@ local function registerWood(name, x, def)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- --- Tree branches ---
|
||||||
|
|
||||||
|
-- Branch completely covered in bark
|
||||||
defaultLog:new({
|
defaultLog:new({
|
||||||
settings = {
|
|
||||||
name = name..'_trunk_4_sides',
|
|
||||||
tiles = getLogTiles(x, 2),
|
|
||||||
inventory_overlay = 'wood_trunk_overlay.png',
|
|
||||||
drop = 'wood:'..name..'_log',
|
|
||||||
paramtype2 = 'facedir',
|
|
||||||
_rarity = def.rarity,
|
|
||||||
},
|
|
||||||
callbacks = {
|
|
||||||
on_place = core.rotate_node
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
local defaultBranch6Sides = defaultLog:getExtended({
|
|
||||||
settings = {
|
settings = {
|
||||||
drawtype = 'nodebox',
|
drawtype = 'nodebox',
|
||||||
name = '',
|
name = name..'_log_branch_6_sides',
|
||||||
tiles = {woodTileSheet:t(x, 3)},
|
tiles = {woodTileSheet:t(x, 3)},
|
||||||
paramtype = 'light',
|
paramtype = 'light',
|
||||||
node_box = {
|
node_box = {
|
||||||
@@ -171,24 +148,11 @@ local function registerWood(name, x, def)
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
local node = defaultBranch6Sides:new({
|
-- Branch with cut annual rings
|
||||||
settings = {
|
defaultLog:new({
|
||||||
name = name..'_log_branch_6_sides',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
defaultBranch6Sides:new({
|
|
||||||
settings = {
|
|
||||||
name = name..'_trunk_branch_6_sides',
|
|
||||||
inventory_overlay = 'wood_trunk_overlay.png',
|
|
||||||
drop = name..'_log_branch_6_sides',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
local defaultBranch4Sides = defaultLog:getExtended({
|
|
||||||
settings = {
|
settings = {
|
||||||
drawtype = 'nodebox',
|
drawtype = 'nodebox',
|
||||||
name = '',
|
name = name..'_log_branch_4_sides',
|
||||||
tiles = getLogTiles(x, 2),
|
tiles = getLogTiles(x, 2),
|
||||||
drop = 'wood:'..name..'_log',
|
drop = 'wood:'..name..'_log',
|
||||||
paramtype = 'light',
|
paramtype = 'light',
|
||||||
@@ -203,20 +167,43 @@ local function registerWood(name, x, def)
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
defaultBranch4Sides:new({
|
-- Tree leafs
|
||||||
|
defaultLeafs:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_log_branch_4_sides',
|
name = name..'_leafs',
|
||||||
}
|
tiles = { woodTileSheet:t(x, 1) },
|
||||||
})
|
_rarity = def.rarity,
|
||||||
|
},
|
||||||
defaultBranch4Sides:new({
|
})
|
||||||
settings = {
|
|
||||||
name = name..'_trunk_branch_4_sides',
|
|
||||||
inventory_overlay = 'wood_trunk_overlay.png',
|
-- --- Tree lumber ---
|
||||||
drop = name..'_log_branch_4_sides',
|
|
||||||
|
-- Timber (block)
|
||||||
|
defaultLog:new({
|
||||||
|
settings = {
|
||||||
|
name = name..'_timber',
|
||||||
|
tiles = {
|
||||||
|
woodTileSheet:t(x, 8)..'^[transformR90',
|
||||||
|
woodTileSheet:t(x, 8)..'^[transformR90',
|
||||||
|
woodTileSheet:t(x, 8), woodTileSheet:t(x, 8),
|
||||||
|
woodTileSheet:t(x, 7), woodTileSheet:t(x, 7)
|
||||||
|
},
|
||||||
|
paramtype2 = 'facedir',
|
||||||
|
_rarity = def.rarity,
|
||||||
|
groups = {segments = 1}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Bar (item)
|
||||||
|
defaultStick:new({
|
||||||
|
settings = {
|
||||||
|
name = name..'_bar',
|
||||||
|
inventory_image = woodTileSheet:t(x, 11)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Planks (block)
|
||||||
defaultPlanks:new({
|
defaultPlanks:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_planks',
|
name = name..'_planks',
|
||||||
@@ -226,21 +213,7 @@ local function registerWood(name, x, def)
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
defaultLeafs:new({
|
-- Plank (item)
|
||||||
settings = {
|
|
||||||
name = name..'_leafs',
|
|
||||||
tiles = { woodTileSheet:t(x, 1) },
|
|
||||||
_rarity = def.rarity,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
defaultStick:new({
|
|
||||||
settings = {
|
|
||||||
name = name..'_stick',
|
|
||||||
inventory_image = woodTileSheet:t(x, 9)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
defaultStick:new({
|
defaultStick:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_plank',
|
name = name..'_plank',
|
||||||
@@ -248,13 +221,15 @@ local function registerWood(name, x, def)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Stick
|
||||||
defaultStick:new({
|
defaultStick:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_bar',
|
name = name..'_stick',
|
||||||
inventory_image = woodTileSheet:t(x, 11)
|
inventory_image = woodTileSheet:t(x, 9)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- --- Crafts ---
|
||||||
InventoryCraftHandler:registerCraft('wood:'..name..'_planks', {
|
InventoryCraftHandler:registerCraft('wood:'..name..'_planks', {
|
||||||
recipe = {
|
recipe = {
|
||||||
'wood:'..name..'_log'
|
'wood:'..name..'_log'
|
||||||
@@ -271,6 +246,14 @@ local function registerWood(name, x, def)
|
|||||||
group = 'wood:logs_stripped',
|
group = 'wood:logs_stripped',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
InventoryCraftHandler:registerCraft('wood:'..name..'_log_stripped_2', {
|
||||||
|
recipe = {
|
||||||
|
'wood:'..name..'_log 2'
|
||||||
|
},
|
||||||
|
output = 'wood:'..name..'_log_stripped 2',
|
||||||
|
group = 'wood:logs_stripped',
|
||||||
|
})
|
||||||
|
|
||||||
InventoryCraftHandler:registerCraft('wood:'..name..'_bar', {
|
InventoryCraftHandler:registerCraft('wood:'..name..'_bar', {
|
||||||
recipe = {
|
recipe = {
|
||||||
'wood:'..name..'_log'
|
'wood:'..name..'_log'
|
||||||
@@ -291,10 +274,6 @@ local function registerWood(name, x, def)
|
|||||||
recipe = {
|
recipe = {
|
||||||
'wood:'..name..'_bar'
|
'wood:'..name..'_bar'
|
||||||
},
|
},
|
||||||
altRecipes = {
|
|
||||||
{ 'wood:'..name..'_plank 2' },
|
|
||||||
{ 'wood:'..name..'_log'}
|
|
||||||
},
|
|
||||||
output = 'wood:'..name..'_stick 4',
|
output = 'wood:'..name..'_stick 4',
|
||||||
group = 'wood:sticks',
|
group = 'wood:sticks',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,54 +1,44 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__formspec')
|
local modInfo = Mod:getInfo('smc__core__formspec')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type AdminListUI
|
---@type PlayerInventoryUI
|
||||||
local AdminListUI = Mod.getInfo('smc__ui__admin_list').require('AdminListUI')
|
local PlayerInventoryUI = Mod:getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
core.register_chatcommand('list', {
|
core.register_chatcommand('list', {
|
||||||
privs = {server = true},
|
privs = {give = true},
|
||||||
|
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player = core.get_player_by_name(name)
|
PlayerInventoryUI:setContex(name, 'left_tab_name', 'admin_list_tab')
|
||||||
|
PlayerInventoryUI:showForm(name)
|
||||||
AdminListUI:showForm(name)
|
|
||||||
|
|
||||||
return true, ''
|
return true, ''
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
AdminListUI:registerOnFormFieldActionMatch('%S+::item_button',function(player, fieldName, fieldValue)
|
core.register_chatcommand('set_param2', {
|
||||||
---@type ItemStackString?
|
privs = {server = true},
|
||||||
local stack = string.match(fieldName, '(%S+)::item_button')
|
|
||||||
|
|
||||||
if stack == nil then
|
func = function(name, param)
|
||||||
|
local player = core.get_player_by_name(name)
|
||||||
|
if player == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local pos = player:get_pos() - vector.new(0, 0.5, 0)
|
||||||
|
pos = pos:round()
|
||||||
|
|
||||||
local playerName = player:get_player_name()
|
local node = core.get_node(pos)
|
||||||
AdminListUI:setContex(playerName, 'select_item', stack)
|
node.param2 = param
|
||||||
|
core.set_node(pos, node)
|
||||||
|
|
||||||
AdminListUI:showForm(playerName)
|
return true, ''
|
||||||
end)
|
|
||||||
|
|
||||||
AdminListUI:registerOnFormFieldAction('admin_commands:list_add_item', function(player, fieldName, fieldValue)
|
|
||||||
---@type InvRef
|
|
||||||
local inv = player:get_inventory()
|
|
||||||
|
|
||||||
local playerName = player:get_player_name()
|
|
||||||
local stack = AdminListUI:getContex(playerName, 'select_item')
|
|
||||||
stack = ItemStack(stack)
|
|
||||||
stack:set_count(fieldValue)
|
|
||||||
|
|
||||||
if inv:room_for_item('main', stack) then
|
|
||||||
inv:add_item('main', stack)
|
|
||||||
end
|
end
|
||||||
end)
|
})
|
||||||
|
|
||||||
core.register_on_joinplayer(function(player, last_login)
|
core.register_on_joinplayer(function(player, last_login)
|
||||||
player:set_sky({
|
player:set_sky({
|
||||||
sky_color = {
|
sky_color = {
|
||||||
day_sky = '#FCF0ED',
|
day_sky = '#b5e8ff',
|
||||||
day_horizon = '#F1D4C3',
|
day_horizon = '#80bbe2',
|
||||||
},
|
},
|
||||||
type = 'regular',
|
type = 'regular',
|
||||||
})
|
})
|
||||||
@@ -99,11 +89,11 @@ core.register_chatcommand('get_missing_locale', {
|
|||||||
local langCodes = params.lang_codes
|
local langCodes = params.lang_codes
|
||||||
|
|
||||||
if shortModName ~= nil and type(shortModName) ~= 'string' then
|
if shortModName ~= nil and type(shortModName) ~= 'string' then
|
||||||
return false
|
return false, 'Incorrect mod name'
|
||||||
end
|
end
|
||||||
|
|
||||||
if langCodes ~= nil and type(langCodes) ~= 'table' then
|
if langCodes ~= nil and type(langCodes) ~= 'table' then
|
||||||
return false
|
return false, 'Incorrect lang code'
|
||||||
end
|
end
|
||||||
|
|
||||||
local items
|
local items
|
||||||
@@ -130,3 +120,60 @@ core.register_chatcommand('get_missing_locale', {
|
|||||||
return true, ''
|
return true, ''
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
core.register_chatcommand('create_locale', {
|
||||||
|
privs = { server = true },
|
||||||
|
description = '<short_mod_name> <lang_code>',
|
||||||
|
func = function(name, params)
|
||||||
|
local shortModName, langCode = string.match(params, '(%S+) (%S+)')
|
||||||
|
|
||||||
|
if shortModName == nil or shortModName == '' then
|
||||||
|
return false, 'Incorrect mod name!'
|
||||||
|
end
|
||||||
|
|
||||||
|
if langCode == nil or langCode == '' or not table.contains(LANG_CODES, langCode)then
|
||||||
|
return false, 'Incorrect lang code!'
|
||||||
|
end
|
||||||
|
|
||||||
|
local items = Smc.getRegisteredItemsListByMod(shortModName)
|
||||||
|
|
||||||
|
if items == nil then
|
||||||
|
return false, 'There are no items registered for this mod (or the entire game)'
|
||||||
|
end
|
||||||
|
|
||||||
|
local filePath = core.get_worldpath()..('/%s.%s.tr'):format(shortModName, langCode)
|
||||||
|
local file, err = io.open(filePath, 'w')
|
||||||
|
|
||||||
|
if not file then
|
||||||
|
return false, 'Cannot open file: '..err
|
||||||
|
end
|
||||||
|
|
||||||
|
file:write('# textdomain: '..shortModName..'\n\n')
|
||||||
|
|
||||||
|
for _, item in ipairs(items) do
|
||||||
|
local itemSettings = item.itemDef.settings
|
||||||
|
local name = string.match(itemSettings.name, ('%S+:(%S+)'))
|
||||||
|
local title = core.strip_colors(core.get_translated_string(langCode, itemSettings._title))
|
||||||
|
local desc = core.strip_colors(core.get_translated_string(langCode, itemSettings._description))
|
||||||
|
|
||||||
|
if title ~= name..'-title' then
|
||||||
|
title = '[locale already exists]'
|
||||||
|
else
|
||||||
|
title = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
if desc ~= name..'-desc' then
|
||||||
|
desc = '[locale already exists]'
|
||||||
|
else
|
||||||
|
desc = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
file:write(('%s-title=%s\n%s-desc=%s\n'):format(name, title, name, desc))
|
||||||
|
end
|
||||||
|
|
||||||
|
file:write('\n')
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
return true, 'File created: '..filePath
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__game__admin_commands
|
name = smc__game__admin_commands
|
||||||
depends = smc__system__system_loader, smc__ui__admin_list
|
depends = smc__system__system_loader, smc__ui__player_inventory
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local setMetaTable, tableCopy = setmetatable, table.copy_with_metatables
|
local tableMerge, setmetatable, tableCopy = table.merge, setmetatable, table.copy_with_metatables
|
||||||
|
|
||||||
---@class Class
|
---@class Class
|
||||||
Class = {}
|
Class = {}
|
||||||
@@ -7,7 +7,7 @@ Class = {}
|
|||||||
---@param parent table
|
---@param parent table
|
||||||
---@param child table?
|
---@param child table?
|
||||||
function Class.extend(parent, child)
|
function Class.extend(parent, child)
|
||||||
return setMetaTable(child or {}, { __index = tableCopy(parent) })
|
return tableMerge(child or {}, tableCopy(parent))
|
||||||
end
|
end
|
||||||
|
|
||||||
---Intended for class constructors.
|
---Intended for class constructors.
|
||||||
@@ -16,7 +16,8 @@ end
|
|||||||
---@generic T:table
|
---@generic T:table
|
||||||
---@param self T Parent class.
|
---@param self T Parent class.
|
||||||
---@param params table Child object parameters.
|
---@param params table Child object parameters.
|
||||||
---@param metatable table? The table that will become the metatable for the object. Note: The `__index` field will be overwritten by a copy of `self`.
|
---@param metatable table? The table that will become the metatable for the object.
|
||||||
|
--- Note: The `__index` field will be overwritten by a copy of `self`.
|
||||||
---@return T
|
---@return T
|
||||||
function Class.getInstance(self, params, metatable)
|
function Class.getInstance(self, params, metatable)
|
||||||
if metatable == nil then
|
if metatable == nil then
|
||||||
@@ -25,7 +26,7 @@ function Class.getInstance(self, params, metatable)
|
|||||||
|
|
||||||
metatable.__index = tableCopy(self)
|
metatable.__index = tableCopy(self)
|
||||||
|
|
||||||
local instance = setMetaTable(params, metatable)
|
local instance = setmetatable(params, metatable)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -1 +1,2 @@
|
|||||||
name = smc__system__class
|
name = smc__system__class
|
||||||
|
depends = smc__system__table
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__system__events')
|
local modInfo = Mod:getInfo('smc__system__events')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
return require('Events')
|
return require('Events')
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__system__events
|
name = smc__system__events
|
||||||
depends = smc__system__table, smc__system__require, smc__system__class
|
depends = smc__system__table, smc__system__require, smc__system__class, smc__system__mod
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local modInfo = Mod.getInfo('smc__system__helper_lib')
|
local modInfo = Mod:getInfo('smc__system__helper_lib')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
require('Lib')
|
require('Lib')
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__system__helper_lib
|
name = smc__system__helper_lib
|
||||||
depends = smc__system__ensure
|
depends = smc__system__ensure, smc__system__mod, smc__system__utf8
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
|
---SMC helper lib
|
||||||
|
---@class Smc
|
||||||
Smc = {}
|
Smc = {}
|
||||||
|
|
||||||
---@type boolean
|
---@type boolean
|
||||||
Smc.isAsync = false
|
Smc.isAsync = false
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__system__helper_lib')
|
local modInfo = Mod:getInfo('smc__system__helper_lib')
|
||||||
local require = modInfo.require
|
local doFile = modInfo.doFile
|
||||||
|
|
||||||
require('Lib.activeFormspecs')
|
-- Independent of SMC methods
|
||||||
require('Lib.globalStep')
|
doFile('Lib.activeFormspecs')
|
||||||
require('Lib.color')
|
doFile('Lib.globalStep')
|
||||||
require('Lib.itemStackInventory')
|
doFile('Lib.inventoryHelpers')
|
||||||
require('Lib.nodeSuperClasses')
|
doFile('Lib.color')
|
||||||
require('Lib.getObjectByGUID')
|
doFile('Lib.itemStackInventory')
|
||||||
require('Lib.receiveFields')
|
doFile('Lib.nodeSuperClasses')
|
||||||
require('Lib.registeredItems')
|
doFile('Lib.getObjectByGUID')
|
||||||
require('Lib.requires')
|
doFile('Lib.receiveFields')
|
||||||
|
doFile('Lib.registeredItems')
|
||||||
|
doFile('Lib.requires')
|
||||||
|
|
||||||
|
--- Dependent of SMC methods
|
||||||
|
doFile('Lib.matchItemDescription')
|
||||||
|
|||||||
23
mods/SYSTEM/HelperLib/src/Lib/inventoryHelpers.lua
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
local ItemStack = ItemStack
|
||||||
|
|
||||||
|
---Adds the specified stack to the player's inventory, provided there is space available.
|
||||||
|
---
|
||||||
|
---If there is no space, it drops the stack on the ground.
|
||||||
|
---
|
||||||
|
---Returns `true` if the stack was placed in the inventory, and `false` if it was dropped.
|
||||||
|
---@param player Player
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param item ItemStack|ItemStackString|ItemStackString
|
||||||
|
---@return boolean
|
||||||
|
function Smc.putOrDrop(player, inventory, item)
|
||||||
|
item = ItemStack(item)
|
||||||
|
if inventory:room_for_item('main', item) then
|
||||||
|
inventory:add_item('main', item)
|
||||||
|
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
core.item_drop(item, player, player:get_pos())
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -16,7 +16,6 @@ function Smc.setItemInventoryList(item, list)
|
|||||||
end
|
end
|
||||||
|
|
||||||
meta:set_string(ITEMSTACK_INVENTORY_LIST_META_KEY, core.serialize(items))
|
meta:set_string(ITEMSTACK_INVENTORY_LIST_META_KEY, core.serialize(items))
|
||||||
print('LIST: ', dump(core.deserialize(meta:get_string(ITEMSTACK_INVENTORY_LIST_META_KEY))))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Return an inventory list to the ItemStack's metadata.
|
---Return an inventory list to the ItemStack's metadata.
|
||||||
@@ -29,7 +28,6 @@ function Smc.getItemInventoryList(item)
|
|||||||
|
|
||||||
---@type ItemStack[]?
|
---@type ItemStack[]?
|
||||||
local list = core.deserialize(meta:get_string(ITEMSTACK_INVENTORY_LIST_META_KEY))
|
local list = core.deserialize(meta:get_string(ITEMSTACK_INVENTORY_LIST_META_KEY))
|
||||||
print('LIST2: ', dump(core.deserialize(meta:get_string(ITEMSTACK_INVENTORY_LIST_META_KEY))))
|
|
||||||
|
|
||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|||||||