diff --git a/elepower_dynamics/craftitems.lua b/elepower_dynamics/craftitems.lua index 66c58b9..1b93dbf 100644 --- a/elepower_dynamics/craftitems.lua +++ b/elepower_dynamics/craftitems.lua @@ -213,9 +213,9 @@ minetest.register_craftitem("elepower_dynamics:soc", { }) minetest.register_craftitem("elepower_dynamics:capacitor", { - description = "Capacitor", + description = "Capacitor\nTier 1 Capacitor", inventory_image = "elepower_capacitor.png", - groups = {capacitor = 2, component = 1} + groups = {capacitor = 1, component = 1} }) -- Assembled Components diff --git a/elepower_dynamics/init.lua b/elepower_dynamics/init.lua index 5610a86..350ea26 100644 --- a/elepower_dynamics/init.lua +++ b/elepower_dynamics/init.lua @@ -1,4 +1,4 @@ --- A Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) diff --git a/elepower_dynamics/nodes.lua b/elepower_dynamics/nodes.lua index 6b54a4d..1eb0af4 100644 --- a/elepower_dynamics/nodes.lua +++ b/elepower_dynamics/nodes.lua @@ -51,6 +51,18 @@ minetest.register_node("elepower_dynamics:particle_board", { sounds = default.node_sound_wood_defaults(), }) +minetest.register_node("elepower_dynamics:hardened_glass", { + description = "Hardened Obsidian Glass\nDoes not let light through", + drawtype = "glasslike_framed_optional", + tiles = {"default_obsidian_glass.png", "elepower_hard_glass_detail.png"}, + paramtype2 = "glasslikeliquidlevel", + is_ground_content = false, + sunlight_propagates = false, + use_texture_alpha = true, + sounds = default.node_sound_glass_defaults(), + groups = {cracky = 3}, +}) + -- Blocks minetest.register_node("elepower_dynamics:viridisium_block", { diff --git a/elepower_dynamics/textures/elepower_hard_glass_detail.png b/elepower_dynamics/textures/elepower_hard_glass_detail.png new file mode 100644 index 0000000..26419a6 Binary files /dev/null and b/elepower_dynamics/textures/elepower_hard_glass_detail.png differ diff --git a/elepower_fapi/init.lua b/elepower_fapi/init.lua index e2fc706..b9ffa2d 100644 --- a/elepower_fapi/init.lua +++ b/elepower_fapi/init.lua @@ -1,4 +1,4 @@ --- A Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) diff --git a/elepower_farming/init.lua b/elepower_farming/init.lua index ec9e9ff..1c3dc3f 100644 --- a/elepower_farming/init.lua +++ b/elepower_farming/init.lua @@ -1,4 +1,4 @@ --- A Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) diff --git a/elepower_machines/crafting.lua b/elepower_machines/crafting.lua index 9fa286b..ca6617b 100644 --- a/elepower_machines/crafting.lua +++ b/elepower_machines/crafting.lua @@ -38,6 +38,11 @@ local alloy_recipes = { output = "elepower_dynamics:silicon_wafer_doped", time = 8, }, + { + recipe = { "default:obsidian_glass", "elepower_dynamics:lead_ingot 4" }, + output = "elepower_dynamics:hardened_glass 4", + time = 8, + }, } -- Register alloy furnace recipes diff --git a/elepower_machines/craftitems.lua b/elepower_machines/craftitems.lua index 6287da2..715859b 100644 --- a/elepower_machines/craftitems.lua +++ b/elepower_machines/craftitems.lua @@ -8,3 +8,32 @@ minetest.register_craftitem("elepower_machines:turbine_blades", { description = "Turbine Blades", inventory_image = "elepower_turbine.png" }) + +--------------- +-- Upgrading -- +--------------- + +-- Capacitors +minetest.register_craftitem("elepower_machines:hardened_capacitor", { + description = "Hardened Capacitor\nTier 2 Capacitor", + groups = {capacitor = 2, ele_upgrade_component = 1}, + inventory_image = "elepower_upgrade_hardened_capacitor.png" +}) + +minetest.register_craftitem("elepower_machines:reinforced_capacitor", { + description = "Reinforced Capacitor\nIt will probably obliterate you if you touched it while charged\nTier 3 Capacitor", + groups = {capacitor = 3, ele_upgrade_component = 1}, + inventory_image = "elepower_upgrade_reinforced_capacitor.png" +}) + +minetest.register_craftitem("elepower_machines:resonant_capacitor", { + description = "Resonant Capacitor\nTier 4 Capacitor", + groups = {capacitor = 4, ele_upgrade_component = 1}, + inventory_image = "elepower_upgrade_resonant_capacitor.png" +}) + +minetest.register_craftitem("elepower_machines:super_capacitor", { + description = "Supercapacitor\nAmazing energy density in a small container! Wow!\nTier 5 Capacitor", + groups = {capacitor = 5, ele_upgrade_component = 1}, + inventory_image = "elepower_upgrade_supercapacitor.png" +}) diff --git a/elepower_machines/init.lua b/elepower_machines/init.lua index 498810b..9d3fc14 100644 --- a/elepower_machines/init.lua +++ b/elepower_machines/init.lua @@ -1,4 +1,4 @@ --- Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) @@ -12,6 +12,9 @@ dofile(modpath.."/craft.lua") -- Machines dofile(modpath.."/machines/init.lua") +-- Upgrading +dofile(modpath.."/upgrading.lua") + -- Other dofile(modpath.."/nodes.lua") dofile(modpath.."/craftitems.lua") diff --git a/elepower_machines/machines/bases/crafter.lua b/elepower_machines/machines/bases/crafter.lua index 73bac83..0dbaa6a 100644 --- a/elepower_machines/machines/bases/crafter.lua +++ b/elepower_machines/machines/bases/crafter.lua @@ -59,6 +59,134 @@ function ele.formspec.get_crafter_formspec(craft_type, power, percent, pos, stat default.get_hotbar_bg(0, 4.25) end +-- Don't duplicate function for every single crafter node +function crafter_timer (pos, elapsed) + local refresh = false + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + -- Specialized for universal crafter node + local machine_node = minetest.get_node(pos).name + local machine_def = minetest.registered_nodes[machine_node] + + -- If this is an active node, get the inactive version + if machine_def.groups['ele_active'] == 1 then + machine_node = machine_def.drop -- Reliable + machine_def = minetest.registered_nodes[machine_node] + end + + 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 speed = ele.helpers.get_node_property(meta, pos, "craft_speed") or 1 + local time = meta:get_int("src_time") + local state = meta:get_int("state") + local status = "Idle" + + local is_enabled = ele.helpers.state_enabled(meta, pos, state) + local res_time = 0 + + local get_formspec = machine_def.get_formspec or ele.formspec.get_crafter_formspec + + local pow_buffer = {capacity = capacity, storage = storage, usage = 0} + + while true do + if not is_enabled then + time = 0 + status = "Off" + break + end + + local result = elepm.get_recipe(machine_def.craft_type, inv:get_list("src")) + local power_operation = false + + -- Determine if there is enough power for this action + res_time = result.time + if result.time ~= 0 and pow_buffer.storage >= usage then + power_operation = true + pow_buffer.usage = usage + end + + if result.time == 0 or not power_operation then + ele.helpers.swap_node(pos, machine_node) + + if result.time == 0 then + time = 0 + status = "Idle" + else + status = "Out of Power!" + end + + break + end + + refresh = true + status = "Active" + + -- One step + pow_buffer.storage = pow_buffer.storage - usage + time = time + ele.helpers.round(speed * 10) + + if machine_def.ele_active_node then + local active_node = machine_node.."_active" + if machine_def.ele_active_node ~= true then + active_node = machine_def.ele_active_node + end + + ele.helpers.swap_node(pos, active_node) + end + + if time <= ele.helpers.round(result.time * 10) then + break + end + + local output = result.output + if type(output) ~= "table" then output = { output } end + local output_stacks = {} + for _, o in ipairs(output) do + table.insert(output_stacks, ItemStack(o)) + end + + local room_for_output = true + inv:set_size("dst_tmp", inv:get_size("dst")) + inv:set_list("dst_tmp", inv:get_list("dst")) + + for _, o in ipairs(output_stacks) do + if not inv:room_for_item("dst_tmp", o) then + room_for_output = false + break + end + inv:add_item("dst_tmp", o) + end + + if not room_for_output then + ele.helpers.swap_node(pos, machine_node) + time = ele.helpers.round(res_time*10) + status = "Output Full!" + break + end + + time = 0 + inv:set_list("src", result.new_input) + inv:set_list("dst", inv:get_list("dst_tmp")) + break + end + + local pct = 0 + if res_time > 0 and time > 0 then + pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100) + end + + meta:set_string("formspec", get_formspec(machine_def.craft_type, pow_buffer, pct, pos, state)) + meta:set_string("infotext", ("%s %s"):format(machine_def.description, status) .. + "\n" .. ele.capacity_text(capacity, storage)) + + meta:set_int("src_time", time) + meta:set_int("storage", pow_buffer.storage) + + return refresh +end + function elepm.register_crafter(nodename, nodedef) local craft_type = nodedef.craft_type if not craft_type or not elepm.craft.types[craft_type] then @@ -74,128 +202,12 @@ function elepm.register_crafter(nodename, nodedef) nodedef.groups["tubedevice"] = 1 nodedef.groups["tubedevice_receiver"] = 1 + nodedef.on_timer = crafter_timer + -- Allow for custom formspec local get_formspec = ele.formspec.get_crafter_formspec if nodedef.get_formspec then get_formspec = nodedef.get_formspec - nodedef.get_formspec = nil - end - - nodedef.on_timer = function (pos, elapsed) - local refresh = false - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - - local machine_node = nodename - local machine_speed = nodedef.craft_speed or 1 - - 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 time = meta:get_int("src_time") - local state = meta:get_int("state") - local status = "Idle" - - local is_enabled = ele.helpers.state_enabled(meta, pos, state) - local res_time = 0 - - local pow_buffer = {capacity = capacity, storage = storage, usage = 0} - - while true do - if not is_enabled then - time = 0 - status = "Off" - break - end - - local result = elepm.get_recipe(craft_type, inv:get_list("src")) - local power_operation = false - - -- Determine if there is enough power for this action - res_time = result.time - if result.time ~= 0 and pow_buffer.storage >= usage then - power_operation = true - pow_buffer.usage = usage - end - - if result.time == 0 or not power_operation then - ele.helpers.swap_node(pos, machine_node) - - if result.time == 0 then - time = 0 - status = "Idle" - else - status = "Out of Power!" - end - - break - end - - refresh = true - status = "Active" - - -- One step - pow_buffer.storage = pow_buffer.storage - usage - time = time + ele.helpers.round(machine_speed * 10) - - if nodedef.ele_active_node then - local active_node = nodename.."_active" - if nodedef.ele_active_node ~= true then - active_node = nodedef.ele_active_node - end - - ele.helpers.swap_node(pos, active_node) - end - - if time <= ele.helpers.round(result.time * 10) then - break - end - - local output = result.output - if type(output) ~= "table" then output = { output } end - local output_stacks = {} - for _, o in ipairs(output) do - table.insert(output_stacks, ItemStack(o)) - end - - local room_for_output = true - inv:set_size("dst_tmp", inv:get_size("dst")) - inv:set_list("dst_tmp", inv:get_list("dst")) - - for _, o in ipairs(output_stacks) do - if not inv:room_for_item("dst_tmp", o) then - room_for_output = false - break - end - inv:add_item("dst_tmp", o) - end - - if not room_for_output then - ele.helpers.swap_node(pos, machine_node) - time = ele.helpers.round(res_time*10) - status = "Output Full!" - break - end - - time = 0 - inv:set_list("src", result.new_input) - inv:set_list("dst", inv:get_list("dst_tmp")) - break - end - - local pct = 0 - if res_time > 0 and time > 0 then - pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100) - end - - meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos, state)) - meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) .. - "\n" .. ele.capacity_text(capacity, storage)) - - meta:set_int("src_time", time) - meta:set_int("storage", pow_buffer.storage) - - return refresh end local sizes = elepm.craft.types[craft_type] @@ -211,5 +223,11 @@ function elepm.register_crafter(nodename, nodedef) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos)) end + -- Upgradable + nodedef.ele_upgrades = { + machine_chip = {"craft_speed", "usage", "inrush"}, + capacitor = {"capacity"}, + } + ele.register_machine(nodename, nodedef) end diff --git a/elepower_machines/machines/bases/fluid_generator.lua b/elepower_machines/machines/bases/fluid_generator.lua index 3f63e75..4816a6c 100644 --- a/elepower_machines/machines/bases/fluid_generator.lua +++ b/elepower_machines/machines/bases/fluid_generator.lua @@ -44,7 +44,7 @@ function ele.register_fluid_generator(nodename, nodedef) on_timer = function (pos, elapsed) local refresh = false local meta = minetest.get_meta(pos) - local nodename = nodename + local nodename = minetest.get_node(pos).name local burn_time = meta:get_int("burn_time") local burn_totaltime = meta:get_int("burn_totaltime") diff --git a/elepower_machines/machines/bases/generator.lua b/elepower_machines/machines/bases/generator.lua index 1f7e0c2..1d95f50 100644 --- a/elepower_machines/machines/bases/generator.lua +++ b/elepower_machines/machines/bases/generator.lua @@ -36,7 +36,8 @@ function elepm.register_fuel_generator(nodename, nodedef) nodedef.on_timer = function (pos, elapsed) local refresh = false - local meta = minetest.get_meta(pos) + local meta = minetest.get_meta(pos) + local nodename = minetest.get_node(pos).name local burn_time = meta:get_int("burn_time") local burn_totaltime = meta:get_int("burn_totaltime") diff --git a/elepower_machines/machines/grindstone.lua b/elepower_machines/machines/grindstone.lua index ea08b9a..5cb99da 100644 --- a/elepower_machines/machines/grindstone.lua +++ b/elepower_machines/machines/grindstone.lua @@ -156,6 +156,12 @@ minetest.register_node("elepower_machines:crank", { {-0.03125, -0.5000, -0.03125, 0.03125, -0.1250, 0.03125} } }, + selection_box = { + type = "fixed", + fixed = { + {-0.2500, -0.5000, -0.2500, 0.2500, 0.000, 0.2500} + } + }, on_rightclick = function (pos, node, clicker, itemstack, pointed_thing) local gpos = vector.add(pos, {x = 0, y = -1, z = 0}) local gnode = minetest.get_node_or_nil(gpos) diff --git a/elepower_machines/machines/storage.lua b/elepower_machines/machines/storage.lua index 3d223f0..2afbb8a 100644 --- a/elepower_machines/machines/storage.lua +++ b/elepower_machines/machines/storage.lua @@ -13,3 +13,63 @@ elepm.register_storage("elepower_machines:power_cell", { }, groups = {oddly_breakable_by_hand = 1} }) + +elepm.register_storage("elepower_machines:hardened_power_cell", { + description = "Hardened Power Cell", + ele_capacity = 64000, + ele_inrush = 640, + tiles = { + "elepower_machine_top.png^elepower_overlay_hardened.png", + "elepower_machine_base.png^elepower_overlay_hardened.png", + "elepower_machine_side.png^elepower_overlay_hardened.png", + "elepower_machine_side.png^elepower_overlay_hardened.png", + "elepower_machine_side.png^elepower_overlay_hardened.png", + "elepower_power_cell.png^elepower_overlay_hardened.png", + }, + groups = {oddly_breakable_by_hand = 1} +}) + +elepm.register_storage("elepower_machines:reinforced_power_cell", { + description = "Reinforced Power Cell", + ele_capacity = 128000, + ele_inrush = 1024, + tiles = { + "elepower_machine_top.png^elepower_overlay_reinforced.png", + "elepower_machine_base.png^elepower_overlay_reinforced.png", + "elepower_machine_side.png^elepower_overlay_reinforced.png", + "elepower_machine_side.png^elepower_overlay_reinforced.png", + "elepower_machine_side.png^elepower_overlay_reinforced.png", + "elepower_power_cell.png^elepower_overlay_reinforced.png", + }, + groups = {oddly_breakable_by_hand = 1} +}) + +elepm.register_storage("elepower_machines:resonant_power_cell", { + description = "Resonant Power Cell", + ele_capacity = 640000, + ele_inrush = 2048, + tiles = { + "elepower_machine_top.png^elepower_overlay_resonant.png", + "elepower_machine_base.png^elepower_overlay_resonant.png", + "elepower_machine_side.png^elepower_overlay_resonant.png", + "elepower_machine_side.png^elepower_overlay_resonant.png", + "elepower_machine_side.png^elepower_overlay_resonant.png", + "elepower_power_cell.png^elepower_overlay_resonant.png", + }, + groups = {oddly_breakable_by_hand = 1} +}) + +elepm.register_storage("elepower_machines:super_power_cell", { + description = "Supercapacitor Cell", + ele_capacity = 1280000, + ele_inrush = 4096, + tiles = { + "elepower_machine_top.png^elepower_overlay_super.png", + "elepower_machine_base.png^elepower_overlay_super.png", + "elepower_machine_side.png^elepower_overlay_super.png", + "elepower_machine_side.png^elepower_overlay_super.png", + "elepower_machine_side.png^elepower_overlay_super.png", + "elepower_power_cell.png^elepower_overlay_super.png", + }, + groups = {oddly_breakable_by_hand = 1} +}) diff --git a/elepower_machines/textures/elepower_overlay_hardened.png b/elepower_machines/textures/elepower_overlay_hardened.png new file mode 100644 index 0000000..fcc1dfe Binary files /dev/null and b/elepower_machines/textures/elepower_overlay_hardened.png differ diff --git a/elepower_machines/textures/elepower_overlay_reinforced.png b/elepower_machines/textures/elepower_overlay_reinforced.png new file mode 100644 index 0000000..5e1eeaa Binary files /dev/null and b/elepower_machines/textures/elepower_overlay_reinforced.png differ diff --git a/elepower_machines/textures/elepower_overlay_resonant.png b/elepower_machines/textures/elepower_overlay_resonant.png new file mode 100644 index 0000000..648a63d Binary files /dev/null and b/elepower_machines/textures/elepower_overlay_resonant.png differ diff --git a/elepower_machines/textures/elepower_overlay_super.png b/elepower_machines/textures/elepower_overlay_super.png new file mode 100644 index 0000000..c1d61c0 Binary files /dev/null and b/elepower_machines/textures/elepower_overlay_super.png differ diff --git a/elepower_machines/textures/elepower_upgrade_hardened_capacitor.png b/elepower_machines/textures/elepower_upgrade_hardened_capacitor.png new file mode 100644 index 0000000..e591a7d Binary files /dev/null and b/elepower_machines/textures/elepower_upgrade_hardened_capacitor.png differ diff --git a/elepower_machines/textures/elepower_upgrade_reinforced_capacitor.png b/elepower_machines/textures/elepower_upgrade_reinforced_capacitor.png new file mode 100644 index 0000000..081d8e1 Binary files /dev/null and b/elepower_machines/textures/elepower_upgrade_reinforced_capacitor.png differ diff --git a/elepower_machines/textures/elepower_upgrade_resonant_capacitor.png b/elepower_machines/textures/elepower_upgrade_resonant_capacitor.png new file mode 100644 index 0000000..6e8bb08 Binary files /dev/null and b/elepower_machines/textures/elepower_upgrade_resonant_capacitor.png differ diff --git a/elepower_machines/textures/elepower_upgrade_supercapacitor.png b/elepower_machines/textures/elepower_upgrade_supercapacitor.png new file mode 100644 index 0000000..01dc8ff Binary files /dev/null and b/elepower_machines/textures/elepower_upgrade_supercapacitor.png differ diff --git a/elepower_machines/upgrading.lua b/elepower_machines/upgrading.lua new file mode 100644 index 0000000..85277c9 --- /dev/null +++ b/elepower_machines/upgrading.lua @@ -0,0 +1,59 @@ + +local metasets = { + "capacity", "usage", "craft_speed", "inrush", "output" +} + +function elepm.handle_machine_upgrades (pos) + local meta = minetest.get_meta(pos) + local comps = meta:get_string("components") + + local node = minetest.get_node(pos) + local nodedef = minetest.registered_nodes[node.name] + + -- Deserialize component list + if comps ~= "" then + comps = minetest.deserialize(comps) + else + comps = {} + end + + if nodedef.ele_upgrades then + for comp, vars in pairs(nodedef.ele_upgrades) do + for _,c in pairs(vars) do + if not comps[comp] then + -- If we're resetting capacity, set storage to max initial capacity + if c == "capacity" then + local abscap = nodedef.ele_capacity + local storage = meta:get_int("storage") + if storage > abscap then + storage = abscap + meta:set_int("storage", storage) + end + end + + -- Set variable to zero in metadata + if meta:get_int(c) ~= 0 then + meta:set_int(c, 0) + end + elseif nodedef["ele_" .. c] ~= nil then + -- Set updated value in metadata + local default = nodedef["ele_" .. c] + local ulevel = minetest.get_item_group(comps[comp], comp) - 1 + local multiplier = 1 + + -- Capacitor value is multiplied + if comp == "capacitor" then + multiplier = math.pow(10, ulevel) + end + + meta:set_int(c, math.abs(default + (default * ulevel * multiplier))) + end + end + end + end + + local t = minetest.get_node_timer(pos) + if not t:is_started() then + t:start(1.0) + end +end diff --git a/elepower_nuclear/init.lua b/elepower_nuclear/init.lua index a5e550b..aba8053 100644 --- a/elepower_nuclear/init.lua +++ b/elepower_nuclear/init.lua @@ -1,4 +1,4 @@ --- A Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) diff --git a/elepower_papi/init.lua b/elepower_papi/init.lua index 0e49d17..df9c554 100644 --- a/elepower_papi/init.lua +++ b/elepower_papi/init.lua @@ -1,4 +1,4 @@ --- Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) diff --git a/elepower_papi/machine.lua b/elepower_papi/machine.lua index 7a2c336..26ff5a9 100644 --- a/elepower_papi/machine.lua +++ b/elepower_papi/machine.lua @@ -96,19 +96,28 @@ ele.default.states = { -- Preserve power storage in the item stack dropped local function preserve_metadata(pos, oldnode, oldmeta, drops) local meta = minetest.get_meta(pos) - local capacity = ele.helpers.get_node_property(meta, pos, "capacity") local storage = ele.helpers.get_node_property(meta, pos, "storage") + local capacity = ele.helpers.get_node_property(meta, pos, "capacity") - local nodedesc = minetest.registered_nodes[oldnode.name].description + local nodedesc = minetest.registered_nodes[oldnode.name].description + local partsstr = meta:get_string("components") - if storage == 0 then + if storage == 0 and partsstr == "" then return drops end for i,stack in pairs(drops) do local stack_meta = stack:get_meta() stack_meta:set_int("storage", storage) - stack_meta:set_string("description", nodedesc .. "\n" .. ele.capacity_text(capacity, storage)) + + local desc = ele.capacity_text(capacity, storage) + + if partsstr ~= "" then + stack_meta:set_string("components", partsstr) + desc = desc .. "\n" .. minetest.colorize("#9647ff", "Modified Device") + end + + stack_meta:set_string("description", nodedesc .. "\n" .. desc) drops[i] = stack end @@ -119,11 +128,24 @@ end local function retrieve_metadata(pos, placer, itemstack, pointed_thing) local item_meta = itemstack:get_meta() local storage = item_meta:get_int("storage") - - if storage and storage > 0 then + local partsstr = item_meta:get_string("components") + + if storage > 0 or partsstr ~= "" then local meta = minetest.get_meta(pos) + meta:set_int("storage", storage) - minetest.get_node_timer(pos):start(1.0) + if partsstr ~= "" then + meta:set_string("components", partsstr) + + if elepm then + elepm.handle_machine_upgrades(pos) + end + else + local t = minetest.get_node_timer(pos) + if not t:is_started() then + t:start(1.0) + end + end end return false @@ -219,6 +241,17 @@ local function switch_state(pos, state_def) end end +-- Patch a table +local function apply_patches (table, patches) + for k,v in pairs(patches) do + if table[k] and type(table[k]) == "table" then + apply_patches(table[k], v) + else + table[k] = v + end + end +end + -- Register a base device function ele.register_base_device(nodename, nodedef) local tlsupp = tl and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"]) @@ -393,23 +426,31 @@ function ele.register_base_device(nodename, nodedef) if nodedef.ele_active_node then local active_nodedef = table.copy(nodedef) active_name = nodename.."_active" - + if nodedef.ele_active_node ~= true then active_name = nodedef.ele_active_node + + if i ~= 1 then + active_name = active_name .. "_" .. i + end end if nodedef.ele_active_nodedef then - for k,v in pairs(nodedef.ele_active_nodedef) do - active_nodedef[k] = v - end + apply_patches(active_nodedef, nodedef.ele_active_nodedef) nodedef.ele_active_nodedef = nil active_nodedef.ele_active_nodedef = nil end + -- Remove formspec functions from active nodedefs + if active_nodedef.get_formspec then + active_nodedef.get_formspec = nil + end + active_nodedef.groups["ele_active"] = 1 active_nodedef.groups["not_in_creative_inventory"] = 1 active_nodedef.drop = nodename + minetest.register_node(active_name, active_nodedef) end diff --git a/elepower_solar/init.lua b/elepower_solar/init.lua index 11f6fd1..bf01b21 100644 --- a/elepower_solar/init.lua +++ b/elepower_solar/init.lua @@ -1,4 +1,4 @@ --- A Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) diff --git a/elepower_tools/crafting.lua b/elepower_tools/crafting.lua index 1a3de66..587688f 100644 --- a/elepower_tools/crafting.lua +++ b/elepower_tools/crafting.lua @@ -35,3 +35,13 @@ minetest.register_craft({ {"elepower_dynamics:motor", "elepower_dynamics:capacitor", ""}, } }) + +-- Soldering Iron +minetest.register_craft({ + output = "elepower_tools:soldering_iron", + recipe = { + {"", "elepower_dynamics:battery", "default:steel_ingot"}, + {"", "elepower_dynamics:wound_silver_coil", ""}, + {"elepower_dynamics:wound_silver_coil", "", ""}, + } +}) diff --git a/elepower_tools/init.lua b/elepower_tools/init.lua index 00b5eb9..579d13b 100644 --- a/elepower_tools/init.lua +++ b/elepower_tools/init.lua @@ -1,4 +1,4 @@ --- A Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname()) @@ -6,6 +6,12 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) eletool = rawget(_G, "eletool") or {} eletool.modpath = modpath +-- Simple tools dofile(modpath .. "/tools.lua") + +-- Complex tools +dofile(modpath .. "/soldering.lua") + +-- Crafting dofile(modpath .. "/craftitems.lua") dofile(modpath .. "/crafting.lua") diff --git a/elepower_tools/soldering.lua b/elepower_tools/soldering.lua new file mode 100644 index 0000000..4e8fd9c --- /dev/null +++ b/elepower_tools/soldering.lua @@ -0,0 +1,172 @@ + +-- Convenience for i18n later on +local dict = { + machine_chip = "Machine Chip", + capacitor = "Capacitor", +} + +local function upgrade_formspec (upgrades, desc) + local posY = 0.5 + local fspec = "" + + for k in pairs(upgrades) do + fspec = fspec .. "label[1,"..(posY + 0.25)..";"..dict[k].."]" + fspec = fspec .. "list[detached:soldering;"..k..";7,"..posY..";1,1;]" + posY = posY + 1 + end + + return "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "label[0,0;Modifying "..desc.."]".. + fspec.. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 4.25) +end + +local function set_component_list (pos, list) + local meta = minetest.get_meta(pos) + local len = 0 + for _,v in pairs(list) do + if v ~= nil then + len = len + 1 + end + end + + if len == 0 and meta:get_string("components") ~= "" then + meta:set_string("components", "") + else + meta:set_string("components", minetest.serialize(list)) + end + + if elepm then + elepm.handle_machine_upgrades(pos) + end +end + +local function machine_modify (pos, node, user) + local nodedef = minetest.registered_nodes[node.name] + + if not nodedef.ele_upgrades then + return minetest.chat_send_player(user:get_player_name(), "This machine cannot be modified.") + end + + local meta = minetest.get_meta(pos) + local comps = meta:get_string("components") + + -- Prevent the node from being dug + -- It is recommended to have this check in can_dig callback. + meta:set_int("drop_lock", 1) + + -- Save the soldered machine as an attribute on the player + local umeta = user:get_meta() + umeta:set_string("soldering", minetest.pos_to_string(pos)) + + -- Deserialize component list + if comps ~= "" then + comps = minetest.deserialize(comps) + else + comps = {} + end + + -- Create detached inventory for upgrades + local inv = minetest.create_detached_inventory("soldering", { + allow_move = function (inv, from_list, from_index, to_list, to_index, count, player) + return 0 + end, + + allow_put = function (inv, listname, index, stack, player) + if minetest.get_item_group(stack:get_name(), "ele_upgrade_component") == 0 or + minetest.get_item_group(stack:get_name(), listname) < 2 then + return 0 + end + + return 1 + end, + + allow_take = function (inv, listname, index, stack, player) + return stack:get_count() + end, + + on_put = function (inv, listname, index, stack, player) + comps[listname] = stack:get_name() + set_component_list(pos, comps) + end, + + on_take = function (inv, listname, index, stack, player) + comps[listname] = nil + set_component_list(pos, comps) + end, + }, user:get_player_name()) + + -- Add lists + for k in pairs(nodedef.ele_upgrades) do + inv:set_size(k, 1) + + if comps[k] then + inv:set_stack(k, 1, ItemStack(comps[k])) + end + end + + -- Open the formspec + minetest.show_formspec(user:get_player_name(), "elepower_tools:soldering_iron", + upgrade_formspec(nodedef.ele_upgrades, nodedef.description)) +end + +minetest.register_on_player_receive_fields(function (player, formname, fields) + if formname ~= "elepower_tools:soldering_iron" or not player then return false end + + local umeta = player:get_meta() + local pos = umeta:get_string("soldering") + if not pos then return false end + + pos = minetest.string_to_pos(pos) + local meta = minetest.get_meta(pos) + + if fields["quit"] then + meta:set_int("drop_lock", 0) + umeta:set_string("soldering", "") + end + + return true +end) + +minetest.register_on_leaveplayer(function (player) + local umeta = player:get_meta() + local soldering = umeta:get_string("soldering") + if soldering == "" then return end + local pos = minetest.string_to_pos(soldering) + local meta = minetest.get_meta(pos) + if meta:get_int("drop_lock") == 1 then + meta:set_int("drop_lock", 0) + end + umeta:set_string("soldering", "") +end) + +ele.register_tool("elepower_tools:soldering_iron", { + description = "Soldering Iron\nUsed to replace components in machines", + inventory_image = "eletools_soldering_iron.png", + wield_image = "eletools_soldering_iron.png^[transformR270", + ele_capacity = 8000, + ele_usage = 64, + on_use = function (itemstack, user, pointed_thing) + if not user or user:get_player_name() == "" then return itemstack end + if pointed_thing and pointed_thing.type == "node" then + local pos = pointed_thing.under + local node = minetest.get_node_or_nil(pos) + + if not node or node.name == "air" or minetest.is_protected(pos, user:get_player_name()) then + return itemstack + end + + if ele.helpers.get_item_group(node.name, "ele_machine") then + machine_modify(pos, node, user) + end + end + + return itemstack + end +}) diff --git a/elepower_tools/textures/eletools_soldering_iron.png b/elepower_tools/textures/eletools_soldering_iron.png new file mode 100644 index 0000000..d797073 Binary files /dev/null and b/elepower_tools/textures/eletools_soldering_iron.png differ diff --git a/elepower_tools/tools.lua b/elepower_tools/tools.lua index bde6124..5d553d4 100644 --- a/elepower_tools/tools.lua +++ b/elepower_tools/tools.lua @@ -1,6 +1,6 @@ ele.register_tool("elepower_tools:hand_drill", { - description = "Hand Drill", + description = "Electric Hand Drill", inventory_image = "eletools_hand_drill.png", wield_image = "eletools_hand_drill.png^[transformFX", tool_capabilities = { @@ -15,7 +15,7 @@ ele.register_tool("elepower_tools:hand_drill", { }) ele.register_tool("elepower_tools:chainsaw", { - description = "Chainsaw", + description = "Electric Chainsaw", inventory_image = "eletools_chainsaw.png", wield_image = "eletools_chainsaw.png^[transformFX", ele_capacity = 8000, diff --git a/elepower_wireless/init.lua b/elepower_wireless/init.lua index 74aea13..ab3c588 100644 --- a/elepower_wireless/init.lua +++ b/elepower_wireless/init.lua @@ -1,4 +1,4 @@ --- Elepower Mod +-- An Elepower Mod -- Copyright 2018 Evert "Diamond" Prants local modpath = minetest.get_modpath(minetest.get_current_modname())