Implement solar panels
This commit is contained in:
parent
9db6ea9ced
commit
e36624f327
155
machines.lua
155
machines.lua
@ -244,7 +244,6 @@ if industrialtest.mclAvailable then
|
||||
definition._doc_items_create_entry=false
|
||||
end
|
||||
minetest.register_node("industrialtest:generator_active",definition)
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:generator",
|
||||
@ -264,6 +263,160 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
local function registerSolarPanelGenerator(config)
|
||||
local function getFormspec(charging)
|
||||
local formspec
|
||||
if industrialtest.mtgAvailable then
|
||||
formspec={
|
||||
"formspec_version[4]",
|
||||
"size[10.8,12]",
|
||||
"label[0.5,0.5;"..S(config.displayName).."]",
|
||||
"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]"),
|
||||
"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(config.displayName).."]",
|
||||
"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]"),
|
||||
"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
|
||||
definition={
|
||||
description=S(config.displayName),
|
||||
tiles={
|
||||
"industrialtest_"..config.name.."_top.png",
|
||||
"industrialtest_machine_block.png"
|
||||
},
|
||||
drop="industrialtest:machine_block",
|
||||
on_construct=function(pos)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
inv:set_size("charged",1)
|
||||
meta:set_string("formspec",getFormspec(false))
|
||||
meta:set_float("prevAmount",0)
|
||||
industrialtest.api.addPowerStorage(meta,config.capacity,config.flow,"oooooo")
|
||||
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 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
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",getFormspec(charging))
|
||||
end
|
||||
|
||||
return true
|
||||
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_list(fromList)[1]
|
||||
if toList=="charged" and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put=function(pos,listname,index,stack)
|
||||
if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_metadata_inventory_put=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end,
|
||||
on_metadata_inventory_take=function(pos)
|
||||
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
|
||||
end
|
||||
}
|
||||
if industrialtest.mtgAvailable then
|
||||
definition.groups={cracky=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 inv:get_list("charged")[1]:get_count()==0
|
||||
end
|
||||
elseif industrialtest.mclAvailable then
|
||||
definition.groups={pickaxey=1}
|
||||
definition.sounds=mcl_sounds.node_sound_metal_defaults()
|
||||
definition._mcl_blast_resistance=1
|
||||
definition._mcl_hardness=3.9
|
||||
definition.after_dig_node=function(pos,oldnode,oldmeta)
|
||||
mclAfterDigNode(pos,oldmeta,{"charged"})
|
||||
end
|
||||
end
|
||||
definition.groups._industrialtest_hasPowerOutput=1
|
||||
definition.groups._industrialtest_wrenchUnmountable=1
|
||||
minetest.register_node("industrialtest:"..config.name,definition)
|
||||
end
|
||||
registerSolarPanelGenerator({
|
||||
name="solar_panel",
|
||||
displayName="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="LV Solar Array",
|
||||
capacity=industrialtest.api.lvPowerFlow*4,
|
||||
flow=industrialtest.api.lvPowerFlow*2
|
||||
})
|
||||
registerSolarPanelGenerator({
|
||||
name="mv_solar_array",
|
||||
displayName="MV Solar Array",
|
||||
capacity=industrialtest.api.mvPowerFlow*2,
|
||||
flow=industrialtest.api.mvPowerFlow
|
||||
})
|
||||
registerSolarPanelGenerator({
|
||||
name="hv_solar_array",
|
||||
displayName="HV Solar Array",
|
||||
capacity=industrialtest.api.hvPowerFlow*2,
|
||||
flow=industrialtest.api.hvPowerFlow
|
||||
})
|
||||
-- TODO: Crafts for solar arrays
|
||||
|
||||
-- Item processing machines
|
||||
local function registerSimpleElectricItemProcessor(config)
|
||||
local function getFormspec(powerPercent,srcPercent)
|
||||
|
BIN
textures/industrialtest_gui_sun_bg.png
Normal file
BIN
textures/industrialtest_gui_sun_bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 730 B |
BIN
textures/industrialtest_gui_sun_fg.png
Normal file
BIN
textures/industrialtest_gui_sun_fg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 746 B |
Loading…
Reference in New Issue
Block a user