Some file tree changes

This commit is contained in:
Evert Prants 2018-06-22 14:51:27 +03:00
parent 009bde499a
commit f8e8538b6e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
22 changed files with 180 additions and 309 deletions

View File

@ -3,6 +3,7 @@
-- Overrides --
---------------
-- Remove iron_lump -> steel_ingot, because dynamics adds iron ingot
minetest.clear_craft({type = "cooking", output = "default:steel_ingot"})
-----------

View File

@ -40,17 +40,6 @@ minetest.register_ore({
-- Nickel
minetest.register_ore({
ore_type = "scatter",
ore = "elepower_dynamics:stone_with_nickel",
wherein = "default:stone",
clust_scarcity = 28 * 28 * 28,
clust_num_ores = 5,
clust_size = 3,
y_max = 31000,
y_min = -31000,
})
minetest.register_ore({
ore_type = "scatter",
ore = "elepower_dynamics:stone_with_nickel",

View File

@ -1,7 +1,5 @@
-- Network graphs are built eminating from provider nodes.
-- Network cache
elefluid.graphcache = {nodes = {}}
-- TODO: Caching
---------------------
-- Graph Functions --
@ -14,9 +12,6 @@ end
local function add_node(nodes, pos, pnodeid)
local node_id = minetest.hash_node_position(pos)
if elefluid.graphcache.nodes[node_id] == "" then
elefluid.graphcache.nodes[node_id] = pnodeid
end
if nodes[node_id] then
return false
end
@ -40,8 +35,7 @@ local function check_node(targets, all_nodes, pos, p_pos, pnodeid, queue)
return
end
if not ele.helpers.get_item_group(node.name, "fluid_container") and
not ele.helpers.get_item_group(node.name, "fluidity_tank") then
if not ele.helpers.get_item_group(node.name, "fluid_container") then
return
end
@ -64,12 +58,7 @@ end
local function fluid_targets(p_pos, pos)
local provider = minetest.get_node(p_pos)
local pnodeid = minetest.pos_to_string(p_pos)
--[[
if elefluid.graphcache[pnodeid] then
local cached = elefluid.graphcache[pnodeid]
return cached.targets
end
]]
local targets = {}
local queue = {}
local all_nodes = {}
@ -77,8 +66,7 @@ local function fluid_targets(p_pos, pos)
local node = minetest.get_node(pos)
if node and ele.helpers.get_item_group(node.name, "elefluid_transport") then
add_duct_node(all_nodes, pos, pnodeid, queue)
elseif node and (ele.helpers.get_item_group(node.name, "fluid_container") or
ele.helpers.get_item_group(node.name, "fluidity_tank")) then
elseif node and ele.helpers.get_item_group(node.name, "fluid_container") then
queue = {p_pos}
end
@ -90,14 +78,9 @@ local function fluid_targets(p_pos, pos)
queue = to_visit
end
local prov_id = minetest.hash_node_position(p_pos)
elefluid.graphcache.nodes[prov_id] = pnodeid
targets = ele.helpers.flatten(targets)
all_nodes = ele.helpers.flatten(all_nodes)
elefluid.graphcache[pnodeid] = {all_nodes = all_nodes, targets = targets}
return targets
end
@ -107,7 +90,7 @@ end
minetest.register_abm({
nodenames = {"group:elefluid_transport_source"},
label = "elefluidFluidGraphSource",
label = "elepower Fluid Transfer Tick",
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
@ -120,7 +103,6 @@ minetest.register_abm({
local tpos = vector.add(minetest.facedir_to_dir(node.param2), pos)
local tname = minetest.get_node(tpos).name
if not ele.helpers.get_item_group(tname, "elefluid_transport") and
not ele.helpers.get_item_group(tname, "fluidity_tank") and
not ele.helpers.get_item_group(tname, "fluid_container") then
minetest.forceload_free_block(pos)
return
@ -145,8 +127,7 @@ minetest.register_abm({
end
-- Make sure source node is a registered fluid container
if not ele.helpers.get_item_group(srcnode.name, "fluid_container") and
not ele.helpers.get_item_group(srcnode.name, "fluidity_tank") then
if not ele.helpers.get_item_group(srcnode.name, "fluid_container") then
return
end
@ -201,113 +182,7 @@ minetest.register_abm({
end,
})
local function check_connections(pos)
local connections = {}
local positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x, y=pos.y+1, z=pos.z},
{x=pos.x, y=pos.y-1, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1}}
for _,connected_pos in pairs(positions) do
local name = minetest.get_node(connected_pos).name
if ele.helpers.get_item_group(name, "elefluid_transport") or
ele.helpers.get_item_group(name, "elefluid_transport_source") or
ele.helpers.get_item_group(name, "fluid_container") or
ele.helpers.get_item_group(name, "fluidity_tank") then
table.insert(connections, connected_pos)
end
end
return connections
end
function elefluid.clear_networks(pos)
-- TODO: Fluid network cache
return
end
--[[
-- Update networks when a node has been placed or removed
function elefluid.clear_networks(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local name = node.name
local placed = name ~= "air"
local positions = check_connections(pos)
if #positions < 1 then return end
local dead_end = #positions == 1
for _,connected_pos in pairs(positions) do
local net = elefluid.graphcache.nodes[minetest.hash_node_position(connected_pos)] or minetest.pos_to_string(connected_pos)
if net and elefluid.graphcache[net] then
if dead_end and placed then
-- Dead end placed, add it to the network
-- Get the network
local node_at = minetest.get_node(positions[1])
local network_id = elefluid.graphcache.nodes[minetest.hash_node_position(positions[1])] or minetest.pos_to_string(positions[1])
if not network_id or not elefluid.graphcache[network_id] then
-- We're evidently not on a network, nothing to add ourselves to
return
end
local c_pos = minetest.string_to_pos(network_id)
local network = elefluid.graphcache[network_id]
-- Actually add it to the (cached) network
-- This is similar to check_node_subp
elefluid.graphcache.nodes[minetest.hash_node_position(pos)] = network_id
pos.visited = 1
if ele.helpers.get_item_group(name, "elefluid_transport") then
table.insert(network.all_nodes, pos)
end
if ele.helpers.get_item_group(name, "fluid_container") or
ele.helpers.get_item_group(name, "fluidity_tank") then
table.insert(network.targets, pos)
end
elseif dead_end and not placed then
-- Dead end removed, remove it from the network
-- Get the network
local network_id = elefluid.graphcache.nodes[minetest.hash_node_position(positions[1])] or minetest.pos_to_string(positions[1])
if not network_id or not elefluid.graphcache[network_id] then
-- We're evidently not on a network, nothing to remove ourselves from
return
end
local network = elefluid.graphcache[network_id]
-- The network was deleted.
if network_id == minetest.pos_to_string(pos) then
for _,v in ipairs(network.all_nodes) do
local pos1 = minetest.hash_node_position(v)
clear_networks_from_node(v)
elefluid.graphcache.nodes[pos1] = nil
end
elefluid.graphcache[network_id] = nil
return
end
-- Search for and remove device
elefluid.graphcache.nodes[minetest.hash_node_position(pos)] = nil
for tblname,table in pairs(network) do
if type(table) == "table" then
for devicenum,device in pairs(table) do
if vector.equals(device, pos) then
table[devicenum] = nil
end
end
end
end
else
-- Not a dead end, so the whole network needs to be recalculated
for _,v in ipairs(elefluid.graphcache[net].all_nodes) do
local pos1 = minetest.hash_node_position(v)
clear_networks_from_node(v)
elefluid.graphcache.nodes[pos1] = nil
end
elefluid.graphcache[net] = nil
end
end
end
end
]]

View File

@ -1,4 +0,0 @@
dofile(elepm.modpath.."/bases/crafter.lua")
dofile(elepm.modpath.."/bases/generator.lua")
dofile(elepm.modpath.."/bases/storage.lua")

View File

@ -1,13 +1,12 @@
--*****************--
-- MACHINE RECIPES --
--*****************--
--------------
-- Alloying --
--------------
elepm.register_craft_type("alloy", {
description = "Alloying",
inputs = 2,
})
local alloy_recipes = {
{
recipe = { "elepower_dynamics:iron_ingot", "elepower_dynamics:coal_dust 4" },
@ -21,6 +20,10 @@ local alloy_recipes = {
{
recipe = { "default:iron_ingot 3", "elepower_dynamics:nickel_ingot" },
output = "elepower_dynamics:invar_ingot 4",
},
{
recipe = { "default:gold_ingot 2", "elepower_dynamics:invar_ingot" },
output = "elepower_dynamics:electrum_ingot 3",
}
}
@ -34,32 +37,10 @@ for _,i in pairs(alloy_recipes) do
})
end
elepm.register_crafter("elepower_machines:alloy_furnace", {
description = "Alloy Furnace",
craft_type = "alloy",
ele_active_node = true,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_alloy_furnace.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_alloy_furnace_active.png",
},
},
groups = {oddly_breakable_by_hand = 1}
})
--------------
-- Grinding --
--------------
elepm.register_craft_type("grind", {
description = "Grinding",
inputs = 1,
})
local keywords = { _ingot = 1, _lump = 2, _block = 9, block = 9 }
for mat, data in pairs(elepd.registered_dusts) do
local kwfound = nil
@ -90,55 +71,10 @@ for mat, data in pairs(elepd.registered_dusts) do
end
end
elepm.register_crafter("elepower_machines:pulverizer", {
description = "Pulverizer",
craft_type = "grind",
ele_active_node = true,
ele_usage = 32,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_grinder.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_grinder_active.png",
},
},
groups = {oddly_breakable_by_hand = 1}
})
-------------
-- Furnace --
-------------
elepm.register_crafter("elepower_machines:furnace", {
description = "Powered Furnace",
craft_type = "cooking",
ele_active_node = true,
ele_usage = 32,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_furnace.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_furnace_active.png",
},
},
groups = {oddly_breakable_by_hand = 1}
})
-------------
-- Sawmill --
-------------
elepm.register_craft_type("saw", {
description = "Sawmilling",
inputs = 1,
})
-- Register all logs as sawable, if we can find a planks version
minetest.after(0.2, function ()
local wood_nodes = {}
@ -171,56 +107,11 @@ minetest.after(0.2, function ()
end
end)
elepm.register_crafter("elepower_machines:sawmill", {
description = "Sawmill",
craft_type = "saw",
ele_usage = 32,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_sawmill.png",
},
groups = {oddly_breakable_by_hand = 1}
})
----------------------
-- Power Generation --
----------------------
elepm.register_fuel_generator("elepower_machines:generator", {
description = "Coal-fired Generator",
ele_active_node = true,
ele_capacity = 6400,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_generator.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_generator_active.png",
}
},
groups = {oddly_breakable_by_hand = 1}
})
-------------------
-- Power Storage --
-------------------
elepm.register_storage("elepower_machines:power_cell", {
description = "Power Cell",
ele_capacity = 16000,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_power_cell.png",
},
groups = {oddly_breakable_by_hand = 1}
})
--******************--
-- CRAFTING RECIPES --
--******************--
-- Machine block
minetest.register_craft({
output = "elepower_machines:machine_block",
recipe = {

View File

@ -6,9 +6,15 @@ local modpath = minetest.get_modpath(minetest.get_current_modname())
elepm = rawget(_G, "elepm") or {}
elepm.modpath = modpath
-- Utility
dofile(modpath.."/craft.lua")
dofile(modpath.."/formspec.lua")
dofile(modpath.."/bases/init.lua")
-- Machines
dofile(modpath.."/machines/init.lua")
-- Other
dofile(modpath.."/nodes.lua")
dofile(modpath.."/special/init.lua")
dofile(modpath.."/register.lua")
-- Crafting recipes
dofile(modpath.."/crafting.lua")

View File

@ -0,0 +1,22 @@
elepm.register_craft_type("alloy", {
description = "Alloying",
inputs = 2,
})
elepm.register_crafter("elepower_machines:alloy_furnace", {
description = "Alloy Furnace",
craft_type = "alloy",
ele_active_node = true,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_alloy_furnace.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_alloy_furnace_active.png",
},
},
groups = {oddly_breakable_by_hand = 1}
})

View File

@ -0,0 +1,4 @@
dofile(elepm.modpath.."/machines/bases/crafter.lua")
dofile(elepm.modpath.."/machines/bases/generator.lua")
dofile(elepm.modpath.."/machines/bases/storage.lua")

View File

@ -0,0 +1,22 @@
-------------
-- Furnace --
-------------
elepm.register_crafter("elepower_machines:furnace", {
description = "Powered Furnace",
craft_type = "cooking",
ele_active_node = true,
ele_usage = 32,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_furnace.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_furnace_active.png",
},
},
groups = {oddly_breakable_by_hand = 1}
})

