Clean up machines.lua and split to multiple files
This commit is contained in:
parent
748e5c9e29
commit
71480f6a62
16
init.lua
16
init.lua
@ -31,7 +31,21 @@ industrialtest.random=PseudoRandom(os.time())
|
||||
dofile(modpath.."/compatibility.lua")
|
||||
dofile(modpath.."/api.lua")
|
||||
dofile(modpath.."/minerals.lua")
|
||||
dofile(modpath.."/machines.lua")
|
||||
|
||||
dofile(modpath.."/machines/common.lua")
|
||||
dofile(modpath.."/machines/compressor.lua")
|
||||
dofile(modpath.."/machines/electric_furnace.lua")
|
||||
dofile(modpath.."/machines/extractor.lua")
|
||||
dofile(modpath.."/machines/fluid_generator.lua")
|
||||
dofile(modpath.."/machines/generator.lua")
|
||||
dofile(modpath.."/machines/iron_furnace.lua")
|
||||
dofile(modpath.."/machines/macerator.lua")
|
||||
dofile(modpath.."/machines/power_storage.lua")
|
||||
dofile(modpath.."/machines/recycler.lua")
|
||||
dofile(modpath.."/machines/transformer.lua")
|
||||
dofile(modpath.."/machines/solar_panel_generator.lua")
|
||||
dofile(modpath.."/machines/wind_mill.lua")
|
||||
|
||||
dofile(modpath.."/craftitems.lua")
|
||||
dofile(modpath.."/nodes.lua")
|
||||
if industrialtest.developerMode then
|
||||
|
1987
machines.lua
1987
machines.lua
File diff suppressed because it is too large
Load Diff
562
machines/common.lua
Normal file
562
machines/common.lua
Normal file
@ -0,0 +1,562 @@
|
||||
-- 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/>.
|
||||
|
||||
local simpleElectricItemProcessor={}
|
||||
|
||||
function industrialtest.internal.mclAfterDigNode(pos,oldmeta,lists)
|
||||
-- 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
|
||||
|
||||
function industrialtest.internal.registerMachine(config)
|
||||
local function getFormspec(pos)
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"formspec_version[4]",
|
||||
"size[10.8,12]",
|
||||
"label[0.5,0.5;"..config.displayName.."]",
|
||||
(config.getFormspec and config.getFormspec(pos) or ""),
|
||||
"list[current_player;main;0.5,6.25;8,1]",
|
||||
"list[current_player;main;0.5,7.5;8,3;8]"
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"size[10.04,12]",
|
||||
"label[0.25,0.25;"..config.displayName.."]",
|
||||
(config.getFormspec and config.getFormspec(pos) or ""),
|
||||
"list[current_player;main;0.5,7;9,3;9]",
|
||||
mcl_formspec.get_itemslot_bg(0.5,7,9,3),
|
||||
"list[current_player;main;0.5,10.24;9,1]",
|
||||
mcl_formspec.get_itemslot_bg(0.5,10.24,9,1)
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
on_construct=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
if config.onConstruct then
|
||||
config.onConstruct(pos,meta,inv)
|
||||
end
|
||||
industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,config.ioConfig)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end,
|
||||
on_timer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local shouldRerunTimer=false
|
||||
local shouldUpdateFormspec=false
|
||||
|
||||
if config.onTimer then
|
||||
shouldRerunTimer,shouldUpdateFormspec=config.onTimer(pos,elapsed,meta,inv)
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
end,
|
||||
allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local movedItemStack=inv:get_stack(fromList,1)
|
||||
local found=false
|
||||
if config.powerSlots then
|
||||
for _,value in ipairs(config.powerSlots) do
|
||||
if value==toList then
|
||||
found=true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if found and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then
|
||||
return 0
|
||||
end
|
||||
if config.allowMetadataInventoryMove then
|
||||
return config.allowMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
local found=false
|
||||
if config.powerSlots then
|
||||
for _,value in ipairs(config.powerSlots) do
|
||||
if value==listname then
|
||||
found=true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if found and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
|
||||
return 0
|
||||
end
|
||||
if config.allowMetadataInventoryPut then
|
||||
return config.allowMetadataInventoryPut(pos,listname,index,stack,player)
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
if config.onMetadataInventoryPut then
|
||||
config.onMetadataInventoryPut(pos,listname,index,stack,player)
|
||||
end
|
||||
end,
|
||||
on_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
if config.onMetadataInventoryPut then
|
||||
config.onMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
end
|
||||
end,
|
||||
on_metadata_inventory_take=function(pos,listname,index,stack,player)
|
||||
if config.onMetadataInventoryTake then
|
||||
config.onMetadataInventoryTake(pos,listname,index,stack,player)
|
||||
end
|
||||
end,
|
||||
_industrialtest_updateFormspec=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
end
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.groups={cracky=2}
|
||||
if config.sounds=="metal" then
|
||||
definition.sounds=default.node_sound_metal_defaults()
|
||||
end
|
||||
definition.can_dig=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
for _,value in ipairs(config.storageSlots) do
|
||||
if inv:get_stack(value,1):get_count()>0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
elseif industrialtest.mclAvailable then
|
||||
definition.after_dig_node=function(pos,oldnode,oldmeta)
|
||||
industrialtest.internal.mclAfterDigNode(pos,oldmeta,config.storageSlots)
|
||||
end
|
||||
if config.sounds=="metal" then
|
||||
definition.sounds=mcl_sounds.node_sound_metal_defaults()
|
||||
end
|
||||
definition.groups={pickaxey=1}
|
||||
definition._mcl_blast_resistance=3.5
|
||||
definition._mcl_hardness=3.9
|
||||
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
|
||||
|
||||
if config.onTimer then
|
||||
shouldRerunTimer,shouldUpdateFormspec=config.activeOnTimer(pos,elapsed,meta,inv)
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
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
|
||||
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
|
||||
}
|
||||
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
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"list[context;src;3.4,1.8;1,1]",
|
||||
"listring[context;src]",
|
||||
(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]",
|
||||
"listring[context;powerStorage]",
|
||||
(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]",
|
||||
"listring[context;dst]",
|
||||
"list[context;upgrades;9,0.9;1,4]",
|
||||
"listring[context;upgrades]"
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"list[context;src;3.4,1.8;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(3.4,1.8,1,1),
|
||||
"listring[context;src]",
|
||||
(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]",
|
||||
mcl_formspec.get_itemslot_bg(3.4,3.9,1,1),
|
||||
"listring[context;powerStorage]",
|
||||
(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]",
|
||||
mcl_formspec.get_itemslot_bg(6.4,2.8,1,1),
|
||||
"listring[context;dst]",
|
||||
"list[context;upgrades;9,0.9;1,4]",
|
||||
mcl_formspec.get_itemslot_bg(9,0.9,1,4),
|
||||
"listring[context;upgrades]"
|
||||
}
|
||||
end
|
||||
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
|
||||
local requiredPower=elapsed*config.opPower
|
||||
if powerStorageSlot:get_count()>0 then
|
||||
local stackMeta=powerStorageSlot:get_meta()
|
||||
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
||||
inv:set_stack("powerStorage",1,powerStorageSlot)
|
||||
end
|
||||
end
|
||||
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
|
||||
if not industrialtest.api.isFullyCharged(meta) then
|
||||
industrialtest.api.triggerNeighbours(pos)
|
||||
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
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
end
|
||||
elseif fromList=="dst" and dstSlot:get_free_space()==0 then
|
||||
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
|
||||
meta:set_string("formspec",getFormspec(pos))
|
||||
end
|
||||
elseif listname=="dst" and dstSlot:get_free_space()==0 then
|
||||
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
|
||||
local requiredPower=elapsed*config.opPower
|
||||
|
||||
if powerStorageSlot:get_count()>0 then
|
||||
local stackMeta=powerStorageSlot:get_meta()
|
||||
if industrialtest.api.transferPower(stackMeta,meta,stackMeta:get_int("industrialtest.powerFlow"))>0 then
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
industrialtest.api.updateItemPowerText(powerStorageSlot)
|
||||
inv:set_stack("powerStorage",1,powerStorageSlot)
|
||||
end
|
||||
end
|
||||
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,{
|
||||
name="industrialtest:"..config.name,
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
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)
|
||||
if output.item:get_count()>0 then
|
||||
inv:add_item("dst",output.item)
|
||||
meta:set_float("srcTime",-1)
|
||||
meta:set_float("maxSrcTime",0)
|
||||
end
|
||||
inv:set_stack("src",1,output.src)
|
||||
end
|
||||
if not industrialtest.api.isFullyCharged(meta) then
|
||||
industrialtest.api.triggerNeighbours(pos)
|
||||
end
|
||||
return shouldRerunTimer,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
function industrialtest.internal.registerSimpleElectricItemProcessor(config)
|
||||
industrialtest.internal.registerMachine({
|
||||
name=config.name,
|
||||
displayName=config.displayName,
|
||||
capacity=config.capacity,
|
||||
getFormspec=getFormspec,
|
||||
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={
|
||||
"industrialtest_machine_block.png"..(config.customTopTexture and "^industrialtest_"..config.name.."_top.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBottomTexture and "^industrialtest_"..config.name.."_bottom.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customRightTexture and "^industrialtest_"..config.name.."_right.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customLeftTexture and "^industrialtest_"..config.name.."_left.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBackTexture and "^industrialtest_"..config.name.."_back.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customFrontTexture and "^industrialtest_"..config.name.."_front.png" or "")
|
||||
},
|
||||
paramtype2="facedir",
|
||||
legacy_facedir_simple=true,
|
||||
_industrialtest_onPowerFlow=simpleElectricItemProcessor.onPowerFlow
|
||||
},
|
||||
activeCustomKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png"..(config.customTopTexture and "^industrialtest_"..config.name.."_top_active.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBottomTexture and "^industrialtest_"..config.name.."_bottom_active.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customRightTexture and "^industrialtest_"..config.name.."_right_active.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customLeftTexture and "^industrialtest_"..config.name.."_left_active.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBackTexture and "^industrialtest_"..config.name.."_back_active.png" or ""),
|
||||
"industrialtest_machine_block.png"..(config.customFrontTexture and "^industrialtest_"..config.name.."_front_active.png" or "")
|
||||
}
|
||||
},
|
||||
onConstruct=simpleElectricItemProcessor.onConstruct,
|
||||
onTimer=function(pos,elapsed,meta,inv)
|
||||
simpleElectricItemProcessor.onTimer(pos,elapsed,meta,inv,config)
|
||||
end,
|
||||
allowMetadataInventoryMove=simpleElectricItemProcessor.allowMetadataInventoryMove,
|
||||
allowMetadataInventoryPut=simpleElectricItemProcessor.allowMetadataInventoryPut,
|
||||
onMetadataInventoryPut=simpleElectricItemProcessor.onMetadataInventoryPut,
|
||||
onMetadataInventoryMove=simpleElectricItemProcessor.onMetadataInventoryMove,
|
||||
onMetadataInventoryTake=simpleElectricItemProcessor.onMetadataInventoryTake,
|
||||
activeOnTimer=function(pos,elapsed,meta,inv)
|
||||
simpleElectricItemProcessor.activeOnTimer(pos,elapsed,meta,inv,config)
|
||||
end
|
||||
})
|
||||
end
|
38
machines/compressor.lua
Normal file
38
machines/compressor.lua
Normal file
@ -0,0 +1,38 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.internal.registerSimpleElectricItemProcessor({
|
||||
name="compressor",
|
||||
displayName=S("Compressor"),
|
||||
customFrontTexture=true,
|
||||
requiresWrench=true,
|
||||
capacity=1400,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
opPower=120,
|
||||
method="industrialtest.compressing",
|
||||
efficiency=1
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:compressor",
|
||||
recipe={
|
||||
{industrialtest.elementKeys.stone,"",industrialtest.elementKeys.stone},
|
||||
{industrialtest.elementKeys.stone,"industrialtest:machine_block",industrialtest.elementKeys.stone},
|
||||
{industrialtest.elementKeys.stone,"industrialtest:electronic_circuit",industrialtest.elementKeys.stone}
|
||||
}
|
||||
})
|
36
machines/electric_furnace.lua
Normal file
36
machines/electric_furnace.lua
Normal file
@ -0,0 +1,36 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.internal.registerSimpleElectricItemProcessor({
|
||||
name="electric_furnace",
|
||||
displayName=S("Electric Furnace"),
|
||||
customFrontTexture=true,
|
||||
capacity=416,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
opPower=60,
|
||||
method="cooking",
|
||||
efficiency=0.5
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:electric_furnace",
|
||||
recipe={
|
||||
{"","industrialtest:electronic_circuit",""},
|
||||
{industrialtest.elementKeys.powerCarrier,"industrialtest:iron_furnace",industrialtest.elementKeys.powerCarrier}
|
||||
}
|
||||
})
|
37
machines/extractor.lua
Normal file
37
machines/extractor.lua
Normal file
@ -0,0 +1,37 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.internal.registerSimpleElectricItemProcessor({
|
||||
name="extractor",
|
||||
displayName=S("Extractor"),
|
||||
customFrontTexture=true,
|
||||
requiresWrench=true,
|
||||
capacity=900,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
opPower=100,
|
||||
method="industrialtest.extracting",
|
||||
efficiency=1
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:extractor",
|
||||
recipe={
|
||||
{"industrialtest:treetap","industrialtest:machine_block","industrialtest:treetap"},
|
||||
{"industrialtest:treetap","industrialtest:electronic_circuit","industrialtest:treetap"}
|
||||
}
|
||||
})
|
315
machines/fluid_generator.lua
Normal file
315
machines/fluid_generator.lua
Normal file
@ -0,0 +1,315 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local fluidGenerator={}
|
||||
|
||||
fluidGenerator.getFormspec=function(pos,getFuel)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local fluidPercent=meta:get_float("fluidAmount")/100
|
||||
local powerPercent=meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")
|
||||
local fluid=meta:get_string("fluid")
|
||||
local formspec
|
||||
local fuel=getFuel(fluid)
|
||||
local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png")
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"list[context;fluid;2,1.8;1,1]",
|
||||
"listring[context;fluid]",
|
||||
(fluidPercent>0 and "image[2,3;1,1;industrialtest_gui_fluid_bg.png^[lowpart:"..fluidPercent..":"..tile.."]" or "image[2,3;1,1;industrialtest_gui_fluid_bg.png]"),
|
||||
"list[context;leftover;2,4.2;1,1]",
|
||||
"listring[context;leftover]",
|
||||
"list[context;charged;6,3;1,1]",
|
||||
"listring[context;charged]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
(powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or "")
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"list[context;fluid;2,1.8;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(2,1.8,1,1),
|
||||
"listring[context;fluid]",
|
||||
(fluidPercent>0 and "image[2,3;1,1;industrialtest_gui_fluid_bg.png^[lowpart:"..fluidPercent..":"..tile.."]" or "image[2,3;1,1;industrialtest_gui_fluid_bg.png]"),
|
||||
"list[context;leftover;2,4.2;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(2,4.2,1,1),
|
||||
"listring[context;leftover]",
|
||||
"list[context;charged;6,3;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(6,3,1,1),
|
||||
"listring[context;charged]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
(powerPercent>0 and "box[9,"..(1+4.8-(powerPercent*4.8))..";0.3,"..(powerPercent*4.8)..";#FF1010]" or "")
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
|
||||
fluidGenerator.onConstruct=function(pos,meta,inv)
|
||||
inv:set_size("charged",1)
|
||||
inv:set_size("fluid",1)
|
||||
inv:set_size("leftover",1)
|
||||
meta:set_float("fluidAmount",0)
|
||||
meta:set_string("fluid","")
|
||||
end
|
||||
|
||||
fluidGenerator.onTimer=function(pos,elapsed,meta,inv,getFuel,getFuelByItem)
|
||||
local fluidSlot=inv:get_stack("fluid",1)
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||
local shouldUpdateFormspec=false
|
||||
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||
if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then
|
||||
local fuel=getFuelByItem(fluidSlot:get_name())
|
||||
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
|
||||
local leftover=false
|
||||
local leftoverAddingSucceeded=false
|
||||
for _,item in ipairs(fuel.storageItems) do
|
||||
if item.name==fluidSlot:get_name() and item.leftover then
|
||||
if inv:room_for_item("leftover",ItemStack(item.leftover)) then
|
||||
inv:add_item("leftover",ItemStack(item.leftover))
|
||||
leftoverAddingSucceeded=true
|
||||
end
|
||||
leftover=true
|
||||
end
|
||||
end
|
||||
if not leftover or leftoverAddingSucceeded then
|
||||
fluidSlot:take_item()
|
||||
inv:set_stack("fluid",1,fluidSlot)
|
||||
meta:set_string("fluid",fuel.name)
|
||||
meta:set_float("fluidAmount",meta:get_float("fluidAmount")+1000)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=false
|
||||
end
|
||||
end
|
||||
end
|
||||
if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then
|
||||
meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed)
|
||||
local toAdd=math.ceil(getFuel(meta:get_string("fluid")).calorificValue*elapsed)
|
||||
industrialtest.api.addPower(meta,toAdd)
|
||||
shouldUpdateFormspec=true
|
||||
if config.registerActiveVariant then
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:"..config.name.."_active",
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
else
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
end
|
||||
if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
end
|
||||
if flowTransferred then
|
||||
shouldUpdateFormspec=true
|
||||
end
|
||||
return shouldRerunTimer,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
fluidGenerator.metadataChange=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
fluidGenerator.activeOnTimer=function(pos,elapsed,meta,inv,getFuelByItem)
|
||||
local fluidSlot=inv:get_stack("fluid",1)
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||
local shouldUpdateFormspec=false
|
||||
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||
|
||||
if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then
|
||||
local fuel=getFuelByItem(fluidSlot:get_name())
|
||||
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
|
||||
local leftover=false
|
||||
local leftoverAddingSucceeded=false
|
||||
for _,item in ipairs(fuel.storageItems) do
|
||||
if item.name==fluidSlot:get_name() and item.leftover then
|
||||
if inv:room_for_item("leftover",ItemStack(item.leftover)) then
|
||||
inv:add_item("leftover",ItemStack(item.leftover))
|
||||
leftoverAddingSucceeded=true
|
||||
end
|
||||
leftover=true
|
||||
end
|
||||
end
|
||||
if not leftover or leftoverAddingSucceeded then
|
||||
fluidSlot:take_item()
|
||||
inv:set_stack("fluid",1,fluidSlot)
|
||||
meta:set_string("fluid",fuel.name)
|
||||
meta:set_float("fluidAmount",meta:get_float("fluidAmount")+1000)
|
||||
minetest.chat_send_all(meta:get_float("fluidAmount"))
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=false
|
||||
end
|
||||
end
|
||||
end
|
||||
if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then
|
||||
meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed)
|
||||
local toAdd=math.ceil(industrialtest.api.getGeothermalGeneratorFuel(meta:get_string("fluid")).calorificValue*elapsed)
|
||||
industrialtest.api.addPower(meta,toAdd)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
else
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:"..config.name,
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
end
|
||||
if flowTransferred then
|
||||
shouldUpdateFormspec=true
|
||||
end
|
||||
return shouldRerunTimer,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
local function registerFluidGenerator(config)
|
||||
local definition={
|
||||
name=config.name,
|
||||
displayName=config.displayName,
|
||||
getFormspec=function(pos)
|
||||
return fluidGenerator.getFormspec(pos,config.getFuel)
|
||||
end,
|
||||
capacity=7000,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
ioConfig="oooooo",
|
||||
requiresWrench=true,
|
||||
registerActiveVariant=config.registerActiveVariant,
|
||||
powerSlots={"charged"},
|
||||
storageSlots={"fluid","fluidLeftover"},
|
||||
sounds="metal",
|
||||
groups={
|
||||
_industrialtest_hasPowerOutput=1
|
||||
},
|
||||
customKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTexture or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBottomTexture and "^"..config.customBottomTexture or ""),
|
||||
"industrialtest_machine_block.png"..(config.customRightTexture and "^"..config.customRightTexture or ""),
|
||||
"industrialtest_machine_block.png"..(config.customLeftTexture and "^"..config.customLeftTexture or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBackTexture and "^"..config.customBackTexture or ""),
|
||||
"industrialtest_machine_block.png"..(config.customFrontTexture and "^"..config.customFrontTexture or "")
|
||||
},
|
||||
paramtype2="facedir",
|
||||
legacy_facedir_simple=true
|
||||
},
|
||||
onConstruct=fluidGenerator.onConstruct,
|
||||
onTimer=function(pos,elapsed,meta,inv)
|
||||
return fluidGenerator.onTimer(pos,elapsed,meta,inv,config.getFuel,config.getFuelByItem)
|
||||
end,
|
||||
onMetadataInventoryPut=fluidGenerator.metadataChange,
|
||||
onMetadataInventoryMove=fluidGenerator.metadataChange
|
||||
}
|
||||
if config.registerActiveVariant then
|
||||
definition.activeCustomKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png"..(config.customTopTexture and "^"..config.customTopTextureActive or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBottomTexture and "^"..config.customBottomTextureActive or ""),
|
||||
"industrialtest_machine_block.png"..(config.customRightTexture and "^"..config.customRightTextureActive or ""),
|
||||
"industrialtest_machine_block.png"..(config.customLeftTexture and "^"..config.customLeftTextureActive or ""),
|
||||
"industrialtest_machine_block.png"..(config.customBackTexture and "^"..config.customBackTextureActive or ""),
|
||||
"industrialtest_machine_block.png"..(config.customFrontTexture and "^"..config.customFrontTextureActive or "")
|
||||
},
|
||||
light_source=8
|
||||
}
|
||||
definition.activeOnTimer=fluidGenerator.activeOnTimer
|
||||
end
|
||||
industrialtest.internal.registerMachine(definition)
|
||||
end
|
||||
|
||||
registerFluidGenerator({
|
||||
name="geothermal_generator",
|
||||
displayName=S("Geothermal Generator"),
|
||||
customFrontTexture="industrialtest_geothermal_generator_front.png",
|
||||
customFrontTextureActive="industrialtest_geothermal_generator_front_active.png",
|
||||
getFuel=industrialtest.api.getGeothermalGeneratorFuel,
|
||||
getFuelByItem=industrialtest.api.getGeothermalGeneratorFuelByItem,
|
||||
registerActiveVariant=true,
|
||||
reactsToNeighbouringNodes=false
|
||||
})
|
||||
|
||||
registerFluidGenerator({
|
||||
name="water_mill",
|
||||
displayName=S("Water Mill"),
|
||||
customLeftTexture="industrialtest_water_mill_side.png",
|
||||
customRightTexture="industrialtest_water_mill_side.png",
|
||||
customFrontTexture="industrialtest_water_mill_side.png",
|
||||
customBackTexture="industrialtest_water_mill_side.png",
|
||||
getFuel=industrialtest.api.getWaterMillFuel,
|
||||
getFuelByItem=industrialtest.api.getWaterMillFuelByItem,
|
||||
registerActiveVariant=false
|
||||
})
|
||||
local neighbors={}
|
||||
for key,_ in pairs(industrialtest.api.waterMillFuels) do
|
||||
table.insert(neighbors,key)
|
||||
end
|
||||
minetest.register_abm({
|
||||
label="Water Mill generating",
|
||||
nodenames={"industrialtest:water_mill"},
|
||||
neighbors=neighbors,
|
||||
interval=industrialtest.updateDelay,
|
||||
chance=1,
|
||||
action=function(pos,node)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local powerToAdd=0
|
||||
local neighbourPositions={
|
||||
vector.offset(pos,-1,0,0),
|
||||
vector.offset(pos,1,0,0),
|
||||
vector.offset(pos,0,-1,0),
|
||||
vector.offset(pos,0,1,0),
|
||||
vector.offset(pos,0,0,-1),
|
||||
vector.offset(pos,0,0,1)
|
||||
}
|
||||
for _,value in ipairs(neighbourPositions) do
|
||||
local node=minetest.get_node_or_nil(value)
|
||||
if node then
|
||||
local fuel=industrialtest.api.getWaterMillFuel(node.name)
|
||||
if fuel then
|
||||
powerToAdd=powerToAdd+fuel.calorificValue*0.2
|
||||
end
|
||||
end
|
||||
end
|
||||
if industrialtest.api.addPower(meta,powerToAdd)>0 then
|
||||
local def=minetest.registered_nodes[node.name]
|
||||
def._industrialtest_updateFormspec(meta)
|
||||
end
|
||||
if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:water_mill",
|
||||
recipe={
|
||||
{"",industrialtest.elementKeys.stick,""},
|
||||
{industrialtest.elementKeys.stick,"industrialtest:generator",industrialtest.elementKeys.stick},
|
||||
{"",industrialtest.elementKeys.stick,""}
|
||||
}
|
||||
})
|
199
machines/generator.lua
Normal file
199
machines/generator.lua
Normal file
@ -0,0 +1,199 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local generator={}
|
||||
|
||||
generator.getFormspec=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local fuelPercent=meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100
|
||||
local charged=meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"list[context;charged;4.9,1.8;1,1]",
|
||||
"listring[context;charged]",
|
||||
(fuelPercent>0 and "image[4.9,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]"
|
||||
or "image[4.9,2.8;1,1;default_furnace_fire_bg.png]"),
|
||||
"list[context;fuel;4.9,3.9;1,1]",
|
||||
"listring[context;fuel]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
(charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*4.8)..";#FF1010]" or "")
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"list[context;charged;4.7,1.8;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(4.7,1.8,1,1),
|
||||
"listring[context;charged]",
|
||||
(fuelPercent>0 and "image[4.7,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]"
|
||||
or "image[4.7,2.8;1,1;default_furnace_fire_bg.png]"),
|
||||
"list[context;fuel;4.7,3.9;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(4.7,3.9,1,1),
|
||||
"listring[context;fuel]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
(charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*4.8)..";#FF1010]" or "")
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
|
||||
generator.onConstruct=function(pos,meta,inv)
|
||||
inv:set_size("charged",1)
|
||||
inv:set_size("fuel",1)
|
||||
meta:set_int("fuelTime",0)
|
||||
meta:set_int("maxFuelTime",1)
|
||||
end
|
||||
|
||||
generator.onTimer=function(pos,elapsed,meta,inv)
|
||||
local powerFlow=meta:get_int("industrialtest.powerFlow")
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local fuelSlot=inv:get_stack("fuel",1)
|
||||
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||
local shouldUpdateFormspec=flowTransferred
|
||||
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||
if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
industrialtest.api.transferPowerToItem(meta,chargedSlot,powerFlow)
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
if fuelSlot:get_count()>0 and meta:get_int("fuelTime")<=0 and not industrialtest.api.isFullyCharged(meta) then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
items={fuelSlot}
|
||||
})
|
||||
if output.time>0 then
|
||||
meta:set_int("fuelTime",output.time)
|
||||
meta:set_int("maxFuelTime",output.time)
|
||||
inv:set_stack("fuel",1,after.items[1])
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:generator_active",
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
return shouldRerunTimer,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
generator.activeOnTimer=function(pos,elapsed,meta,inv)
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local fuelSlot=inv:get_stack("fuel",1)
|
||||
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||
local shouldUpdateFormspec=flowTransferred
|
||||
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||
if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
industrialtest.api.transferPowerToItem(meta,chargedSlot,chargedSlot:get_meta():get_int("industrialtest.powerFlow"))
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
if fuelSlot:get_count()>0 and meta:get_int("fuelTime")<=0 and not industrialtest.api.isFullyCharged(meta) then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
items={fuelSlot}
|
||||
})
|
||||
if output.time>0 then
|
||||
meta:set_int("fuelTime",output.time)
|
||||
meta:set_int("maxFuelTime",output.time)
|
||||
inv:set_stack("fuel",1,after.items[1])
|
||||
end
|
||||
end
|
||||
if meta:get_int("fuelTime")>0 then
|
||||
meta:set_int("fuelTime",meta:get_int("fuelTime")-elapsed)
|
||||
industrialtest.api.addPower(meta,200)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
else
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:generator",
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
end
|
||||
return shouldRerunTimer,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
generator.metadataChange=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
industrialtest.internal.registerMachine({
|
||||
name="generator",
|
||||
displayName=S("Generator"),
|
||||
getFormspec=generator.getFormspec,
|
||||
capacity=7000,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
ioConfig="oooooo",
|
||||
registerActiveVariant=true,
|
||||
powerSlots={"charged"},
|
||||
storageSlots={"charged","fuel"},
|
||||
sounds="metal",
|
||||
groups={
|
||||
_industrialtest_hasPowerOutput=1
|
||||
},
|
||||
customKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png^industrialtest_iron_furnace_front.png",
|
||||
"industrialtest_machine_block.png"
|
||||
},
|
||||
paramtype2="facedir",
|
||||
legacy_facedir_simple=true
|
||||
},
|
||||
activeCustomKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png^industrialtest_iron_furnace_front_active.png",
|
||||
"industrialtest_machine_block.png"
|
||||
},
|
||||
light_source=8
|
||||
},
|
||||
onConstruct=generator.onConstruct,
|
||||
onTimer=generator.onTimer,
|
||||
activeOnTimer=generator.activeOnTimer,
|
||||
onMetadataInventoryPut=generator.metadataChange,
|
||||
onMetadataInventoryMove=generator.metadataChange
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:generator",
|
||||
recipe={
|
||||
{"industrialtest:re_battery"},
|
||||
{"industrialtest:machine_block"},
|
||||
{industrialtest.elementKeys.furnace}
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:generator",
|
||||
recipe={
|
||||
{"","industrialtest:re_battery",""},
|
||||
{"industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot"},
|
||||
{"","industrialtest:iron_furnace",""}
|
||||
}
|
||||
})
|
||||
|
341
machines/iron_furnace.lua
Normal file
341
machines/iron_furnace.lua
Normal file
@ -0,0 +1,341 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local ironFurnace={}
|
||||
|
||||
ironFurnace.getFormspec=function(fuelPercent,srcPercent)
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"formspec_version[4]",
|
||||
"size[10.8,12]",
|
||||
"label[0.5,0.5;"..S("Iron Furnace").."]",
|
||||
"list[context;src;3.4,1.8;1,1]",
|
||||
"listring[context;src]",
|
||||
(fuelPercent>0 and "image[3.4,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]"
|
||||
or "image[3.4,2.8;1,1;default_furnace_fire_bg.png]"),
|
||||
"list[context;fuel;3.4,3.9;1,1]",
|
||||
"listring[context;fuel]",
|
||||
(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]",
|
||||
"listring[context;dst]",
|
||||
"list[current_player;main;0.5,6.25;8,1]",
|
||||
"list[current_player;main;0.5,7.5;8,3;8]"
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"size[10.04,12]",
|
||||
"label[0.25,0.25;"..S("Iron Furnace").."]",
|
||||
"list[context;src;3.4,1.8;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(3.4,1.8,1,1),
|
||||
"listring[context;src]",
|
||||
(fuelPercent>0 and "image[3.4,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]"
|
||||
or "image[3.4,2.8;1,1;default_furnace_fire_bg.png]"),
|
||||
"list[context;fuel;3.4,3.9;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(3.4,3.9,1,1),
|
||||
"listring[context;fuel]",
|
||||
(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]",
|
||||
mcl_formspec.get_itemslot_bg(6.4,2.8,1,1),
|
||||
"listring[context;dst]",
|
||||
"list[current_player;main;0.5,7;9,3;9]",
|
||||
mcl_formspec.get_itemslot_bg(0.5,7,9,3),
|
||||
"list[current_player;main;0.5,10.24;9,1]",
|
||||
mcl_formspec.get_itemslot_bg(0.5,10.24,9,1)
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
|
||||
ironFurnace.onConstruct=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
inv:set_size("src",1)
|
||||
inv:set_size("dst",1)
|
||||
inv:set_size("fuel",1)
|
||||
meta:set_string("formspec",ironFurnace.getFormspec(0,0))
|
||||
meta:set_float("fuelTime",0)
|
||||
meta:set_float("maxFuelTime",1)
|
||||
meta:set_float("srcTime",-1)
|
||||
meta:set_float("maxSrcTime",0)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
ironFurnace.onTimer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local srcSlot=inv:get_stack("src",1)
|
||||
local fuelSlot=inv:get_stack("fuel",1)
|
||||
local shouldUpdateFormspec=false
|
||||
local shouldRerunTimer=false
|
||||
|
||||
if fuelSlot:get_count()>0 and meta:get_float("fuelTime")<=0 then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="cooking",
|
||||
width=1,
|
||||
items={srcSlot}
|
||||
})
|
||||
if output.time>0 and inv:room_for_item("dst",output.item) then
|
||||
output,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
items={fuelSlot}
|
||||
})
|
||||
if output.time>0 then
|
||||
meta:set_float("fuelTime",output.time)
|
||||
meta:set_float("maxFuelTime",output.time)
|
||||
inv:set_stack("fuel",1,after.items[1])
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:iron_furnace_active",
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",ironFurnace.getFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
end
|
||||
|
||||
ironFurnace.activeOnTimer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local srcSlot=inv:get_stack("src",1)
|
||||
local fuelSlot=inv:get_stack("fuel",1)
|
||||
local shouldUpdateFormspec=false
|
||||
local shouldRerunTimer=false
|
||||
|
||||
if fuelSlot:get_count()>0 and meta:get_float("fuelTime")<=0 then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="cooking",
|
||||
width=1,
|
||||
items={srcSlot}
|
||||
})
|
||||
if output.time>0 and inv:room_for_item("dst",output.item) then
|
||||
output,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
items={fuelSlot}
|
||||
})
|
||||
if output.time>0 then
|
||||
meta:set_float("fuelTime",output.time)
|
||||
meta:set_float("maxFuelTime",output.time)
|
||||
inv:set_stack("fuel",1,after.items[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
if srcSlot:get_count()>0 and meta:get_float("maxSrcTime")<=0 and meta:get_float("fuelTime")>0 then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="cooking",
|
||||
width=1,
|
||||
items={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*0.7)
|
||||
end
|
||||
end
|
||||
if meta:get_float("fuelTime")>0 then
|
||||
meta:set_float("fuelTime",meta:get_float("fuelTime")-elapsed)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
if meta:get_float("maxSrcTime")>0 then
|
||||
if meta:get_float("fuelTime")>0 then
|
||||
meta:set_float("srcTime",meta:get_float("srcTime")+elapsed)
|
||||
else
|
||||
meta:set_float("srcTime",0)
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:iron_furnace",
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
else
|
||||
minetest.swap_node(pos,{
|
||||
name="industrialtest:iron_furnace",
|
||||
param2=minetest.get_node(pos).param2
|
||||
})
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
if meta:get_float("srcTime")>=meta:get_float("maxSrcTime") then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="cooking",
|
||||
width=1,
|
||||
items={srcSlot}
|
||||
})
|
||||
if output.item:get_count()>0 then
|
||||
inv:set_stack("src",1,after.items[1])
|
||||
inv:add_item("dst",output.item)
|
||||
meta:set_float("srcTime",-1)
|
||||
meta:set_float("maxSrcTime",0)
|
||||
end
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",ironFurnace.getFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
end
|
||||
|
||||
ironFurnace.allowMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,count)
|
||||
if toList=="dst" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
ironFurnace.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
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
ironFurnace.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_float("maxFuelTime")>0 then
|
||||
meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0))
|
||||
end
|
||||
elseif fromList=="dst" and dstSlot:get_free_space()==0 then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
|
||||
ironFurnace.onMetadataInventoryPut=function(pos,listname,index,stack)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
ironFurnace.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_float("maxFuelTime")>0 then
|
||||
meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0))
|
||||
end
|
||||
elseif listname=="dst" and dstSlot:get_free_space()==0 then
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
end
|
||||
|
||||
local definition={
|
||||
description=S("Iron Furnace"),
|
||||
tiles={
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png^industrialtest_iron_furnace_front.png",
|
||||
"industrialtest_machine_block.png"
|
||||
},
|
||||
paramtype2="facedir",
|
||||
legacy_facedir_simple=true,
|
||||
on_construct=ironFurnace.onConstruct,
|
||||
on_timer=ironFurnace.onTimer,
|
||||
allow_metadata_inventory_move=ironFurnace.allowMetadataInventoryMove,
|
||||
allow_metadata_inventory_put=ironFurnace.allowMetadataInventoryPut,
|
||||
on_metadata_inventory_move=ironFurnace.onMetadataInventoryMove,
|
||||
on_metadata_inventory_put=ironFurnace.onMetadataInventoryPut,
|
||||
on_metadata_inventory_take=ironFurnace.onMetadataInventoryTake
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.groups={
|
||||
cracky=1,
|
||||
level=2
|
||||
}
|
||||
definition.sounds=default.node_sound_metal_defaults()
|
||||
definition.can_dig=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return not (inv:get_list("src")[1]:get_count()>0 or inv:get_list("fuel")[1]:get_count()>0 or inv:get_list("dst")[1]:get_count()>0)
|
||||
end
|
||||
elseif industrialtest.mclAvailable then
|
||||
definition.after_dig_node=function(pos,oldnode,oldmeta)
|
||||
industrialtest.internal.mclAfterDigNode(pos,oldmeta,{"src","fuel","dst"})
|
||||
end
|
||||
definition.sounds=mcl_sounds.node_sound_metal_defaults()
|
||||
definition._mcl_blast_resistance=3
|
||||
definition._mcl_hardness=3.5
|
||||
end
|
||||
minetest.register_node("industrialtest:iron_furnace",definition)
|
||||
definition=table.copy(definition)
|
||||
definition.description=nil
|
||||
definition.tiles={
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png^industrialtest_iron_furnace_front_active.png",
|
||||
"industrialtest_machine_block.png"
|
||||
}
|
||||
definition.light_source=8
|
||||
definition.drop="industrialtest:iron_furnace"
|
||||
definition.on_timer=ironFurnace.activeOnTimer
|
||||
if industrialtest.mclAvailable then
|
||||
definition.groups={
|
||||
not_in_creative_inventory=1
|
||||
}
|
||||
definition._doc_items_create_entry=false
|
||||
end
|
||||
minetest.register_node("industrialtest:iron_furnace_active",definition)
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:iron_furnace",
|
||||
recipe={
|
||||
{industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot},
|
||||
{industrialtest.elementKeys.ironIngot,"",industrialtest.elementKeys.ironIngot},
|
||||
{industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot}
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:iron_furnace",
|
||||
recipe={
|
||||
{"",industrialtest.elementKeys.ironIngot,""},
|
||||
{industrialtest.elementKeys.ironIngot,"",industrialtest.elementKeys.ironIngot},
|
||||
{industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.furnace,industrialtest.elementKeys.ironIngot}
|
||||
}
|
||||
})
|
38
machines/macerator.lua
Normal file
38
machines/macerator.lua
Normal file
@ -0,0 +1,38 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.internal.registerSimpleElectricItemProcessor({
|
||||
name="macerator",
|
||||
displayName=S("Macerator"),
|
||||
customFrontTexture=true,
|
||||
requiresWrench=true,
|
||||
capacity=1200,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
opPower=100,
|
||||
method="industrialtest.macerating",
|
||||
efficiency=1
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:macerator",
|
||||
recipe={
|
||||
{industrialtest.elementKeys.flint,industrialtest.elementKeys.flint,industrialtest.elementKeys.flint},
|
||||
{industrialtest.elementKeys.cobble,"industrialtest:machine_block",industrialtest.elementKeys.cobble},
|
||||
{"","industrialtest:electronic_circuit",""}
|
||||
}
|
||||
})
|
201
machines/power_storage.lua
Normal file
201
machines/power_storage.lua
Normal file
@ -0,0 +1,201 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local powerStorage={}
|
||||
|
||||
powerStorage.getFormspec=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local charged=meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"list[context;charged;1,2.5;1,1]",
|
||||
"listring[context;charged]",
|
||||
"label[0.9,3.9;"..S("Charge").."]",
|
||||
"list[context;discharged;3,2.5;1,1]",
|
||||
"listring[context;discharged]",
|
||||
"label[2.7,3.9;"..S("Discharge").."]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
(charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*4.8)..";#FF1010]" or "")
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"list[context;charged;1,2.5;1,1]",
|
||||
"listring[context;charged]",
|
||||
mcl_formspec.get_itemslot_bg(1,2.5,1,1),
|
||||
"label[0.9,3.9;"..S("Charge").."]",
|
||||
"list[context;discharged;3,2.5;1,1]",
|
||||
"listring[context;discharged]",
|
||||
mcl_formspec.get_itemslot_bg(3,2.5,1,1),
|
||||
"label[2.7,3.9;"..S("Discharge").."]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
(charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*4.8)..";#FF1010]" or "")
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
|
||||
powerStorage.onConstruct=function(pos,meta,inv)
|
||||
inv:set_size("charged",1)
|
||||
inv:set_size("discharged",1)
|
||||
end
|
||||
|
||||
powerStorage.onTimer=function(pos,elapsed,meta,inv,config)
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local dischargedSlot=inv:get_stack("discharged",1)
|
||||
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
|
||||
local shouldUpdateFormspec=flowTransferred
|
||||
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
|
||||
|
||||
if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 and industrialtest.api.transferPowerToItem(meta,chargedSlot,config.flow)>0 then
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
shouldRerunTimer=true
|
||||
shouldUpdateFormspec=true
|
||||
end
|
||||
if dischargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(meta) and industrialtest.api.transferPowerFromItem(dischargedSlot,meta,config.flow)>0 then
|
||||
inv:set_stack("discharged",1,dischargedSlot)
|
||||
shouldRerunTimer=true
|
||||
shouldUpdateFormspec=true
|
||||
end
|
||||
if not industrialtest.api.isFullyCharged(meta) then
|
||||
industrialtest.api.triggerNeighbours(pos)
|
||||
end
|
||||
|
||||
return shouldRerunTimer,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
powerStorage.onMetadataInventoryPut=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
powerStorage.onMetadataInventoryMove=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
local function registerPowerStorageNode(config)
|
||||
industrialtest.internal.registerMachine({
|
||||
name=config.name,
|
||||
displayName=config.displayName,
|
||||
capacity=config.capacity,
|
||||
flow=config.flow,
|
||||
ioConfig="iiiioi",
|
||||
sounds=config.sounds,
|
||||
powerSlots={"charged","discharged"},
|
||||
storageSlots={"charged","discharged"},
|
||||
registerActiveVariant=false,
|
||||
groups={
|
||||
_industrialtest_hasPowerOutput=1,
|
||||
_industrialtest_hasPowerInput=1
|
||||
},
|
||||
customKeys={
|
||||
tiles={
|
||||
config.machineBlockTexture,
|
||||
config.machineBlockTexture,
|
||||
config.machineBlockTexture,
|
||||
config.machineBlockTexture,
|
||||
config.machineBlockTexture,
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_front.png"
|
||||
},
|
||||
paramtype2="facedir",
|
||||
legacy_facedir_simple=true
|
||||
},
|
||||
requiresWrench=config.requiresWrench,
|
||||
getFormspec=powerStorage.getFormspec,
|
||||
onConstruct=powerStorage.onConstruct,
|
||||
onTimer=function(pos,elapsed,meta,inv)
|
||||
powerStorage.onTimer(pos,elapsed,meta,inv,config)
|
||||
end,
|
||||
onMetadataInventoryPut=powerStorage.onMetadataInventoryPut,
|
||||
onMetadataInventoryMove=powerStorage.onMetadataInventoryMove
|
||||
})
|
||||
end
|
||||
|
||||
registerPowerStorageNode({
|
||||
name="batbox",
|
||||
displayName=S("BatBox"),
|
||||
capacity=25000,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
sounds="wood",
|
||||
machineBlockTexture="industrialtest_wood_machine_block.png",
|
||||
requiresWrench=false
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:batbox",
|
||||
recipe={
|
||||
{"group:wood","industrialtest:insulated_tin_cable","group:wood"},
|
||||
{"industrialtest:re_battery","industrialtest:re_battery","industrialtest:re_battery"},
|
||||
{"group:wood","group:wood","group:wood"}
|
||||
}
|
||||
})
|
||||
|
||||
registerPowerStorageNode({
|
||||
name="cesu",
|
||||
displayName=S("CESU"),
|
||||
capacity=400000,
|
||||
flow=industrialtest.api.mvPowerFlow,
|
||||
sounds="metal",
|
||||
machineBlockTexture="industrialtest_bronze_machine_block.png",
|
||||
requiresWrench=false
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:cesu",
|
||||
recipe={
|
||||
{"industrialtest:bronze_plate","industrialtest:insulated_copper_cable","industrialtest:bronze_plate"},
|
||||
{"industrialtest:advanced_re_battery","industrialtest:advanced_re_battery","industrialtest:advanced_re_battery"},
|
||||
{"industrialtest:bronze_plate","industrialtest:bronze_plate","industrialtest:bronze_plate"}
|
||||
}
|
||||
})
|
||||
|
||||
registerPowerStorageNode({
|
||||
name="mfe",
|
||||
displayName=S("MFE"),
|
||||
capacity=3000000,
|
||||
flow=industrialtest.api.hvPowerFlow,
|
||||
sounds="metal",
|
||||
machineBlockTexture="industrialtest_machine_block.png",
|
||||
requiresWrench=true
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:mfe",
|
||||
recipe={
|
||||
{"industrialtest:insulated_gold_cable","industrialtest:energy_crystal","industrialtest:insulated_gold_cable"},
|
||||
{"industrialtest:energy_crystal","industrialtest:machine_block","industrialtest:energy_crystal"},
|
||||
{"industrialtest:insulated_gold_cable","industrialtest:energy_crystal","industrialtest:insulated_gold_cable"}
|
||||
}
|
||||
})
|
||||
|
||||
registerPowerStorageNode({
|
||||
name="mfsu",
|
||||
displayName=S("MFSU"),
|
||||
capacity=30000000,
|
||||
flow=industrialtest.api.evPowerFlow,
|
||||
sounds="metal",
|
||||
machineBlockTexture="industrialtest_advanced_machine_block.png",
|
||||
requiresWrench=false
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:mfsu",
|
||||
recipe={
|
||||
{"industrialtest:lapotron_crystal","industrialtest:advanced_electronic_circuit","industrialtest:lapotron_crystal"},
|
||||
{"industrialtest:lapotron_crystal","industrialtest:mfe","industrialtest:lapotron_crystal"},
|
||||
{"industrialtest:lapotron_crystal","industrialtest:advanced_machine_block","industrialtest:lapotron_crystal"}
|
||||
}
|
||||
})
|
38
machines/recycler.lua
Normal file
38
machines/recycler.lua
Normal file
@ -0,0 +1,38 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
|
||||
industrialtest.internal.registerSimpleElectricItemProcessor({
|
||||
name="recycler",
|
||||
displayName=S("Recycler"),
|
||||
customTopTexture=true,
|
||||
requiresWrench=true,
|
||||
capacity=80,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
opPower=40,
|
||||
method="industrialtest.recycling",
|
||||
efficiency=1
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:recycler",
|
||||
recipe={
|
||||
{"",industrialtest.elementKeys.glowstone,""},
|
||||
{industrialtest.elementKeys.dirt,"industrialtest:compressor",industrialtest.elementKeys.dirt},
|
||||
{"industrialtest:refined_iron_ingot",industrialtest.elementKeys.dirt,"industrialtest:refined_iron_ingot"}
|
||||
}
|
||||
})
|
161
machines/solar_panel_generator.lua
Normal file
161
machines/solar_panel_generator.lua
Normal file
@ -0,0 +1,161 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local solarPanel={}
|
||||
|
||||
solarPanel.getFormspec=function(pos)
|
||||
local amount=minetest.get_natural_light(vector.offset(pos,0,1,0))/15.0
|
||||
local charging=amount>0.5
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"list[context;charged;4.9,1.8;1,1]",
|
||||
"listring[context;charged]",
|
||||
(charging and "image[4.9,2.8;1,1;industrialtest_gui_sun_fg.png]"
|
||||
or "image[4.9,2.8;1,1;industrialtest_gui_sun_bg.png]")
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"list[context;charged;4.7,1.8;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(4.7,1.8,1,1),
|
||||
"listring[context;charged]",
|
||||
(charging and "image[4.7,2.8;1,1;industrialtest_gui_sun_fg.png]"
|
||||
or "image[4.7,2.8;1,1;industrialtest_gui_sun_bg.png]")
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
|
||||
solarPanel.onConstruct=function(pos,meta,inv)
|
||||
inv:set_size("charged",1)
|
||||
meta:set_float("prevAmount",0)
|
||||
end
|
||||
|
||||
solarPanel.onTimer=function(pos,elapsed,meta,inv,config)
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local shouldUpdateFormspec=false
|
||||
local amount=minetest.get_natural_light(vector.offset(pos,0,1,0))/15.0
|
||||
local charging=amount>0.5
|
||||
if charging then
|
||||
industrialtest.api.addPower(meta,math.ceil(amount*config.flow*elapsed))
|
||||
end
|
||||
if meta:get_int("industrialtest.powerAmount")>0 then
|
||||
if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) then
|
||||
industrialtest.api.transferPowerToItem(meta,chargedSlot,math.ceil(config.flow*elapsed))
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
end
|
||||
industrialtest.api.powerFlow(pos)
|
||||
end
|
||||
if amount~=meta:get_float("prevAmount") then
|
||||
shouldUpdateFormspec=true
|
||||
meta:set_float("prevAmount",amount)
|
||||
end
|
||||
return true,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
local function registerSolarPanelGenerator(config)
|
||||
industrialtest.internal.registerMachine({
|
||||
name=config.name,
|
||||
displayName=config.displayName,
|
||||
getFormspec=solarPanel.getFormspec,
|
||||
capacity=config.capacity,
|
||||
flow=config.flow,
|
||||
ioConfig="oooooo",
|
||||
requiresWrench=true,
|
||||
registerActiveVariant=false,
|
||||
powerSlots={"charged"},
|
||||
storageSlots={"charged"},
|
||||
sounds="metal",
|
||||
groups={
|
||||
_industrialtest_hasPowerOutput=1
|
||||
},
|
||||
customKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png^industrialtest_"..config.name.."_top.png",
|
||||
"industrialtest_machine_block.png"
|
||||
}
|
||||
},
|
||||
onConstruct=solarPanel.onConstruct,
|
||||
onTimer=function(pos,elapsed,meta,inv)
|
||||
solarPanel.onTimer(pos,elapsed,meta,inv,config)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
registerSolarPanelGenerator({
|
||||
name="solar_panel",
|
||||
displayName=S("Solar Panel"),
|
||||
capacity=industrialtest.api.lvPowerFlow*2,
|
||||
flow=industrialtest.api.lvPowerFlow
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:solar_panel",
|
||||
recipe={
|
||||
{"industrialtest:coal_dust",industrialtest.elementKeys.glass,"industrialtest:coal_dust"},
|
||||
{industrialtest.elementKeys.glass,"industrialtest:coal_dust",industrialtest.elementKeys.glass},
|
||||
{"industrialtest:insulated_copper_cable","industrialtest:generator","industrialtest:insulated_copper_cable"}
|
||||
}
|
||||
})
|
||||
|
||||
registerSolarPanelGenerator({
|
||||
name="lv_solar_array",
|
||||
displayName=S("LV Solar Array"),
|
||||
capacity=industrialtest.api.lvPowerFlow*4,
|
||||
flow=industrialtest.api.lvPowerFlow*2
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:lv_solar_array",
|
||||
recipe={
|
||||
{"industrialtest:solar_panel","industrialtest:solar_panel","industrialtest:solar_panel"},
|
||||
{"industrialtest:solar_panel","industrialtest:lv_transformer","industrialtest:solar_panel"},
|
||||
{"industrialtest:solar_panel","industrialtest:solar_panel","industrialtest:solar_panel"}
|
||||
}
|
||||
})
|
||||
|
||||
registerSolarPanelGenerator({
|
||||
name="mv_solar_array",
|
||||
displayName=S("MV Solar Array"),
|
||||
capacity=industrialtest.api.mvPowerFlow*2,
|
||||
flow=industrialtest.api.mvPowerFlow
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:mv_solar_array",
|
||||
recipe={
|
||||
{"industrialtest:lv_solar_array","industrialtest:lv_solar_array","industrialtest:lv_solar_array"},
|
||||
{"industrialtest:lv_solar_array","industrialtest:mv_transformer","industrialtest:lv_solar_array"},
|
||||
{"industrialtest:lv_solar_array","industrialtest:lv_solar_array","industrialtest:lv_solar_array"}
|
||||
}
|
||||
})
|
||||
|
||||
registerSolarPanelGenerator({
|
||||
name="hv_solar_array",
|
||||
displayName=S("HV Solar Array"),
|
||||
capacity=industrialtest.api.hvPowerFlow*2,
|
||||
flow=industrialtest.api.hvPowerFlow
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:hv_solar_array",
|
||||
recipe={
|
||||
{"industrialtest:mv_solar_array","industrialtest:mv_solar_array","industrialtest:mv_solar_array"},
|
||||
{"industrialtest:mv_solar_array","industrialtest:hv_transformer","industrialtest:mv_solar_array"},
|
||||
{"industrialtest:mv_solar_array","industrialtest:mv_solar_array","industrialtest:mv_solar_array"}
|
||||
}
|
||||
})
|
190
machines/transformer.lua
Normal file
190
machines/transformer.lua
Normal file
@ -0,0 +1,190 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local transformer={}
|
||||
|
||||
transformer.onConstruct=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
industrialtest.api.addPowerStorage(meta,config.upperFlow,0,"aaaaaa")
|
||||
end
|
||||
|
||||
transformer.onTimer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local node=minetest.get_node(pos)
|
||||
local neighbourPositions={
|
||||
vector.offset(pos,-1,0,0),
|
||||
vector.offset(pos,1,0,0),
|
||||
vector.offset(pos,0,-1,0),
|
||||
vector.offset(pos,0,1,0),
|
||||
vector.offset(pos,0,0,-1),
|
||||
vector.offset(pos,0,0,1)
|
||||
}
|
||||
local upperPowerDistribution=0
|
||||
local lowerPowerDistribution=0
|
||||
|
||||
for key,value in ipairs(neighbourPositions) do
|
||||
local normalized=industrialtest.api.normalizeSide(pos,key)
|
||||
if industrialtest.api.hasPowerStorage(minetest.get_meta(value)) and industrialtest.api.isPowerOutput(meta,normalized) then
|
||||
if normalized==5 then
|
||||
upperPowerDistribution=config.upperFlow
|
||||
else
|
||||
lowerPowerDistribution=lowerPowerDistribution+1
|
||||
end
|
||||
else
|
||||
neighbourPositions[key]=0
|
||||
end
|
||||
end
|
||||
if lowerPowerDistribution>0 then
|
||||
lowerPowerDistribution=math.floor(industrialtest.internal.clamp(math.min(config.upperFlow,meta:get_int("industrialtest.powerAmount"))/lowerPowerDistribution,0,config.lowerFlow))
|
||||
end
|
||||
|
||||
local roomAvailable=false
|
||||
for key,value in ipairs(neighbourPositions) do
|
||||
if value~=0 then
|
||||
local neighbourMeta=minetest.get_meta(value)
|
||||
local normalized=industrialtest.api.normalizeSide(pos,key)
|
||||
if normalized==5 then
|
||||
if meta:get_int("industrialtest.powerAmount")==config.upperFlow then
|
||||
industrialtest.api.transferPower(meta,neighbourMeta,config.upperFlow)
|
||||
end
|
||||
else
|
||||
industrialtest.api.transferPower(meta,neighbourMeta,lowerPowerDistribution)
|
||||
end
|
||||
if not industrialtest.api.isFullyCharged(neighbourMeta) then
|
||||
roomAvailable=true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
meta:set_string("industrialtest.ioConfig","aaaaaa")
|
||||
|
||||
return (meta:get_int("industrialtest.powerAmount")>0 and roomAvailable)
|
||||
end
|
||||
|
||||
transformer.onPowerFlow=function(pos,side)
|
||||
industrialtest.api.changeIoConfig(minetest.get_meta(pos),industrialtest.api.normalizeSide(pos,side),"i")
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
|
||||
local function registerTransformer(config)
|
||||
local definition={
|
||||
description=config.displayName,
|
||||
tiles={
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png",
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png",
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png",
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png",
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_side.png",
|
||||
config.machineBlockTexture.."^industrialtest_"..config.name.."_front.png"
|
||||
},
|
||||
paramtype2="facedir",
|
||||
legacy_facedir_simple=true,
|
||||
drop=(config.requiresWrench and "industrialtest:machine_block" or "industrialtest:"..config.name),
|
||||
on_construct=transformer.onConstruct,
|
||||
on_timer=transformer.onTimer,
|
||||
_industrialtest_onPowerFlow=transformer.onPowerFlow
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.groups={cracky=2}
|
||||
definition.sounds=(config.sounds=="metal" and default.node_sound_metal_defaults() or default.node_sound_wood_defaults())
|
||||
elseif industrialtest.mclAvailable then
|
||||
definition.groups={pickaxey=1}
|
||||
definition.sounds=(config.sounds=="metal" and mcl_sounds.node_sound_metal_defaults() or mcl_sounds.node_sound_wood_defaults())
|
||||
definition._mcl_blast_resistance=3
|
||||
definition._mcl_hardness=3.5
|
||||
end
|
||||
definition.groups._industrialtest_hasPowerInput=1
|
||||
definition.groups._industrialtest_hasPowerOutput=1
|
||||
definition.groups._industrialtest_wrenchUnmountable=1
|
||||
minetest.register_node("industrialtest:"..config.name,definition)
|
||||
end
|
||||
|
||||
registerTransformer({
|
||||
name="lv_transformer",
|
||||
displayName="LV Transformer",
|
||||
machineBlockTexture="industrialtest_wood_machine_block.png",
|
||||
requiresWrench=false,
|
||||
lowerFlow=industrialtest.api.lvPowerFlow,
|
||||
upperFlow=industrialtest.api.mvPowerFlow,
|
||||
sounds="wood"
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:lv_transformer",
|
||||
recipe={
|
||||
{"group:wood","industrialtest:insulated_tin_cable","group:wood"},
|
||||
{industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot,industrialtest.elementKeys.copperIngot},
|
||||
{"group:wood","industrialtest:insulated_copper_cable","group:wood"}
|
||||
}
|
||||
})
|
||||
|
||||
registerTransformer({
|
||||
name="mv_transformer",
|
||||
displayName="MV Transformer",
|
||||
machineBlockTexture="industrialtest_machine_block.png",
|
||||
requiresWrench=true,
|
||||
lowerFlow=industrialtest.api.mvPowerFlow,
|
||||
upperFlow=industrialtest.api.hvPowerFlow,
|
||||
sounds="metal"
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:mv_transformer",
|
||||
recipe={
|
||||
{"industrialtest:insulated_copper_cable"},
|
||||
{"industrialtest:machine_block"},
|
||||
{"industrialtest:insulated_gold_cable"}
|
||||
}
|
||||
})
|
||||
|
||||
registerTransformer({
|
||||
name="hv_transformer",
|
||||
displayName="HV Transformer",
|
||||
machineBlockTexture="industrialtest_machine_block.png",
|
||||
requiresWrench=true,
|
||||
lowerFlow=industrialtest.api.hvPowerFlow,
|
||||
upperFlow=industrialtest.api.evPowerFlow,
|
||||
sounds="metal"
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:hv_transformer",
|
||||
recipe={
|
||||
{"","industrialtest:insulated_iron_cable",""},
|
||||
{"industrialtest:electronic_circuit","industrialtest:mv_transformer","industrialtest:energy_crystal"},
|
||||
{"","industrialtest:insulated_iron_cable",""}
|
||||
}
|
||||
})
|
||||
|
||||
registerTransformer({
|
||||
name="ev_transformer",
|
||||
displayName="EV Transformer",
|
||||
machineBlockTexture="industrialtest_machine_block.png",
|
||||
requiresWrench=true,
|
||||
lowerFlow=industrialtest.api.evPowerFlow,
|
||||
upperFlow=industrialtest.api.ivPowerFlow,
|
||||
sounds="metal"
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:ev_transformer",
|
||||
recipe={
|
||||
{"","industrialtest:insulated_iron_cable",""},
|
||||
{"industrialtest:advanced_electronic_circuit","industrialtest:hv_transformer","industrialtest:lapotron_crystal"},
|
||||
{"","industrialtest:insulated_iron_cable",""}
|
||||
}
|
||||
})
|
131
machines/wind_mill.lua
Normal file
131
machines/wind_mill.lua
Normal file
@ -0,0 +1,131 @@
|
||||
-- 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/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
local windMill={}
|
||||
|
||||
windMill.getFormspec=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local charging=meta:get_int("charging")
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"list[context;charged;4.9,1.8;1,1]",
|
||||
"listring[context;charged]",
|
||||
(charging>0 and "image[4.9,3;1,1;industrialtest_gui_wind_bg.png^[lowpart:"..charging..":industrialtest_gui_wind_fg.png]"
|
||||
or "image[4.9,3;1,1;industrialtest_gui_wind_bg.png]")
|
||||
}
|
||||
elseif industrialtest.mclAvailable then
|
||||
formspec={
|
||||
"list[context;charged;4.7,1.8;1,1]",
|
||||
mcl_formspec.get_itemslot_bg(4.7,1.8,1,1),
|
||||
"listring[context;charged]",
|
||||
(charging>0 and "image[4.7,3;1,1;industrialtest_gui_wind_bg.png^[lowpart:"..charging..":industrialtest_gui_wind_fg.png]"
|
||||
or "image[4.7,3;1,1;industrialtest_gui_wind_bg.png]")
|
||||
}
|
||||
end
|
||||
return table.concat(formspec,"")
|
||||
end
|
||||
|
||||
windMill.onConstruct=function(pos,meta,inv)
|
||||
inv:set_size("charged",1)
|
||||
meta:set_int("prevCharging",0)
|
||||
meta:set_int("charging",0)
|
||||
end
|
||||
|
||||
windMill.onTimer=function(pos,elapsed,meta,inv)
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local shouldUpdateFormspec=false
|
||||
local charging
|
||||
if industrialtest.mtgAvailable then
|
||||
charging=math.min(math.max(pos.y,0)/150,1.0)
|
||||
elseif industrialtest.mclAvailable then
|
||||
local dimMax=31000
|
||||
local dim=mcl_worlds.pos_to_dimension(pos)
|
||||
if dim=="overworld" then
|
||||
dimMax=mcl_vars.mg_overworld_max
|
||||
elseif dim=="nether" then
|
||||
dimMax=mcl_vars.mg_nether_max
|
||||
elseif dim=="end" then
|
||||
dimMax=mcl_vars.mg_end_max
|
||||
end
|
||||
charging=math.max(mcl_worlds.layer_to_y(pos.y,dim),0)/dimMax
|
||||
end
|
||||
local neighbourPositions={
|
||||
vector.offset(pos,-1,0,0),
|
||||
vector.offset(pos,1,0,0),
|
||||
vector.offset(pos,0,0,-1),
|
||||
vector.offset(pos,0,0,1)
|
||||
}
|
||||
for _,value in ipairs(neighbourPositions) do
|
||||
local node=minetest.get_node_or_nil(value)
|
||||
if node and node.name~="air" then
|
||||
charging=0
|
||||
break
|
||||
end
|
||||
end
|
||||
industrialtest.api.addPower(meta,math.ceil(charging*elapsed*industrialtest.api.lvPowerFlow))
|
||||
if meta:get_int("prevCharging")~=charging then
|
||||
shouldUpdateFormspec=true
|
||||
end
|
||||
if chargedSlot:get_count()>0 and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
if industrialtest.api.transferPowerToItem(meta,chargedSlot,industrialtest.api.lvPowerFlow)>0 then
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
end
|
||||
end
|
||||
industrialtest.api.powerFlow(pos)
|
||||
meta:set_int("charging",charging*100)
|
||||
return true,shouldUpdateFormspec
|
||||
end
|
||||
|
||||
industrialtest.internal.registerMachine({
|
||||
name="wind_mill",
|
||||
displayName=S("Wind Mill"),
|
||||
getFormspec=windMill.getFormspec,
|
||||
capacity=7000,
|
||||
flow=industrialtest.api.lvPowerFlow,
|
||||
ioConfig="oooooo",
|
||||
requiresWrench=true,
|
||||
registerActiveVariant=false,
|
||||
powerSlots={"charged"},
|
||||
storageSlots={"charged"},
|
||||
sounds="metal",
|
||||
groups={
|
||||
_industrialtest_hasPowerOutput=1
|
||||
},
|
||||
customKeys={
|
||||
tiles={
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png",
|
||||
"industrialtest_machine_block.png^industrialtest_wind_mill_side.png",
|
||||
"industrialtest_machine_block.png^industrialtest_wind_mill_side.png",
|
||||
"industrialtest_machine_block.png^industrialtest_wind_mill_side.png",
|
||||
"industrialtest_machine_block.png^industrialtest_wind_mill_side.png"
|
||||
}
|
||||
},
|
||||
onConstruct=windMill.onConstruct,
|
||||
onTimer=windMill.onTimer
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:wind_mill",
|
||||
recipe={
|
||||
{"","industrialtest:refined_iron_ingot",""},
|
||||
{"industrialtest:refined_iron_ingot","industrialtest:generator","industrialtest:refined_iron_ingot"},
|
||||
{"","industrialtest:refined_iron_ingot",""}
|
||||
}
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user