Concept of soldering, tiers of power storage cells

This commit is contained in:
Evert Prants 2018-12-12 15:04:53 +02:00
parent f826e18ad9
commit 5c2a6f6f2a
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
33 changed files with 566 additions and 144 deletions

View File

@ -213,9 +213,9 @@ minetest.register_craftitem("elepower_dynamics:soc", {
}) })
minetest.register_craftitem("elepower_dynamics:capacitor", { minetest.register_craftitem("elepower_dynamics:capacitor", {
description = "Capacitor", description = "Capacitor\nTier 1 Capacitor",
inventory_image = "elepower_capacitor.png", inventory_image = "elepower_capacitor.png",
groups = {capacitor = 2, component = 1} groups = {capacitor = 1, component = 1}
}) })
-- Assembled Components -- Assembled Components

View File

@ -1,4 +1,4 @@
-- A Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())

View File

@ -51,6 +51,18 @@ minetest.register_node("elepower_dynamics:particle_board", {
sounds = default.node_sound_wood_defaults(), 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 -- Blocks
minetest.register_node("elepower_dynamics:viridisium_block", { minetest.register_node("elepower_dynamics:viridisium_block", {

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

View File

@ -1,4 +1,4 @@
-- A Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())

View File

@ -1,4 +1,4 @@
-- A Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())

View File

@ -38,6 +38,11 @@ local alloy_recipes = {
output = "elepower_dynamics:silicon_wafer_doped", output = "elepower_dynamics:silicon_wafer_doped",
time = 8, time = 8,
}, },
{
recipe = { "default:obsidian_glass", "elepower_dynamics:lead_ingot 4" },
output = "elepower_dynamics:hardened_glass 4",
time = 8,
},
} }
-- Register alloy furnace recipes -- Register alloy furnace recipes

View File

@ -8,3 +8,32 @@ minetest.register_craftitem("elepower_machines:turbine_blades", {
description = "Turbine Blades", description = "Turbine Blades",
inventory_image = "elepower_turbine.png" 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"
})

View File

@ -1,4 +1,4 @@
-- Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())
@ -12,6 +12,9 @@ dofile(modpath.."/craft.lua")
-- Machines -- Machines
dofile(modpath.."/machines/init.lua") dofile(modpath.."/machines/init.lua")
-- Upgrading
dofile(modpath.."/upgrading.lua")
-- Other -- Other
dofile(modpath.."/nodes.lua") dofile(modpath.."/nodes.lua")
dofile(modpath.."/craftitems.lua") dofile(modpath.."/craftitems.lua")

View File

