Refactor Wind Mill
This commit is contained in:
parent
0ac1dd0e49
commit
1343aa2c23
@ -15,9 +15,46 @@
|
|||||||
-- 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")
|
||||||
local windMill={}
|
industrialtest.WindMill=table.copy(industrialtest.ElectricMachine)
|
||||||
|
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",
|
||||||
|
})
|
||||||
|
|
||||||
windMill.getFormspec=function(pos)
|
function industrialtest.WindMill.onConstruct(self,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={
|
||||||
@ -27,18 +64,11 @@ windMill.getFormspec=function(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 table.concat(formspec,"")
|
return parentFormspec..table.concat(formspec,"")
|
||||||
end
|
end
|
||||||
|
|
||||||
windMill.onConstruct=function(pos,meta,inv)
|
function industrialtest.WindMill.action(self,pos)
|
||||||
inv:set_size("charged",1)
|
local meta=minetest.get_meta(pos)
|
||||||
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)
|
||||||
@ -67,48 +97,17 @@ windMill.onTimer=function(pos,elapsed,meta,inv)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
industrialtest.api.addPower(meta,math.ceil(charging*elapsed*industrialtest.api.lvPowerFlow))
|
if industrialtest.api.addPower(meta,math.ceil(charging*industrialtest.api.lvPowerFlow))>0 then
|
||||||
|
self:trigger(pos)
|
||||||
|
end
|
||||||
if meta:get_int("prevCharging")~=charging then
|
if meta:get_int("prevCharging")~=charging then
|
||||||
shouldUpdateFormspec=true
|
meta:set_int("prevCharging",charging)
|
||||||
|
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.internal.registerMachine({
|
industrialtest.WindMill:register()
|
||||||
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",
|
||||||
@ -119,3 +118,13 @@ 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