From aa41f5c36aa89a679aa9f4b1c48cfa597caefa15 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Mon, 3 Apr 2023 21:26:41 +0200 Subject: [PATCH] Implement Wind Mill --- machines.lua | 151 ++++++++++++++++++++++++ textures/industrialtest_gui_wind_bg.png | Bin 0 -> 882 bytes textures/industrialtest_gui_wind_fg.png | Bin 0 -> 863 bytes 3 files changed, 151 insertions(+) create mode 100644 textures/industrialtest_gui_wind_bg.png create mode 100644 textures/industrialtest_gui_wind_fg.png diff --git a/machines.lua b/machines.lua index 2aa1ce9..5a399c0 100644 --- a/machines.lua +++ b/machines.lua @@ -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) diff --git a/textures/industrialtest_gui_wind_bg.png b/textures/industrialtest_gui_wind_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..0f5504ebde05effda17f11e7de44e356e5482aa5 GIT binary patch literal 882 zcmV-&1C9KNP)EX>4Tx04R}tkv&MmKpe$iKcpfRK|6>zWT;LSL`6gwtwIqhgj%6h2a`*`ph-iL z;^HW{799LotU9+0Yt2!bCVt}afBE>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