2023-11-11 17:42:05 +01:00
|
|
|
-- IndustrialTest
|
|
|
|
-- Copyright (C) 2023 mrkubax10
|
|
|
|
|
|
|
|
-- This program is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
|
|
|
-- (at your option) any later version.
|
|
|
|
|
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2023-11-12 15:00:28 +01:00
|
|
|
local machine={}
|
2023-11-11 17:42:05 +01:00
|
|
|
local simpleElectricItemProcessor={}
|
|
|
|
|
2023-11-25 17:58:42 +01:00
|
|
|
industrialtest.internal.mclAfterDigNode=function(pos,oldmeta,lists)
|
2023-11-11 17:42:05 +01:00
|
|
|
-- Taken from https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/ITEMS/mcl_furnaces/init.lua#L538
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local meta2=meta
|
|
|
|
meta:from_table(oldmeta)
|
|
|
|
local inv=meta:get_inventory()
|
|
|
|
for _,listname in ipairs(lists) do
|
|
|
|
local stack=inv:get_stack(listname,1)
|
|
|
|
if not stack:is_empty() then
|
|
|
|
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
|
|
|
minetest.add_item(p, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
meta:from_table(meta2:to_table())
|
|
|
|
end
|
|
|
|
|
2024-03-08 08:56:56 +01:00
|
|
|
industrialtest.internal.chargeFromPowerStorageItem=function(meta,inv)
|
|
|
|
local shouldRerunTimer=false
|
|
|
|
local shouldUpdateFormspec=false
|
|
|
|
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
|
|
|
if not powerStorageSlot:is_empty() then
|
|
|
|
local stackMeta=powerStorageSlot:get_meta()
|
|
|
|
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
|
|
|
shouldUpdateFormspec=true
|
|
|
|
shouldRerunTimer=stackMeta:get_int("industrialtest.powerAmount")>0 and not industrialtest.api.isFullyCharged(meta)
|
|
|
|
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
|
|
|
inv:set_stack("powerStorage",1,powerStorageSlot)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return shouldRerunTimer,shouldUpdateFormspec
|
|
|
|
end
|
|
|
|
|
2023-11-12 15:00:28 +01:00
|
|
|
function industrialtest.internal.registerMachine(config)
|
2023-11-11 17:42:05 +01:00
|
|
|
local definition={
|
|
|
|
description=config.displayName,
|
|
|
|
on_construct=function(pos)
|
2023-11-12 15:00:28 +01:00
|
|
|
machine.onConstruct(pos,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end,
|
2024-03-23 13:34:18 +01:00
|
|
|
on_destruct=function(pos)
|
|
|
|
machine.onDestruct(pos,config)
|
|
|
|
end,
|
2023-11-11 17:42:05 +01:00
|
|
|
on_timer=function(pos,elapsed)
|
2023-11-15 21:44:02 +01:00
|
|
|
local shouldRerunTimer,_=machine.onTimer(pos,elapsed,config)
|
|
|
|
return shouldRerunTimer
|
2023-11-11 17:42:05 +01:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
|
2023-11-12 15:00:28 +01:00
|
|
|
return machine.allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
2023-11-12 15:00:28 +01:00
|
|
|
return machine.allowMetadataInventoryPut(pos,listname,index,stack,player,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end,
|
2024-01-12 20:17:36 +01:00
|
|
|
allow_metadata_inventory_take=function(pos,listname,index,stack,player)
|
|
|
|
return machine.allowMetadataInventoryTake(pos,listname,index,stack,player,config)
|
|
|
|
end,
|
2023-11-11 17:42:05 +01:00
|
|
|
on_metadata_inventory_put=function(pos,listname,index,stack,player)
|
2023-11-25 17:58:42 +01:00
|
|
|
machine.onMetadataInventoryPut(pos,listname,index,stack)
|
2023-11-11 17:42:05 +01:00
|
|
|
if config.onMetadataInventoryPut then
|
|
|
|
config.onMetadataInventoryPut(pos,listname,index,stack,player)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
|
2023-11-25 17:58:42 +01:00
|
|
|
machine.onMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex)
|
2023-11-11 17:42:05 +01:00
|
|
|
if config.onMetadataInventoryPut then
|
|
|
|
config.onMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_metadata_inventory_take=function(pos,listname,index,stack,player)
|
2023-11-25 17:58:42 +01:00
|
|
|
machine.onMetadataInventoryTake(pos,listname,index,stack)
|
2023-11-11 17:42:05 +01:00
|
|
|
if config.onMetadataInventoryTake then
|
|
|
|
config.onMetadataInventoryTake(pos,listname,index,stack,player)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
_industrialtest_updateFormspec=function(pos)
|
2023-11-12 15:00:28 +01:00
|
|
|
machine.updateFormspec(pos,config)
|
2024-03-23 13:34:18 +01:00
|
|
|
end,
|
|
|
|
_industrialtest_getFormspec=function(pos)
|
|
|
|
if config.withoutFormspec then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
return machine.getFormspec(pos,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
|
|
|
}
|
|
|
|
definition.groups._industrialtest_wrenchUnmountable=1
|
|
|
|
if config.requiresWrench then
|
|
|
|
definition.drop="industrialtest:machine_block"
|
|
|
|
end
|
|
|
|
if config.customKeys then
|
|
|
|
for key,value in pairs(config.customKeys) do
|
|
|
|
definition[key]=value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if config.groups then
|
|
|
|
for key,value in pairs(config.groups) do
|
|
|
|
definition.groups[key]=value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.register_node("industrialtest:"..config.name,definition)
|
|
|
|
if config.registerActiveVariant then
|
|
|
|
definition=table.copy(definition)
|
|
|
|
definition.description=nil
|
|
|
|
definition.on_timer=function(pos,elapsed)
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local inv=meta:get_inventory()
|
|
|
|
local shouldRerunTimer=false
|
|
|
|
local shouldUpdateFormspec=false
|
|
|
|
|
2023-11-15 21:44:02 +01:00
|
|
|
if config.activeOnTimer then
|
2023-11-11 17:42:05 +01:00
|
|
|
shouldRerunTimer,shouldUpdateFormspec=config.activeOnTimer(pos,elapsed,meta,inv)
|
|
|
|
end
|
|
|
|
|
2023-11-22 20:28:38 +01:00
|
|
|
local def=minetest.registered_nodes[minetest.get_node(pos).name]
|
|
|
|
if def.groups and def.groups._industrialtest_hasPowerInput and not industrialtest.api.isFullyCharged(meta) then
|
|
|
|
local networks=industrialtest.api.isAttachedToNetwork(meta)
|
|
|
|
if networks then
|
|
|
|
for _,network in ipairs(networks) do
|
|
|
|
minetest.get_node_timer(network):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-11 17:42:05 +01:00
|
|
|
if shouldUpdateFormspec then
|
2023-11-15 21:44:02 +01:00
|
|
|
machine.updateFormspec(pos,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return shouldRerunTimer
|
|
|
|
end
|
|
|
|
if not definition.drop then
|
|
|
|
definition.drop="industrialtest:"..config.name
|
|
|
|
end
|
|
|
|
if config.activeCustomKeys then
|
|
|
|
for key,value in pairs(config.activeCustomKeys) do
|
|
|
|
definition[key]=value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if industrialtest.mclAvailable then
|
|
|
|
definition.groups.not_in_creative_inventory=1
|
|
|
|
definition._doc_items_create_entry=false
|
|
|
|
end
|
|
|
|
minetest.register_node("industrialtest:"..config.name.."_active",definition)
|
|
|
|
end
|
2024-09-14 17:35:57 +02:00
|
|
|
industrialtest.api.addTag("industrialtest:"..config.name,"usesTimer")
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function craftResultProxy(method,item)
|
|
|
|
if method=="cooking" then
|
|
|
|
local output,after=minetest.get_craft_result({
|
|
|
|
method=method,
|
|
|
|
width=1,
|
|
|
|
items={item}
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
item=output.item,
|
|
|
|
time=output.time,
|
|
|
|
src=after.items[1]
|
|
|
|
}
|
|
|
|
elseif method=="industrialtest.macerating" then
|
|
|
|
local output=industrialtest.api.getMaceratorRecipeResult(item:get_name())
|
|
|
|
if not output then
|
|
|
|
return {
|
|
|
|
item=ItemStack(),
|
|
|
|
time=0,
|
|
|
|
src=item
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local srcAfter=ItemStack(item:get_name())
|
|
|
|
srcAfter:set_count(item:get_count()-1)
|
|
|
|
return {
|
|
|
|
item=ItemStack(output.output),
|
|
|
|
time=output.time,
|
|
|
|
src=srcAfter
|
|
|
|
}
|
|
|
|
elseif method=="industrialtest.compressing" then
|
|
|
|
local output=industrialtest.api.getCompressorRecipeResult(item:get_name())
|
|
|
|
if not output or item:get_count()<output.count then
|
|
|
|
return {
|
|
|
|
item=ItemStack(),
|
|
|
|
time=0,
|
|
|
|
src=item
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local srcAfter=ItemStack(item:get_name())
|
|
|
|
srcAfter:set_count(item:get_count()-output.count)
|
|
|
|
return {
|
|
|
|
item=ItemStack(output.output),
|
|
|
|
time=output.time,
|
|
|
|
src=srcAfter
|
|
|
|
}
|
|
|
|
elseif method=="industrialtest.extracting" then
|
|
|
|
local output=industrialtest.api.getExtractorRecipeResult(item:get_name())
|
|
|
|
if not output then
|
|
|
|
return {
|
|
|
|
item=ItemStack(),
|
|
|
|
time=0,
|
|
|
|
src=item
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local srcAfter=ItemStack(item:get_name())
|
|
|
|
srcAfter:set_count(item:get_count()-1)
|
|
|
|
return {
|
|
|
|
item=ItemStack(output.output),
|
|
|
|
time=output.time,
|
|
|
|
src=srcAfter
|
|
|
|
}
|
|
|
|
elseif method=="industrialtest.recycling" then
|
|
|
|
local srcAfter=ItemStack(item:get_name())
|
|
|
|
srcAfter:set_count(item:get_count()-1)
|
|
|
|
return {
|
|
|
|
item=ItemStack(industrialtest.random:next(1,8)==1 and "industrialtest:scrap" or ""),
|
|
|
|
time=2,
|
|
|
|
src=srcAfter
|
|
|
|
}
|
2023-11-19 19:59:33 +01:00
|
|
|
elseif method=="industrialtest.cable_forming" then
|
|
|
|
local output=industrialtest.api.getCableFormerRecipeResult(item:get_name())
|
|
|
|
if not output then
|
|
|
|
return {
|
|
|
|
item=ItemStack(),
|
|
|
|
time=0,
|
|
|
|
src=item
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local srcAfter=ItemStack(item:get_name())
|
|
|
|
srcAfter:set_count(item:get_count()-1)
|
|
|
|
return {
|
|
|
|
item=ItemStack(output.output),
|
|
|
|
time=output.time,
|
|
|
|
src=srcAfter
|
|
|
|
}
|
2023-11-23 19:17:19 +01:00
|
|
|
elseif method=="industrialtest.mass_fabricating" then
|
|
|
|
if item:get_count()<34 then
|
|
|
|
return {
|
|
|
|
item=ItemStack(),
|
|
|
|
time=0,
|
|
|
|
src=item
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local srcAfter=ItemStack(item:get_name())
|
|
|
|
srcAfter:set_count(item:get_count()-34)
|
|
|
|
return {
|
|
|
|
item=ItemStack("industrialtest:uu_matter"),
|
|
|
|
time=15,
|
|
|
|
src=srcAfter
|
|
|
|
}
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
|
|
|
error("Unknown craft method passed to craftResultProxy")
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.getFormspec=function(pos)
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local powerPercent=meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100
|
|
|
|
local srcPercent=meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100
|
2024-05-11 11:54:33 +02:00
|
|
|
local formspec={
|
|
|
|
"list[context;src;3.4,1.8;1,1]",
|
|
|
|
industrialtest.internal.getItemSlotBg(3.4,1.8,1,1),
|
|
|
|
(powerPercent>0 and "image[3.4,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]"
|
|
|
|
or "image[3.4,2.8;1,1;industrialtest_gui_electricity_bg.png]"),
|
|
|
|
"list[context;powerStorage;3.4,3.9;1,1]",
|
|
|
|
industrialtest.internal.getItemSlotBg(3.4,3.9,1,1),
|
|
|
|
(srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]"
|
|
|
|
or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"),
|
|
|
|
"list[context;dst;6.4,2.8;1,1]",
|
|
|
|
industrialtest.internal.getItemSlotBg(6.4,2.8,1,1),
|
|
|
|
"list[context;upgrades;9,0.9;1,4]",
|
|
|
|
industrialtest.internal.getItemSlotBg(9,0.9,1,4),
|
2024-05-11 12:53:18 +02:00
|
|
|
"listring[context;src]",
|
|
|
|
"listring[context;dst]"
|
2024-05-11 11:54:33 +02:00
|
|
|
}
|
2023-11-11 17:42:05 +01:00
|
|
|
return table.concat(formspec,"")
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.onPowerFlow=function(pos)
|
|
|
|
-- FIXME: this probably will require refactor so node timer won't be started
|
|
|
|
-- just to test if machine can process item
|
|
|
|
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.onConstruct=function(pos,meta,inv)
|
|
|
|
inv:set_size("src",1)
|
|
|
|
inv:set_size("dst",1)
|
|
|
|
inv:set_size("powerStorage",1)
|
|
|
|
inv:set_size("upgrades",4)
|
|
|
|
meta:set_float("srcTime",-1)
|
|
|
|
meta:set_float("maxSrcTime",0)
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.onTimer=function(pos,elapsed,meta,inv,config)
|
|
|
|
local srcSlot=inv:get_stack("src",1)
|
|
|
|
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
|
|
|
local shouldUpdateFormspec=false
|
|
|
|
local shouldRerunTimer=false
|
2023-11-25 17:58:42 +01:00
|
|
|
local requiredPower=elapsed*config.opPower*industrialtest.api.getMachineSpeed(meta)
|
2024-03-08 08:56:56 +01:00
|
|
|
|
|
|
|
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
|
|
|
|
|
2023-11-11 17:42:05 +01:00
|
|
|
if srcSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
|
|
|
local output=craftResultProxy(config.method,srcSlot)
|
|
|
|
if output.time>0 and inv:room_for_item("dst",output.item) then
|
|
|
|
if meta:get_float("maxSrcTime")<=0 then
|
|
|
|
meta:set_float("srcTime",0)
|
|
|
|
meta:set_float("maxSrcTime",output.time*config.efficiency)
|
|
|
|
end
|
|
|
|
minetest.swap_node(pos,{
|
|
|
|
name="industrialtest:"..config.name.."_active",
|
|
|
|
param2=minetest.get_node(pos).param2
|
|
|
|
})
|
|
|
|
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return shouldRerunTimer,shouldUpdateFormspec
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.allowMetadataInventoryMove=function(pos,fromList,fromIndex,toList,count)
|
|
|
|
if toList=="dst" then
|
|
|
|
return 0
|
|
|
|
elseif toList=="upgrades" then
|
|
|
|
-- TODO: Add support for upgrades when they will be added
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return count
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.allowMetadataInventoryPut=function(pos,listname,index,stack)
|
|
|
|
if listname=="dst" then
|
|
|
|
return 0
|
|
|
|
elseif listname=="src" then
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local inv=meta:get_inventory()
|
|
|
|
local srcSlot=inv:get_stack("src",1)
|
|
|
|
if srcSlot:get_name()~=stack:get_name() then
|
|
|
|
meta:set_float("srcTime",-1)
|
|
|
|
meta:set_float("maxSrcTime",0)
|
|
|
|
end
|
|
|
|
elseif listname=="upgrades" then
|
|
|
|
--TODO: See allow_metadata_inventory_move
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.onMetadataInventoryPut=function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.onMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,count)
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local inv=meta:get_inventory()
|
|
|
|
local srcSlot=inv:get_stack("src",1)
|
|
|
|
local dstSlot=inv:get_stack("dst",1)
|
|
|
|
if fromList=="src" and count==srcSlot:get_count() then
|
|
|
|
meta:set_float("srcTime",-1)
|
|
|
|
meta:set_float("maxSrcTime",0)
|
|
|
|
if meta:get_int("industrialtest.powerAmount")>0 then
|
2023-11-12 15:00:28 +01:00
|
|
|
meta:set_string("formspec",simpleElectricItemProcessor.getFormspec(pos))
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
2024-03-18 15:34:08 +01:00
|
|
|
elseif fromList=="dst" and dstSlot:get_free_space()>0 then
|
2023-11-11 17:42:05 +01:00
|
|
|
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.onMetadataInventoryTake=function(pos,listname,index,stack)
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local inv=meta:get_inventory()
|
|
|
|
local srcSlot=inv:get_stack("src",1)
|
|
|
|
local dstSlot=inv:get_stack("dst",1)
|
|
|
|
if listname=="src" and stack:get_count()==srcSlot:get_count() then
|
|
|
|
meta:set_float("srcTime",-1)
|
|
|
|
meta:set_float("maxSrcTime",0)
|
|
|
|
if meta:get_int("industrialtest.powerAmount")>0 then
|
2023-11-12 15:00:28 +01:00
|
|
|
meta:set_string("formspec",simpleElectricItemProcessor.getFormspec(pos))
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
2024-03-18 15:34:08 +01:00
|
|
|
elseif listname=="dst" and dstSlot:get_free_space()>0 then
|
2023-11-11 17:42:05 +01:00
|
|
|
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
simpleElectricItemProcessor.activeOnTimer=function(pos,elapsed,meta,inv,config)
|
|
|
|
local srcSlot=inv:get_stack("src",1)
|
|
|
|
local powerStorageSlot=inv:get_stack("powerStorage",1)
|
|
|
|
local shouldUpdateFormspec=false
|
|
|
|
local shouldRerunTimer=false
|
2023-11-25 17:58:42 +01:00
|
|
|
local requiredPower=elapsed*config.opPower*industrialtest.api.getMachineSpeed(meta)
|
2023-11-11 17:42:05 +01:00
|
|
|
|
2024-03-08 08:56:56 +01:00
|
|
|
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
|
|
|
|
|
2023-11-11 17:42:05 +01:00
|
|
|
if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
|
|
|
local output=craftResultProxy(config.method,srcSlot)
|
|
|
|
if output.time>0 and inv:room_for_item("dst",output.item) then
|
|
|
|
meta:set_float("srcTime",0)
|
|
|
|
meta:set_float("maxSrcTime",output.time*config.efficiency)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if srcSlot:get_count()==0 and meta:get_float("maxSrcTime")>0 then
|
|
|
|
meta:set_float("srcTime",-1)
|
|
|
|
meta:set_float("maxSrcTime",0)
|
|
|
|
shouldUpdateFormspec=true
|
|
|
|
end
|
|
|
|
if meta:get_float("maxSrcTime")>0 then
|
|
|
|
if meta:get_int("industrialtest.powerAmount")>=requiredPower then
|
|
|
|
meta:set_int("industrialtest.powerAmount",meta:get_int("industrialtest.powerAmount")-requiredPower)
|
|
|
|
meta:set_float("srcTime",meta:get_float("srcTime")+elapsed)
|
|
|
|
shouldRerunTimer=true
|
|
|
|
end
|
|
|
|
shouldUpdateFormspec=true
|
|
|
|
end
|
|
|
|
if meta:get_float("maxSrcTime")<=0 or meta:get_int("industrialtest.powerAmount")<requiredPower then
|
|
|
|
minetest.swap_node(pos,{
|
2023-11-15 21:44:02 +01:00
|
|
|
name="industrialtest:"..config.name,
|
|
|
|
param2=minetest.get_node(pos).param2
|
2023-11-11 17:42:05 +01:00
|
|
|
})
|
|
|
|
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
|
|
|
end
|
|
|
|
if meta:get_float("srcTime")>=meta:get_float("maxSrcTime") then
|
|
|
|
local output=craftResultProxy(config.method,srcSlot)
|
2023-11-25 17:58:42 +01:00
|
|
|
local speed=industrialtest.api.getMachineSpeed(meta)
|
|
|
|
local usedItems=srcSlot:get_count()-output.src:get_count()
|
|
|
|
local multiplier=1
|
|
|
|
if srcSlot:get_count()>=speed*usedItems then
|
|
|
|
multiplier=speed
|
|
|
|
end
|
2023-11-11 17:42:05 +01:00
|
|
|
if output.item:get_count()>0 then
|
2023-11-25 17:58:42 +01:00
|
|
|
output.item:set_count(output.item:get_count()*multiplier)
|
2023-11-11 17:42:05 +01:00
|
|
|
inv:add_item("dst",output.item)
|
|
|
|
meta:set_float("srcTime",-1)
|
|
|
|
meta:set_float("maxSrcTime",0)
|
|
|
|
end
|
2023-11-25 17:58:42 +01:00
|
|
|
srcSlot:set_count(srcSlot:get_count()-multiplier*usedItems)
|
|
|
|
inv:set_stack("src",1,srcSlot)
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
|
|
|
return shouldRerunTimer,shouldUpdateFormspec
|
|
|
|
end
|
|
|
|
|
|
|
|
function industrialtest.internal.registerSimpleElectricItemProcessor(config)
|
2023-11-23 19:17:19 +01:00
|
|
|
local machineBlockTexture=config.machineBlockTexture or "industrialtest_machine_block.png"
|
2023-11-11 17:42:05 +01:00
|
|
|
industrialtest.internal.registerMachine({
|
|
|
|
name=config.name,
|
|
|
|
displayName=config.displayName,
|
|
|
|
capacity=config.capacity,
|
2023-11-12 15:00:28 +01:00
|
|
|
getFormspec=simpleElectricItemProcessor.getFormspec,
|
2023-11-11 17:42:05 +01:00
|
|
|
flow=config.flow,
|
|
|
|
ioConfig="iiiiii",
|
|
|
|
requiresWrench=config.requiresWrench,
|
|
|
|
registerActiveVariant=true,
|
|
|
|
sounds="metal",
|
|
|
|
powerSlots={"powerStorage"},
|
|
|
|
storageSlots={"src","dst","powerStorage","upgrades"},
|
|
|
|
groups={
|
|
|
|
_industrialtest_hasPowerInput=1
|
|
|
|
},
|
|
|
|
customKeys={
|
|
|
|
tiles={
|
2023-11-23 19:17:19 +01:00
|
|
|
machineBlockTexture..(config.customTopTexture and "^industrialtest_"..config.name.."_top.png" or ""),
|
|
|
|
machineBlockTexture..(config.customBottomTexture and "^industrialtest_"..config.name.."_bottom.png" or ""),
|
|
|
|
machineBlockTexture..(config.customRightTexture and "^industrialtest_"..config.name.."_right.png" or ""),
|
|
|
|
machineBlockTexture..(config.customLeftTexture and "^industrialtest_"..config.name.."_left.png" or ""),
|
|
|
|
machineBlockTexture..(config.customBackTexture and "^industrialtest_"..config.name.."_back.png" or ""),
|
|
|
|
machineBlockTexture..(config.customFrontTexture and "^industrialtest_"..config.name.."_front.png" or "")
|
2023-11-11 17:42:05 +01:00
|
|
|
},
|
|
|
|
paramtype2="facedir",
|
|
|
|
legacy_facedir_simple=true,
|
|
|
|
_industrialtest_onPowerFlow=simpleElectricItemProcessor.onPowerFlow
|
|
|
|
},
|
|
|
|
activeCustomKeys={
|
|
|
|
tiles={
|
2023-11-23 19:17:19 +01:00
|
|
|
machineBlockTexture..(config.customTopTexture and "^industrialtest_"..config.name.."_top_active.png" or ""),
|
|
|
|
machineBlockTexture..(config.customBottomTexture and "^industrialtest_"..config.name.."_bottom_active.png" or ""),
|
|
|
|
machineBlockTexture..(config.customRightTexture and "^industrialtest_"..config.name.."_right_active.png" or ""),
|
|
|
|
machineBlockTexture..(config.customLeftTexture and "^industrialtest_"..config.name.."_left_active.png" or ""),
|
|
|
|
machineBlockTexture..(config.customBackTexture and "^industrialtest_"..config.name.."_back_active.png" or ""),
|
|
|
|
machineBlockTexture..(config.customFrontTexture and "^industrialtest_"..config.name.."_front_active.png" or "")
|
2023-11-11 17:42:05 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onConstruct=simpleElectricItemProcessor.onConstruct,
|
|
|
|
onTimer=function(pos,elapsed,meta,inv)
|
2023-11-15 21:44:02 +01:00
|
|
|
return simpleElectricItemProcessor.onTimer(pos,elapsed,meta,inv,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end,
|
|
|
|
allowMetadataInventoryMove=simpleElectricItemProcessor.allowMetadataInventoryMove,
|
|
|
|
allowMetadataInventoryPut=simpleElectricItemProcessor.allowMetadataInventoryPut,
|
|
|
|
onMetadataInventoryPut=simpleElectricItemProcessor.onMetadataInventoryPut,
|
|
|
|
onMetadataInventoryMove=simpleElectricItemProcessor.onMetadataInventoryMove,
|
|
|
|
onMetadataInventoryTake=simpleElectricItemProcessor.onMetadataInventoryTake,
|
|
|
|
activeOnTimer=function(pos,elapsed,meta,inv)
|
2023-11-15 21:44:02 +01:00
|
|
|
return simpleElectricItemProcessor.activeOnTimer(pos,elapsed,meta,inv,config)
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|
|
|
|
})
|
2024-09-11 15:29:03 +02:00
|
|
|
industrialtest.api.addTag("industrialtest:"..config.name,"simpleElectricItemProcessor")
|
2023-11-11 17:42:05 +01:00
|
|
|
end
|