Add active machine variations
This commit is contained in:
parent
618ccfedc2
commit
e104ff8931
329
machines.lua
329
machines.lua
|
@ -121,14 +121,13 @@ local definition={
|
|||
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
|
||||
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
|
||||
end
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",generatorFormspec(meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")))
|
||||
|
@ -180,6 +179,71 @@ elseif industrialtest.mclAvailable then
|
|||
end
|
||||
definition.groups._industrialtest_hasPowerOutput=1
|
||||
minetest.register_node("industrialtest:generator",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.drop="industrialtest:generator"
|
||||
definition.light_source=8
|
||||
definition.on_timer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local powerFlow=meta:get_int("industrialtest.powerFlow")
|
||||
local inv=meta:get_inventory()
|
||||
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])
|
||||
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
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",generatorFormspec(meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
end
|
||||
if industrialtest.mclAvailable then
|
||||
definition.groups.not_in_creative_inventory=1
|
||||
definition._doc_items_create_entry=false
|
||||
end
|
||||
minetest.register_node("industrialtest:generator_active",definition)
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:generator",
|
||||
|
@ -370,30 +434,13 @@ local function registerSimpleElectricItemProcessor(config)
|
|||
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)
|
||||
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 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("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
|
||||
|
@ -492,6 +539,86 @@ local function registerSimpleElectricItemProcessor(config)
|
|||
end
|
||||
definition.groups._industrialtest_hasPowerInput=1
|
||||
minetest.register_node("industrialtest:"..config.name,definition)
|
||||
definition=table.copy(definition)
|
||||
definition.description=nil
|
||||
definition.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 "")
|
||||
}
|
||||
definition.drop="industrialtest:"..config.name
|
||||
definition.on_timer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
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
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
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
|
||||
|
||||
local function ironFurnaceFormspec(fuelPercent,srcPercent)
|
||||
|
@ -589,47 +716,14 @@ definition={
|
|||
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 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)
|
||||
end
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
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",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
|
||||
|
@ -705,6 +799,107 @@ elseif industrialtest.mclAvailable then
|
|||
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=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",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
|
||||
end
|
||||
|
||||
return shouldRerunTimer
|
||||
end
|
||||
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",
|
||||
|
@ -820,4 +1015,4 @@ minetest.register_craft({
|
|||
{industrialtest.elementKeys.dirt,"industrialtest:compressor",industrialtest.elementKeys.dirt},
|
||||
{"industrialtest:refined_iron_ingot",industrialtest.elementKeys.dirt,"industrialtest:refined_iron_ingot"}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue