Compare commits
No commits in common. "1343aa2c237592baa27821ddfa19e35b94e03570" and "329dd0e293505d777bb6717f8ff40bba27073d82" have entirely different histories.
1343aa2c23
...
329dd0e293
@ -15,35 +15,9 @@
|
|||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
local S=minetest.get_translator("industrialtest")
|
||||||
industrialtest.SolarPanelBase=table.copy(industrialtest.ElectricMachine)
|
local solarPanel={}
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.SolarPanelBase,{
|
|
||||||
sounds="metal",
|
|
||||||
requiresWrench=true,
|
|
||||||
storageLists={
|
|
||||||
"charged"
|
|
||||||
},
|
|
||||||
powerLists={
|
|
||||||
{
|
|
||||||
list="charged",
|
|
||||||
direction="o"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
hasPowerOutput=true,
|
|
||||||
ioConfig="oooooo"
|
|
||||||
})
|
|
||||||
|
|
||||||
local solarPanels={}
|
solarPanel.getFormspec=function(pos)
|
||||||
|
|
||||||
function industrialtest.SolarPanelBase.onConstruct(self,pos)
|
|
||||||
local meta=minetest.get_meta(pos)
|
|
||||||
local inv=meta:get_inventory()
|
|
||||||
inv:set_size("charged",1)
|
|
||||||
meta:set_float("prevAmount",0)
|
|
||||||
industrialtest.ElectricMachine.onConstruct(self,pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
function industrialtest.SolarPanelBase.getFormspec(self,pos)
|
|
||||||
local parentFormspec=industrialtest.ElectricMachine.getFormspec(self,pos)
|
|
||||||
local amount=minetest.get_natural_light(vector.offset(pos,0,1,0))/15.0
|
local amount=minetest.get_natural_light(vector.offset(pos,0,1,0))/15.0
|
||||||
local charging=amount>0.5
|
local charging=amount>0.5
|
||||||
local formspec={
|
local formspec={
|
||||||
@ -53,48 +27,71 @@ function industrialtest.SolarPanelBase.getFormspec(self,pos)
|
|||||||
or "image[4.7,2.8;1,1;industrialtest_gui_sun_bg.png]"),
|
or "image[4.7,2.8;1,1;industrialtest_gui_sun_bg.png]"),
|
||||||
"listring[context;charged]"
|
"listring[context;charged]"
|
||||||
}
|
}
|
||||||
return parentFormspec..table.concat(formspec,"")
|
return table.concat(formspec,"")
|
||||||
end
|
end
|
||||||
|
|
||||||
function industrialtest.SolarPanelBase.register(self)
|
solarPanel.onConstruct=function(pos,meta,inv)
|
||||||
industrialtest.ElectricMachine.register(self)
|
inv:set_size("charged",1)
|
||||||
table.insert(solarPanels,self.name)
|
meta:set_float("prevAmount",0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function industrialtest.SolarPanelBase.action(self,pos)
|
solarPanel.onTimer=function(pos,elapsed,meta,inv,config)
|
||||||
local meta=minetest.get_meta(pos)
|
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 amount=minetest.get_natural_light(vector.offset(pos,0,1,0))/15.0
|
||||||
local charging=amount>0.5
|
local charging=amount>0.5
|
||||||
if charging then
|
if charging then
|
||||||
if industrialtest.api.addPower(meta,math.ceil(amount*self.flow))>0 then
|
industrialtest.api.addPower(meta,math.ceil(amount*config.flow*elapsed))
|
||||||
self:updateFormspec(pos)
|
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
|
end
|
||||||
self:trigger(pos)
|
industrialtest.api.powerFlow(pos)
|
||||||
end
|
end
|
||||||
if amount~=meta:get_float("prevAmount") then
|
if amount~=meta:get_float("prevAmount") then
|
||||||
self:updateFormspec(pos)
|
shouldUpdateFormspec=true
|
||||||
meta:set_float("prevAmount",amount)
|
meta:set_float("prevAmount",amount)
|
||||||
end
|
end
|
||||||
|
return true,shouldUpdateFormspec
|
||||||
end
|
end
|
||||||
|
|
||||||
industrialtest.SolarPanel=table.copy(industrialtest.SolarPanelBase)
|
local function registerSolarPanelGenerator(config)
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.SolarPanel,{
|
industrialtest.internal.registerMachine({
|
||||||
name="industrialtest:solar_panel",
|
name=config.name,
|
||||||
description=S("Solar Panel"),
|
displayName=config.displayName,
|
||||||
tiles={
|
getFormspec=solarPanel.getFormspec,
|
||||||
"industrialtest_machine_block.png^industrialtest_solar_panel_top.png",
|
capacity=config.capacity,
|
||||||
"industrialtest_machine_block.png",
|
flow=config.flow,
|
||||||
"industrialtest_machine_block.png",
|
ioConfig="oooooo",
|
||||||
"industrialtest_machine_block.png",
|
requiresWrench=true,
|
||||||
"industrialtest_machine_block.png",
|
registerActiveVariant=false,
|
||||||
"industrialtest_machine_block.png"
|
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)
|
||||||
|
return solarPanel.onTimer(pos,elapsed,meta,inv,config)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
registerSolarPanelGenerator({
|
||||||
|
name="solar_panel",
|
||||||
|
displayName=S("Solar Panel"),
|
||||||
capacity=industrialtest.api.lvPowerFlow*2,
|
capacity=industrialtest.api.lvPowerFlow*2,
|
||||||
flow=industrialtest.api.lvPowerFlow
|
flow=industrialtest.api.lvPowerFlow
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.SolarPanel:register()
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:solar_panel",
|
output="industrialtest:solar_panel",
|
||||||
@ -105,24 +102,12 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.LVSolarArray=table.copy(industrialtest.SolarPanelBase)
|
registerSolarPanelGenerator({
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.LVSolarArray,{
|
name="lv_solar_array",
|
||||||
name="industrialtest:lv_solar_array",
|
displayName=S("LV Solar Array"),
|
||||||
description=S("LV Solar Array"),
|
|
||||||
tiles={
|
|
||||||
"industrialtest_machine_block.png^industrialtest_lv_solar_array_top.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png"
|
|
||||||
},
|
|
||||||
capacity=industrialtest.api.lvPowerFlow*4,
|
capacity=industrialtest.api.lvPowerFlow*4,
|
||||||
flow=industrialtest.api.lvPowerFlow*2
|
flow=industrialtest.api.lvPowerFlow*2
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.LVSolarArray:register()
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:lv_solar_array",
|
output="industrialtest:lv_solar_array",
|
||||||
@ -133,24 +118,12 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.MVSolarArray=table.copy(industrialtest.SolarPanelBase)
|
registerSolarPanelGenerator({
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.MVSolarArray,{
|
name="mv_solar_array",
|
||||||
name="industrialtest:mv_solar_array",
|
displayName=S("MV Solar Array"),
|
||||||
description=S("MV Solar Array"),
|
|
||||||
tiles={
|
|
||||||
"industrialtest_machine_block.png^industrialtest_mv_solar_array_top.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png"
|
|
||||||
},
|
|
||||||
capacity=industrialtest.api.mvPowerFlow*2,
|
capacity=industrialtest.api.mvPowerFlow*2,
|
||||||
flow=industrialtest.api.mvPowerFlow
|
flow=industrialtest.api.mvPowerFlow
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.MVSolarArray:register()
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:mv_solar_array",
|
output="industrialtest:mv_solar_array",
|
||||||
@ -161,25 +134,12 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerSolarPanelGenerator({
|
||||||
industrialtest.HVSolarArray=table.copy(industrialtest.SolarPanelBase)
|
name="hv_solar_array",
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.HVSolarArray,{
|
displayName=S("HV Solar Array"),
|
||||||
name="industrialtest:hv_solar_array",
|
|
||||||
description=S("HV Solar Array"),
|
|
||||||
tiles={
|
|
||||||
"industrialtest_machine_block.png^industrialtest_hv_solar_array_top.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png",
|
|
||||||
"industrialtest_machine_block.png"
|
|
||||||
},
|
|
||||||
capacity=industrialtest.api.hvPowerFlow*2,
|
capacity=industrialtest.api.hvPowerFlow*2,
|
||||||
flow=industrialtest.api.hvPowerFlow
|
flow=industrialtest.api.hvPowerFlow
|
||||||
})
|
})
|
||||||
|
|
||||||
industrialtest.HVSolarArray:register()
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
output="industrialtest:hv_solar_array",
|
output="industrialtest:hv_solar_array",
|
||||||
@ -189,14 +149,3 @@ minetest.register_craft({
|
|||||||
{"industrialtest:mv_solar_array","industrialtest:mv_solar_array","industrialtest:mv_solar_array"}
|
{"industrialtest:mv_solar_array","industrialtest:mv_solar_array","industrialtest:mv_solar_array"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
name="Solar panel updating",
|
|
||||||
nodenames=solarPanels,
|
|
||||||
interval=industrialtest.updateDelay,
|
|
||||||
chance=1,
|
|
||||||
action=function(pos,node)
|
|
||||||
local def=minetest.registered_nodes[node.name]
|
|
||||||
def._industrialtest_self:action(pos)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
@ -15,46 +15,9 @@
|
|||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
local S=minetest.get_translator("industrialtest")
|
||||||
industrialtest.WindMill=table.copy(industrialtest.ElectricMachine)
|
local windMill={}
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.WindMill,{
|
|
||||||
name="industrialtest:wind_mill",
|
|
||||||
description=S("Wind Mill"),
|
|
||||||
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"
|
|
||||||
},
|
|
||||||
sounds="metal",
|
|
||||||
requiresWrench=true,
|
|
||||||
storageLists={
|
|
||||||
"charged"
|
|
||||||
},
|
|
||||||
powerLists={
|
|
||||||
{
|
|
||||||
list="charged",
|
|
||||||
direction="o"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
capacity=7000,
|
|
||||||
flow=industrialtest.api.lvPowerFlow,
|
|
||||||
hasPowerOutput=true,
|
|
||||||
ioConfig="oooooo",
|
|
||||||
})
|
|
||||||
|
|
||||||
function industrialtest.WindMill.onConstruct(self,pos)
|
windMill.getFormspec=function(pos)
|
||||||
local meta=minetest.get_meta(pos)
|
|
||||||
local inv=meta:get_inventory()
|
|
||||||
inv:set_size("charged",1)
|
|
||||||
meta:set_int("prevCharging",0)
|
|
||||||
meta:set_int("charging",0)
|
|
||||||
industrialtest.ElectricMachine.onConstruct(self,pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
function industrialtest.WindMill.getFormspec(self,pos)
|
|
||||||
local parentFormspec=industrialtest.ElectricMachine.getFormspec(self,pos)
|
|
||||||
local meta=minetest.get_meta(pos)
|
local meta=minetest.get_meta(pos)
|
||||||
local charging=meta:get_int("charging")
|
local charging=meta:get_int("charging")
|
||||||
local formspec={
|
local formspec={
|
||||||
@ -64,11 +27,18 @@ function industrialtest.WindMill.getFormspec(self,pos)
|
|||||||
or "image[4.7,3;1,1;industrialtest_gui_wind_bg.png]"),
|
or "image[4.7,3;1,1;industrialtest_gui_wind_bg.png]"),
|
||||||
"listring[context;charged]"
|
"listring[context;charged]"
|
||||||
}
|
}
|
||||||
return parentFormspec..table.concat(formspec,"")
|
return table.concat(formspec,"")
|
||||||
end
|
end
|
||||||
|
|
||||||
function industrialtest.WindMill.action(self,pos)
|
windMill.onConstruct=function(pos,meta,inv)
|
||||||
local meta=minetest.get_meta(pos)
|
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
|
local charging
|
||||||
if industrialtest.mtgAvailable then
|
if industrialtest.mtgAvailable then
|
||||||
charging=math.min(math.max(pos.y,0)/150,1.0)
|
charging=math.min(math.max(pos.y,0)/150,1.0)
|
||||||
@ -97,17 +67,48 @@ function industrialtest.WindMill.action(self,pos)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if industrialtest.api.addPower(meta,math.ceil(charging*industrialtest.api.lvPowerFlow))>0 then
|
industrialtest.api.addPower(meta,math.ceil(charging*elapsed*industrialtest.api.lvPowerFlow))
|
||||||
self:trigger(pos)
|
|
||||||
end
|
|
||||||
if meta:get_int("prevCharging")~=charging then
|
if meta:get_int("prevCharging")~=charging then
|
||||||
meta:set_int("prevCharging",charging)
|
shouldUpdateFormspec=true
|
||||||
self:updateFormspec(pos)
|
|
||||||
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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
industrialtest.api.powerFlow(pos)
|
||||||
meta:set_int("charging",charging*100)
|
meta:set_int("charging",charging*100)
|
||||||
|
return true,shouldUpdateFormspec
|
||||||
end
|
end
|
||||||
|
|
||||||
industrialtest.WindMill:register()
|
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({
|
minetest.register_craft({
|
||||||
type="shaped",
|
type="shaped",
|
||||||
@ -118,13 +119,3 @@ minetest.register_craft({
|
|||||||
{"","industrialtest:refined_iron_ingot",""}
|
{"","industrialtest:refined_iron_ingot",""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
name="Wind mill updating",
|
|
||||||
nodenames={"industrialtest:wind_mill"},
|
|
||||||
interval=industrialtest.updateDelay,
|
|
||||||
chance=1,
|
|
||||||
action=function(pos)
|
|
||||||
industrialtest.WindMill:action(pos)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user