Implement Wind Mill

This commit is contained in:
mrkubax10 2023-04-03 21:26:41 +02:00
parent 190f83a60f
commit aa41f5c36a
3 changed files with 151 additions and 0 deletions

View File

@ -788,6 +788,157 @@ minetest.register_craft({
}
})
local function windMillFormspec(charging)
local formspec
if industrialtest.mtgAvailable then
formspec={
"formspec_version[4]",
"size[10.8,12]",
"label[0.5,0.5;"..S("Wind Mill").."]",
"list[context;charged;4.9,1.8;1,1]",
"listring[context;charged]",
(charging>0 and "image[4.9,2.8;1,1;industrialtest_gui_wind_bg.png^[lowpart:"..charging..":industrialtest_gui_wind_fg.png]"
or "image[4.9,2.8;1,1;industrialtest_gui_wind_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("Wind Mill").."]",
"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,2.8;1,1;industrialtest_gui_wind_bg.png^[lowpart:"..charging..":industrialtest_gui_wind_fg.png]"
or "image[4.7,2.8;1,1;industrialtest_gui_wind_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("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"
},
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_int("prevCharging",0)
meta:set_string("formspec",windMillFormspec(0))
industrialtest.api.addPowerStorage(meta,7000,industrialtest.api.lvPowerFlow,"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 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
minetest.chat_send_all("charging")
end
industrialtest.api.powerFlow(pos)
if shouldUpdateFormspec then
meta:set_string("formspec",windMillFormspec(charging*100))
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 itemstack=inv:get_stack(fromList,fromIndex)
if toList=="charged" and not industrialtest.api.hasPowerStorage(itemstack:get_meta()) then
return 0
end
return count
end,
allow_metadata_inventory_put=function(pos,listname,index,stack)
if toList=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
return 0
end
return stack:get_count()
end
}
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 inv:get_list("charged")[1]:get_count()==0
end
elseif industrialtest.mclAvailable then
definition.after_dig_node=function(pos,oldnode,oldmeta)
mclAfterDigNode(pos,oldmeta,{"charged"})
end
definition.groups={pickaxey=1}
definition.sounds=mcl_sounds.node_sound_metal_defaults()
definition._mcl_blast_resistance=3
definition._mcl_hardness=3.5
end
definition.groups._industrialtest_hasPowerOutput=1
definition.groups._industrialtest_wrenchUnmountable=1
minetest.register_node("industrialtest:wind_mill",definition)
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",""}
}
})
-- Item processing machines
local function registerSimpleElectricItemProcessor(config)
local function getFormspec(powerPercent,srcPercent)

Binary file not shown.

After

Width:  |  Height:  |  Size: 882 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B