13 Commits

40 changed files with 596 additions and 313 deletions

View File

@@ -106,7 +106,7 @@ end
function ImmersiveCraft:startCraft(pos, player, amount) function ImmersiveCraft:startCraft(pos, player, amount)
-- Adding craft to the counter. -- Adding craft to the counter.
-- If crafting has not been added... -- If crafting has not been added...
if not ImmersiveCraftCounter:addCraft(pos, player) then if not ImmersiveCraftCounter:addCraft(pos, player:get_player_name()) then
-- ...then we don't let the player start a new craft. -- ...then we don't let the player start a new craft.
core.chat_send_player(player:get_player_name(), core.chat_send_player(player:get_player_name(),
'The limit of simultaneously active crafts has been reached:'.. 'The limit of simultaneously active crafts has been reached:'..
@@ -142,6 +142,7 @@ function ImmersiveCraft:startCraft(pos, player, amount)
-- Create a temporary data table for crafting. -- Create a temporary data table for crafting.
---@type ImmersiveCraftData ---@type ImmersiveCraftData
local craftData = { local craftData = {
playerName = player:get_player_name(), -- The name of the player who started the craft.
craftName = self.name, craftName = self.name,
stageName = stage.name, stageName = stage.name,
amount = amount, amount = amount,
@@ -157,8 +158,8 @@ end
---Complete the immersive crafting process. ---Complete the immersive crafting process.
---@param pos MapPosition ---@param pos MapPosition
---@param Player Player ---@param player Player
function ImmersiveCraft:endCraft(pos, Player) function ImmersiveCraft:endCraft(pos, player)
-- We get current data on crafting. -- We get current data on crafting.
---@type ImmersiveCraftData? ---@type ImmersiveCraftData?
local craftData = Smc.getCraftDataByPos(pos) local craftData = Smc.getCraftDataByPos(pos)
@@ -170,17 +171,16 @@ function ImmersiveCraft:endCraft(pos, Player)
core.item_drop(ItemStack(self.output), nil, dropPos) core.item_drop(ItemStack(self.output), nil, dropPos)
end end
-- Remove craft from the counter.
ImmersiveCraftCounter:removeCraft(pos, craftData.playerName)
-- Clearing the temporary data table for crafting, freeing up the work station for new crafts. -- Clearing the temporary data table for crafting, freeing up the work station for new crafts.
Smc.setCraftDataByPos(pos) Smc.setCraftDataByPos(pos)
-- Remove craft from the counter.
ImmersiveCraftCounter:removeCraft(pos, Player)
end end
---Stop the crafting process and free up the workbench. ---Stop the crafting process and free up the workbench.
---@param pos MapPosition ---@param pos MapPosition
---@param Player Player function ImmersiveCraft:abortCraft(pos)
function ImmersiveCraft:abortCraft(pos, Player)
-- We get current data on crafting. -- We get current data on crafting.
---@type ImmersiveCraftData? ---@type ImmersiveCraftData?
local craftData = Smc.getCraftDataByPos(pos) local craftData = Smc.getCraftDataByPos(pos)
@@ -188,13 +188,13 @@ function ImmersiveCraft:abortCraft(pos, Player)
-- We get the current stage and start the abort process. -- We get the current stage and start the abort process.
local stage = self.stagesByName[craftData.stageName] local stage = self.stagesByName[craftData.stageName]
stage:abortHandler(pos, Player) stage:abortHandler(pos)
-- Clearing the temporary data table for crafting, freeing up the work station for new crafts. -- Clearing the temporary data table for crafting, freeing up the work station for new crafts.
Smc.setCraftDataByPos(pos) Smc.setCraftDataByPos(pos)
-- Remove craft from the counter. -- Remove craft from the counter.
ImmersiveCraftCounter:removeCraft(pos, Player) ImmersiveCraftCounter:removeCraft(pos, craftData.playerName)
end end
---Returns a human-readable description of the crafting process. ---Returns a human-readable description of the crafting process.

View File

@@ -20,10 +20,9 @@ local ImmersiveCraftCounter = {
--- ---
---Returns `false` if the counter is already full. ---Returns `false` if the counter is already full.
---@param pos MapPosition ---@param pos MapPosition
---@param Player Player ---@param playerName string
---@return boolean ---@return boolean
function ImmersiveCraftCounter:addCraft(pos, Player) function ImmersiveCraftCounter:addCraft(pos, playerName)
local playerName = Player:get_player_name()
if self.craftsCountForPlayers[playerName] == nil then if self.craftsCountForPlayers[playerName] == nil then
self.craftsCountForPlayers[playerName] = {} self.craftsCountForPlayers[playerName] = {}
end end
@@ -45,9 +44,9 @@ end
---Remove craft from the counter. ---Remove craft from the counter.
---@param pos MapPosition ---@param pos MapPosition
---@param Player Player ---@param playerName string
function ImmersiveCraftCounter:removeCraft(pos, Player) function ImmersiveCraftCounter:removeCraft(pos, playerName)
local playerCrafts = self.craftsCountForPlayers[Player:get_player_name()] local playerCrafts = self.craftsCountForPlayers[playerName]
if playerCrafts == nil then if playerCrafts == nil then
return return
end end

View File

@@ -22,10 +22,14 @@ local tappingNode = ImmersiveCraftNode:new({
_name = 'craft_system:tapping_node', _name = 'craft_system:tapping_node',
_add_mod_name = false, _add_mod_name = false,
---@type ObjectProperties
initial_properties = { initial_properties = {
visual = 'wielditem', visual = 'wielditem',
visual_size = {x=0.4, y=0.4, z=0.4}, visual_size = {x=0.5, y=0.5, z=0.5},
--static_save = false, collisionbox = {
-0.375, -0.375, -0.375,
0.375, 0.375, 0.375
},
}, },
_item_name = '', _item_name = '',

View File

@@ -7,10 +7,10 @@ local getInstance = Class.getInstance
---@field name string ---@field name string
---@field type CraftSystem.ImmersiveCraftStage.Type ---@field type CraftSystem.ImmersiveCraftStage.Type
---@field craftName string ---@field craftName string
---@field startHandler fun(self, pos:Position, Player:Player) ---@field startHandler fun(self, pos:Position, player:Player)
---@field processHandler fun(self, pos:Position, Player:Player) ---@field processHandler fun(self, pos:Position, player:Player)
---@field endHandler fun(self, pos:Position, Player:Player) ---@field endHandler fun(self, pos:Position, player:Player)
---@field abortHandler fun(self, pos:Position, Player:Player) ---@field abortHandler fun(self, pos:Position)
---@field toString fun(self):string ---@field toString fun(self):string
---@field nextStage string? ---@field nextStage string?
---@field returnItems ItemStackString[]? ---@field returnItems ItemStackString[]?

View File

@@ -11,6 +11,7 @@ local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
---@class CraftSystem.ImmersiveCraftStage.TappingStage : CraftSystem.ImmersiveCraftStage ---@class CraftSystem.ImmersiveCraftStage.TappingStage : CraftSystem.ImmersiveCraftStage
---@field targetItem string ---@field targetItem string
---@field clicksNeed string ---@field clicksNeed string
---@field toolGroup string?
---@field startHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player) ---@field startHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player)
---@field processHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player) ---@field processHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player)
---@field endHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player) ---@field endHandler fun(self:CraftSystem.ImmersiveCraftStage.TappingStage, pos:MapPosition, Player:Player)
@@ -23,6 +24,7 @@ local TappingStage = extend(ImmersiveCraftStage, {})
---@class CraftSystem.ImmersiveCraftStage.TappingStageDef : CraftSystem.ImmersiveCraftStageDef ---@class CraftSystem.ImmersiveCraftStage.TappingStageDef : CraftSystem.ImmersiveCraftStageDef
---@field targetItem string ---@field targetItem string
---@field clicksNeed string ---@field clicksNeed string
---@field toolGroup string?
---Data table for transferring various time parameters between calls. ---Data table for transferring various time parameters between calls.
--- ---
@@ -39,11 +41,12 @@ function TappingStage:new(def)
local instance = ImmersiveCraftStage:new(def) local instance = ImmersiveCraftStage:new(def)
instance.targetItem = def.targetItem instance.targetItem = def.targetItem
instance.clicksNeed = def.clicksNeed instance.clicksNeed = def.clicksNeed
instance.toolGroup = def.toolGroup
-- Registering the crafting stage start handler. -- Registering the crafting stage start handler.
instance.startHandler = function(tappingStage , pos, Player) instance.startHandler = function(tappingStage , pos, player)
-- We determine the coordinate where we will create the crafting node (entity). -- We determine the coordinate where we will create the crafting node (entity).
local entityPos = vector.new(pos) + vector.new(0,0.8,0) local entityPos = vector.new(pos) + vector.new(0,0.875,0)
-- We create a table of initial parameters that we will pass to the entity. -- We create a table of initial parameters that we will pass to the entity.
---@class CraftSystem.ImmersiveCraftStage.TappingNode.InitParams ---@class CraftSystem.ImmersiveCraftStage.TappingNode.InitParams
@@ -75,7 +78,7 @@ function TappingStage:new(def)
-- Registering the crafting stage process handler. -- Registering the crafting stage process handler.
-- Called when a player clicks on a crafting node (entity). -- Called when a player clicks on a crafting node (entity).
instance.processHandler = function(tappingStage, pos, Player) instance.processHandler = function(tappingStage, pos, player)
-- Obtaining stage time data from work station metadata. -- Obtaining stage time data from work station metadata.
---@type ImmersiveStageData.TappingStageData? ---@type ImmersiveStageData.TappingStageData?
local stageData = getStageDataByPos(pos) local stageData = getStageDataByPos(pos)
@@ -88,7 +91,7 @@ function TappingStage:new(def)
-- If the number of clicks is greater than required to complete the step... -- If the number of clicks is greater than required to complete the step...
if clickCount >= tappingStage.clicksNeed then if clickCount >= tappingStage.clicksNeed then
-- ...we are completing the stage. -- ...we are completing the stage.
tappingStage:endHandler(pos, Player) tappingStage:endHandler(pos, player)
else else
-- ...else we save the number of clicks in the temporary data table. -- ...else we save the number of clicks in the temporary data table.
stageData.clickCount = clickCount stageData.clickCount = clickCount
@@ -97,7 +100,7 @@ function TappingStage:new(def)
end end
-- Registering the crafting stage end handler. -- Registering the crafting stage end handler.
instance.endHandler = function(tappingStage, pos, Player) instance.endHandler = function(tappingStage, pos, player)
-- Obtaining stage time data from work station metadata. -- Obtaining stage time data from work station metadata.
---@type ImmersiveStageData.TappingStageData? ---@type ImmersiveStageData.TappingStageData?
local stageData = getStageDataByPos(pos) local stageData = getStageDataByPos(pos)
@@ -111,12 +114,12 @@ function TappingStage:new(def)
entity:remove() entity:remove()
-- We trigger an event that the crafting stage has been completed. -- We trigger an event that the crafting stage has been completed.
Events.call('craft_system:next_immersive_stage:'..tappingStage.craftName, tappingStage, pos, Player) Events.call('craft_system:next_immersive_stage:'..tappingStage.craftName, tappingStage, pos, player)
end end
-- Registering the aborting the crafting process handler. -- Registering the aborting the crafting process handler.
---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage ---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage
instance.abortHandler = function(tappingStage, pos, Player) instance.abortHandler = function(tappingStage, pos)
-- We receive current data on crafting. -- We receive current data on crafting.
---@type ImmersiveCraftData? ---@type ImmersiveCraftData?
local craftData = Smc.getCraftDataByPos(pos) local craftData = Smc.getCraftDataByPos(pos)
@@ -143,7 +146,12 @@ function TappingStage:new(def)
-- Returns a human-readable description of the crafting stage. -- Returns a human-readable description of the crafting stage.
instance.toString = function(tappingStage) instance.toString = function(tappingStage)
local stageDesc = ('Tapping x%s'):format(tappingStage.clicksNeed) local stageDesc
if tappingStage.toolGroup ~= nil then
stageDesc = ('Tapping x%s tool with a group "%s"'):format(tappingStage.clicksNeed, tappingStage.toolGroup)
else
stageDesc = ('Tapping x%s'):format(tappingStage.clicksNeed)
end
return stageDesc return stageDesc
end end
@@ -151,7 +159,17 @@ function TappingStage:new(def)
-- Subscribe to an event that means the player hit the entity. -- Subscribe to an event that means the player hit the entity.
Events.subscribe(('craft_system:punch_tapping_node:%s:%s'):format(instance.craftName, instance.name), Events.subscribe(('craft_system:punch_tapping_node:%s:%s'):format(instance.craftName, instance.name),
---@param craftNode LuaEntity ---@param craftNode LuaEntity
function(eventName, pos, Player, craftNode) ---@param player Player
function(eventName, pos, player, craftNode)
-- We get the item that the player clicked on the crafting node.
local toolDef = player:get_wielded_item():get_definition()
-- If a crafting stage requires a specific tool group and he doesn't have it...
if instance.toolGroup and (not toolDef.groups or not toolDef.groups[instance.toolGroup]) then
-- ...then we don't do anything.
return
end
-- DRAFT START: -- DRAFT START:
-- Creating particles -- Creating particles
for i=0, 10 do for i=0, 10 do
@@ -172,7 +190,7 @@ function TappingStage:new(def)
-- DRAFT END -- DRAFT END
-- Calling the crafting stage process handler. -- Calling the crafting stage process handler.
instance:processHandler(pos, Player) instance:processHandler(pos, player)
end) end)
return instance return instance

View File

@@ -2,10 +2,7 @@ local getInstance, extend = Class.getInstance, Class.extend
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
local modInfo = Mod.getInfo('smc__core__item') local ItemFactory = Smc.requireItemFactory()
local require = modInfo.require
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
---Determines whether common rarity will be shown in item descriptions or not. ---Determines whether common rarity will be shown in item descriptions or not.
local SHOW_COMMON_RARITY = true local SHOW_COMMON_RARITY = true
@@ -37,7 +34,7 @@ local RARITY_INDEX = {
---@class Item ---@class Item
---@field itemDef Item.ItemDefinition ---@field itemDef Item.ItemDefinition
---@field luantiDef ItemDefinition ---@field luantiDef ItemDefinition
---@field getVisual fun(): string ---@field getType fun():string
---@field defaultDef Item.ItemDefinition ---@field defaultDef Item.ItemDefinition
local Item = { local Item = {
defaultDef = { defaultDef = {
@@ -49,6 +46,7 @@ local Item = {
_description_color = '#C0C0C0', _description_color = '#C0C0C0',
_rarity = 'common', _rarity = 'common',
_add_mod_name = true, _add_mod_name = true,
stack_max = 128,
}, },
callbacks = {} callbacks = {}
} }
@@ -123,7 +121,7 @@ local function itemDefToLuantiDef(itemDef)
end end
---@param luantiDef NodeDefinition ---@param luantiDef NodeDefinition
local function register3dItem(luantiDef) local function registerNode(luantiDef)
local name = luantiDef.name local name = luantiDef.name
luantiDef.name = nil luantiDef.name = nil
@@ -131,13 +129,21 @@ local function register3dItem(luantiDef)
end end
---@param luantiDef ItemDefinition ---@param luantiDef ItemDefinition
local function registerFlatItem(luantiDef) local function registerCraftitem(luantiDef)
local name = luantiDef.name local name = luantiDef.name
luantiDef.name = nil luantiDef.name = nil
core.register_craftitem(':'..name, luantiDef) core.register_craftitem(':'..name, luantiDef)
end end
---@param luantiDef ItemDefinition
local function registerTool(luantiDef)
local name = luantiDef.name
luantiDef.name = nil
core.register_tool(':'..name, luantiDef)
end
---The alias `table.merge` for EmmyLua ---The alias `table.merge` for EmmyLua
---@type fun(...):(Item.ItemDefinition) ---@type fun(...):(Item.ItemDefinition)
local defMerge = function(...) local defMerge = function(...)
@@ -164,23 +170,26 @@ function Item:new(itemDef)
local instance = getInstance(self, {}) local instance = getInstance(self, {})
local luantiDef = itemDefToLuantiDef(itemDef) local luantiDef = itemDefToLuantiDef(itemDef)
local visual = itemDef.settings._visual local type = itemDef.settings._type
if visual == nil then if type == nil then
visual = 'item_2d' type = 'craftitem'
end end
itemDef.settings._visual = nil itemDef.settings._type = nil
if visual == 'item_3d' then if type == 'node' then
register3dItem(luantiDef) registerNode(luantiDef)
elseif type == 'craftitem' then
registerCraftitem(luantiDef)
elseif type == 'tool' then
registerTool(luantiDef)
else else
visual = 'item_2d' error(('Unknown item type: `%s`.'):format(type))
registerFlatItem(luantiDef)
end end
function instance:getVisual() function instance:getType()
return visual return type
end end
instance.itemDef = itemDef instance.itemDef = itemDef
@@ -195,7 +204,7 @@ end
---@param defaultDef Item.ItemDefinition ---@param defaultDef Item.ItemDefinition
---@return Item ---@return Item
function Item:getExtended(defaultDef) function Item:getExtended(defaultDef)
defaultDef = defMerge(defaultDef, self.defaultDef) defaultDef = defMerge(defaultDef, self.defaultDef, true)
---@type Item ---@type Item
local ChildClass = extend(self, { local ChildClass = extend(self, {
@@ -212,7 +221,7 @@ function Item:getFactory(defaultDef)
if defaultDef == nil then if defaultDef == nil then
defaultDef = self.defaultDef defaultDef = self.defaultDef
else else
defaultDef = defMerge(self.defaultDef, defaultDef) defaultDef = defMerge(self.defaultDef, defaultDef, true)
end end
---@type ItemFactory ---@type ItemFactory

View File

@@ -33,8 +33,8 @@ Settings._title_color = nil
Settings._description_color = nil Settings._description_color = nil
---Visual node type. ---Visual node type.
---@type Item.Visual? ---@type Item.Type?
Settings._visual = nil Settings._type = nil
---Formal (lore) rarity of an item. Default `common`. ---Formal (lore) rarity of an item. Default `common`.
---@type Item.Rarity? ---@type Item.Rarity?

View File

@@ -0,0 +1 @@
---@alias Item.Type 'craftitem'|'node'|'tool'

View File

@@ -1 +0,0 @@
---@alias Item.Visual 'item_2d'|'item_3d'

View File

@@ -1,10 +1,4 @@
local itemRequire = Mod.getInfo('smc__core__item').require local Item, ItemFactory = Smc.requireItem(), Smc.requireItemFactory()
---@type Item
local Item = itemRequire('Item')
---@type ItemFactory
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
---@class Node : Item ---@class Node : Item
---@field defaultDef Node.NodeDefinition ---@field defaultDef Node.NodeDefinition
@@ -22,7 +16,7 @@ function Node:new(nodeDef)
---Adding default parameters ---Adding default parameters
nodeDef = defMerge(nodeDef, self.defaultDef, true) nodeDef = defMerge(nodeDef, self.defaultDef, true)
nodeDef.settings._visual = 'item_3d' nodeDef.settings._type = 'node'
---@type Node ---@type Node
local instance = Item:new(nodeDef) local instance = Item:new(nodeDef)

View File

@@ -1,10 +1,4 @@
local nodeRequire = Mod.getInfo('smc__core__node').require local Node = Smc.requireNode()
---@type Node
local Node = nodeRequire('Node')
-- -@type ItemFactory
---local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
---@class Plant : Node ---@class Plant : Node
local Plant = Node:getExtended({ local Plant = Node:getExtended({

4
mods/CORE/Tool/init.lua Normal file
View File

@@ -0,0 +1,4 @@
local modInfo = Mod.getInfo('smc__core__tool')
local require = modInfo.require
return require('Tool')

2
mods/CORE/Tool/mod.conf Normal file
View File

@@ -0,0 +1,2 @@
name = smc__core__tool
depends = smc__core__item

View File

@@ -0,0 +1,70 @@
local Item, ItemFactory = Smc.requireItem(), Smc.requireItemFactory()
---@class Tool : Item
---@field defaultDef Item.ItemDefinition
local Tool = Class.extend(Item, {})
---The alias `table.merge` for EmmyLua
---@type fun(...):(Item.ItemDefinition)
local defMerge = function(...)
return table.merge(...)
end
---@param ToolDef Item.ItemDefinition
---@return Tool
function Tool:new(ToolDef)
---Adding default parameters
ToolDef = defMerge(ToolDef, self.defaultDef, true)
ToolDef.settings._type = 'tool'
---@type Tool
local instance = Item:new(ToolDef)
return instance
end
---Allows you to create a child class of an tool by specifying
---default parameters that will be added to the tool's parameters
---when an instance is received.
---@param defaultDef Item.ItemDefinition
---@return Tool
function Tool:getExtended(defaultDef)
defaultDef = defMerge(defaultDef, self.defaultDef)
---@type Tool
local ChildClass = Class.extend(self, {
defaultDef = defaultDef,
})
return ChildClass
end
---Returns an instance of the `ItemFactory` class that can be used to mass-register identical items.
---@param defaultDef? Item.ItemDefinition
---@return ItemFactory
function Tool:getFactory(defaultDef)
if defaultDef == nil then
defaultDef = self.defaultDef
else
defaultDef = defMerge(self.defaultDef, defaultDef)
end
---@type ItemFactory
local instance = ItemFactory:new(self, defaultDef)
return instance
end
--[[
Tool:new({
settings = {
name = 'tool',
inventory_image = 'anoba.png',
tool_capabilities = {
groupcaps={
crumbly={maxlevel=2, uses=20, times={[1]=1.60, [2]=1.20, [3]=0.80}}
},
}
}
})--]]
return Tool

View File

@@ -6,8 +6,7 @@ local ImmersiveCraftHandler = Mod.getInfo('smc__core__craft_system').require('Cr
---@type WorkStationUI ---@type WorkStationUI
local WorkStationUI = Mod.getInfo('smc__ui__work_station').require('WorkStationUI') local WorkStationUI = Mod.getInfo('smc__ui__work_station').require('WorkStationUI')
---@type Node local Node = Smc.requireNode()
local Node = Mod.getInfo('smc__core__node').require('Node')
-- Default settings that a work station node should have. -- Default settings that a work station node should have.
local WorkStationNode = Node:getExtended({ local WorkStationNode = Node:getExtended({
@@ -79,6 +78,18 @@ function WorkStation:new(name, def)
end end
end end
callbacks.on_punch = function(pos, node, puncher, pointed_thing)
if Smc.workStationIsFree(pos) then
return
end
local craftData = Smc.getCraftDataByPos(pos)
assert(craftData ~= nil, 'Immersive crafting data is empty.')
local craft = ImmersiveCraftHandler:getCraftByName(craftData.craftName)
craft:abortCraft(pos)
end
callbacks.on_dig = function(pos, node, digger) callbacks.on_dig = function(pos, node, digger)
if Smc.workStationIsFree(pos) then if Smc.workStationIsFree(pos) then
return core.node_dig(pos, node, digger) return core.node_dig(pos, node, digger)
@@ -107,6 +118,7 @@ function WorkStation:showSelectionCraftForm(player, crafts, pos)
-- Create a table in the format craft result - craft name. -- Create a table in the format craft result - craft name.
local outputs = {} local outputs = {}
for _, craft in ipairs(crafts) do for _, craft in ipairs(crafts) do
-- TODO: добавить проверку только на известные игроку рецепты
outputs[craft.output] = craft.name outputs[craft.output] = craft.name
end end
@@ -190,6 +202,23 @@ ImmersiveCraftHandler:registerCraft('bricks', {
targetItem = 'rocks:sylite', targetItem = 'rocks:sylite',
type = 'tapping', type = 'tapping',
clicksNeed = 3, clicksNeed = 3,
nextStage = 'tapping_2',
},
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
{
name = 'tapping_2',
toolGroup = 'crushing',
targetItem = 'rocks:sylite_block',
type = 'tapping',
clicksNeed = 5,
nextStage = 'tapping_3',
},
---@type CraftSystem.ImmersiveCraftStage.TappingStageDef
{
name = 'tapping_3',
targetItem = 'rocks:sylite_bricks',
type = 'tapping',
clicksNeed = 1,
} }
}, },
}) })

View File

@@ -1,73 +0,0 @@
local modInfo = Mod.getInfo('smc__core__formspec')
local require = modInfo.require
---@type Formspec
local Formspec = require('Formspec')
local listForm = Formspec:new({
size = {x=21, y=12},
})
listForm:list('current_player', 'main', 10.5, 6.5, 8, 4)
local listFormItems = Formspec:new()
local items = table.get_keys(core.registered_nodes)
table.sort(items)
local w, h = 0, 0
---@param name string
for _, name in ipairs(items) do
listFormItems:itemImageButton(w, h, 1, 1, name, name..'::item_button')
w = w + 1
if w > 9 then
w = 0
h = h + 1
end
end
--listFormItems:list('current_player', 'main', 0, 0, 1, 32)
listForm:
scrollContainer(listFormItems, 0.5, 0.5, 9, 11, 'admin_commands:list_items', 'vertical'):
scrollbar(10, 0.5, 0.25, 10, 'vertical', 'admin_commands:list_items')
core.register_chatcommand('list', {
privs = {server = true},
func = function(name, param)
local player = core.get_player_by_name(name)
core.show_formspec(name, 'admin_commands:list_form', listForm:toString())
return true, ''
end
})
core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= 'admin_commands:list_form' then
return
end
for key, value in pairs(fields) do
if string.ends_with(key, '::item_button') then
---@type ItemStackString?
local stack = string.match(key, '(%S+)::item_button')
if stack == nil then
return
end
core.log(tostring(stack))
---@type InvRef
local inv = player:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
end
end
end
end)

View File

@@ -1,2 +0,0 @@
name = smc__core__admin_commands
depends = smc__system__system_loader, smc__core__formspec, smc__core__item

View File

@@ -1,3 +1,3 @@
name = smc__game__items__items_loader name = smc__game__items__items_loader
description = Include this mod in your `depends` to ensure all items are registered description = Include this mod in your `depends` to ensure all items are registered
depends = smc__game__items__rocks, smc__game__items__wood, smc__game__items__soils, smc__game__items__liquids depends = smc__game__items__rocks, smc__game__items__wood, smc__game__items__soils, smc__game__items__liquids, smc__game__items__plants

View File

@@ -0,0 +1,35 @@
local Item, TileSheet = Smc.requireItem(), Smc.requireTileSheet()
---@type Item.ItemDefinition
local defaultEssenceDef = {
settings = {
name = '',
_rarity = 'uncommon',
stack_max = 32,
}
}
local defaultEssence = Item:getExtended(defaultEssenceDef)
local ts = TileSheet:new('essences_sheet.png', 16, 16)
defaultEssence:new({
settings = {
name = 'essence_experience',
inventory_image = ts:t(0, 0)
}
})
defaultEssence:new({
settings = {
name = 'essence_spell',
inventory_image = ts:t(1, 0)
}
})
defaultEssence:new({
settings = {
name = 'essence_life',
inventory_image = ts:t(2, 0)
}
})

View File

@@ -0,0 +1,10 @@
# textdomain: essences
essence_experience-title=Эссенция опыта
essence_experience-desc=Сгусток желеобразной материи,@nзаключающий в себе ремесленный опыт.
essence_spell-title=Эссенция заклятия
essence_spell-desc=Сгусток желеобразной материи,@nзаключающий в себе мистическую силу.
essence_life-title=Эссенция жизни
essence_life-desc=Сгусток желеобразной материи,@nзаключающий в себе жизненную энергию.

View File

@@ -0,0 +1,2 @@
name = smc__game__items__essences
depends = smc__core__item

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -1,5 +1,4 @@
---@type Node local Node = Smc.requireNode()
local Node = Mod.getInfo('smc__core__node').require('Node')
---@type Node.NodeDefinition ---@type Node.NodeDefinition
local defaultLiquidDef = { local defaultLiquidDef = {

View File

@@ -1,10 +1,4 @@
local modInfo = Mod.getInfo('smc__core__plant') local Plant, TileSheet = Smc.requirePlant(), Smc.requireTileSheet()
---@type TileSheet
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
---@type Plant
local Plant = modInfo.require('Plant')
Plant:new({ Plant:new({
settings = { settings = {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1,8 +1,4 @@
---@type TileSheet local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
---@type Node
local Node = Mod.getInfo('smc__core__node').require('Node')
---@type Node.NodeDefinition ---@type Node.NodeDefinition
local defaultRockDef = { local defaultRockDef = {

View File

@@ -1,8 +1,4 @@
---@type TileSheet local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
---@type Node
local Node = Mod.getInfo('smc__core__node').require('Node')
---@type Node.NodeDefinition ---@type Node.NodeDefinition
local defaultSoilDef = { local defaultSoilDef = {
@@ -12,6 +8,7 @@ local defaultSoilDef = {
tiles = {}, tiles = {},
groups = { groups = {
dig_immediate = 2, dig_immediate = 2,
soil = 1,
soil_fertiliry = 100, -- Soil fertility for agriculture soil_fertiliry = 100, -- Soil fertility for agriculture
} }
}, },
@@ -245,14 +242,10 @@ soilFactory:registerItems({
---@type TileSheet ---@type TileSheet
local tsT = TileSheet:new("soils_turfs_sheet.png", 16, 16) local tsT = TileSheet:new("soils_turfs_sheet.png", 16, 16)
Node:new({ defaultSoil:new({
settings = { settings = {
name = 'turf_swamp', name = 'turf_swamp',
tiles = {tsT:t(0,0), ts:t(6, 0), ts:t(6,0)..'^'..tsT:t(0,1)}, tiles = {tsT:t(0,0), ts:t(6, 0), ts:t(6,0)..'^'..tsT:t(0,1)},
groups = {
dig_immediate = 2,
soil_fertiliry = 100, -- Soil fertility for agriculture
},
_rarity = 'unique' _rarity = 'unique'
} }
}) })

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -1,43 +1,54 @@
---@type Node local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
local Node = Mod.getInfo('smc__core__node').require('Node')
---@type TileSheet
local TileSheet = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
---@type Node.NodeDefinition ---@type Node.NodeDefinition
local defaultRockDef = { local defaultLogDef = {
settings = { settings = {
name = "", name = '',
_description = "A log",
tiles = {}, tiles = {},
groups = { groups = {
dig_immediate = 2, dig_immediate = 2,
wood = 1
}, },
paramtype2 = "facedir", }
},
} }
---@type Node.NodeDefinition ---@type Node.NodeDefinition
local defaultPlanksDef = { local defaultPlanksDef = {
settings = { settings = {
name = "", name = '',
_description = "A planks",
tiles = {}, tiles = {},
groups = { groups = {
dig_immediate = 2, dig_immediate = 2,
}, },
paramtype2 = "facedir", paramtype2 = 'facedir',
}, },
} }
local defaultLog = Node:getExtended(defaultRockDef) ---@type Node.NodeDefinition
local defaultLeafsDef = {
settings = {
drawtype = 'allfaces_optional',
name = '',
tiles = {},
groups = {
dig_immediate = 2,
},
--paramtype = 'light',
paramtype2 = 'facedir',
use_texture_alpha = 'clip',
sunlight_propagates = true,
},
}
local defaultLog = Node:getExtended(defaultLogDef)
local defaultPlanks = Node:getExtended(defaultPlanksDef) local defaultPlanks = Node:getExtended(defaultPlanksDef)
local defaultLeafs = Node:getExtended(defaultLeafsDef)
local logFactory = defaultLog:getFactory() local logFactory = defaultLog:getFactory()
local planksFactory = defaultPlanks:getFactory() local planksFactory = defaultPlanks:getFactory()
---@type TileSheet ---@type TileSheet
local logTileSheet = TileSheet:new("wood_sheet.png", 16, 16) local logTileSheet = TileSheet:new('wood_sheet.png', 16, 16)
local function getLogTiles(x, y) local function getLogTiles(x, y)
return { return {
@@ -47,126 +58,112 @@ local function getLogTiles(x, y)
} }
end end
local t = getLogTiles local t = logTileSheet
logFactory:registerItems({ local function registerWood(name, x)
---@type Node.NodeDefinition defaultLog:new({
{
settings = { settings = {
name = "marentine_log", name = name..'_log',
_title = "Marentine Log", tiles = getLogTiles(x, 1),
--description = "", paramtype2 = 'facedir',
tiles = t(0, 1),
}, },
}, callbacks = {
---@type Node.NodeDefinition on_place = core.rotate_node
{ }
settings = { })
name = "allwhere_log",
_title = "Allwhere Log",
--description = "",
tiles = t(2, 1),
},
},
---@type Node.NodeDefinition
{
settings = {
name = "fis_log",
_title = "Fis Log",
--description = "",
tiles = t(4, 1),
},
},
---@type Node.NodeDefinition
{
settings = {
name = "tammoy_log",
_title = "Tammoy Log",
--description = "",
tiles = t(6, 1),
},
},
---@type Node.NodeDefinition
{
settings = {
name = "dallalia_log",
_title = "Dallalia Log",
--description = "",
tiles = t(8, 1),
},
},
---@type Node.NodeDefinition
{
settings = {
name = "zuph_log",
_title = "Zuph Log",
--description = "",
tiles = t(10, 1),
},
},
})
planksFactory:registerItems({ defaultLog:new({
---@type Node.NodeDefinition
{
settings = { settings = {
name = "marentine_planks", name = name..'_trunk',
_title = "Marentine Planks", tiles = {logTileSheet:t(x, 2)},
--description = "", inventory_overlay = 'wood_trunk_overlay.png',
tiles = { logTileSheet:t(0, 4) }, drop = 'wood:'..name..'_log',
paramtype2 = 'facedir',
}, },
}, callbacks = {
---@type Node.NodeDefinition on_place = core.rotate_node
{ }
})
defaultLog:new({
settings = { settings = {
name = "allwhere_planks", name = name..'_trunk_vertical',
_title = "Allwhere Planks", tiles = getLogTiles(x, 1),
--description = "", inventory_overlay = 'wood_trunk_overlay.png',
tiles = { logTileSheet:t(2, 4) }, drop = 'wood:'..name..'_log',
paramtype2 = 'facedir',
}, },
}, callbacks = {
---@type Node.NodeDefinition on_place = core.rotate_node
{ }
})
defaultLog:new({
settings = { settings = {
name = "fis_planks", drawtype = 'nodebox',
_title = "Fis Planks", name = name..'_trunk_branch',
--description = "", tiles = {logTileSheet:t(x, 2)},
tiles = { logTileSheet:t(4, 4) }, inventory_overlay = 'wood_trunk_overlay.png',
drop = 'wood:'..name..'_log',
paramtype = 'light',
node_box = {
type = 'connected',
fixed = {-.25,-.25,-.25, .25,.25,.25},
connect_top = {-.25,-.25,-.25, .25,.5,.25},
connect_bottom = {-.25,-.5,-.25, .25,.25,.25},
connect_front = {-.25,-.25,-.5, .25,.25,.25},
connect_left = {-.5,-.25,-.25, .25,.25,.25},
connect_back = {-.25,-.25,-.25, .25,.25,.5},
connect_right = {-.25,-.25,-.25, .5,.25,.25},
}, },
connects_to = {'group:wood', 'group:soil'}
}, },
---@type Node.NodeDefinition })
{
defaultLog:new({
settings = { settings = {
name = "tammoy_planks", drawtype = 'nodebox',
_title = "Tammoy Planks", name = name..'_trunk_branch_vertical',
--description = "", tiles = getLogTiles(x, 1),
tiles = { logTileSheet:t(6, 4) }, inventory_overlay = 'wood_trunk_overlay.png',
drop = 'wood:'..name..'_log',
paramtype = 'light',
node_box = {
type = 'connected',
fixed = {-.25,-.25,-.25, .25,.25,.25},
connect_top = {-.25,-.25,-.25, .25,.5,.25},
connect_bottom = {-.25,-.5,-.25, .25,.25,.25},
}, },
connects_to = {'group:wood', 'group:soil'}
}, },
---@type Node.NodeDefinition })
{
defaultPlanks:new({
settings = { settings = {
name = "dallalia_planks", name = name..'_planks',
_title = "Dallalia Planks", tiles = { logTileSheet:t(x, 4) },
--description = "",
tiles = { logTileSheet:t(8, 4) },
}, },
}, })
---@type Node.NodeDefinition
{ defaultLeafs:new({
settings = { settings = {
name = "zuph_planks", name = name..'_leafs',
_title = "Zuph Planks", tiles = { logTileSheet:t(x, 0) },
--description = "",
tiles = { logTileSheet:t(10, 4) },
}, },
}, })
}) end
registerWood('marentine', 0)
registerWood('allwhere', 2)
registerWood('fis', 4)
registerWood('tammoy', 6)
registerWood('dallalia', 8)
registerWood('zuph', 10)
-- сундучки -- сундучки
---@type TileSheet ---@type TileSheet
local caseTileSheet = TileSheet:new("cases_sheet.png", 16, 16) local caseTileSheet = TileSheet:new('cases_sheet.png', 16, 16)
local function getCaseTiles(x, y) local function getCaseTiles(x, y)
return { return {
@@ -182,22 +179,22 @@ planksFactory:registerItems({
---@type Node.NodeDefinition ---@type Node.NodeDefinition
{ {
settings = { settings = {
name = "case_closed", name = 'case_closed',
_title = "Case", _title = 'Case',
--description = "", --description = '',
tiles = t(0,0) tiles = t(0,0)
}, },
}, },
---@type Node.NodeDefinition ---@type Node.NodeDefinition
{ {
settings = { settings = {
name = "case_open", name = 'case_open',
_title = "Case", _title = 'Case',
--description = "", --description = '',
tiles = t(1,0); tiles = t(1,0);
drawtype = 'nodebox'; drawtype = 'nodebox';
node_box = { node_box = {
type = "fixed", type = 'fixed',
fixed = { fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5 - 1/16*2, 0.5}, {-0.5, -0.5, -0.5, 0.5, 0.5 - 1/16*2, 0.5},
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,68 @@
local modInfo = Mod.getInfo('smc__core__formspec')
local require = modInfo.require
---@type AdminListUI
local AdminListUI = Mod.getInfo('smc__ui__admin_list').require('AdminListUI')
core.register_chatcommand('list', {
privs = {server = true},
func = function(name, param)
local player = core.get_player_by_name(name)
AdminListUI:showForm(name, false)
return true, ''
end
})
AdminListUI:registerOnFormFieldActionMatch('%S+::item_button',function(player, fieldName, fieldValue)
---@type ItemStackString?
local stack = string.match(fieldName, '(%S+)::item_button')
if stack == nil then
return
end
local playerName = player:get_player_name()
AdminListUI:setContex(playerName, 'select_item', stack)
AdminListUI:showForm(playerName, 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)
core.register_on_joinplayer(function(player, last_login)
player:set_sky({
sky_color = {
day_sky = '#FAE6E0',
day_horizon = '#E7A985',
},
type = 'regular',
})
player:set_lighting({
shadows = { intensity = 0.33 },
volumetric_light = { strength = 0.45 },
exposure = {
luminance_min = -3.5,
luminance_max = -2.5,
exposure_correction = 0.35,
speed_dark_bright = 1500,
speed_bright_dark = 700,
},
saturation = 1.0,
})
end)

View File

@@ -0,0 +1,2 @@
name = smc__game__admin_commands
depends = smc__system__system_loader, smc__ui__admin_list

View File

@@ -8,3 +8,4 @@ require('Lib.color')
require('Lib.immersiveCraftData') require('Lib.immersiveCraftData')
require('Lib.getObjectByGUID') require('Lib.getObjectByGUID')
require('Lib.receiveFields') require('Lib.receiveFields')
require('Lib.requires')

View File

@@ -3,6 +3,7 @@ local EMPTY_FLAG = 'EMPTY_FLAG'
---@class ImmersiveStageData ---@class ImmersiveStageData
---@class ImmersiveCraftData ---@class ImmersiveCraftData
---@field playerName string The name of the player who started the craft.
---@field craftName string ---@field craftName string
---@field stageName string ---@field stageName string
---@field amount integer ---@field amount integer

View File

@@ -0,0 +1,66 @@
-- Global methods for require classes.
---@return Item
function Smc.requireItem()
---@type Item
local class = Mod.getInfo('smc__core__item').require('Item')
return class
end
---@return Node
function Smc.requireNode()
---@type Node
local class = Mod.getInfo('smc__core__node').require('Node')
return class
end
---@return Tool
function Smc.requireTool()
---@type Tool
local class = Mod.getInfo('smc__core__tool').require('Tool')
return class
end
---@return Plant
function Smc.requirePlant()
---@type Plant
local class = Mod.getInfo('smc__core__plant').require('Plant')
return class
end
---@return ItemFactory
function Smc.requireItemFactory()
---@type ItemFactory
local class = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
return class
end
---@return TileSheet
function Smc.requireTileSheet()
---@type TileSheet
local class = Mod.getInfo('smc__core__tilesheet').require('TileSheet')
return class
end
---@return BaseUI
function Smc.requireBaseUI()
---@type BaseUI
local class = Mod.getInfo('smc__core__base_ui').require('BaseUI')
return class
end
---@return Formspec
function Smc.requireFormspec()
---@type Formspec
local class = Mod.getInfo('smc__core__formspec').require('Formspec')
return class
end

View File

@@ -0,0 +1,4 @@
local modInfo = Mod.getInfo('smc__ui__admin_list')
local require = modInfo.require
return require('AdminListUI')

View File

@@ -0,0 +1,2 @@
name = smc__ui__admin_list
depends = smc__core__formspec

View File

@@ -0,0 +1,72 @@
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
---@param self BaseUI
---@param playerName string
---@param isSelect boolean
---@return string
local function getFormSpecString(self, playerName, isSelect)
local items = {}
for name, def in pairs(core.registered_items) do
if def.groups and not def.groups.not_in_creative_inventory then
table.insert(items, name)
end
end
table.sort(items)
local listFormItems = Formspec:new()
local w, h = 0, 0
---@param name string
for _, name in ipairs(items) do
listFormItems:itemImageButton(w, h, 1, 1, name, name..'::item_button')
w = w + 1
if w >= 9 then
w = 0
h = h + 1
end
end
local listForm = Formspec:new({
size = {x=21, y=12},
})
listForm:
list('current_player', 'main', 10.5, 6.5, 8, 4):
scrollContainer(listFormItems, 0.5, 0.5, 9, 11, 'admin_commands:list_items', 'vertical'):
scrollbar(10, 0.5, 0.25, 10, 'vertical', 'admin_commands:list_items', self:getContex(playerName, 'scroll'))
if isSelect then
---@type ItemStackString
local item = self:getContex(playerName, 'select_item')
local itemDef = core.registered_items[item]
listForm:
itemImage(11, 0.5, 2, 2, item):
areaLabel(11, 4.5, 4, 1, 'Add to inventory:'):
button(11, 5, 3, 1, 'admin_commands:list_add_item', '1'):
button(14, 5,3, 1, 'admin_commands:list_add_item', ''..tostring(itemDef.stack_max)):
areaLabel(14.5, 0.5, 6, 4,
item..'\n\n'..
itemDef._title..'\n'..
itemDef._description)
end
return listForm:toString()
end
---@class AdminListUI : BaseUI
---@field getFormSpecString fun(self:BaseUI,playerName:string,isSelect:boolean):string
---@field showForm fun(self:BaseUI,playerName:string,isSelect:boolean):string
local AdminListUI = BaseUI:new('admin_commands:list_form', getFormSpecString)
AdminListUI:registerOnFormFieldAction('admin_commands:list_items', function(player, fieldName, fieldValue)
local scrollValue = string.match(fieldValue, 'CHG:(%S+)')
if scrollValue then
AdminListUI:setContex(player, 'scroll', scrollValue)
end
end)
return AdminListUI

View File

@@ -1,11 +1,4 @@
local modInfo = Mod.getInfo('smc__core__formspec') local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
local require = modInfo.require
---@type Formspec
local Formspec = require('Formspec')
---@type BaseUI
local BaseUI = Mod.getInfo('smc__core__base_ui').require('BaseUI')
---@param self BaseUI ---@param self BaseUI
---@param playerName string ---@param playerName string