diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua index c283828..4438864 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraft.lua @@ -106,7 +106,7 @@ end function ImmersiveCraft:startCraft(pos, player, amount) -- Adding craft to the counter. -- 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. core.chat_send_player(player:get_player_name(), 'The limit of simultaneously active crafts has been reached:'.. @@ -142,9 +142,10 @@ function ImmersiveCraft:startCraft(pos, player, amount) -- Create a temporary data table for crafting. ---@type ImmersiveCraftData local craftData = { - craftName = self.name, - stageName = stage.name, - amount = amount, + playerName = player:get_player_name(), -- The name of the player who started the craft. + craftName = self.name, + stageName = stage.name, + amount = amount, } -- We save it to the workstation metadata. Smc.setCraftDataByPos(pos, craftData) @@ -157,8 +158,8 @@ end ---Complete the immersive crafting process. ---@param pos MapPosition ----@param Player Player -function ImmersiveCraft:endCraft(pos, Player) +---@param player Player +function ImmersiveCraft:endCraft(pos, player) -- We get current data on crafting. ---@type ImmersiveCraftData? local craftData = Smc.getCraftDataByPos(pos) @@ -170,17 +171,16 @@ function ImmersiveCraft:endCraft(pos, Player) core.item_drop(ItemStack(self.output), nil, dropPos) 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. Smc.setCraftDataByPos(pos) - - -- Remove craft from the counter. - ImmersiveCraftCounter:removeCraft(pos, Player) end ---Stop the crafting process and free up the workbench. ---@param pos MapPosition ----@param Player Player -function ImmersiveCraft:abortCraft(pos, Player) +function ImmersiveCraft:abortCraft(pos) -- We get current data on crafting. ---@type ImmersiveCraftData? local craftData = Smc.getCraftDataByPos(pos) @@ -188,13 +188,13 @@ function ImmersiveCraft:abortCraft(pos, Player) -- We get the current stage and start the abort process. 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. Smc.setCraftDataByPos(pos) -- Remove craft from the counter. - ImmersiveCraftCounter:removeCraft(pos, Player) + ImmersiveCraftCounter:removeCraft(pos, craftData.playerName) end ---Returns a human-readable description of the crafting process. diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftCounter.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftCounter.lua index 84be27f..f45def9 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftCounter.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftCounter.lua @@ -19,11 +19,10 @@ local ImmersiveCraftCounter = { ---Add craft to the counter. --- ---Returns `false` if the counter is already full. ----@param pos MapPosition ----@param Player Player ----@return boolean -function ImmersiveCraftCounter:addCraft(pos, Player) - local playerName = Player:get_player_name() +---@param pos MapPosition +---@param playerName string +---@return boolean +function ImmersiveCraftCounter:addCraft(pos, playerName) if self.craftsCountForPlayers[playerName] == nil then self.craftsCountForPlayers[playerName] = {} end @@ -44,10 +43,10 @@ function ImmersiveCraftCounter:addCraft(pos, Player) end ---Remove craft from the counter. ----@param pos MapPosition ----@param Player Player -function ImmersiveCraftCounter:removeCraft(pos, Player) - local playerCrafts = self.craftsCountForPlayers[Player:get_player_name()] +---@param pos MapPosition +---@param playerName string +function ImmersiveCraftCounter:removeCraft(pos, playerName) + local playerCrafts = self.craftsCountForPlayers[playerName] if playerCrafts == nil then return end diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua index 5f08c50..a2a9d0b 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftNode/tappingNode.lua @@ -22,10 +22,14 @@ local tappingNode = ImmersiveCraftNode:new({ _name = 'craft_system:tapping_node', _add_mod_name = false, + ---@type ObjectProperties initial_properties = { visual = 'wielditem', - visual_size = {x=0.4, y=0.4, z=0.4}, - --static_save = false, + visual_size = {x=0.5, y=0.5, z=0.5}, + collisionbox = { + -0.375, -0.375, -0.375, + 0.375, 0.375, 0.375 + }, }, _item_name = '', diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage.lua index f2a4cb5..c350b9d 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage.lua @@ -7,10 +7,10 @@ local getInstance = Class.getInstance ---@field name string ---@field type CraftSystem.ImmersiveCraftStage.Type ---@field craftName string ----@field startHandler fun(self, pos:Position, Player:Player) ----@field processHandler fun(self, pos:Position, Player:Player) ----@field endHandler fun(self, pos:Position, Player:Player) ----@field abortHandler fun(self, pos:Position, Player:Player) +---@field startHandler fun(self, pos:Position, player:Player) +---@field processHandler fun(self, pos:Position, player:Player) +---@field endHandler fun(self, pos:Position, player:Player) +---@field abortHandler fun(self, pos:Position) ---@field toString fun(self):string ---@field nextStage string? ---@field returnItems ItemStackString[]? diff --git a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua index c9be85d..42371b4 100644 --- a/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua +++ b/mods/CORE/CraftSystem/src/CraftSystem/ImmersiveCraftStage/TappingStage.lua @@ -41,9 +41,9 @@ function TappingStage:new(def) instance.clicksNeed = def.clicksNeed -- 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). - 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. ---@class CraftSystem.ImmersiveCraftStage.TappingNode.InitParams @@ -75,7 +75,7 @@ function TappingStage:new(def) -- Registering the crafting stage process handler. -- 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. ---@type ImmersiveStageData.TappingStageData? local stageData = getStageDataByPos(pos) @@ -88,7 +88,7 @@ function TappingStage:new(def) -- If the number of clicks is greater than required to complete the step... if clickCount >= tappingStage.clicksNeed then -- ...we are completing the stage. - tappingStage:endHandler(pos, Player) + tappingStage:endHandler(pos, player) else -- ...else we save the number of clicks in the temporary data table. stageData.clickCount = clickCount @@ -97,7 +97,7 @@ function TappingStage:new(def) end -- 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. ---@type ImmersiveStageData.TappingStageData? local stageData = getStageDataByPos(pos) @@ -111,12 +111,12 @@ function TappingStage:new(def) entity:remove() -- 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 -- Registering the aborting the crafting process handler. ---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage - instance.abortHandler = function(tappingStage, pos, Player) + instance.abortHandler = function(tappingStage, pos) -- We receive current data on crafting. ---@type ImmersiveCraftData? local craftData = Smc.getCraftDataByPos(pos) @@ -151,7 +151,7 @@ function TappingStage:new(def) -- 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), ---@param craftNode LuaEntity - function(eventName, pos, Player, craftNode) + function(eventName, pos, player, craftNode) -- DRAFT START: -- Creating particles for i=0, 10 do @@ -172,7 +172,7 @@ function TappingStage:new(def) -- DRAFT END -- Calling the crafting stage process handler. - instance:processHandler(pos, Player) + instance:processHandler(pos, player) end) return instance diff --git a/mods/CORE/WorkStation/src/WorkStation.lua b/mods/CORE/WorkStation/src/WorkStation.lua index e6d4ac2..4d20f38 100644 --- a/mods/CORE/WorkStation/src/WorkStation.lua +++ b/mods/CORE/WorkStation/src/WorkStation.lua @@ -79,6 +79,18 @@ function WorkStation:new(name, def) 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) if Smc.workStationIsFree(pos) then return core.node_dig(pos, node, digger) @@ -190,6 +202,22 @@ ImmersiveCraftHandler:registerCraft('bricks', { targetItem = 'rocks:sylite', type = 'tapping', clicksNeed = 3, + nextStage = 'tapping_2', + }, + ---@type CraftSystem.ImmersiveCraftStage.TappingStageDef + { + name = 'tapping_2', + 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, } }, }) diff --git a/mods/SYSTEM/HelperLib/src/Lib/immersiveCraftData.lua b/mods/SYSTEM/HelperLib/src/Lib/immersiveCraftData.lua index 9c98299..061e51f 100644 --- a/mods/SYSTEM/HelperLib/src/Lib/immersiveCraftData.lua +++ b/mods/SYSTEM/HelperLib/src/Lib/immersiveCraftData.lua @@ -3,10 +3,11 @@ local EMPTY_FLAG = 'EMPTY_FLAG' ---@class ImmersiveStageData ---@class ImmersiveCraftData ----@field craftName string ----@field stageName string ----@field amount integer ----@field stageData ImmersiveStageData? +---@field playerName string The name of the player who started the craft. +---@field craftName string +---@field stageName string +---@field amount integer +---@field stageData ImmersiveStageData? ---Returns craft data for immersive crafting, which is stored in the desktop metadata. ---@param meta NodeMetaRef