Create Plant class

This commit is contained in:
Van
2025-12-29 19:51:28 +03:00
parent 96b51caaaf
commit 475b199ddb
6 changed files with 55 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory'
---@field itemDef Item.ItemDefinition ---@field itemDef Item.ItemDefinition
---@field luantiDef table ---@field luantiDef table
---@field getVisual fun(): string ---@field getVisual fun(): string
---@field defaultDef Item.ItemDefinition ---@field defaultDef Item.ItemDefinition
local Item = { local Item = {
defaultDef = { defaultDef = {
settings = { settings = {

View File

@@ -10,9 +10,18 @@ local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory'
---@field defaultDef Node.NodeDefinition ---@field defaultDef Node.NodeDefinition
local Node = Class.extend(Item, {}) local Node = Class.extend(Item, {})
---The alias `table.merge` for EmmyLua
---@type fun(...):(Node.NodeDefinition)
local defMerge = function(...)
return table.merge(...)
end
---@param nodeDef Node.NodeDefinition ---@param nodeDef Node.NodeDefinition
---@return Node ---@return Node
function Node:new(nodeDef) function Node:new(nodeDef)
---Adding default parameters
nodeDef = defMerge(nodeDef, self.defaultDef, true)
nodeDef.settings.visual = 'item_3d' nodeDef.settings.visual = 'item_3d'
---@type Node ---@type Node

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

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

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

@@ -0,0 +1,2 @@
name = smc__core__plant
depends = smc__core__node

View File

@@ -0,0 +1,27 @@
local nodeRequire = Mod.getInfo('smc__core__node').require
---@type Node
local Node = nodeRequire('Node')
-- -@type ItemFactory
---local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
---@class Plant : Node
local Plant = Node:getExtended({
settings = {
name = 'smc__core__plant:abstract_plant',
drawtype = "plantlike",
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "meshoptions",
walkable = false,
buildable_to = true,
groups = {dig_immediate = 3},
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.5, 0.25},
},
}
})
return Plant

View File

@@ -1,23 +1,13 @@
core.register_node(":plants:plants", { local modInfo = Mod.getInfo('smc__core__plant')
description = 'Plant',
drawtype = "plantlike", ---@type Plant
tiles = { "test_plant.png" }, local Plant = modInfo.require('Plant')
sunlight_propagates = true,
paramtype = "light", Plant:new({
paramtype2 = "meshoptions", settings = {
place_param2 = 3, name = 'plants:plants',
waving = 1, description = 'Plant',
walkable = false, tiles = { "test_plant.png" },
buildable_to = true, place_param2 = 3,
groups = {dig_immediate = 2},
selection_box = {
type = "fixed",
fixed = { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 },
}, },
on_construct = function(pos) })
local node = core.get_node(pos)
node.param2 = 3
end,
})