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 0000000..2528391 Binary files /dev/null and b/elepower_tools/textures/elepower_machine_ed_reconstructor.png differ diff --git a/elepower_tools/textures/eletools_repair_core.png b/elepower_tools/textures/eletools_repair_core.png new file mode 100644 index 0000000..267776a Binary files /dev/null and b/elepower_tools/textures/eletools_repair_core.png differ