Compare commits
4 Commits
ba4dc2db62
...
fa4fb0cac1
| Author | SHA1 | Date | |
|---|---|---|---|
| fa4fb0cac1 | |||
| e515686487 | |||
| b10214edb9 | |||
| d3f583272d |
@@ -1,5 +1,11 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local v = vector.new
|
||||||
local require = modInfo.require
|
local assert, ipairs, tostring = assert, ipairs, tostring
|
||||||
|
local coreChatSendPlayer, coreItemDrop = core.chat_send_player, core.item_drop
|
||||||
|
|
||||||
|
local require = Mod.getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
|
---@type Events.ImmersiveCraftEvents
|
||||||
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents')
|
||||||
|
|
||||||
---@type CraftSystem.BaseCraft
|
---@type CraftSystem.BaseCraft
|
||||||
local BaseCraft = require('CraftSystem.BaseCraft')
|
local BaseCraft = require('CraftSystem.BaseCraft')
|
||||||
@@ -48,24 +54,21 @@ 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,
|
ImmersiveCraftEvents:subscribeOnNextStage(name, function(stage, pos, player)
|
||||||
---@param eventName string
|
|
||||||
---@param stage CraftSystem.ImmersiveCraftStage
|
|
||||||
---@param pos MapVector
|
|
||||||
---@param Player Player
|
|
||||||
function(eventName, stage, pos, Player)
|
|
||||||
local nextStageName = stage.nextStage
|
local nextStageName = stage.nextStage
|
||||||
|
|
||||||
if nextStageName == nil then
|
if nextStageName == nil then
|
||||||
instance:endCraft(pos, Player)
|
instance:endCraft(pos, player)
|
||||||
else
|
else
|
||||||
|
---@type ImmersiveWorkStation?
|
||||||
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
local nextStage = instance.stagesByName[nextStageName]
|
local nextStage = instance.stagesByName[nextStageName]
|
||||||
|
|
||||||
---@type ImmersiveWorkStation.MetaData
|
local meta = workStation:getMeta(pos)
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
meta:set_string('stage_name', nextStage.name)
|
meta:set_string('stage_name', nextStage.name)
|
||||||
|
|
||||||
nextStage:startHandler(pos, Player)
|
nextStage:startHandler(pos, player)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -80,16 +83,19 @@ end
|
|||||||
---@param amount integer
|
---@param amount integer
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function ImmersiveCraft:startCraft(pos, player, amount)
|
function ImmersiveCraft:startCraft(pos, player, amount)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
local craftName = meta:get_string('craft_name')
|
local craftName = meta:get_string('craft_name')
|
||||||
if craftName ~= '' then
|
if craftName ~= '' then
|
||||||
core.chat_send_player(player:get_player_name(), 'The workbench is occupied by another craft.')
|
coreChatSendPlayer(player:get_player_name(), 'The workbench is occupied by another craft.')
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ImmersiveCraftCounter:addCraft(pos, player:get_player_name()) then
|
if not ImmersiveCraftCounter:addCraft(pos, player:get_player_name()) then
|
||||||
core.chat_send_player(player:get_player_name(),
|
coreChatSendPlayer(player:get_player_name(),
|
||||||
'The limit of simultaneously active crafts has been reached: '..
|
'The limit of simultaneously active crafts has been reached: '..
|
||||||
'complete or cancel active crafts to start a new one')
|
'complete or cancel active crafts to start a new one')
|
||||||
|
|
||||||
@@ -112,17 +118,20 @@ end
|
|||||||
---@param pos MapVector
|
---@param pos MapVector
|
||||||
---@param player Player
|
---@param player Player
|
||||||
function ImmersiveCraft:endCraft(pos, player)
|
function ImmersiveCraft:endCraft(pos, player)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
local playerName = meta:get_string('player_name')
|
local playerName = meta:get_string('player_name')
|
||||||
assert(playerName ~= '')
|
assert(playerName ~= '')
|
||||||
local amount = meta:get_float('craft_amount')
|
local amount = meta:get_float('craft_amount')
|
||||||
assert(amount ~= 0)
|
assert(amount ~= 0)
|
||||||
|
|
||||||
-- Drop the result of crafting.
|
-- Drop the result of crafting.
|
||||||
local dropPos = vector.new(pos) + vector.new(0, 0.9,0)
|
local dropPos = v(pos) + v(0, 0.9,0)
|
||||||
for i=1, amount do
|
for i=1, amount do
|
||||||
core.item_drop(ItemStack(self.output), nil, dropPos)
|
coreItemDrop(ItemStack(self.output), nil, dropPos)
|
||||||
end
|
end
|
||||||
|
|
||||||
ImmersiveCraftCounter:removeCraft(pos, playerName)
|
ImmersiveCraftCounter:removeCraft(pos, playerName)
|
||||||
@@ -138,8 +147,11 @@ end
|
|||||||
---Stop the crafting process and free up the workbench.
|
---Stop the crafting process and free up the workbench.
|
||||||
---@param pos MapVector
|
---@param pos MapVector
|
||||||
function ImmersiveCraft:abortCraft(pos)
|
function ImmersiveCraft:abortCraft(pos)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
local playerName = meta:get_string('player_name')
|
local playerName = meta:get_string('player_name')
|
||||||
assert(playerName ~= '')
|
assert(playerName ~= '')
|
||||||
local stageName = meta:get_string('stage_name')
|
local stageName = meta:get_string('stage_name')
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__craft_system')
|
local require = Mod.getInfo('smc__core__craft_system').require
|
||||||
local require = modInfo.require
|
|
||||||
|
---@type Events.ImmersiveCraftEvents
|
||||||
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents')
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftNode
|
---@type CraftSystem.ImmersiveCraftNode
|
||||||
local ImmersiveCraftNode = require('CraftSystem.ImmersiveCraftNode')
|
local ImmersiveCraftNode = require('CraftSystem.ImmersiveCraftNode')
|
||||||
@@ -59,8 +61,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(
|
ImmersiveCraftEvents:callOnPunchTappingNode(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
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
local v = vector.new
|
||||||
|
local assert = assert
|
||||||
local extend = Class.extend
|
local extend = Class.extend
|
||||||
|
local coreItemDrop = core.item_drop
|
||||||
|
|
||||||
local require = Mod.getInfo('smc__core__craft_system').require
|
local require = Mod.getInfo('smc__core__craft_system').require
|
||||||
|
|
||||||
|
---@type Events.ImmersiveCraftEvents
|
||||||
|
local ImmersiveCraftEvents = Smc.requireEvents('ImmersiveCraftEvents')
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftStage
|
---@type CraftSystem.ImmersiveCraftStage
|
||||||
local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
|
local ImmersiveCraftStage = require('CraftSystem.ImmersiveCraftStage')
|
||||||
|
|
||||||
@@ -43,7 +49,7 @@ function TappingStage:new(def)
|
|||||||
|
|
||||||
-- Registering the crafting stage start handler.
|
-- Registering the crafting stage start handler.
|
||||||
instance.startHandler = function(tappingStage , pos, player)
|
instance.startHandler = function(tappingStage , pos, player)
|
||||||
local entityPos = vector.new(pos) + vector.new(0,0.875,0)
|
local entityPos = v(pos) + v(0,0.875,0)
|
||||||
|
|
||||||
---@class CraftSystem.ImmersiveCraftStage.TappingNode.InitParams
|
---@class CraftSystem.ImmersiveCraftStage.TappingNode.InitParams
|
||||||
local params = {
|
local params = {
|
||||||
@@ -65,16 +71,22 @@ function TappingStage:new(def)
|
|||||||
entityGUID = obj:get_guid()
|
entityGUID = obj:get_guid()
|
||||||
}
|
}
|
||||||
|
|
||||||
--@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
meta:set_string('stage_data', core.serialize(stageData))
|
meta:set_string('stage_data', core.serialize(stageData))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Registering the crafting stage process handler.
|
-- Registering the crafting stage process handler.
|
||||||
-- Called when a player clicks on a crafting node (entity).
|
-- Called when a player clicks on a crafting node (entity).
|
||||||
instance.processHandler = function(tappingStage, pos, player)
|
instance.processHandler = function(tappingStage, pos, player)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
||||||
local stageData = core.deserialize(meta:get_string('stage_data'))
|
local stageData = core.deserialize(meta:get_string('stage_data'))
|
||||||
assert(stageData ~= nil)
|
assert(stageData ~= nil)
|
||||||
@@ -92,29 +104,35 @@ function TappingStage:new(def)
|
|||||||
|
|
||||||
-- Registering the crafting stage end handler.
|
-- Registering the crafting stage end handler.
|
||||||
instance.endHandler = function(tappingStage, pos, player)
|
instance.endHandler = function(tappingStage, pos, player)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
||||||
local stageData = core.deserialize(meta:get_string('stage_data'))
|
local stageData = core.deserialize(meta:get_string('stage_data'))
|
||||||
assert(stageData ~= nil)
|
assert(stageData ~= nil)
|
||||||
|
|
||||||
|
|
||||||
local entity = Smc.getObjectByGUID(stageData.entityGUID)
|
local entity = Smc.getObjectByGUID(stageData.entityGUID)
|
||||||
assert(entity ~= nil, 'The entity for immersive crafting is nil.')
|
assert(entity ~= nil, 'The entity for immersive crafting is nil.')
|
||||||
|
|
||||||
entity:remove()
|
entity:remove()
|
||||||
|
|
||||||
Events:call('craft_system:next_immersive_stage:'..tappingStage.craftName, tappingStage, pos, player)
|
ImmersiveCraftEvents:callOnNextStage(tappingStage.craftName, tappingStage, pos, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Registering the aborting the crafting process handler.
|
-- Registering the aborting the crafting process handler.
|
||||||
---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage
|
---@param tappingStage CraftSystem.ImmersiveCraftStage.TappingStage
|
||||||
instance.abortHandler = function(tappingStage, pos)
|
instance.abortHandler = function(tappingStage, pos)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
---@type ImmersiveWorkStation?
|
||||||
local meta = core.get_meta(pos)
|
local workStation = Smc.getNodeSuperclassByPos(pos)
|
||||||
|
assert(workStation ~= nil)
|
||||||
|
local meta = workStation:getMeta(pos)
|
||||||
|
|
||||||
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
|
||||||
local stageData = core.deserialize(meta:get_string('stage_data'))
|
local stageData = core.deserialize(meta:get_string('stage_data'))
|
||||||
assert(stageData ~= nil)
|
assert(stageData ~= nil)
|
||||||
|
|
||||||
local amount = meta:get_float('craft_amount')
|
local amount = meta:get_float('craft_amount')
|
||||||
assert(amount ~= 0)
|
assert(amount ~= 0)
|
||||||
|
|
||||||
@@ -128,9 +146,9 @@ function TappingStage:new(def)
|
|||||||
entity:remove()
|
entity:remove()
|
||||||
|
|
||||||
-- We drop the item as it was before processing.
|
-- We drop the item as it was before processing.
|
||||||
local dropPos = vector.new(pos)+vector.new(0, 0.9,0)
|
local dropPos = v(pos) + v(0, 0.9,0)
|
||||||
for i=1, amount do
|
for i=1, amount do
|
||||||
core.item_drop(ItemStack(tappingStage.targetItem), nil, dropPos)
|
coreItemDrop(ItemStack(tappingStage.targetItem), nil, dropPos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -147,10 +165,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),
|
ImmersiveCraftEvents:subscribeOnPunchTappingNode(instance.craftName, instance.name, function(pos, player, craftNode)
|
||||||
---@param craftNode LuaEntity
|
|
||||||
---@param player Player
|
|
||||||
function(eventName, pos, player, craftNode)
|
|
||||||
local toolDef = player:get_wielded_item():get_definition()
|
local toolDef = player:get_wielded_item():get_definition()
|
||||||
|
|
||||||
-- If a crafting stage requires a specific tool group and he doesn't have it then we don't do anything.
|
-- If a crafting stage requires a specific tool group and he doesn't have it then we don't do anything.
|
||||||
@@ -162,7 +177,7 @@ function TappingStage:new(def)
|
|||||||
-- Creating particles
|
-- Creating particles
|
||||||
for i=0, 10 do
|
for i=0, 10 do
|
||||||
core.add_particle({
|
core.add_particle({
|
||||||
pos = vector.new(pos)+vector.new(0,0.5,0),
|
pos = v(pos) + v(0,0.5,0),
|
||||||
velocity = {x=math.random(-1,1), y=4, z=math.random(-1,1)},
|
velocity = {x=math.random(-1,1), y=4, z=math.random(-1,1)},
|
||||||
acceleration = {x=0, y=-9.8, z=0},
|
acceleration = {x=0, y=-9.8, z=0},
|
||||||
expirationtime = 2,
|
expirationtime = 2,
|
||||||
@@ -172,9 +187,9 @@ function TappingStage:new(def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Making the entity shake (silly method :P).
|
-- Making the entity shake (silly method :P).
|
||||||
craftNode.object:set_rotation(vector.new(0.01,0.1,0.01))
|
craftNode.object:set_rotation(v(0.01,0.1,0.01))
|
||||||
core.after(0.1, function() craftNode.object:set_rotation(vector.new(-0.01,-0.1,-0.01))end)
|
core.after(0.1, function() craftNode.object:set_rotation(v(-0.01,-0.1,-0.01))end)
|
||||||
core.after(0.2, function() craftNode.object:set_rotation(vector.new(0,0,0))end)
|
core.after(0.2, function() craftNode.object:set_rotation(v(0,0,0))end)
|
||||||
-- DRAFT END
|
-- DRAFT END
|
||||||
|
|
||||||
instance:processHandler(pos, player)
|
instance:processHandler(pos, player)
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
local getInstance = Class.getInstance
|
local assert = assert
|
||||||
|
local coreNodePunch, coreNodeDig, coreChatSendPlayer, coreGetMeta, coreSwapNode = core.node_punch, core.node_dig, core.chat_send_player, core.get_meta, core.swap_node
|
||||||
|
|
||||||
local CraftSystem = Smc.requireCraftSystem()
|
local CraftSystem = Smc.requireCraftSystem()
|
||||||
|
|
||||||
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
local PlayerInventoryUI = Smc.requirePlayerInventoryUI()
|
||||||
|
|
||||||
local Node = Smc.requireNode()
|
local Node = Smc.requireNode()
|
||||||
|
|
||||||
-- Default settings that a work station node should have.
|
|
||||||
local ImmersiveWorkStationNode = Node:getExtended({
|
local ImmersiveWorkStationNode = Node:getExtended({
|
||||||
settings = {
|
settings = {
|
||||||
name = '',
|
name = '',
|
||||||
drawtype = 'normal',
|
drawtype = 'normal',
|
||||||
paramtype = 'light',
|
paramtype = 'light',
|
||||||
groups = { immersive_station = 1, dig_immediate = 2 }
|
groups = { immersive_work_station = 1, dig_immediate = 2 }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
---A work station (node) that enables player interaction
|
---A work station (node) that enables player interaction
|
||||||
---with the immersive crafting mechanics.
|
---with the immersive crafting mechanics.
|
||||||
---@class ImmersiveWorkStation
|
---@class ImmersiveWorkStation : Class, NodeSuperClass
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field craftType CraftSystem.ImmersiveCraftType
|
---@field craftType CraftSystem.ImmersiveCraftType
|
||||||
---@field handler CraftSystem.ImmersiveCraftHandler
|
---@field handler CraftSystem.ImmersiveCraftHandler
|
||||||
---@field tab PlayerInventoryUI.getTabFunc
|
---@field tab PlayerInventoryUI.getTabFunc
|
||||||
local ImmersiveWorkStation = {}
|
---@field nodeName string?
|
||||||
|
---@field activeNodeName string?
|
||||||
|
local ImmersiveWorkStation = Class:extend({})
|
||||||
|
|
||||||
---Definition table for the `ImmersiveWorkStation`.
|
---Definition table for the `ImmersiveWorkStation`.
|
||||||
---
|
---
|
||||||
@@ -32,67 +32,86 @@ local ImmersiveWorkStation = {}
|
|||||||
---@field craftType CraftSystem.ImmersiveCraftType
|
---@field craftType CraftSystem.ImmersiveCraftType
|
||||||
---@field tab PlayerInventoryUI.getTabFunc
|
---@field tab PlayerInventoryUI.getTabFunc
|
||||||
|
|
||||||
---@param name string
|
---@alias ImmersiveWorkStation.NodesDefinition {settings:Node.Settings, activeSettings:Node.Settings?, callbacks:Node.Callbacks?}
|
||||||
---@param def ImmersiveWorkStationDef
|
|
||||||
---@param nodeDef Node.NodeDefinition
|
---@param def ImmersiveWorkStationDef
|
||||||
function ImmersiveWorkStation:new(name, def, nodeDef)
|
---@param nodesDef ImmersiveWorkStation.NodesDefinition
|
||||||
|
function ImmersiveWorkStation:new(def, nodesDef)
|
||||||
local handler = CraftSystem:getImmersiveCraftHandler(def.craftType)
|
local handler = CraftSystem:getImmersiveCraftHandler(def.craftType)
|
||||||
|
|
||||||
---@type ImmersiveWorkStation
|
---@type ImmersiveWorkStation
|
||||||
local instance = getInstance(self, {})
|
local instance = self:getInstance({})
|
||||||
instance.name = name
|
|
||||||
instance.craftType = def.craftType
|
instance.craftType = def.craftType
|
||||||
instance.handler = handler
|
instance.handler = handler
|
||||||
instance.tab = def.tab
|
instance.tab = def.tab
|
||||||
|
|
||||||
if nodeDef.callbacks == nil then
|
local settings = nodesDef.settings
|
||||||
---@type Node.Callbacks
|
local activeSettings = nodesDef.activeSettings
|
||||||
nodeDef.callbacks = {}
|
local callbacks = nodesDef.callbacks or {}
|
||||||
end
|
|
||||||
local settings = nodeDef.settings
|
|
||||||
local callbacks = nodeDef.callbacks
|
|
||||||
|
|
||||||
-- Callback when the work station block is installed in the world
|
local oldCallback = callbacks.on_construct or function(...) end
|
||||||
-- Ensures initialization of necessary parameters
|
|
||||||
callbacks.on_construct = function(pos)
|
callbacks.on_construct = function(pos)
|
||||||
|
oldCallback(pos)
|
||||||
|
|
||||||
instance:init(pos)
|
instance:init(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
oldCallback = callbacks.on_rightclick or function(...) end
|
||||||
-- Callback for interaction with a work station (start of crafting)
|
-- Callback for interaction with a work station (start of crafting)
|
||||||
callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
oldCallback(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
|
||||||
instance:showForm(pos, clicker)
|
instance:showForm(pos, clicker)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
oldCallback = callbacks.on_punch or function(...) end
|
||||||
|
-- Callback for interaction with a work station (abort of crafting)
|
||||||
callbacks.on_punch = function(pos, node, puncher, pointed_thing)
|
callbacks.on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
|
oldCallback(pos, node, puncher, pointed_thing)
|
||||||
|
|
||||||
instance:abortCraft(pos)
|
instance:abortCraft(pos)
|
||||||
|
coreNodePunch(pos, node, puncher, pointed_thing)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
oldCallback = callbacks.on_dig or function(...) end
|
||||||
callbacks.on_dig = function(pos, node, digger)
|
callbacks.on_dig = function(pos, node, digger)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
oldCallback(pos, node, digger)
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
|
|
||||||
local craftName = meta:get_string('craft_name')
|
return instance:onDig(pos, node, digger)
|
||||||
if craftName == '' then
|
|
||||||
return core.node_dig(pos, node, digger)
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Registering a node for Luanti.
|
-- Registering a nodes for Luanti.
|
||||||
ImmersiveWorkStationNode:new(nodeDef)
|
local node = ImmersiveWorkStationNode:new({ settings = settings, callbacks = callbacks })
|
||||||
|
instance.nodeName = node.itemDef.settings.name
|
||||||
|
|
||||||
|
if activeSettings ~= nil then
|
||||||
|
local activeNode = ImmersiveWorkStationNode:new({ settings = activeSettings, callbacks = callbacks })
|
||||||
|
instance.activeNodeName = activeNode.itemDef.settings.name
|
||||||
|
|
||||||
|
Smc.addNodeSuperclass(instance.activeNodeName, instance)
|
||||||
|
end
|
||||||
|
|
||||||
|
Smc.addNodeSuperclass(instance.nodeName, instance)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---A wrapper around `core.get_meta()` for convenience
|
||||||
|
---and returning the correct `MetaDataRef` type.
|
||||||
|
---@static
|
||||||
|
---@param pos MapVector
|
||||||
|
---@return ImmersiveWorkStation.MetaData
|
||||||
|
function ImmersiveWorkStation:getMeta(pos)
|
||||||
|
return coreGetMeta(pos)
|
||||||
|
end
|
||||||
|
|
||||||
function ImmersiveWorkStation:showForm(pos, player)
|
function ImmersiveWorkStation:showForm(pos, player)
|
||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
---@type ImmersiveWorkStation.MetaData
|
local meta = self:getMeta(pos)
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
|
|
||||||
local craftName = meta:get_string('craft_name')
|
local craftName = meta:get_string('craft_name')
|
||||||
if craftName ~= '' then
|
if craftName ~= '' then
|
||||||
core.chat_send_player(playerName, 'The workbench is occupied by another craft.')
|
coreChatSendPlayer(playerName, 'The workbench is occupied by another craft.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -106,14 +125,45 @@ end
|
|||||||
|
|
||||||
---@param pos MapVector
|
---@param pos MapVector
|
||||||
function ImmersiveWorkStation:init(pos)
|
function ImmersiveWorkStation:init(pos)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
local meta = self:getMeta(pos)
|
||||||
local meta = core.get_meta(pos)
|
end
|
||||||
|
|
||||||
|
---Replaces the node with active or inactive depending on the status of the craft.
|
||||||
|
---
|
||||||
|
---If an active node is not specified for a station,
|
||||||
|
---then no replacement will occur regardless of the status of the process.
|
||||||
|
---@param isCrafting boolean The stations process status. If `true`, the process is running.
|
||||||
|
---@param pos MapVector
|
||||||
|
function ImmersiveWorkStation:swapNode(isCrafting, pos)
|
||||||
|
assert(self.nodeName ~= nil)
|
||||||
|
|
||||||
|
if self.activeNodeName ~= nil then
|
||||||
|
if isCrafting then
|
||||||
|
coreSwapNode(pos, {name = self.activeNodeName})
|
||||||
|
else
|
||||||
|
coreSwapNode(pos, {name = self.nodeName})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param pos MapVector
|
||||||
|
---@param node NodeTable
|
||||||
|
---@param digger Player
|
||||||
|
---@return boolean
|
||||||
|
function ImmersiveWorkStation:onDig(pos, node, digger)
|
||||||
|
local meta = self:getMeta(pos)
|
||||||
|
|
||||||
|
local craftName = meta:get_string('craft_name')
|
||||||
|
if craftName == '' then
|
||||||
|
return coreNodeDig(pos, node, digger)
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos MapVector
|
---@param pos MapVector
|
||||||
function ImmersiveWorkStation:abortCraft(pos)
|
function ImmersiveWorkStation:abortCraft(pos)
|
||||||
---@type ImmersiveWorkStation.MetaData
|
local meta = self:getMeta(pos)
|
||||||
local meta = core.get_meta(pos)
|
|
||||||
|
|
||||||
local craftName = meta:get_string('craft_name')
|
local craftName = meta:get_string('craft_name')
|
||||||
if craftName == '' then
|
if craftName == '' then
|
||||||
@@ -139,7 +189,7 @@ local function tab(self, playerName, tabType)
|
|||||||
return baseGetCraftTab(self, playerName, tabType, 'node_tab', handler)
|
return baseGetCraftTab(self, playerName, tabType, 'node_tab', handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
ImmersiveWorkStation:new('test_station', {
|
ImmersiveWorkStation:new({
|
||||||
craftType = 'workbench',
|
craftType = 'workbench',
|
||||||
tab = tab,
|
tab = tab,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
---@alias Events.Callback fun(...)
|
---@alias Events.Callback fun(...)
|
||||||
|
|
||||||
---@alias Events.Types
|
---@alias Events.Type
|
||||||
--- 'ControlsEvents'
|
--- 'ControlsEvents'|
|
||||||
|
--- 'ImmersiveCraftEvents'
|
||||||
|
|
||||||
---@class Events : Class
|
---@class Events : Class
|
||||||
---@field registeredEvents table<string, Events.Callback[]>
|
---@field registeredEvents table<string, Events.Callback[]>
|
||||||
|
|||||||
42
mods/SYSTEM/Events/src/Events/ImmersiveCraftEvents.lua
Normal file
42
mods/SYSTEM/Events/src/Events/ImmersiveCraftEvents.lua
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
---@alias Events.ImmersiveCraftEvents.EventName string
|
||||||
|
|
||||||
|
---@class Events.ImmersiveCraftEvents : Events
|
||||||
|
---@field subscribe fun(self:Events.ImmersiveCraftEvents, eventName:Events.ImmersiveCraftEvents.EventName, callback:Events.Callback)
|
||||||
|
---@field call fun(self:Events.ImmersiveCraftEvents, eventName:Events.ImmersiveCraftEvents.EventName, ...)
|
||||||
|
local ImmersiveCraftEvents = Events:extend()
|
||||||
|
|
||||||
|
-- On next stage --
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@param callback fun(stage:CraftSystem.ImmersiveCraftStage, pos:MapVector, player:Player)
|
||||||
|
function ImmersiveCraftEvents:subscribeOnNextStage(craftName, callback)
|
||||||
|
self:subscribe(('next_stage:%s'):format(craftName), callback)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@param stage CraftSystem.ImmersiveCraftStage
|
||||||
|
---@param pos MapVector
|
||||||
|
---@param player Player
|
||||||
|
function ImmersiveCraftEvents:callOnNextStage(craftName, stage, pos, player)
|
||||||
|
self:call(('next_stage:%s'):format(craftName), stage, pos, player)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- On punch tapping node --
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@param stageName string
|
||||||
|
---@param callback fun(pos:MapVector, player:Player, craftNode:LuaEntity)
|
||||||
|
function ImmersiveCraftEvents:subscribeOnPunchTappingNode(craftName, stageName, callback)
|
||||||
|
self:subscribe(('punch_tapping_node:%s:%s'):format(craftName, stageName), callback)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param craftName string
|
||||||
|
---@param stageName string
|
||||||
|
---@param pos MapVector
|
||||||
|
---@param player Player
|
||||||
|
---@param craftNode LuaEntity
|
||||||
|
function ImmersiveCraftEvents:callOnPunchTappingNode(craftName, stageName, pos, player, craftNode)
|
||||||
|
self:call(('punch_tapping_node:%s:%s'):format(craftName, stageName), pos, player, craftNode)
|
||||||
|
end
|
||||||
|
|
||||||
|
return ImmersiveCraftEvents
|
||||||
@@ -104,7 +104,7 @@ function Smc.requireProcessingFuelStation()
|
|||||||
return class
|
return class
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param eventsType Events.Types
|
---@param eventsType Events.Type
|
||||||
---@return Events
|
---@return Events
|
||||||
function Smc.requireEvents(eventsType)
|
function Smc.requireEvents(eventsType)
|
||||||
---@type Events
|
---@type Events
|
||||||
|
|||||||
Reference in New Issue
Block a user