CraftSystem: TappingStage can now require a tool with a specific group for crafting
This commit is contained in:
@@ -11,6 +11,7 @@ local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
|
||||
---@class CraftSystem.ImmersiveCraftStage.TappingStage : CraftSystem.ImmersiveCraftStage
|
||||
---@field targetItem string
|
||||
---@field clicksNeed string
|
||||
---@field toolGroup string?
|
||||
---@field startHandler 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)
|
||||
@@ -23,6 +24,7 @@ local TappingStage = extend(ImmersiveCraftStage, {})
|
||||
---@class CraftSystem.ImmersiveCraftStage.TappingStageDef : CraftSystem.ImmersiveCraftStageDef
|
||||
---@field targetItem string
|
||||
---@field clicksNeed string
|
||||
---@field toolGroup string?
|
||||
|
||||
---Data table for transferring various time parameters between calls.
|
||||
---
|
||||
@@ -39,6 +41,7 @@ function TappingStage:new(def)
|
||||
local instance = ImmersiveCraftStage:new(def)
|
||||
instance.targetItem = def.targetItem
|
||||
instance.clicksNeed = def.clicksNeed
|
||||
instance.toolGroup = def.toolGroup
|
||||
|
||||
-- Registering the crafting stage start handler.
|
||||
instance.startHandler = function(tappingStage , pos, player)
|
||||
@@ -143,7 +146,12 @@ function TappingStage:new(def)
|
||||
|
||||
-- Returns a human-readable description of the crafting stage.
|
||||
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
|
||||
end
|
||||
@@ -151,7 +159,17 @@ 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
|
||||
---@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:
|
||||
-- Creating particles
|
||||
for i=0, 10 do
|
||||
|
||||
Reference in New Issue
Block a user