@ -59,39 +59,26 @@ function ele.formspec.get_crafter_formspec(craft_type, power, percent, pos, stat
default.get_hotbar_bg(0, 4.25) default.get_hotbar_bg(0, 4.25)
end end
function elepm.register_crafter(nodename, nodedef) -- Don't duplicate function for every single crafter node
local craft_type = nodedef.craft_type function crafter_timer (pos, elapsed)
if not craft_type or not elepm.craft.types[craft_type] then
return nil
end
if not nodedef.groups then
nodedef.groups = {}
end
nodedef.groups["ele_machine"] = 1
nodedef.groups["ele_user"] = 1
nodedef.groups["tubedevice"] = 1
nodedef.groups["tubedevice_receiver"] = 1
-- 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 refresh = false
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local machine_node = nodename -- Specialized for universal crafter node
local machine_speed = nodedef.craft_speed or 1 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 capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local usage = ele.helpers.get_node_property(meta, pos, "usage") local usage = ele.helpers.get_node_property(meta, pos, "usage")
local storage = ele.helpers.get_node_property(meta, pos, "storage") 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 time = meta:get_int("src_time")
local state = meta:get_int("state") local state = meta:get_int("state")
local status = "Idle" local status = "Idle"
@ -99,6 +86,8 @@ function elepm.register_crafter(nodename, nodedef)
local is_enabled = ele.helpers.state_enabled(meta, pos, state) local is_enabled = ele.helpers.state_enabled(meta, pos, state)
local res_time = 0 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} local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
while true do while true do
@ -108,7 +97,7 @@ function elepm.register_crafter(nodename, nodedef)
break break
end end
local result = elepm.get_recipe(craft_type, inv:get_list("src")) local result = elepm.get_recipe(machine_def.craft_type, inv:get_list("src"))
local power_operation = false local power_operation = false
-- Determine if there is enough power for this action -- Determine if there is enough power for this action
@ -136,12 +125,12 @@ function elepm.register_crafter(nodename, nodedef)
-- One step -- One step
pow_buffer.storage = pow_buffer.storage - usage pow_buffer.storage = pow_buffer.storage - usage
time = time + ele.helpers.round(machine_speed * 10) time = time + ele.helpers.round(speed * 10)
if nodedef.ele_active_node then if machine_def.ele_active_node then
local active_node = nodename.."_active" local active_node = machine_node.."_active"
if nodedef.ele_active_node ~= true then if machine_def.ele_active_node ~= true then
active_node = nodedef.ele_active_node active_node = machine_def.ele_active_node
end end
ele.helpers.swap_node(pos, active_node) ele.helpers.swap_node(pos, active_node)
@ -188,8 +177,8 @@ function elepm.register_crafter(nodename, nodedef)
pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100) pct = math.floor((time / ele.helpers.round(res_time * 10)) * 100)
end end
meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos, state)) meta:set_string("formspec", get_formspec(machine_def.craft_type, pow_buffer, pct, pos, state))
meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) .. meta:set_string("infotext", ("%s %s"):format(machine_def.description, status) ..
"\n" .. ele.capacity_text(capacity, storage)) "\n" .. ele.capacity_text(capacity, storage))
meta:set_int("src_time", time) meta:set_int("src_time", time)
@ -198,6 +187,29 @@ function elepm.register_crafter(nodename, nodedef)
return refresh return refresh
end 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
return nil
end
if not nodedef.groups then
nodedef.groups = {}
end
nodedef.groups["ele_machine"] = 1
nodedef.groups["ele_user"] = 1
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
end
local sizes = elepm.craft.types[craft_type] local sizes = elepm.craft.types[craft_type]
nodedef.on_construct = function (pos) nodedef.on_construct = function (pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -211,5 +223,11 @@ function elepm.register_crafter(nodename, nodedef)
meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos)) meta:set_string("formspec", get_formspec(craft_type, pow_buffer, nil, pos))
end end
-- Upgradable
nodedef.ele_upgrades = {
machine_chip = {"craft_speed", "usage", "inrush"},
capacitor = {"capacity"},
}
ele.register_machine(nodename, nodedef) ele.register_machine(nodename, nodedef)
end end

View File

@ -44,7 +44,7 @@ function ele.register_fluid_generator(nodename, nodedef)
on_timer = function (pos, elapsed) on_timer = function (pos, elapsed)
local refresh = false local refresh = false
local meta = minetest.get_meta(pos) 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_time = meta:get_int("burn_time")
local burn_totaltime = meta:get_int("burn_totaltime") local burn_totaltime = meta:get_int("burn_totaltime")

View File

@ -37,6 +37,7 @@ function elepm.register_fuel_generator(nodename, nodedef)
nodedef.on_timer = function (pos, elapsed) nodedef.on_timer = function (pos, elapsed)
local refresh = false 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_time = meta:get_int("burn_time")
local burn_totaltime = meta:get_int("burn_totaltime") local burn_totaltime = meta:get_int("burn_totaltime")

View File

@ -156,6 +156,12 @@ minetest.register_node("elepower_machines:crank", {
{-0.03125, -0.5000, -0.03125, 0.03125, -0.1250, 0.03125} {-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) on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
local gpos = vector.add(pos, {x = 0, y = -1, z = 0}) local gpos = vector.add(pos, {x = 0, y = -1, z = 0})
local gnode = minetest.get_node_or_nil(gpos) local gnode = minetest.get_node_or_nil(gpos)

View File

@ -13,3 +13,63 @@ elepm.register_storage("elepower_machines:power_cell", {
}, },
groups = {oddly_breakable_by_hand = 1} 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}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -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

View File

@ -1,4 +1,4 @@
-- A Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())

View File

@ -1,4 +1,4 @@
-- Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())

View File

