Lazy commit: processing stations
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
|
local TICKRATE = 1
|
||||||
|
|
||||||
local CraftSystem = Smc.requireCraftSystem()
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|
||||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||||
|
|
||||||
---@class BaseProcessingStation : Class
|
---@class BaseProcessingStation : Class
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field timeout number
|
|
||||||
---@field craftType CraftSystem.ProcessingCraftType
|
---@field craftType CraftSystem.ProcessingCraftType
|
||||||
---@field handler CraftSystem.ProcessingCraftHandler
|
---@field handler CraftSystem.ProcessingCraftHandler
|
||||||
---@field tab PlayerInventoryUI.getTabFunc
|
---@field tab PlayerInventoryUI.getTabFunc
|
||||||
---@field nodeName string
|
---@field nodeName string?
|
||||||
---@field activeNodeName string?
|
---@field activeNodeName string?
|
||||||
local BaseProcessingStation = Class:extend({})
|
local BaseProcessingStation = Class:extend({})
|
||||||
|
|
||||||
@@ -16,7 +17,6 @@ local BaseProcessingStation = Class:extend({})
|
|||||||
---
|
---
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class BaseProcessingStationDef
|
---@class BaseProcessingStationDef
|
||||||
---@field timeout number?
|
|
||||||
---@field craftType CraftSystem.ProcessingCraftType
|
---@field craftType CraftSystem.ProcessingCraftType
|
||||||
---@field tab PlayerInventoryUI.getTabFunc
|
---@field tab PlayerInventoryUI.getTabFunc
|
||||||
|
|
||||||
@@ -24,14 +24,13 @@ local BaseProcessingStation = Class:extend({})
|
|||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param def BaseProcessingStationDef
|
---@param def BaseProcessingStationDef
|
||||||
---@param nodesDef BaseProcessingStation.NodesDef
|
---@param nodesDef BaseProcessingStation.NodesDef?
|
||||||
function BaseProcessingStation:new(name, def, nodesDef)
|
function BaseProcessingStation:new(name, def, nodesDef)
|
||||||
local handler = CraftSystem:getProcessingCraftHandler(def.craftType)
|
local handler = CraftSystem:getProcessingCraftHandler(def.craftType)
|
||||||
|
|
||||||
---@type BaseProcessingStation
|
---@type BaseProcessingStation
|
||||||
local instance = self:getInstance({})
|
local instance = self:getInstance({})
|
||||||
instance.name = name
|
instance.name = name
|
||||||
instance.timeout = def.timeout or 1
|
|
||||||
instance.craftType = def.craftType
|
instance.craftType = def.craftType
|
||||||
instance.handler = handler
|
instance.handler = handler
|
||||||
instance.tab = def.tab
|
instance.tab = def.tab
|
||||||
@@ -40,7 +39,7 @@ function BaseProcessingStation:new(name, def, nodesDef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Opens the player's inventory, adding the node tab described in `self.tab`.
|
---Opens the player's inventory, adding the node tab described in `self.tab`.
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
---@param player Player
|
---@param player Player
|
||||||
function BaseProcessingStation:showForm(pos, player)
|
function BaseProcessingStation:showForm(pos, player)
|
||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
@@ -58,12 +57,12 @@ end
|
|||||||
---The timer timeout is set to the timeout specified `self.timeout`.
|
---The timer timeout is set to the timeout specified `self.timeout`.
|
||||||
---
|
---
|
||||||
---Returns `true` if the timer has been started.
|
---Returns `true` if the timer has been started.
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function BaseProcessingStation:startTimer(pos)
|
function BaseProcessingStation:startTimer(pos)
|
||||||
local timer = core.get_node_timer(pos)
|
local timer = core.get_node_timer(pos)
|
||||||
if not timer:is_started() then
|
if not timer:is_started() then
|
||||||
timer:start(self.timeout)
|
timer:start(TICKRATE)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -75,8 +74,10 @@ end
|
|||||||
---If an active node is not specified for a station,
|
---If an active node is not specified for a station,
|
||||||
---then no replacement will occur regardless of the status of the process.
|
---then no replacement will occur regardless of the status of the process.
|
||||||
---@param isProcessing boolean The stations process status. If `true`, the process is running.
|
---@param isProcessing boolean The stations process status. If `true`, the process is running.
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
function BaseProcessingStation:swapNode(isProcessing, pos)
|
function BaseProcessingStation:swapNode(isProcessing, pos)
|
||||||
|
assert(self.nodeName ~= nil)
|
||||||
|
|
||||||
if self.activeNodeName ~= nil then
|
if self.activeNodeName ~= nil then
|
||||||
if isProcessing then
|
if isProcessing then
|
||||||
core.swap_node(pos, {name = self.activeNodeName})
|
core.swap_node(pos, {name = self.activeNodeName})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local Control = {}
|
|||||||
|
|
||||||
---@param callbackFunc fun(player:Player, controlName:string)
|
---@param callbackFunc fun(player:Player, controlName:string)
|
||||||
function Control.subcribeOnPress(callbackFunc)
|
function Control.subcribeOnPress(callbackFunc)
|
||||||
Events.subscribe('control.on_press', callbackFunc)
|
Events:subscribe('control.on_press', callbackFunc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ end
|
|||||||
|
|
||||||
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number)
|
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number)
|
||||||
function Control.subcribeOnRelease(callbackFunc)
|
function Control.subcribeOnRelease(callbackFunc)
|
||||||
Events.subscribe('control.on_release', callbackFunc)
|
Events:subscribe('control.on_release', callbackFunc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ end
|
|||||||
|
|
||||||
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number, dtime:number)
|
---@param callbackFunc fun(player:Player, controlName:string, holdTime:number, dtime:number)
|
||||||
function Control.subcribeOnHold(callbackFunc)
|
function Control.subcribeOnHold(callbackFunc)
|
||||||
Events.subscribe('control.on_hold', callbackFunc)
|
Events:subscribe('control.on_hold', callbackFunc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ end
|
|||||||
|
|
||||||
---@param callbackFunc fun(player:Player, player_wield_index:number, player_last_wield_index:number)
|
---@param callbackFunc fun(player:Player, player_wield_index:number, player_last_wield_index:number)
|
||||||
function Control.subcribeOnWieldChange(callbackFunc)
|
function Control.subcribeOnWieldChange(callbackFunc)
|
||||||
Events.subscribe('control.on_wield_change', callbackFunc)
|
Events:subscribe('control.on_wield_change', callbackFunc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -107,19 +107,19 @@ Smc.registerGlobalStepForEachPlayer(0, function(deltaTime, player)
|
|||||||
|
|
||||||
-- on_press
|
-- on_press
|
||||||
if not lastPressed and nowPressed then
|
if not lastPressed and nowPressed then
|
||||||
Events.call('control.on_press', key)
|
Events:call('control.on_press', key)
|
||||||
|
|
||||||
controlTimer[key] = 0
|
controlTimer[key] = 0
|
||||||
|
|
||||||
-- on_release
|
-- on_release
|
||||||
elseif lastPressed and not nowPressed then
|
elseif lastPressed and not nowPressed then
|
||||||
Events.call('control.on_release', key, controlTimer[key])
|
Events:call('control.on_release', key, controlTimer[key])
|
||||||
|
|
||||||
controlTimer[key] = 0
|
controlTimer[key] = 0
|
||||||
|
|
||||||
-- on_hold
|
-- on_hold
|
||||||
elseif lastPressed and nowPressed then
|
elseif lastPressed and nowPressed then
|
||||||
Events.call('control.on_hold', key, controlTimer[key], deltaTime)
|
Events:call('control.on_hold', key, controlTimer[key], deltaTime)
|
||||||
|
|
||||||
controlTimer[key] = controlTimer[key] + deltaTime
|
controlTimer[key] = controlTimer[key] + deltaTime
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ function ImmersiveCraft:new(name, def)
|
|||||||
instance.stagesByName = stagesByName
|
instance.stagesByName = stagesByName
|
||||||
|
|
||||||
-- Subscribe to an event that will determine that the player has completed the crafting stage.
|
-- Subscribe to an event that will determine that the player has completed the crafting stage.
|
||||||
Events.subscribe('craft_system:next_immersive_stage:'..name,
|
Events:subscribe('craft_system:next_immersive_stage:'..name,
|
||||||
---@param eventName string
|
---@param eventName string
|
||||||
---@param stage CraftSystem.ImmersiveCraftStage
|
---@param stage CraftSystem.ImmersiveCraftStage
|
||||||
---@param pos MapVector
|
---@param pos MapVector
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ local tappingNode = ImmersiveCraftNode:new({
|
|||||||
---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode
|
---@param luaEntity CraftSystem.ImmersiveCraftNode.LuaTappingNode
|
||||||
on_punch = function(luaEntity, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
on_punch = function(luaEntity, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
-- We simply trigger the event that the player hits the crafting node, bound to the work station with coordinates.
|
-- We simply trigger the event that the player hits the crafting node, bound to the work station with coordinates.
|
||||||
Events.call(('craft_system:punch_tapping_node:%s:%s'):format(
|
Events:call(('craft_system:punch_tapping_node:%s:%s'):format(
|
||||||
luaEntity._craft_name, luaEntity._stage_name), luaEntity._work_station_pos, puncher, luaEntity)
|
luaEntity._craft_name, luaEntity._stage_name), luaEntity._work_station_pos, puncher, luaEntity)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ function TappingStage:new(def)
|
|||||||
|
|
||||||
entity:remove()
|
entity:remove()
|
||||||
|
|
||||||
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.
|
||||||
@@ -147,7 +147,7 @@ function TappingStage:new(def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- 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
|
||||||
---@param player Player
|
---@param player Player
|
||||||
function(eventName, pos, player, craftNode)
|
function(eventName, pos, player, craftNode)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ local Callbacks = Class.extend(ItemCallbacks, {})
|
|||||||
---
|
---
|
||||||
---default: nil
|
---default: nil
|
||||||
---* `pos`: node position
|
---* `pos`: node position
|
||||||
---@type fun(pos:MapPosition)?
|
---@type fun(pos:MapVector)?
|
||||||
Callbacks.on_construct = nil
|
Callbacks.on_construct = nil
|
||||||
|
|
||||||
---Node destructor; called before removing node.
|
---Node destructor; called before removing node.
|
||||||
@@ -21,7 +21,7 @@ Callbacks.on_construct = nil
|
|||||||
---
|
---
|
||||||
---default: nil
|
---default: nil
|
||||||
---* `pos`: node position
|
---* `pos`: node position
|
||||||
---@type fun(pos:MapPosition)?
|
---@type fun(pos:MapVector)?
|
||||||
Callbacks.on_destruct = nil
|
Callbacks.on_destruct = nil
|
||||||
|
|
||||||
---Node destructor; called after removing node.
|
---Node destructor; called after removing node.
|
||||||
@@ -30,7 +30,7 @@ Callbacks.on_destruct = nil
|
|||||||
---default: nil
|
---default: nil
|
||||||
---* `pos`: node position
|
---* `pos`: node position
|
||||||
---* `oldnode`: node table of node before it was deleted
|
---* `oldnode`: node table of node before it was deleted
|
||||||
---@type fun(pos:MapPosition, old_node)?
|
---@type fun(pos:MapVector, old_node)?
|
||||||
Callbacks.after_destruct = nil
|
Callbacks.after_destruct = nil
|
||||||
|
|
||||||
---Called when a liquid (newnode) is about to flood oldnode, if it has
|
---Called when a liquid (newnode) is about to flood oldnode, if it has
|
||||||
@@ -45,7 +45,7 @@ Callbacks.after_destruct = nil
|
|||||||
---* `pos`: table node position
|
---* `pos`: table node position
|
||||||
---* `oldnode`: table node table of node before it was deleted
|
---* `oldnode`: table node table of node before it was deleted
|
||||||
---* `newnode`: TODO: какой тут тип?
|
---* `newnode`: TODO: какой тут тип?
|
||||||
---@type fun(pos:MapPosition, old_node, new_node)?
|
---@type fun(pos:MapVector, old_node, new_node)?
|
||||||
Callbacks.on_flood = nil
|
Callbacks.on_flood = nil
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ Callbacks.on_flood = nil
|
|||||||
---* `drops`: a table of `ItemStack`s, so any metadata to be preserved can
|
---* `drops`: a table of `ItemStack`s, so any metadata to be preserved can
|
||||||
--- be added directly to one or more of the dropped items. See
|
--- be added directly to one or more of the dropped items. See
|
||||||
--- "ItemStackMetaRef".
|
--- "ItemStackMetaRef".
|
||||||
---@type fun(pos:MapPosition, old_node, new_node, old_meta, drops:ItemStack[])?
|
---@type fun(pos:MapVector, old_node, new_node, old_meta, drops:ItemStack[])?
|
||||||
Callbacks.preserve_metadata = nil
|
Callbacks.preserve_metadata = nil
|
||||||
|
|
||||||
---Called after constructing node when node was placed using
|
---Called after constructing node when node was placed using
|
||||||
@@ -73,7 +73,7 @@ Callbacks.preserve_metadata = nil
|
|||||||
---* `placer`: may be any valid ObjectRef or nil
|
---* `placer`: may be any valid ObjectRef or nil
|
||||||
---* `itemstack`: TODO: сделать описание
|
---* `itemstack`: TODO: сделать описание
|
||||||
---* `pointed_thing`: Vector of the direction of the gaze of the person who placed the block
|
---* `pointed_thing`: Vector of the direction of the gaze of the person who placed the block
|
||||||
---@type fun(pos:MapPosition, placer:Player|ObjectRef|nil, itemstack:ItemStack, pointed_thing:pointed_thing)?
|
---@type fun(pos:MapVector, placer:Player|ObjectRef|nil, itemstack:ItemStack, pointed_thing:pointed_thing)?
|
||||||
Callbacks.after_place_node = nil
|
Callbacks.after_place_node = nil
|
||||||
|
|
||||||
---Called after destructing the node when node was dug using
|
---Called after destructing the node when node was dug using
|
||||||
@@ -92,7 +92,7 @@ Callbacks.after_dig_node = nil
|
|||||||
---default: nil
|
---default: nil
|
||||||
---* `pos`: node position
|
---* `pos`: node position
|
||||||
---* player: ObjectRef of digger
|
---* player: ObjectRef of digger
|
||||||
---@type fun(pos:MapPosition, player:Player|ObjectRef|nil)?
|
---@type fun(pos:MapVector, player:Player|ObjectRef|nil)?
|
||||||
Callbacks.can_dig = nil
|
Callbacks.can_dig = nil
|
||||||
|
|
||||||
---Called when puncher (an ObjectRef) punches the node at pos.
|
---Called when puncher (an ObjectRef) punches the node at pos.
|
||||||
@@ -103,7 +103,7 @@ Callbacks.can_dig = nil
|
|||||||
---* `node`: node being hit
|
---* `node`: node being hit
|
||||||
---* `puncher`: ObjectRef of punch
|
---* `puncher`: ObjectRef of punch
|
||||||
---* `pointed_thing`: Vector of the direction of the gaze of the person who placed the block
|
---* `pointed_thing`: Vector of the direction of the gaze of the person who placed the block
|
||||||
---@type fun(pos:MapPosition, node:NodeTable, puncher:Player|ObjectRef|nil, pointed_thing:pointed_thing)?
|
---@type fun(pos:MapVector, node:NodeTable, puncher:Player|ObjectRef|nil, pointed_thing:pointed_thing)?
|
||||||
Callbacks.on_punch = nil
|
Callbacks.on_punch = nil
|
||||||
|
|
||||||
---Called when clicker (an ObjectRef) used the 'place/build' key
|
---Called when clicker (an ObjectRef) used the 'place/build' key
|
||||||
@@ -115,7 +115,7 @@ Callbacks.on_punch = nil
|
|||||||
---Note: pointed_thing can be nil, if a mod calls this function.
|
---Note: pointed_thing can be nil, if a mod calls this function.
|
||||||
---
|
---
|
||||||
---default: nil
|
---default: nil
|
||||||
---@type (fun(pos:MapPosition, node:NodeTable, clicker:Player|ObjectRef, itemstack:ItemStack, pointed_thing:pointed_thing|nil):ItemStack|nil)?
|
---@type (fun(pos:MapVector, node:NodeTable, clicker:Player|ObjectRef, itemstack:ItemStack, pointed_thing:pointed_thing|nil):ItemStack|nil)?
|
||||||
Callbacks.on_rightclick = core.node_punch
|
Callbacks.on_rightclick = core.node_punch
|
||||||
|
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ Callbacks.on_rightclick = core.node_punch
|
|||||||
---Deprecated: returning nil is the same as returning true.
|
---Deprecated: returning nil is the same as returning true.
|
||||||
---
|
---
|
||||||
---default: core.node_dig
|
---default: core.node_dig
|
||||||
---@type (fun(pos:MapPosition, node:NodeTable, digger:Player): boolean)?
|
---@type (fun(pos:MapVector, node:NodeTable, digger:Player): boolean)?
|
||||||
Callbacks.on_dig = minetest.node_dig
|
Callbacks.on_dig = minetest.node_dig
|
||||||
|
|
||||||
---called by NodeTimers, see core.get_node_timer and NodeTimerRef.
|
---called by NodeTimers, see core.get_node_timer and NodeTimerRef.
|
||||||
@@ -134,7 +134,7 @@ Callbacks.on_dig = minetest.node_dig
|
|||||||
---return true to run the timer for another cycle with the same timeout value.
|
---return true to run the timer for another cycle with the same timeout value.
|
||||||
---
|
---
|
||||||
---default: nil
|
---default: nil
|
||||||
---@type (fun(pos:MapPosition, elapsed:number, node:NodeTable, timeout:number):boolean?)?
|
---@type (fun(pos:MapVector, elapsed:number, node:NodeTable, timeout:number):boolean?)?
|
||||||
Callbacks.on_timer = nil
|
Callbacks.on_timer = nil
|
||||||
|
|
||||||
---fields = {name1 = value1, name2 = value2, ...}
|
---fields = {name1 = value1, name2 = value2, ...}
|
||||||
@@ -144,7 +144,7 @@ Callbacks.on_timer = nil
|
|||||||
---See `core.register_on_player_receive_fields` for more info.
|
---See `core.register_on_player_receive_fields` for more info.
|
||||||
---
|
---
|
||||||
---default: nil
|
---default: nil
|
||||||
---@type fun(pos:MapPosition, formname:string, fields:table, sender:Player)?
|
---@type fun(pos:MapVector, formname:string, fields:table, sender:Player)?
|
||||||
Callbacks.on_receive_fields = nil
|
Callbacks.on_receive_fields = nil
|
||||||
|
|
||||||
---Called when a player wants to put something into the inventory.
|
---Called when a player wants to put something into the inventory.
|
||||||
@@ -152,7 +152,7 @@ Callbacks.on_receive_fields = nil
|
|||||||
---Return value: number of items allowed to put.
|
---Return value: number of items allowed to put.
|
||||||
---
|
---
|
||||||
---Return value -1: Allow and don't modify item count in inventory.
|
---Return value -1: Allow and don't modify item count in inventory.
|
||||||
---@type (fun(pos:MapPosition, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player): number)?
|
---@type (fun(pos:MapVector, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player): number)?
|
||||||
Callbacks.allow_metadata_inventory_move = nil
|
Callbacks.allow_metadata_inventory_move = nil
|
||||||
|
|
||||||
---Called when a player wants to take something out of the inventory.
|
---Called when a player wants to take something out of the inventory.
|
||||||
@@ -160,31 +160,31 @@ Callbacks.allow_metadata_inventory_move = nil
|
|||||||
---Return value: number of items allowed to take.
|
---Return value: number of items allowed to take.
|
||||||
---
|
---
|
||||||
---Return value -1: Allow and don't modify item count in inventory.
|
---Return value -1: Allow and don't modify item count in inventory.
|
||||||
---@type (fun(pos:MapPosition, listname:string, index:number, stack:ItemStack, player:Player): number)?
|
---@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): number)?
|
||||||
Callbacks.allow_metadata_inventory_take = nil
|
Callbacks.allow_metadata_inventory_take = nil
|
||||||
|
|
||||||
---Called after the actual action has happened, according to what was allowed.
|
---Called after the actual action has happened, according to what was allowed.
|
||||||
---
|
---
|
||||||
---No return value.
|
---No return value.
|
||||||
---@type (fun(pos:MapPosition, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player): void)?
|
---@type (fun(pos:MapVector, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player): void)?
|
||||||
Callbacks.on_metadata_inventory_move = nil
|
Callbacks.on_metadata_inventory_move = nil
|
||||||
|
|
||||||
---Called after the actual action has happened, according to what was allowed.
|
---Called after the actual action has happened, according to what was allowed.
|
||||||
---
|
---
|
||||||
---No return value.
|
---No return value.
|
||||||
---@type (fun(pos:MapPosition, listname:string, index:number, stack:ItemStack, player:Player): void)?
|
---@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): void)?
|
||||||
Callbacks.on_metadata_inventory_put = nil
|
Callbacks.on_metadata_inventory_put = nil
|
||||||
|
|
||||||
---Called after the actual action has happened, according to what was allowed.
|
---Called after the actual action has happened, according to what was allowed.
|
||||||
---
|
---
|
||||||
---No return value.
|
---No return value.
|
||||||
---@type (fun(pos:MapPosition, listname:string, index:number, stack:ItemStack, player:Player): void)?
|
---@type (fun(pos:MapVector, listname:string, index:number, stack:ItemStack, player:Player): void)?
|
||||||
Callbacks.on_metadata_inventory_take = nil
|
Callbacks.on_metadata_inventory_take = nil
|
||||||
|
|
||||||
---If defined, called when an explosion touches the node, instead of
|
---If defined, called when an explosion touches the node, instead of
|
||||||
---removing the node.
|
---removing the node.
|
||||||
---* `intensity`: 1.0 = mid range of regular TNT.
|
---* `intensity`: 1.0 = mid range of regular TNT.
|
||||||
---@type (fun(pos:MapPosition, intensity:number): void)?
|
---@type (fun(pos:MapVector, intensity:number): void)?
|
||||||
Callbacks.on_blast = nil
|
Callbacks.on_blast = nil
|
||||||
|
|
||||||
return Callbacks
|
return Callbacks
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local FUEL_ENERGY_FACTOR = 0.1
|
|
||||||
|
|
||||||
local BaseProcessingStation = Smc.requireBaseProcessingStation()
|
local BaseProcessingStation = Smc.requireBaseProcessingStation()
|
||||||
|
---@type Events.ProcessingStationEvents
|
||||||
|
local ProcessingStationEvents = Smc.requireEvents('ProcessingStationEvents')
|
||||||
|
|
||||||
|
|
||||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ local ProcessingStationNode = Node:getExtended({
|
|||||||
|
|
||||||
---@class ProcessingContainerStation : BaseProcessingStation
|
---@class ProcessingContainerStation : BaseProcessingStation
|
||||||
---@field enableRegression boolean?
|
---@field enableRegression boolean?
|
||||||
|
---@field fuelGroup string
|
||||||
---@field inputSlots integer
|
---@field inputSlots integer
|
||||||
---@field outputSlots integer
|
---@field outputSlots integer
|
||||||
local ProcessingContainerStation = BaseProcessingStation:extend({})
|
local ProcessingContainerStation = BaseProcessingStation:extend({})
|
||||||
@@ -26,19 +28,25 @@ local ProcessingContainerStation = BaseProcessingStation:extend({})
|
|||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class ProcessingContainerStationDef : BaseProcessingStationDef
|
---@class ProcessingContainerStationDef : BaseProcessingStationDef
|
||||||
---@field enableRegression boolean?
|
---@field enableRegression boolean?
|
||||||
|
---@field fuelGroup string?
|
||||||
---@field inputSlots integer?
|
---@field inputSlots integer?
|
||||||
---@field outputSlots integer?
|
---@field outputSlots integer?
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param def ProcessingContainerStationDef
|
---@param def ProcessingContainerStationDef
|
||||||
---@param nodesDef BaseProcessingStation.NodesDef
|
---@param nodesDef BaseProcessingStation.NodesDef?
|
||||||
function ProcessingContainerStation:new(name, def, nodesDef)
|
function ProcessingContainerStation:new(name, def, nodesDef)
|
||||||
---@type ProcessingContainerStation
|
---@type ProcessingContainerStation
|
||||||
local instance = self:getInstance(BaseProcessingStation:new(name, def, nodesDef))
|
local instance = self:getInstance(BaseProcessingStation:new(name, def))
|
||||||
instance.enableRegression = def.enableRegression
|
instance.enableRegression = def.enableRegression
|
||||||
|
instance.fuelGroup = def.fuelGroup or 'fuel'
|
||||||
instance.inputSlots = def.inputSlots or 1
|
instance.inputSlots = def.inputSlots or 1
|
||||||
instance.outputSlots = def.outputSlots or 1
|
instance.outputSlots = def.outputSlots or 1
|
||||||
|
|
||||||
|
if nodesDef == nil then
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
local settings = nodesDef.settings
|
local settings = nodesDef.settings
|
||||||
local activeSettings = nodesDef.activeSettings
|
local activeSettings = nodesDef.activeSettings
|
||||||
local callbacks = nodesDef.callbacks or {}
|
local callbacks = nodesDef.callbacks or {}
|
||||||
@@ -89,7 +97,7 @@ function ProcessingContainerStation:new(name, def, nodesDef)
|
|||||||
callbacks.on_timer = function(pos, elapsed, node, timeout)
|
callbacks.on_timer = function(pos, elapsed, node, timeout)
|
||||||
oldCallback(pos, elapsed, node, timeout)
|
oldCallback(pos, elapsed, node, timeout)
|
||||||
|
|
||||||
return self:onTimer(pos, elapsed, node, timeout)
|
return instance:onTimer(pos, elapsed, node, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Registering a nodes for Luanti.
|
-- Registering a nodes for Luanti.
|
||||||
@@ -105,7 +113,7 @@ function ProcessingContainerStation:new(name, def, nodesDef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Opens the player's inventory, adding the tab described in `self.tab`.
|
---Opens the player's inventory, adding the tab described in `self.tab`.
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
---@param player Player
|
---@param player Player
|
||||||
function ProcessingContainerStation:showForm(pos, player)
|
function ProcessingContainerStation:showForm(pos, player)
|
||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
@@ -118,11 +126,13 @@ function ProcessingContainerStation:showForm(pos, player)
|
|||||||
PlayerInventoryUI:showForm(playerName)
|
PlayerInventoryUI:showForm(playerName)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
function ProcessingContainerStation:init(pos)
|
function ProcessingContainerStation:init(pos)
|
||||||
---@type ProcessingContainerStation.MetaData
|
---@type ProcessingContainerStation.MetaData
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
meta:set_float('processing_time', 0.0)
|
meta:set_float('processing_time', 0.0)
|
||||||
|
meta:set_string('fuel_group', self.fuelGroup)
|
||||||
|
meta:set_float('energy', 0.0)
|
||||||
|
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
inventory:set_size('input', self.inputSlots)
|
inventory:set_size('input', self.inputSlots)
|
||||||
@@ -133,10 +143,9 @@ end
|
|||||||
|
|
||||||
---@param isProcessing boolean
|
---@param isProcessing boolean
|
||||||
---@param meta ProcessingContainerStation.MetaData
|
---@param meta ProcessingContainerStation.MetaData
|
||||||
---@param timeout number
|
|
||||||
---@return boolean isProcessing
|
---@return boolean isProcessing
|
||||||
---@return CraftSystem.ProcessingCraft?
|
---@return CraftSystem.ProcessingCraft?
|
||||||
function ProcessingContainerStation:getCraft(isProcessing, meta, timeout)
|
function ProcessingContainerStation:getCraft(isProcessing, meta)
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
|
|
||||||
local processingTime = meta:get_float('processing_time')
|
local processingTime = meta:get_float('processing_time')
|
||||||
@@ -165,19 +174,20 @@ end
|
|||||||
|
|
||||||
---@param isProcessing boolean
|
---@param isProcessing boolean
|
||||||
---@param meta ProcessingContainerStation.MetaData
|
---@param meta ProcessingContainerStation.MetaData
|
||||||
---@param timeout number
|
---@param elapsed number
|
||||||
---@param craft CraftSystem.ProcessingCraft?
|
---@param craft CraftSystem.ProcessingCraft?
|
||||||
---@return boolean isProcessing
|
---@return boolean isProcessing
|
||||||
function ProcessingContainerStation:processing(isProcessing, meta, timeout, craft)
|
function ProcessingContainerStation:processing(isProcessing, meta, elapsed, craft)
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
|
|
||||||
local processingTime = meta:get_float('processing_time')
|
local processingTime = meta:get_float('processing_time')
|
||||||
|
local lastCraftName = meta:get_string('craft_name')
|
||||||
|
|
||||||
if isProcessing and craft ~= nil then
|
if isProcessing and craft ~= nil then
|
||||||
processingTime = processingTime + timeout
|
processingTime = processingTime + elapsed
|
||||||
else
|
else
|
||||||
if self.enableRegression then
|
if self.enableRegression then
|
||||||
processingTime = processingTime - timeout
|
processingTime = processingTime - elapsed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -188,28 +198,37 @@ function ProcessingContainerStation:processing(isProcessing, meta, timeout, craf
|
|||||||
|
|
||||||
inventory:add_item('output', craft.output)
|
inventory:add_item('output', craft.output)
|
||||||
processingTime = 0
|
processingTime = 0
|
||||||
|
lastCraftName = ''
|
||||||
end
|
end
|
||||||
|
|
||||||
if processingTime < 0 then
|
if processingTime < 0 then
|
||||||
processingTime = 0
|
processingTime = 0
|
||||||
|
lastCraftName = ''
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_float('processing_time', processingTime)
|
meta:set_float('processing_time', processingTime)
|
||||||
|
meta:set_string('craft_name', lastCraftName)
|
||||||
|
|
||||||
return isProcessing or (self.enableRegression == true and processingTime ~= 0)
|
return isProcessing or (self.enableRegression == true and processingTime ~= 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
---@param elapsed number
|
---@param elapsed number
|
||||||
---@param node NodeTable
|
---@param node NodeTable
|
||||||
---@param timeout number
|
---@param timeout number
|
||||||
---@return boolean?
|
---@return boolean?
|
||||||
function ProcessingContainerStation:onTimer(pos, elapsed, node, timeout)
|
function ProcessingContainerStation:onTimer(pos, elapsed, node, timeout)
|
||||||
|
---@type ProcessingContainerStation.MetaData
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
local energy = meta:get_float('energy')
|
||||||
|
|
||||||
local isProcessing, craft = self:getCraft(true, meta, timeout)
|
local isProcessing, craft = self:getCraft(true, meta)
|
||||||
local isProcessing = self:processing(isProcessing, meta, timeout, craft)
|
|
||||||
|
if energy <= 0 then
|
||||||
|
isProcessing = false
|
||||||
|
end
|
||||||
|
|
||||||
|
isProcessing = self:processing(isProcessing, meta, elapsed, craft)
|
||||||
|
|
||||||
self:swapNode(isProcessing, pos)
|
self:swapNode(isProcessing, pos)
|
||||||
|
|
||||||
@@ -218,37 +237,45 @@ function ProcessingContainerStation:onTimer(pos, elapsed, node, timeout)
|
|||||||
return isProcessing
|
return isProcessing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ProcessingContainerStation:onPush(pos, energy)
|
||||||
|
---@type ProcessingContainerStation.MetaData
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
|
meta:set_float('energy', energy)
|
||||||
|
core.log(tostring(energy))
|
||||||
|
self:startTimer(pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
ProcessingStationEvents:subscribeOnPushContainer(ProcessingContainerStation.onPush)
|
||||||
|
|
||||||
--- DEBUG ---
|
--- DEBUG ---
|
||||||
--[[
|
|
||||||
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
local Formspec = Smc.requireFormspec()
|
local Formspec = Smc.requireFormspec()
|
||||||
local TileSheet = Smc.requireTileSheet()
|
local TileSheet = Smc.requireTileSheet()
|
||||||
local tileSheet = TileSheet:new('debug_processing_station_sheet.png', 16, 16)
|
local tileSheet = TileSheet:new('debug_processing_station_sheet.png', 16, 16)
|
||||||
local handler = CraftSystem:getProcessingCraftHandler('test')
|
local handler = CraftSystem:getProcessingCraftHandler('test')
|
||||||
|
|
||||||
handler:registerCraft('test_pro_craft', {
|
|
||||||
output = 'wood:allwhere_log',
|
|
||||||
recipe = {'wood:allwhere_stick', 'rocks:sylite'},
|
|
||||||
time = 5,
|
|
||||||
})
|
|
||||||
|
|
||||||
---@param self PlayerInventoryUI
|
---@param self PlayerInventoryUI
|
||||||
---@param playerName string
|
---@param playerName string
|
||||||
---@param tabType PlayerInventoryUI.TabType
|
---@param tabType PlayerInventoryUI.TabType
|
||||||
---@return Formspec
|
---@return Formspec
|
||||||
local tab = function(self, playerName, tabType)
|
local tab = function(self, playerName, tabType)
|
||||||
local form = Formspec:new()
|
local form = Formspec:new()
|
||||||
|
---@type MapVector
|
||||||
local pos = self:getContex(playerName, 'node_tab_pos')
|
local pos = self:getContex(playerName, 'node_tab_pos')
|
||||||
local inventoryLocation = ('nodemeta:%s,%s,%s'):format(pos.x, pos.y, pos.z)
|
local inventoryLocation = ('nodemeta:%s,%s,%s'):format(pos.x, pos.y, pos.z)
|
||||||
|
|
||||||
---@type ProcessingContainerStation.MetaData
|
---@type ProcessingContainerStation.MetaData
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
---@type ProcessingFuelStation.MetaData
|
||||||
|
local fuelMeta = core.get_meta(pos - vector.new(0, 1, 0))
|
||||||
|
|
||||||
form
|
form
|
||||||
:image(0, 0, 11, 9, 'player_inventory_tab_background.png')
|
:image(0, 0, 11, 9, 'player_inventory_tab_background.png')
|
||||||
:list(inventoryLocation, 'input', 1, 1, 1, 2)
|
:list(inventoryLocation, 'input', 1, 1, 1, 2)
|
||||||
:list(inventoryLocation, 'output', 3, 1, 1, 1)
|
:list(inventoryLocation, 'output', 3, 1, 1, 1)
|
||||||
:list(inventoryLocation, 'fuel', 1, 4, 1, 1)
|
:label(4, 3, tostring(fuelMeta:get_float('remaining_fuel')))
|
||||||
:label(4, 3, tostring(meta:get_float('remaining_fuel')))
|
|
||||||
:label(4.5, 3, tostring(meta:get_float('processing_time')))
|
:label(4.5, 3, tostring(meta:get_float('processing_time')))
|
||||||
|
|
||||||
return form
|
return form
|
||||||
@@ -264,8 +291,8 @@ ProcessingContainerStation:new('test_processing_node', {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = 'test_processing_node',
|
name = 'test_container_node',
|
||||||
tiles = {
|
--[[tiles = {
|
||||||
tileSheet:t(0, 0),
|
tileSheet:t(0, 0),
|
||||||
tileSheet:t(0, 0),
|
tileSheet:t(0, 0),
|
||||||
tileSheet:t(0, 1),
|
tileSheet:t(0, 1),
|
||||||
@@ -283,7 +310,7 @@ ProcessingContainerStation:new('test_processing_node', {
|
|||||||
tileSheet:t(0, 2),
|
tileSheet:t(0, 2),
|
||||||
tileSheet:t(0, 2),
|
tileSheet:t(0, 2),
|
||||||
tileSheet:t(0, 2)
|
tileSheet:t(0, 2)
|
||||||
}
|
}--]]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
--]]
|
--]]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@alias ProcessingContainerStation.MetaData.FloatKey 'processing_time'
|
---@alias ProcessingContainerStation.MetaData.FloatKey 'processing_time'|'energy'
|
||||||
---@alias ProcessingContainerStation.MetaData.StringKey 'craft_name'
|
---@alias ProcessingContainerStation.MetaData.StringKey 'craft_name'|'fuel_group'
|
||||||
|
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class ProcessingContainerStation.MetaData : NodeMetaRef
|
---@class ProcessingContainerStation.MetaData : NodeMetaRef
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
local FUEL_ENERGY_FACTOR = 0.1
|
local FUEL_ENERGY_FACTOR = 0.1
|
||||||
|
|
||||||
local BaseProcessingStation = Smc.requireBaseProcessingStation()
|
local BaseProcessingStation = Smc.requireBaseProcessingStation()
|
||||||
|
---@type Events.ProcessingStationEvents
|
||||||
|
local ProcessingStationEvents = Smc.requireEvents('ProcessingStationEvents')
|
||||||
|
|
||||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||||
|
|
||||||
@@ -16,28 +18,35 @@ local ProcessingFuelStationNode = Node:getExtended({
|
|||||||
})
|
})
|
||||||
|
|
||||||
---@class ProcessingFuelStation : BaseProcessingStation
|
---@class ProcessingFuelStation : BaseProcessingStation
|
||||||
---@field enableIdling boolean?
|
---@field enableIdling boolean?
|
||||||
---@field fuelGroup string
|
---@field enableContainerProcessing boolean?
|
||||||
---@field fuelSlots integer
|
---@field fuelGroup string
|
||||||
|
---@field fuelSlots integer
|
||||||
local ProcessingFuelStation = BaseProcessingStation:extend({})
|
local ProcessingFuelStation = BaseProcessingStation:extend({})
|
||||||
|
|
||||||
---Definition table for the `ProcessingFuelStation`.
|
---Definition table for the `ProcessingFuelStation`.
|
||||||
---
|
---
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class ProcessingFuelStationDef : BaseProcessingStationDef
|
---@class ProcessingFuelStationDef : BaseProcessingStationDef
|
||||||
---@field enableIdling boolean?
|
---@field enableIdling boolean?
|
||||||
---@field fuelGroup string?
|
---@field enableContainerProcessing boolean?
|
||||||
---@field fuelSlots integer?
|
---@field fuelGroup string?
|
||||||
|
---@field fuelSlots integer?
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param def ProcessingFuelStationDef
|
---@param def ProcessingFuelStationDef
|
||||||
---@param nodesDef BaseProcessingStation.NodesDef
|
---@param nodesDef BaseProcessingStation.NodesDef?
|
||||||
function ProcessingFuelStation:new(name, def, nodesDef)
|
function ProcessingFuelStation:new(name, def, nodesDef)
|
||||||
---@type ProcessingFuelStation
|
---@type ProcessingFuelStation
|
||||||
local instance = self:getInstance(BaseProcessingStation:new(name, def, nodesDef))
|
local instance = self:getInstance(BaseProcessingStation:new(name, def))
|
||||||
instance.enableIdling = def.enableIdling
|
instance.enableIdling = def.enableIdling
|
||||||
instance.fuelGroup = def.fuelGroup or 'fuel'
|
instance.enableContainerProcessing = def.enableContainerProcessing
|
||||||
instance.fuelSlots = def.fuelSlots or 1
|
instance.fuelGroup = def.fuelGroup or 'fuel'
|
||||||
|
instance.fuelSlots = def.fuelSlots or 1
|
||||||
|
|
||||||
|
if nodesDef == nil then
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
local settings = nodesDef.settings
|
local settings = nodesDef.settings
|
||||||
local activeSettings = nodesDef.activeSettings
|
local activeSettings = nodesDef.activeSettings
|
||||||
@@ -104,11 +113,12 @@ function ProcessingFuelStation:new(name, def, nodesDef)
|
|||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
function ProcessingFuelStation:init(pos)
|
function ProcessingFuelStation:init(pos)
|
||||||
---@type ProcessingFuelStation.MetaData
|
---@type ProcessingFuelStation.MetaData
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
meta:set_float('remaining_fuel', 0.0)
|
meta:set_float('remaining_fuel', 0.0)
|
||||||
|
meta:set_string('fuel_group', self.fuelGroup)
|
||||||
|
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
inventory:set_size('fuel', self.fuelSlots)
|
inventory:set_size('fuel', self.fuelSlots)
|
||||||
@@ -116,11 +126,18 @@ function ProcessingFuelStation:init(pos)
|
|||||||
self:startTimer(pos)
|
self:startTimer(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param remainingFuel number
|
---@param isProcessing boolean
|
||||||
---@param inventory InvRef
|
---@param meta ProcessingFuelStation.MetaData
|
||||||
---@param timeout number
|
---@param elapsed number
|
||||||
---@return number remainingFuel
|
---@return boolean isProcessing
|
||||||
function ProcessingFuelStation:takeFuel(remainingFuel, inventory, timeout)
|
function ProcessingFuelStation:takeFuel(isProcessing, meta, elapsed)
|
||||||
|
local inventory = meta:get_inventory()
|
||||||
|
local remainingFuel = meta:get_float('remaining_fuel')
|
||||||
|
|
||||||
|
if remainingFuel > 0 or inventory:is_empty('fuel') then
|
||||||
|
return isProcessing
|
||||||
|
end
|
||||||
|
|
||||||
local fuelList = inventory:get_list('fuel')
|
local fuelList = inventory:get_list('fuel')
|
||||||
|
|
||||||
for _, fuelStack in ipairs(fuelList) do
|
for _, fuelStack in ipairs(fuelList) do
|
||||||
@@ -134,8 +151,8 @@ function ProcessingFuelStation:takeFuel(remainingFuel, inventory, timeout)
|
|||||||
|
|
||||||
-- If the energy of one item is not enough for one iteration,
|
-- If the energy of one item is not enough for one iteration,
|
||||||
-- we calculate how many items we need to take
|
-- we calculate how many items we need to take
|
||||||
if fuelEnergy < timeout then
|
if fuelEnergy < elapsed then
|
||||||
itemCount = math.min(math.ceil(timeout/fuelEnergy), itemCount)
|
itemCount = math.min(math.ceil(elapsed/fuelEnergy), itemCount)
|
||||||
else
|
else
|
||||||
itemCount = 1
|
itemCount = 1
|
||||||
end
|
end
|
||||||
@@ -148,29 +165,27 @@ function ProcessingFuelStation:takeFuel(remainingFuel, inventory, timeout)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return remainingFuel
|
isProcessing = true
|
||||||
|
|
||||||
|
meta:set_float('remaining_fuel', remainingFuel)
|
||||||
|
|
||||||
|
return isProcessing
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param isProcessing boolean
|
---@param isProcessing boolean
|
||||||
---@param meta ProcessingFuelStation.MetaData
|
---@param meta ProcessingFuelStation.MetaData
|
||||||
---@param timeout number
|
---@param elapsed number
|
||||||
---@return boolean isProcessing
|
---@return boolean isProcessing
|
||||||
function ProcessingFuelStation:burnFuel(isProcessing, meta, timeout)
|
function ProcessingFuelStation:burnFuel(isProcessing, meta, elapsed)
|
||||||
local inventory = meta:get_inventory()
|
|
||||||
|
|
||||||
local remainingFuel = meta:get_float('remaining_fuel')
|
local remainingFuel = meta:get_float('remaining_fuel')
|
||||||
|
|
||||||
if isProcessing and remainingFuel <= 0 and not inventory:is_empty('fuel') then
|
|
||||||
remainingFuel = self:takeFuel(remainingFuel, inventory, timeout)
|
|
||||||
end
|
|
||||||
|
|
||||||
if isProcessing then
|
if isProcessing then
|
||||||
remainingFuel = remainingFuel - timeout
|
remainingFuel = remainingFuel - elapsed
|
||||||
elseif self.enableIdling then
|
elseif self.enableIdling then
|
||||||
remainingFuel = remainingFuel - timeout
|
remainingFuel = remainingFuel - elapsed
|
||||||
end
|
end
|
||||||
|
|
||||||
if remainingFuel < 0 then
|
if remainingFuel <= 0 then
|
||||||
remainingFuel = 0
|
remainingFuel = 0
|
||||||
isProcessing = false
|
isProcessing = false
|
||||||
end
|
end
|
||||||
@@ -180,15 +195,39 @@ function ProcessingFuelStation:burnFuel(isProcessing, meta, timeout)
|
|||||||
return isProcessing or (self.enableIdling == true and remainingFuel ~= 0)
|
return isProcessing or (self.enableIdling == true and remainingFuel ~= 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
|
function ProcessingFuelStation:pushContainer(pos)
|
||||||
|
if not self.enableContainerProcessing then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local containerPos = pos + vector.new(0, 1, 0)
|
||||||
|
---@type ProcessingContainerStation.MetaData
|
||||||
|
local containerMeta = core.get_meta(containerPos)
|
||||||
|
|
||||||
|
local fuelGroup = containerMeta:get_string('fuel_group')
|
||||||
|
|
||||||
|
if fuelGroup ~= self.fuelGroup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type ProcessingFuelStation.MetaData
|
||||||
|
local fuelMeta = core.get_meta(pos)
|
||||||
|
|
||||||
|
ProcessingStationEvents:callOnPushContainer(containerPos, fuelMeta:get_float('remaining_fuel'))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param pos MapVector
|
||||||
---@param elapsed number
|
---@param elapsed number
|
||||||
---@param node NodeTable
|
---@param node NodeTable
|
||||||
---@param timeout number
|
---@param elapsed number
|
||||||
---@return boolean?
|
---@return boolean?
|
||||||
function ProcessingFuelStation:onTimer(pos, elapsed, node, timeout)
|
function ProcessingFuelStation:onTimer(pos, elapsed, node, timeout)
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
local isProcessing = self:burnFuel(true, meta, timeout)
|
local isProcessing = self:burnFuel(true, meta, elapsed)
|
||||||
|
isProcessing = self:takeFuel(isProcessing, meta, elapsed) -- TODO: if-else
|
||||||
|
self:pushContainer(pos)
|
||||||
|
|
||||||
self:swapNode(isProcessing, pos)
|
self:swapNode(isProcessing, pos)
|
||||||
|
|
||||||
@@ -198,17 +237,9 @@ function ProcessingFuelStation:onTimer(pos, elapsed, node, timeout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- DEBUG ---
|
--- DEBUG ---
|
||||||
--[[
|
|
||||||
local Formspec = Smc.requireFormspec()
|
local Formspec = Smc.requireFormspec()
|
||||||
local TileSheet = Smc.requireTileSheet()
|
local TileSheet = Smc.requireTileSheet()
|
||||||
local tileSheet = TileSheet:new('debug_processing_station_sheet.png', 16, 16)
|
|
||||||
local handler = CraftSystem:getProcessingCraftHandler('test')
|
|
||||||
|
|
||||||
handler:registerCraft('test_pro_craft', {
|
|
||||||
output = 'wood:allwhere_log',
|
|
||||||
recipe = {'wood:allwhere_stick', 'rocks:sylite'},
|
|
||||||
time = 5,
|
|
||||||
})
|
|
||||||
|
|
||||||
---@param self PlayerInventoryUI
|
---@param self PlayerInventoryUI
|
||||||
---@param playerName string
|
---@param playerName string
|
||||||
@@ -224,11 +255,9 @@ local tab = function(self, playerName, tabType)
|
|||||||
|
|
||||||
form
|
form
|
||||||
:image(0, 0, 11, 9, 'player_inventory_tab_background.png')
|
:image(0, 0, 11, 9, 'player_inventory_tab_background.png')
|
||||||
:list(inventoryLocation, 'input', 1, 1, 1, 2)
|
|
||||||
:list(inventoryLocation, 'output', 3, 1, 1, 1)
|
|
||||||
:list(inventoryLocation, 'fuel', 1, 4, 1, 1)
|
:list(inventoryLocation, 'fuel', 1, 4, 1, 1)
|
||||||
:label(4, 3, tostring(meta:get_float('remaining_fuel')))
|
:label(4, 3, tostring(meta:get_float('remaining_fuel')))
|
||||||
:label(4.5, 3, tostring(meta:get_float('processing_time')))
|
--:label(4.5, 3, tostring(meta:get_float('processing_time')))
|
||||||
|
|
||||||
return form
|
return form
|
||||||
end
|
end
|
||||||
@@ -238,32 +267,13 @@ ProcessingFuelStation:new('test_processing_node', {
|
|||||||
tab = tab,
|
tab = tab,
|
||||||
inputSlots = 2,
|
inputSlots = 2,
|
||||||
fuelGroup = 'wood',
|
fuelGroup = 'wood',
|
||||||
enableIdling = true,
|
enableIdling = false,
|
||||||
enableRegression = false,
|
enableContainerProcessing = true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
name = 'test_processing_node',
|
name = 'test_processing_node',
|
||||||
tiles = {
|
|
||||||
tileSheet:t(0, 0),
|
|
||||||
tileSheet:t(0, 0),
|
|
||||||
tileSheet:t(0, 1),
|
|
||||||
tileSheet:t(0, 2),
|
|
||||||
tileSheet:t(0, 2),
|
|
||||||
tileSheet:t(0, 2)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
activeSettings = {
|
|
||||||
name = 'test_processing_node_active',
|
|
||||||
tiles = {
|
|
||||||
tileSheet:t(0, 0),
|
|
||||||
tileSheet:t(0, 0),
|
|
||||||
tileSheet:t(1, 1),
|
|
||||||
tileSheet:t(0, 2),
|
|
||||||
tileSheet:t(0, 2),
|
|
||||||
tileSheet:t(0, 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
--]]
|
--]]
|
||||||
return ProcessingFuelStation
|
return ProcessingFuelStation
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
---@alias ProcessingFuelStation.MetaData.FloatKey 'remaining_fuel'
|
---@alias ProcessingFuelStation.MetaData.FloatKey 'remaining_fuel'
|
||||||
|
---@alias ProcessingFuelStation.MetaData.StringKey 'fuel_group'
|
||||||
|
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class ProcessingFuelStation.MetaData : NodeMetaRef
|
---@class ProcessingFuelStation.MetaData : NodeMetaRef
|
||||||
---@field get_float fun(self, key:ProcessingFuelStation.MetaData.FloatKey):number
|
---@field get_float fun(self, key:ProcessingFuelStation.MetaData.FloatKey):number
|
||||||
---@field set_float fun(self, key:ProcessingFuelStation.MetaData.FloatKey, value:number)
|
---@field set_float fun(self, key:ProcessingFuelStation.MetaData.FloatKey, value:number)
|
||||||
|
---@field get_string fun(self, key:ProcessingFuelStation.MetaData.StringKey):string
|
||||||
|
---@field set_string fun(self, key:ProcessingFuelStation.MetaData.StringKey, value:string)
|
||||||
|
|||||||
@@ -28,11 +28,10 @@ local ProcessingStation = BaseProcessingStation:extend({})
|
|||||||
---@param def ProcessingStationDef
|
---@param def ProcessingStationDef
|
||||||
---@param nodesDef BaseProcessingStation.NodesDef
|
---@param nodesDef BaseProcessingStation.NodesDef
|
||||||
function ProcessingStation:new(name, def, nodesDef)
|
function ProcessingStation:new(name, def, nodesDef)
|
||||||
|
|
||||||
---@type ProcessingStation
|
---@type ProcessingStation
|
||||||
local instance = self:getInstance(BaseProcessingStation:new(name, def, nodesDef))
|
local instance = self:getInstance(BaseProcessingStation:new(name, def))
|
||||||
instance.containerStation = ProcessingContainerStation:new(name, def, nodesDef)
|
instance.containerStation = ProcessingContainerStation:new(name, def)
|
||||||
instance.fuelStation = ProcessingFuelStation:new(name, def, nodesDef)
|
instance.fuelStation = ProcessingFuelStation:new(name, def)
|
||||||
|
|
||||||
local settings = nodesDef.settings
|
local settings = nodesDef.settings
|
||||||
local activeSettings = nodesDef.activeSettings
|
local activeSettings = nodesDef.activeSettings
|
||||||
@@ -63,21 +62,21 @@ function ProcessingStation:new(name, def, nodesDef)
|
|||||||
callbacks.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
callbacks.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
oldCallback(pos, from_list, from_index, to_list, to_index, count, player)
|
oldCallback(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
|
||||||
instance:startTimer(pos)
|
instance.fuelStation:startTimer(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
oldCallback = callbacks.on_metadata_inventory_put or function(...) end
|
oldCallback = callbacks.on_metadata_inventory_put or function(...) end
|
||||||
callbacks.on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
callbacks.on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
oldCallback(pos, listname, index, stack, player)
|
oldCallback(pos, listname, index, stack, player)
|
||||||
|
|
||||||
instance:startTimer(pos)
|
instance.fuelStation:startTimer(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
oldCallback = callbacks.on_metadata_inventory_take or function(...) end
|
oldCallback = callbacks.on_metadata_inventory_take or function(...) end
|
||||||
callbacks.on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
callbacks.on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
oldCallback(pos, listname, index, stack, player)
|
oldCallback(pos, listname, index, stack, player)
|
||||||
|
|
||||||
instance:startTimer(pos)
|
instance.fuelStation:startTimer(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
oldCallback = callbacks.on_timer or function(...) end
|
oldCallback = callbacks.on_timer or function(...) end
|
||||||
@@ -100,7 +99,7 @@ function ProcessingStation:new(name, def, nodesDef)
|
|||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos MapPosition
|
---@param pos MapVector
|
||||||
---@param elapsed number
|
---@param elapsed number
|
||||||
---@param node NodeTable
|
---@param node NodeTable
|
||||||
---@param timeout number
|
---@param timeout number
|
||||||
@@ -108,12 +107,12 @@ end
|
|||||||
function ProcessingStation:onTimer(pos, elapsed, node, timeout)
|
function ProcessingStation:onTimer(pos, elapsed, node, timeout)
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
local isProcessing, craft = self.containerStation:getCraft(true, meta, timeout)
|
local isProcessing, craft = self.containerStation:getCraft(true, meta)
|
||||||
core.log(tostring(isProcessing))
|
isProcessing = self.fuelStation:burnFuel(isProcessing, meta, elapsed)
|
||||||
isProcessing = self.fuelStation:burnFuel(isProcessing, meta, timeout)
|
if craft ~= nil then
|
||||||
core.log(tostring(isProcessing))
|
isProcessing = self.fuelStation:takeFuel(isProcessing, meta, elapsed)
|
||||||
isProcessing = self.containerStation:processing(isProcessing, meta, timeout, craft)
|
end
|
||||||
core.log(tostring(isProcessing))
|
isProcessing = self.containerStation:processing(isProcessing, meta, elapsed, craft)
|
||||||
|
|
||||||
self:swapNode(isProcessing, pos)
|
self:swapNode(isProcessing, pos)
|
||||||
|
|
||||||
@@ -153,8 +152,8 @@ local tab = function(self, playerName, tabType)
|
|||||||
:list(inventoryLocation, 'input', 1, 1, 1, 2)
|
:list(inventoryLocation, 'input', 1, 1, 1, 2)
|
||||||
:list(inventoryLocation, 'output', 3, 1, 1, 1)
|
:list(inventoryLocation, 'output', 3, 1, 1, 1)
|
||||||
:list(inventoryLocation, 'fuel', 1, 4, 1, 1)
|
:list(inventoryLocation, 'fuel', 1, 4, 1, 1)
|
||||||
:label(4, 3, tostring(meta:get_float('remaining_fuel')))
|
:label(4, 3, tostring(math.round(meta:get_float('remaining_fuel'))))
|
||||||
:label(4.5, 3, tostring(meta:get_float('processing_time')))
|
:label(4.5, 3, tostring(math.round(meta:get_float('processing_time'))))
|
||||||
|
|
||||||
return form
|
return form
|
||||||
end
|
end
|
||||||
@@ -165,7 +164,8 @@ ProcessingStation:new('test_processing_node', {
|
|||||||
inputSlots = 2,
|
inputSlots = 2,
|
||||||
fuelGroup = 'wood',
|
fuelGroup = 'wood',
|
||||||
enableIdling = true,
|
enableIdling = true,
|
||||||
enableRegression = true,
|
enableContainerProcessing = true,
|
||||||
|
--enableRegression = true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
settings = {
|
settings = {
|
||||||
|
|||||||
@@ -1,31 +1,4 @@
|
|||||||
Events = {}
|
local modInfo = Mod.getInfo('smc__system__events')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
---@alias Events.callback fun(eventName, ...)
|
return require('Events')
|
||||||
|
|
||||||
---@type table<string, Events.callback[]>
|
|
||||||
local registeredEvents = {}
|
|
||||||
|
|
||||||
---@param eventName string
|
|
||||||
---@param callback Events.callback
|
|
||||||
function Events.subscribe(eventName, callback)
|
|
||||||
local callbacks = registeredEvents[eventName]
|
|
||||||
|
|
||||||
if callbacks == nil then
|
|
||||||
registeredEvents[eventName] = {callback}
|
|
||||||
else
|
|
||||||
table.insert(callbacks, callback)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param eventName string
|
|
||||||
---@param ... any
|
|
||||||
function Events.call(eventName, ...)
|
|
||||||
local callbacks = registeredEvents[eventName]
|
|
||||||
if callbacks == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, func in ipairs(callbacks) do
|
|
||||||
func(eventName, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__system__events
|
name = smc__system__events
|
||||||
depends = smc__system__table
|
depends = smc__system__table, smc__system__require, smc__system__class
|
||||||
|
|||||||
37
mods/SYSTEM/Events/src/Events.lua
Normal file
37
mods/SYSTEM/Events/src/Events.lua
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
---@alias Events.Callback fun(eventName:string, ...)
|
||||||
|
|
||||||
|
---@alias Events.Types
|
||||||
|
--- 'ProcessingStationEvents'
|
||||||
|
|
||||||
|
---@class Events : Class
|
||||||
|
---@field registeredEvents table<string, Events.Callback[]>
|
||||||
|
Events = Class:extend({
|
||||||
|
registeredEvents = {}
|
||||||
|
})
|
||||||
|
|
||||||
|
---@param eventName string
|
||||||
|
---@param callback Events.Callback
|
||||||
|
function Events:subscribe(eventName, callback)
|
||||||
|
local callbacks = self.registeredEvents[eventName]
|
||||||
|
|
||||||
|
if callbacks == nil then
|
||||||
|
self.registeredEvents[eventName] = {callback}
|
||||||
|
else
|
||||||
|
table.insert(callbacks, callback)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param eventName string
|
||||||
|
---@param ... any
|
||||||
|
function Events:call(eventName, ...)
|
||||||
|
local callbacks = self.registeredEvents[eventName]
|
||||||
|
if callbacks == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, func in ipairs(callbacks) do
|
||||||
|
func(eventName, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Events
|
||||||
21
mods/SYSTEM/Events/src/Events/ProcessingStationEvents.lua
Normal file
21
mods/SYSTEM/Events/src/Events/ProcessingStationEvents.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---@alias Events.ProcessingStationEvents.EventName 'on_push_container'
|
||||||
|
|
||||||
|
---@alias Events.ProcessingStationEvents.Callback fun(eventName:Events.ProcessingStationEvents.EventName, ...)
|
||||||
|
|
||||||
|
---@class Events.ProcessingStationEvents : Events
|
||||||
|
---@field subscribe fun(self:Events.ProcessingStationEvents,eventName:Events.ProcessingStationEvents.EventName, callback:Events.ProcessingStationEvents.Callback)
|
||||||
|
---@field call fun(self:Events.ProcessingStationEvents,eventName:Events.ProcessingStationEvents.EventName, ...)
|
||||||
|
local ProcessingStationEvents = Events:extend()
|
||||||
|
|
||||||
|
---@param callback fun(eventName:Events.ProcessingStationEvents.EventName, pos:MapVector, energy:number)
|
||||||
|
function ProcessingStationEvents:subscribeOnPushContainer(callback)
|
||||||
|
self:subscribe('on_push_container', callback)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param pos MapVector
|
||||||
|
---@param energy number
|
||||||
|
function ProcessingStationEvents:callOnPushContainer(pos, energy)
|
||||||
|
self:call('on_push_container', pos, energy)
|
||||||
|
end
|
||||||
|
|
||||||
|
return ProcessingStationEvents
|
||||||
@@ -103,3 +103,12 @@ function Smc.requireProcessingFuelStation()
|
|||||||
|
|
||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param eventsType Events.Types
|
||||||
|
---@return Events
|
||||||
|
function Smc.requireEvents(eventsType)
|
||||||
|
---@type Events
|
||||||
|
local class = Mod.getInfo('smc__system__events').require('Events.'..eventsType)
|
||||||
|
|
||||||
|
return class
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user