From 9c481b6055f6ab74d21f1cb873cffd23bcab7d59 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Fri, 8 Feb 2019 19:21:25 +0200 Subject: [PATCH] tool repairing machine --- .../machines/evaporation_plant.lua | 7 +- elepower_tools/crafting.lua | 19 +++ elepower_tools/craftitems.lua | 6 + elepower_tools/ed_reconstructor.lua | 136 ++++++++++++++++++ elepower_tools/init.lua | 3 + .../elepower_machine_ed_reconstructor.png | Bin 0 -> 520 bytes .../textures/eletools_repair_core.png | Bin 0 -> 353 bytes 7 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 elepower_tools/ed_reconstructor.lua create mode 100644 elepower_tools/textures/elepower_machine_ed_reconstructor.png create mode 100644 elepower_tools/textures/eletools_repair_core.png diff --git a/elepower_thermal/machines/evaporation_plant.lua b/elepower_thermal/machines/evaporation_plant.lua index 76ffc90..ead6faa 100644 --- a/elepower_thermal/machines/evaporation_plant.lua +++ b/elepower_thermal/machines/evaporation_plant.lua @@ -200,7 +200,12 @@ local function controller_timer (pos, elapsed) local outp_perc = math.floor(heat_perc * recipe.output:get_count()) if in_buffer.amount < take_perc then - break + if in_buffer.amount <= 0 then + break + end + + take_perc = in_buffer.amount + outp_perc = math.floor(take_perc / recipe.output:get_count()) end if out_buffer.amount + outp_perc > out_buffer.capacity then diff --git a/elepower_tools/crafting.lua b/elepower_tools/crafting.lua index 13ed058..10ff211 100644 --- a/elepower_tools/crafting.lua +++ b/elepower_tools/crafting.lua @@ -45,3 +45,22 @@ minetest.register_craft({ {"elepower_dynamics:wound_silver_coil", "", ""}, } }) + +-- Repairing +minetest.register_craft({ + output = "elepower_tools:repair_core", + recipe = { + {"", "default:diamondblock", "elepower_dynamics:steel_plate"}, + {"elepower_dynamics:lead_plate", "elepower_dynamics:xycrone_lump", "elepower_dynamics:lead_plate"}, + {"elepower_dynamics:steel_plate", "default:mese", ""}, + } +}) + +minetest.register_craft({ + output = "elepower_tools:ed_reconstructor", + recipe = { + {"elepower_dynamics:wound_copper_coil", "elepower_dynamics:micro_circuit", "elepower_dynamics:wound_copper_coil"}, + {"elepower_tools:repair_core", "elepower_machines:machine_block", "elepower_tools:repair_core"}, + {"elepower_dynamics:induction_coil", "elepower_dynamics:induction_coil_advanced", "elepower_dynamics:induction_coil"}, + } +}) diff --git a/elepower_tools/craftitems.lua b/elepower_tools/craftitems.lua index d87ad22..24e5dbf 100644 --- a/elepower_tools/craftitems.lua +++ b/elepower_tools/craftitems.lua @@ -8,3 +8,9 @@ minetest.register_craftitem("elepower_tools:chain", { description = "Chainsaw Chain", inventory_image = "eletools_chain.png", }) + +minetest.register_craftitem("elepower_tools:repair_core", { + description = "Repair Core", + inventory_image = "eletools_repair_core.png", + stack_max = 1, +}) diff --git a/elepower_tools/ed_reconstructor.lua b/elepower_tools/ed_reconstructor.lua new file mode 100644 index 0000000..94a75f9 --- /dev/null +++ b/elepower_tools/ed_reconstructor.lua @@ -0,0 +1,136 @@ + +local function get_formspec(power, state) + return "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + ele.formspec.power_meter(power).. + "list[context;tool;3.5,1.5;1,1;]".. + ele.formspec.state_switcher(7, 0, state).. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + "listring[current_player;main]".. + "listring[context;tool]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 4.25) +end + +local function is_tool (istack) + if not minetest.registered_tools[istack:get_name()] then + return false + end + + -- Do not accept (ele)power tools and unrepairable tools + if minetest.get_item_group(istack:get_name(), "ele_tool") > 0 or + minetest.get_item_group(istack:get_name(), "unrepairable") > 0 then + return false + end + + return true +end + +local function ed_timer(pos) + local refresh = false + + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + local capacity = ele.helpers.get_node_property(meta, pos, "capacity") + local usage = ele.helpers.get_node_property(meta, pos, "usage") + local storage = ele.helpers.get_node_property(meta, pos, "storage") + local pow_buffer = {capacity = capacity, storage = storage, usage = 0} + + local state = meta:get_int("state") + local status = "Idle" + + local speed = 1 + + local is_enabled = ele.helpers.state_enabled(meta, pos, state) + local tool = inv:get_stack("tool", 1) + + while true do + if not is_enabled then + status = "Off" + break + end + + if not tool or tool:is_empty() or not is_tool(tool) then + status = "Invalid Input" + break + end + + if pow_buffer.storage < usage then + status = "Out of Power!" + break + end + + local t_wear = tool:get_wear() + if t_wear == 0 then + break + end + + status = "Active" + pow_buffer.usage = usage + pow_buffer.storage = pow_buffer.storage - usage + t_wear = t_wear - 64 * speed + refresh = true + + if t_wear < 0 then t_wear = 0 end + tool:set_wear(t_wear) + + break + end + + if refresh then + inv:set_stack("tool", 1, tool) + end + + meta:set_int("storage", pow_buffer.storage) + + meta:set_string("infotext", ("Energy Density Reconstructor %s\n%s"):format(status, ele.capacity_text(pow_buffer.capacity, pow_buffer.storage))) + meta:set_string("formspec", get_formspec(pow_buffer, state)) + + return refresh +end + +local function allow_metadata_inventory_put(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + if not is_tool(stack) and listname == "tool" then + return 0 + end + + return stack:get_count() +end + +local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + return allow_metadata_inventory_put(pos, to_list, to_index, stack, player) +end + +ele.register_machine("elepower_tools:ed_reconstructor", { + description = "Energy Density Reconstructor\nRepairs tools using energy", + tiles = { + "elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png", + "elepower_machine_side.png", "elepower_machine_side.png", "elepower_machine_ed_reconstructor.png", + }, + groups = {cracky = 1, ele_user = 1}, + on_timer = ed_timer, + ele_usage = 128, + ele_inrush = 128, + on_construct = function (pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("tool", 1) + meta:set_string("formspec", get_formspec()) + end, + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + ele_upgrades = { + capacitor = {"capacity"}, + }, +}) diff --git a/elepower_tools/init.lua b/elepower_tools/init.lua index 5d400c9..df73513 100644 --- a/elepower_tools/init.lua +++ b/elepower_tools/init.lua @@ -16,6 +16,9 @@ dofile(modpath .. "/soldering.lua") dofile(modpath .. "/craftitems.lua") dofile(modpath .. "/crafting.lua") +-- Repair +dofile(modpath .. "/ed_reconstructor.lua") + -- Armor if minetest.get_modpath("3d_armor") then dofile(modpath .. "/armor.lua") diff --git a/elepower_tools/textures/elepower_machine_ed_reconstructor.png b/elepower_tools/textures/elepower_machine_ed_reconstructor.png new file mode 100644 index 0000000000000000000000000000000000000000..2528391ef22896fe14245a57bccbb7a8f6259339 GIT binary patch literal 520 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPggwCN?2`t*fg%rvim!GeaUuobz*Y zQ}arITm}Z`qSVBa)D(sC%#sWRcTeAd6une-pmp({E{-7_$+$gjTkhr*g~CwL z*JYpDl(IACl8LX{oKDy8iVxL`N@TY&JO~jD{To&lIql5zVun?#7Ol%Zqr>SM{Cw~E zwy)BUzMSpZ_x|vkvfZ-hc7_C9HktYR>%L79t}(eeN9|+nK7ab?RT#n$@L=-et&-wt zcV=w7C4Hy#`^*2IUm52-%qltg^W==Ar^esi1@E~86@`Y1XrKR)a^^(^3mYFJ-#42h z&i9vBY`)nN+Wxh5XF`Ky?A_FN47cBYi~f|falz`{2FyA4KO{66%W3A zCW|UC4mN^ZAFj+*e#rKQ`koi~z-fr>mdK II;Vst0LoU|lK=n! literal 0 HcmV?d00001 diff --git a/elepower_tools/textures/eletools_repair_core.png b/elepower_tools/textures/eletools_repair_core.png new file mode 100644 index 0000000000000000000000000000000000000000..267776a698ad6613013fc6b6ffce1cfced493c37 GIT binary patch literal 353 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85s1GL71^(seKtxkiEpy*OmP-6NezHID-MhF`$raW=KSdbAE1a zYF-JD%fR4Vl$uzQnxasiS(2gP?&%wlqL<1J6yM?L;uvCa`sxKm{w4>BV;}9$yyW1y zBg44*W`XDBtG|2d*sTvb8Q)dk;I%_iA@I(*LlPU9k1i3vfBXH-&-*@v`*S2t4ccb? z`S}AC&l6o;c^&rB%LPkgx7XiOmvFET*FE?7PPKFaV>FZX1FktO3OtA9=EW>zkvkx1 zVX|3Kj(0-PEr}h>(GS=%*3Qip*W=m1m~vTV-j0dpM;rwvh>8~Nm0A0i=S9*~H;H7o nZ0r0Fyzka;u)nqQhxt8j&o=)j$4^~Z3G$q$tDnm{r-UW|n?QbW literal 0 HcmV?d00001