@ -96,19 +96,28 @@ ele.default.states = {
-- Preserve power storage in the item stack dropped -- Preserve power storage in the item stack dropped
local function preserve_metadata(pos, oldnode, oldmeta, drops) local function preserve_metadata(pos, oldnode, oldmeta, drops)
local meta = minetest.get_meta(pos) 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 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 return drops
end end
for i,stack in pairs(drops) do for i,stack in pairs(drops) do
local stack_meta = stack:get_meta() local stack_meta = stack:get_meta()
stack_meta:set_int("storage", storage) 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 drops[i] = stack
end end
@ -119,11 +128,24 @@ end
local function retrieve_metadata(pos, placer, itemstack, pointed_thing) local function retrieve_metadata(pos, placer, itemstack, pointed_thing)
local item_meta = itemstack:get_meta() local item_meta = itemstack:get_meta()
local storage = item_meta:get_int("storage") local storage = item_meta:get_int("storage")
local partsstr = item_meta:get_string("components")
if storage and storage > 0 then if storage > 0 or partsstr ~= "" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("storage", storage) 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 end
return false return false
@ -219,6 +241,17 @@ local function switch_state(pos, state_def)
end end
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 -- Register a base device
function ele.register_base_device(nodename, nodedef) function ele.register_base_device(nodename, nodedef)
local tlsupp = tl and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"]) local tlsupp = tl and nodedef.groups and (nodedef.groups["tubedevice"] or nodedef.groups["tube"])
@ -396,20 +429,28 @@ function ele.register_base_device(nodename, nodedef)
if nodedef.ele_active_node ~= true then if nodedef.ele_active_node ~= true then
active_name = nodedef.ele_active_node active_name = nodedef.ele_active_node
if i ~= 1 then
active_name = active_name .. "_" .. i
end
end end
if nodedef.ele_active_nodedef then if nodedef.ele_active_nodedef then
for k,v in pairs(nodedef.ele_active_nodedef) do apply_patches(active_nodedef, nodedef.ele_active_nodedef)
active_nodedef[k] = v
end
nodedef.ele_active_nodedef = nil nodedef.ele_active_nodedef = nil
active_nodedef.ele_active_nodedef = nil active_nodedef.ele_active_nodedef = nil
end 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["ele_active"] = 1
active_nodedef.groups["not_in_creative_inventory"] = 1 active_nodedef.groups["not_in_creative_inventory"] = 1
active_nodedef.drop = nodename active_nodedef.drop = nodename
minetest.register_node(active_name, active_nodedef) minetest.register_node(active_name, active_nodedef)
end end

View File

@ -1,4 +1,4 @@
-- A Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())

View File

@ -35,3 +35,13 @@ minetest.register_craft({
{"elepower_dynamics:motor", "elepower_dynamics:capacitor", ""}, {"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", "", ""},
}
})

View File

@ -1,4 +1,4 @@
-- A Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) 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 = rawget(_G, "eletool") or {}
eletool.modpath = modpath eletool.modpath = modpath
-- Simple tools
dofile(modpath .. "/tools.lua") dofile(modpath .. "/tools.lua")
-- Complex tools
dofile(modpath .. "/soldering.lua")
-- Crafting
dofile(modpath .. "/craftitems.lua") dofile(modpath .. "/craftitems.lua")
dofile(modpath .. "/crafting.lua") dofile(modpath .. "/crafting.lua")

View File

@ -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
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,6 +1,6 @@
ele.register_tool("elepower_tools:hand_drill", { ele.register_tool("elepower_tools:hand_drill", {
description = "Hand Drill", description = "Electric Hand Drill",
inventory_image = "eletools_hand_drill.png", inventory_image = "eletools_hand_drill.png",
wield_image = "eletools_hand_drill.png^[transformFX", wield_image = "eletools_hand_drill.png^[transformFX",
tool_capabilities = { tool_capabilities = {
@ -15,7 +15,7 @@ ele.register_tool("elepower_tools:hand_drill", {
}) })
ele.register_tool("elepower_tools:chainsaw", { ele.register_tool("elepower_tools:chainsaw", {
description = "Chainsaw", description = "Electric Chainsaw",
inventory_image = "eletools_chainsaw.png", inventory_image = "eletools_chainsaw.png",
wield_image = "eletools_chainsaw.png^[transformFX", wield_image = "eletools_chainsaw.png^[transformFX",
ele_capacity = 8000, ele_capacity = 8000,

View File

@ -1,4 +1,4 @@
-- Elepower Mod -- An Elepower Mod
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee> -- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())