From 475b199ddb0044dbdf774321015e586ea5904b60 Mon Sep 17 00:00:00 2001 From: Vanic Date: Mon, 29 Dec 2025 19:51:28 +0300 Subject: [PATCH] Create Plant class --- mods/CORE/Item/src/Item.lua | 2 +- mods/CORE/Node/src/Node.lua | 9 +++++++++ mods/CORE/Plant/init.lua | 4 ++++ mods/CORE/Plant/mod.conf | 2 ++ mods/CORE/Plant/src/Plant.lua | 27 ++++++++++++++++++++++++++ mods/GAME/ITEMS/Plants/init.lua | 34 ++++++++++++--------------------- 6 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 mods/CORE/Plant/init.lua create mode 100644 mods/CORE/Plant/mod.conf create mode 100644 mods/CORE/Plant/src/Plant.lua diff --git a/mods/CORE/Item/src/Item.lua b/mods/CORE/Item/src/Item.lua index 5d9ea9b..166f52a 100644 --- a/mods/CORE/Item/src/Item.lua +++ b/mods/CORE/Item/src/Item.lua @@ -7,7 +7,7 @@ local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory' ---@field itemDef Item.ItemDefinition ---@field luantiDef table ---@field getVisual fun(): string ----@field defaultDef Item.ItemDefinition +---@field defaultDef Item.ItemDefinition local Item = { defaultDef = { settings = { diff --git a/mods/CORE/Node/src/Node.lua b/mods/CORE/Node/src/Node.lua index 54174fe..eac0de9 100644 --- a/mods/CORE/Node/src/Node.lua +++ b/mods/CORE/Node/src/Node.lua @@ -10,9 +10,18 @@ local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory' ---@field defaultDef Node.NodeDefinition 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 ---@return Node function Node:new(nodeDef) + ---Adding default parameters + nodeDef = defMerge(nodeDef, self.defaultDef, true) + nodeDef.settings.visual = 'item_3d' ---@type Node diff --git a/mods/CORE/Plant/init.lua b/mods/CORE/Plant/init.lua new file mode 100644 index 0000000..fa524ab --- /dev/null +++ b/mods/CORE/Plant/init.lua @@ -0,0 +1,4 @@ +local modInfo = Mod.getInfo('smc__core__plant') +local require = modInfo.require + +return require('Plant') \ No newline at end of file diff --git a/mods/CORE/Plant/mod.conf b/mods/CORE/Plant/mod.conf new file mode 100644 index 0000000..31b9498 --- /dev/null +++ b/mods/CORE/Plant/mod.conf @@ -0,0 +1,2 @@ +name = smc__core__plant +depends = smc__core__node diff --git a/mods/CORE/Plant/src/Plant.lua b/mods/CORE/Plant/src/Plant.lua new file mode 100644 index 0000000..4d40b4a --- /dev/null +++ b/mods/CORE/Plant/src/Plant.lua @@ -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 \ No newline at end of file diff --git a/mods/GAME/ITEMS/Plants/init.lua b/mods/GAME/ITEMS/Plants/init.lua index 74b46be..5ea9a99 100644 --- a/mods/GAME/ITEMS/Plants/init.lua +++ b/mods/GAME/ITEMS/Plants/init.lua @@ -1,23 +1,13 @@ -core.register_node(":plants:plants", { - description = 'Plant', - drawtype = "plantlike", - tiles = { "test_plant.png" }, - sunlight_propagates = true, - paramtype = "light", - paramtype2 = "meshoptions", - place_param2 = 3, - waving = 1, - walkable = false, - buildable_to = true, - groups = {dig_immediate = 2}, - selection_box = { - type = "fixed", - fixed = { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 }, +local modInfo = Mod.getInfo('smc__core__plant') + +---@type Plant +local Plant = modInfo.require('Plant') + +Plant:new({ + settings = { + name = 'plants:plants', + description = 'Plant', + tiles = { "test_plant.png" }, + place_param2 = 3, }, - on_construct = function(pos) - local node = core.get_node(pos) - - node.param2 = 3 - end, -}) - +}) \ No newline at end of file