View File

@ -0,0 +1,21 @@
----------------------
-- Power Generation --
----------------------
elepm.register_fuel_generator("elepower_machines:generator", {
description = "Coal-fired Generator",
ele_active_node = true,
ele_capacity = 6400,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_generator.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_generator_active.png",
}
},
groups = {oddly_breakable_by_hand = 1}
})

View File

@ -0,0 +1,9 @@
dofile(elepm.modpath.."/machines/bases/init.lua")
dofile(elepm.modpath.."/machines/accumulator.lua")
dofile(elepm.modpath.."/machines/furnace.lua")
dofile(elepm.modpath.."/machines/alloy_furnace.lua")
dofile(elepm.modpath.."/machines/pulverizer.lua")
dofile(elepm.modpath.."/machines/sawmill.lua")
dofile(elepm.modpath.."/machines/generator.lua")
dofile(elepm.modpath.."/machines/storage.lua")

View File

@ -0,0 +1,23 @@
elepm.register_craft_type("grind", {
description = "Grinding",
inputs = 1,
})
elepm.register_crafter("elepower_machines:pulverizer", {
description = "Pulverizer",
craft_type = "grind",
ele_active_node = true,
ele_usage = 32,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_grinder.png",
},
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_grinder_active.png",
},
},
groups = {oddly_breakable_by_hand = 1}
})

View File

@ -0,0 +1,16 @@
elepm.register_craft_type("saw", {
description = "Sawmilling",
inputs = 1,
})
elepm.register_crafter("elepower_machines:sawmill", {
description = "Sawmill",
craft_type = "saw",
ele_usage = 32,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_sawmill.png",
},
groups = {oddly_breakable_by_hand = 1}
})

View File

@ -0,0 +1,14 @@
-------------------
-- Power Storage --
-------------------
elepm.register_storage("elepower_machines:power_cell", {
description = "Power Cell",
ele_capacity = 16000,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_power_cell.png",
},
groups = {oddly_breakable_by_hand = 1}
})

View File

@ -1,5 +1,4 @@
-- Nodes other than machines.
-- Machines are registered in `register.lua`!
minetest.register_node("elepower_machines:machine_block", {
description = "Machine Block\nSafe for decoration",

View File

@ -1,2 +0,0 @@
dofile(elepm.modpath.."/special/accumulator.lua")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -162,28 +162,13 @@ end
minetest.register_abm({
nodenames = {"group:ele_provider"},
label = "elepowerPowerGraphSource",
label = "elepower Power Transfer Tick",
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local meta1 = nil
-- Check if a provider is attached to a network.
-- If that network has been abolished, we will use this node as the network's root this time.
local netwrkto = meta:get_string("ele_network")
if netwrkto ~= "" and netwrkto ~= nil then
if not ele.helpers.get_item_group(node.name, "ele_storage") then
local lpos = minetest.string_to_pos(netwrkto)
if ele.helpers.get_item_group(minetest.get_node(lpos).name, "ele_provider") then
return
else
ele.graphcache[netwrkto] = nil
end
meta:set_string("ele_network", "")
end
end
local users = {}
local providers = {}
@ -200,10 +185,12 @@ minetest.register_abm({
}
local branches = {}
for _,pos1 in pairs(positions) do
for _,pos1 in ipairs(positions) do
local pnode = minetest.get_node(pos1)
local name = pnode.name
local networked = ele.helpers.get_item_group(name, "ele_machine") or ele.helpers.get_item_group(name, "ele_conductor")
local networked = ele.helpers.get_item_group(name, "ele_machine") or
ele.helpers.get_item_group(name, "ele_conductor")
if networked then
branches[#branches + 1] = pos1
end
@ -243,14 +230,13 @@ minetest.register_abm({
end
-- Sharing: Determine how much each user gets
local user_supply = (pw_supply - pw_demand) / #users
local user_gets, user_storage = give_node_power(ndv, user_supply)
local user_gets, user_storage = give_node_power(ndv, (pw_supply - pw_demand))
pw_demand = pw_demand + user_gets
if user_gets > 0 then
local user_meta = minetest.get_meta(ndv)
user_meta:set_int("storage", user_storage + user_gets)
if user_gets > 0 then
-- Set timer on this node
local t = minetest.get_node_timer(ndv)
if not t:is_started() then
@ -289,7 +275,7 @@ local function check_connections(pos)
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1}}
for _,connected_pos in pairs(positions) do
for _,connected_pos in ipairs(positions) do
local name = minetest.get_node(connected_pos).name
if ele.helpers.get_item_group(name, "ele_conductor") or ele.helpers.get_item_group(name, "ele_machine") then
table.insert(connections, connected_pos)
@ -306,8 +292,9 @@ function ele.clear_networks(pos)
local placed = name ~= "air"
local positions = check_connections(pos)
if #positions < 1 then return end
local hash_pos = minetest.hash_node_position(pos)
local dead_end = #positions == 1
for _,connected_pos in pairs(positions) do
for _,connected_pos in ipairs(positions) do
local networks = ele.graphcache.devices[minetest.hash_node_position(connected_pos)] or
{minetest.pos_to_string(connected_pos)}
@ -328,17 +315,15 @@ function ele.clear_networks(pos)
for _, int_net in ipairs(network_ids) do
if ele.graphcache[int_net] then
local c_pos = minetest.string_to_pos(int_net)
local network = ele.graphcache[int_net]
-- Actually add it to the (cached) network
if not ele.graphcache.devices[minetest.hash_node_position(pos)] then
ele.graphcache.devices[minetest.hash_node_position(pos)] = {}
if not ele.graphcache.devices[hash_pos] then
ele.graphcache.devices[hash_pos] = {}
end
local t = ele.graphcache.devices[minetest.hash_node_position(pos)]
if not table_has_string(t, int_net) then
table.insert(t, int_net)
if not table_has_string(ele.graphcache.devices[hash_pos], int_net) then
table.insert(ele.graphcache.devices[hash_pos], int_net)
end
if ele.helpers.get_item_group(name, "ele_conductor") then
@ -379,7 +364,7 @@ function ele.clear_networks(pos)
ele.graphcache[int_net] = nil
else
-- Search for and remove device
ele.graphcache.devices[minetest.hash_node_position(pos)] = nil
ele.graphcache.devices[hash_pos] = nil
for tblname, table in pairs(network) do
if type(table) == "table" then
for devicenum, device in pairs(table) do