Unify spacing

* Fix spacing in various files

---------

Co-authored-by: theFox6 <the.Fox6@gmx.de>
This commit is contained in:
beepbopbeepboop 2024-01-24 00:53:14 -08:00 committed by GitHub
parent e00028cc09
commit a21dbd9b82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 2110 additions and 2109 deletions

176
api.lua

@ -3,67 +3,67 @@ local BASENAME = "microexpansion"
-- [function] Register Recipe -- [function] Register Recipe
function microexpansion.register_recipe(output, recipe) function microexpansion.register_recipe(output, recipe)
-- Check if disabled -- Check if disabled
if recipe.disabled == true then if recipe.disabled == true then
return return
end end
for _,r in ipairs(recipe) do for _,r in ipairs(recipe) do
local def = { local def = {
type = type(r[2]) == "string" and r[2] or nil, type = type(r[2]) == "string" and r[2] or nil,
output = output.." "..(r[1] or 1), output = output.." "..(r[1] or 1),
recipe = r[3] or r[2] recipe = r[3] or r[2]
} }
minetest.register_craft(def) minetest.register_craft(def)
end end
end end
-- [function] Register oredef -- [function] Register oredef
function microexpansion.register_oredef(ore, defs) function microexpansion.register_oredef(ore, defs)
-- Check if disabled -- Check if disabled
if defs.disabled == true then if defs.disabled == true then
return return
end end
for _,d in ipairs(defs) do for _,d in ipairs(defs) do
d.ore = ore d.ore = ore
minetest.log("action", minetest.serialize(d)) minetest.log("action", minetest.serialize(d))
minetest.register_ore(d) minetest.register_ore(d)
end end
end end
-- [local function] Choose description colour -- [local function] Choose description colour
local function desc_colour(status, desc) local function desc_colour(status, desc)
if status == "unstable" then if status == "unstable" then
return minetest.colorize("orange", desc) return minetest.colorize("orange", desc)
elseif status == "no" then elseif status == "no" then
return minetest.colorize("red", desc) return minetest.colorize("red", desc)
else else
return minetest.colorize("white", desc) return minetest.colorize("white", desc)
end end
end end
-- [function] Register Item -- [function] Register Item
function microexpansion.register_item(itemstring, def) function microexpansion.register_item(itemstring, def)
-- Check if disabled -- Check if disabled
if def.disabled == true then if def.disabled == true then
return return
end end
-- Set usedfor -- Set usedfor
if def.usedfor then if def.usedfor then
def.description = def.description .. "\n"..minetest.colorize("grey", def.usedfor) def.description = def.description .. "\n"..minetest.colorize("grey", def.usedfor)
end end
-- Update inventory image -- Update inventory image
if def.inventory_image then if def.inventory_image then
def.inventory_image = BASENAME.."_"..def.inventory_image..".png" def.inventory_image = BASENAME.."_"..def.inventory_image..".png"
else else
def.inventory_image = BASENAME.."_"..itemstring..".png" def.inventory_image = BASENAME.."_"..itemstring..".png"
end end
-- Colour description -- Colour description
def.description = desc_colour(def.status, def.description) def.description = desc_colour(def.status, def.description)
-- Register craftitem -- Register craftitem
minetest.register_craftitem(BASENAME..":"..itemstring, def) minetest.register_craftitem(BASENAME..":"..itemstring, def)
-- if recipe, Register recipe -- if recipe, Register recipe
if def.recipe then if def.recipe then
@ -74,11 +74,11 @@ end
-- [function] Register Node -- [function] Register Node
function microexpansion.register_node(itemstring, def) function microexpansion.register_node(itemstring, def)
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
def._mcl_hardness = def._mcl_hardness or 3 def._mcl_hardness = def._mcl_hardness or 3
def._mcl_blast_resistance = def._mcl_blast_resistance or 3 def._mcl_blast_resistance = def._mcl_blast_resistance or 3
def._mcl_hardness = def._mcl_hardness or 3 def._mcl_hardness = def._mcl_hardness or 3
def._mcl_silk_touch_drop = def._mcl_silk_touch_drop or true def._mcl_silk_touch_drop = def._mcl_silk_touch_drop or true
def.groups.pickaxey = def.groups.pickaxey or 3 def.groups.pickaxey = def.groups.pickaxey or 3
end end
-- Check if disabled -- Check if disabled
if def.disabled == true then if def.disabled == true then
@ -101,45 +101,45 @@ function microexpansion.register_node(itemstring, def)
end end
end end
end end
-- Colour description -- Colour description
def.description = desc_colour(def.status, def.description) def.description = desc_colour(def.status, def.description)
-- Update connect_sides -- Update connect_sides
if def.connect_sides == "nobottom" then if def.connect_sides == "nobottom" then
def.connect_sides = { "top", "front", "left", "back", "right" } def.connect_sides = { "top", "front", "left", "back", "right" }
elseif def.connect_sides == "machine" then elseif def.connect_sides == "machine" then
def.connect_sides = { "top", "bottom", "left", "back", "right" } def.connect_sides = { "top", "bottom", "left", "back", "right" }
end end
-- Register node -- Register node
minetest.register_node(BASENAME..":"..itemstring, def) minetest.register_node(BASENAME..":"..itemstring, def)
-- if recipe, Register recipe -- if recipe, Register recipe
if def.recipe then if def.recipe then
microexpansion.register_recipe(BASENAME..":"..itemstring, def.recipe) microexpansion.register_recipe(BASENAME..":"..itemstring, def.recipe)
end end
-- if oredef, Register oredef -- if oredef, Register oredef
if def.oredef then if def.oredef then
microexpansion.register_oredef(BASENAME..":"..itemstring, def.oredef) microexpansion.register_oredef(BASENAME..":"..itemstring, def.oredef)
end end
end end
-- get a node, if nessecary load it -- get a node, if nessecary load it
function microexpansion.get_node(pos) function microexpansion.get_node(pos)
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)
if node then return node end if node then return node end
local vm = VoxelManip() local vm = VoxelManip()
vm:read_from_map(pos, pos) vm:read_from_map(pos, pos)
return minetest.get_node(pos) return minetest.get_node(pos)
end end
function microexpansion.update_node(pos,event) function microexpansion.update_node(pos,event)
local node = microexpansion.get_node(pos) local node = microexpansion.get_node(pos)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
local ev = event or {type = "n/a"} local ev = event or {type = "n/a"}
if def.me_update then if def.me_update then
def.me_update(pos,node,ev) def.me_update(pos,node,ev)
end end
end end
-- [function] Move items from inv to inv -- [function] Move items from inv to inv
@ -157,25 +157,25 @@ function microexpansion.move_inv(inv1, inv2, max, filter)
end end
if not v:is_empty() then if not v:is_empty() then
if v:get_count() > left then if v:get_count() > left then
v = v:peek_item(left) v = v:peek_item(left)
end end
if tinv and tinv:room_for_item(tname, v) and (not filter or not filter(v)) then if tinv and tinv:room_for_item(tname, v) and (not filter or not filter(v)) then
if huge then if huge then
microexpansion.insert_item(v, tinv, tname) microexpansion.insert_item(v, tinv, tname)
finv:remove_item(fname, v) finv:remove_item(fname, v)
else else
--TODO: continue inserting from the same stack if it is bigger than max --TODO: continue inserting from the same stack if it is bigger than max
if v:get_count() > v:get_stack_max() then if v:get_count() > v:get_stack_max() then
v = v:peek_item(v:get_stack_max()) v = v:peek_item(v:get_stack_max())
end end
local leftover = tinv:add_item(tname, v) local leftover = tinv:add_item(tname, v)
finv:remove_item(fname, v) finv:remove_item(fname, v)
if leftover and not(leftover:is_empty()) then if leftover and not(leftover:is_empty()) then
microexpansion.log("leftover items when transferring inventory","warning") microexpansion.log("leftover items when transferring inventory","warning")
finv:add_item(fname, leftover) finv:add_item(fname, leftover)
end end
end end
inserted = inserted + v:get_count() inserted = inserted + v:get_count()
end end
end end
end end

@ -11,18 +11,18 @@ microexpansion.gui_bg = "bgcolor[#080808BB;true]background[5,5;1,1;gui_formbg.pn
microexpansion.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]" microexpansion.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
microexpansion.settings = { microexpansion.settings = {
huge_stacks = minetest.settings:get_bool("microexpansion_huge_stacks"), huge_stacks = minetest.settings:get_bool("microexpansion_huge_stacks"),
simple_craft = minetest.settings:get_bool("microexpansion_simple_craft") simple_craft = minetest.settings:get_bool("microexpansion_simple_craft")
} }
microexpansion.uinv_category_enabled = minetest.global_exists("unified_inventory") and unified_inventory.add_category_item and true or false microexpansion.uinv_category_enabled = minetest.global_exists("unified_inventory") and unified_inventory.add_category_item and true or false
-- logger -- logger
function microexpansion.log(content, log_type) function microexpansion.log(content, log_type)
assert(content, "microexpansion.log: missing content") assert(content, "microexpansion.log: missing content")
if not content then return false end if not content then return false end
if log_type == nil then log_type = "action" end if log_type == nil then log_type = "action" end
minetest.log(log_type, "[MicroExpansion] "..content) minetest.log(log_type, "[MicroExpansion] "..content)
end end
-- Load API -- Load API
@ -40,45 +40,45 @@ local settings = Settings(modpath.."/modules.conf"):to_table()
-- [function] Get module path -- [function] Get module path
function microexpansion.get_module_path(name) function microexpansion.get_module_path(name)
local module_path = modpath.."/modules/"..name local module_path = modpath.."/modules/"..name
local handle = io.open(module_path.."/init.lua") local handle = io.open(module_path.."/init.lua")
if handle then if handle then
io.close(handle) io.close(handle)
return module_path return module_path
end end
end end
-- [function] Load module (overrides modules.conf) -- [function] Load module (overrides modules.conf)
function microexpansion.load_module(name) function microexpansion.load_module(name)
if not loaded_modules[name] then if not loaded_modules[name] then
local module_path = microexpansion.get_module_path(name) local module_path = microexpansion.get_module_path(name)
if module_path then if module_path then
dofile(module_path.."/init.lua") dofile(module_path.."/init.lua")
loaded_modules[name] = true loaded_modules[name] = true
return true return true
else else
microexpansion.log("Invalid module \""..name.."\". The module either does not exist ".. microexpansion.log("Invalid module \""..name.."\". The module either does not exist "..
"or is missing an init.lua file.", "error") "or is missing an init.lua file.", "error")
end end
else else
return true return true
end end
end end
-- [function] Require module (does not override modules.conf) -- [function] Require module (does not override modules.conf)
function microexpansion.require_module(name) function microexpansion.require_module(name)
if settings[name] then if settings[name] then
microexpansion.log("loading module " .. name) microexpansion.log("loading module " .. name)
return microexpansion.load_module(name) return microexpansion.load_module(name)
else else
microexpansion.log("not loading module " .. name) microexpansion.log("not loading module " .. name)
end end
end end
for name,enabled in pairs(settings) do for name,enabled in pairs(settings) do
if enabled ~= false then if enabled ~= false then
microexpansion.load_module(name) microexpansion.load_module(name)
end end
end end

@ -10,28 +10,28 @@ local me = microexpansion
-- a different logic chip that uses gold, quartz and wood -- a different logic chip that uses gold, quartz and wood
-- for use instead of basic_materials:ic that requires sand, coal and copper -- for use instead of basic_materials:ic that requires sand, coal and copper
me.register_item("logic_chip", { me.register_item("logic_chip", {
description = "Control Unit", description = "Control Unit",
recipe = { recipe = {
{ 2, { 2,
{ {
{"basic_materials:gold_wire"}, {"basic_materials:gold_wire"},
{"basic_materials:silicon"}, {"basic_materials:silicon"},
{"basic_materials:plastic_sheet"} {"basic_materials:plastic_sheet"}
}, },
}, },
{ 2, { 2,
{ {
{"basic_materials:gold_wire"}, {"basic_materials:gold_wire"},
{"microexpansion:quartz_crystal"}, {"microexpansion:quartz_crystal"},
{"basic_materials:plastic_sheet"} {"basic_materials:plastic_sheet"}
}, },
}, },
{ 2, { 2,
{ {
{"microexpansion:gold_wire"}, {"microexpansion:gold_wire"},
{"microexpansion:quartz_crystal"}, {"microexpansion:quartz_crystal"},
{"group:wood"} {"group:wood"}
}, },
}, },
}, },
}) })

@ -3,29 +3,30 @@
local me = microexpansion local me = microexpansion
local substitute_basic_materials = microexpansion.settings.simple_craft == true or not minetest.get_modpath("basic_materials") local substitute_basic_materials = microexpansion.settings.simple_craft == true or not minetest.get_modpath("basic_materials")
local gold_wire_recipe
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
gold_wire_recipe = { gold_wire_recipe = {
{ 2, { { 2, {
{"mcl_core:gold_ingot", "mcl_core:stick"}, {"mcl_core:gold_ingot", "mcl_core:stick"},
{"mcl_core:stick", ""} {"mcl_core:stick", ""}
}, },
}, },
} }
else else
gold_wire_recipe = { gold_wire_recipe = {
{ 2, { { 2, {
{"default:gold_ingot", "default:stick"}, {"default:gold_ingot", "default:stick"},
{"default:stick", ""} {"default:stick", ""}
}, },
}, },
} }
end end
-- [register item] Gold Wire -- [register item] Gold Wire
me.register_item("gold_wire", { me.register_item("gold_wire", {
description = "Gold Wire", description = "Gold Wire",
groups = { wire = 1 }, groups = { wire = 1 },
recipe = substitute_basic_materials and gold_wire_recipe or nil, recipe = substitute_basic_materials and gold_wire_recipe or nil,
}) })

@ -3,50 +3,51 @@
local me = microexpansion local me = microexpansion
-- custom items that are used by multiple devices -- custom items that are used by multiple devices
local steel_infused_obsidian_ingot_recipe, machine_casing_recipe
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
steel_infused_obsidian_ingot_recipe = { steel_infused_obsidian_ingot_recipe = {
{ 2, { { 2, {
{ "mcl_core:iron_ingot", "mcl_core:obsidian", "mcl_core:iron_ingot" }, { "mcl_core:iron_ingot", "mcl_core:obsidian", "mcl_core:iron_ingot" },
}, },
}, },
} }
machine_casing_recipe = { machine_casing_recipe = {
{ 1, { { 1, {
{"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
}, },
}, },
} }
else else
steel_infused_obsidian_ingot_recipe = { steel_infused_obsidian_ingot_recipe = {
{ 2, { { 2, {
{ "default:steel_ingot", "default:obsidian_shard", "default:steel_ingot" }, { "default:steel_ingot", "default:obsidian_shard", "default:steel_ingot" },
}, },
}, },
} }
machine_casing_recipe = { machine_casing_recipe = {
{ 1, { { 1, {
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
}, },
}, },
} }
end end
-- [register item] Steel Infused Obsidian Ingot -- [register item] Steel Infused Obsidian Ingot
me.register_item("steel_infused_obsidian_ingot", { me.register_item("steel_infused_obsidian_ingot", {
description = "Steel Infused Obsidian Ingot", description = "Steel Infused Obsidian Ingot",
recipe = steel_infused_obsidian_ingot_recipe, recipe = steel_infused_obsidian_ingot_recipe,
}) })
-- [register item] Machine Casing -- [register item] Machine Casing
me.register_item("machine_casing", { me.register_item("machine_casing", {
description = "Machine Casing", description = "Machine Casing",
recipe = machine_casing_recipe, recipe = machine_casing_recipe,
}) })

@ -7,13 +7,13 @@ function item_transfer.get_output_inventory(pos,metadata,inventory)
local meta = metadata or minetest.get_meta(pos) local meta = metadata or minetest.get_meta(pos)
local inv = inventory or meta:get_inventory() local inv = inventory or meta:get_inventory()
local lists = inv:get_lists() local lists = inv:get_lists()
if not lists then if not lists then
return return
elseif lists["dst"] then elseif lists["dst"] then
return "dst", inv return "dst", inv
elseif lists["main"] then elseif lists["main"] then
return "main", inv return "main", inv
end end
end end
function item_transfer.get_input_inventory(pos,metadata,inventory) function item_transfer.get_input_inventory(pos,metadata,inventory)
@ -21,243 +21,243 @@ function item_transfer.get_input_inventory(pos,metadata,inventory)
local inv = inventory or meta:get_inventory() local inv = inventory or meta:get_inventory()
local lists = inv:get_lists() local lists = inv:get_lists()
if not lists then if not lists then
return return
elseif lists["src"] then elseif lists["src"] then
return "src", inv return "src", inv
elseif lists["main"] then elseif lists["main"] then
return "main", inv return "main", inv
end end
end end
function microexpansion.vector_cross(a, b) function microexpansion.vector_cross(a, b)
return { return {
x = a.y * b.z - a.z * b.y, x = a.y * b.z - a.z * b.y,
y = a.z * b.x - a.x * b.z, y = a.z * b.x - a.x * b.z,
z = a.x * b.y - a.y * b.x z = a.x * b.y - a.y * b.x
} }
end end
function microexpansion.facedir_to_top_dir(facedir) function microexpansion.facedir_to_top_dir(facedir)
return ({[0] = {x = 0, y = 1, z = 0}, return ({[0] = {x = 0, y = 1, z = 0},
{x = 0, y = 0, z = 1}, {x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}, {x = 0, y = 0, z = -1},
{x = 1, y = 0, z = 0}, {x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0}, {x = -1, y = 0, z = 0},
{x = 0, y = -1, z = 0}}) {x = 0, y = -1, z = 0}})
[math.floor(facedir / 4)] [math.floor(facedir / 4)]
end end
function microexpansion.facedir_to_right_dir(facedir) function microexpansion.facedir_to_right_dir(facedir)
return microexpansion.vector_cross( return microexpansion.vector_cross(
microexpansion.facedir_to_top_dir(facedir), microexpansion.facedir_to_top_dir(facedir),
minetest.facedir_to_dir(facedir) minetest.facedir_to_dir(facedir)
) )
end end
function microexpansion.count_upgrades(inv) function microexpansion.count_upgrades(inv)
local upgrades = {} local upgrades = {}
for i = 0, inv:get_size("upgrades") do for i = 0, inv:get_size("upgrades") do
local stack = inv:get_stack("upgrades", i) local stack = inv:get_stack("upgrades", i)
local item = stack:get_name() local item = stack:get_name()
if item == "microexpansion:upgrade_filter" then if item == "microexpansion:upgrade_filter" then
upgrades.filter = (upgrades.filter or 0) + stack:get_count() upgrades.filter = (upgrades.filter or 0) + stack:get_count()
elseif item == "microexpansion:upgrade_bulk" then elseif item == "microexpansion:upgrade_bulk" then
upgrades.bulk = (upgrades.bulk or 0) + stack:get_count() upgrades.bulk = (upgrades.bulk or 0) + stack:get_count()
end end
end end
return upgrades return upgrades
end end
function item_transfer.update_timer_based(pos,_,ev) function item_transfer.update_timer_based(pos,_,ev)
if ev then if ev then
if ev.type ~= "disconnect" if ev.type ~= "disconnect"
and ev.type ~= "connect" and ev.type ~= "connect"
and ev.type ~= "construct" then and ev.type ~= "construct" then
return return
end end
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if me.get_connected_network(pos) then if me.get_connected_network(pos) then
meta:set_string("infotext", "Network connected") meta:set_string("infotext", "Network connected")
if not minetest.get_node_timer(pos):is_started() then if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(2) minetest.get_node_timer(pos):start(2)
end end
else else
meta:set_string("infotext", "No Network") meta:set_string("infotext", "No Network")
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
end end
end end
function item_transfer.setup_io_device(title, pos, metadata, inventory) function item_transfer.setup_io_device(title, pos, metadata, inventory)
local meta = metadata or minetest.get_meta(pos) local meta = metadata or minetest.get_meta(pos)
local inv = inventory or meta:get_inventory() local inv = inventory or meta:get_inventory()
local formspec = [[ local formspec = [[
formspec_version[2] formspec_version[2]
size[11,11] size[11,11]
]] .. ]] ..
microexpansion.gui_bg .. microexpansion.gui_bg ..
microexpansion.gui_slots microexpansion.gui_slots
if title then if title then
formspec = formspec .. "label[9,0.5;"..title.."]" formspec = formspec .. "label[9,0.5;"..title.."]"
end end
local upgrades = me.count_upgrades(inv) local upgrades = me.count_upgrades(inv)
if upgrades.filter then if upgrades.filter then
inv:set_size("filter", math.pow(2, upgrades.filter - 1)) inv:set_size("filter", math.pow(2, upgrades.filter - 1))
formspec = formspec .. [[ formspec = formspec .. [[
label[0.5,0.75;filter] label[0.5,0.75;filter]
list[context;filter;0.5,1;5,3] list[context;filter;0.5,1;5,3]
]] ]]
else else
inv:set_size("filter",0) inv:set_size("filter",0)
end end
--TODO: target inventory dropdown --TODO: target inventory dropdown
inv:set_size("upgrades", 4) inv:set_size("upgrades", 4)
meta:set_string("formspec", meta:set_string("formspec",
formspec .. formspec ..
[[ [[
label[8.5,2.5;upgrades] label[8.5,2.5;upgrades]
list[context;upgrades;8,2.75;2,2] list[context;upgrades;8,2.75;2,2]
list[current_player;main;0.5,5.5;8,1;] list[current_player;main;0.5,5.5;8,1;]
list[current_player;main;0.5,7;8,3;8] list[current_player;main;0.5,7;8,3;8]
listring[current_name;upgrades] listring[current_name;upgrades]
listring[current_player;main] listring[current_player;main]
]]) ]])
end end
local access_level = microexpansion.constants.security.access_levels local access_level = microexpansion.constants.security.access_levels
local io_device_base = { local io_device_base = {
is_ground_content = false, is_ground_content = false,
groups = { crumbly = 1, me_connect = 1 }, groups = { crumbly = 1, me_connect = 1 },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
me_update = item_transfer.update_timer_based, me_update = item_transfer.update_timer_based,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
if not placer then if not placer then
return false return false
end end
local name = placer:get_player_name() local name = placer:get_player_name()
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if net then if net then
if net:get_access_level(name) < access_level.modify then if net:get_access_level(name) < access_level.modify then
-- prevent placing exporters on a network that a player doesn't have access to -- prevent placing exporters on a network that a player doesn't have access to
--Do we need to send a disconnect or stop any node timers? --Do we need to send a disconnect or stop any node timers?
minetest.remove_node(pos) minetest.remove_node(pos)
return true return true
else else
return false return false
end end
elseif minetest.is_protected(pos, name) then elseif minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
--protection probably handles this itself --protection probably handles this itself
--minetest.remove_node(pos) --minetest.remove_node(pos)
return true return true
end end
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
if not player then if not player then
return false return false
end end
local name = player:get_player_name() local name = player:get_player_name()
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if net then if net then
if net:get_access_level(name) < access_level.modify then if net:get_access_level(name) < access_level.modify then
return false return false
end end
elseif minetest.is_protected(pos, name) then elseif minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return false return false
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("upgrades") return inv:is_empty("upgrades")
end, end,
allow_metadata_inventory_put = function(pos, listname, _, stack, player) allow_metadata_inventory_put = function(pos, listname, _, stack, player)
local max_allowed = stack:get_count() local max_allowed = stack:get_count()
if listname == "upgrades" then if listname == "upgrades" then
local item = stack:get_name() local item = stack:get_name()
if item == "microexpansion:upgrade_filter" then if item == "microexpansion:upgrade_filter" then
local filter_upgrades = me.count_upgrades(minetest.get_meta(pos):get_inventory()).filter local filter_upgrades = me.count_upgrades(minetest.get_meta(pos):get_inventory()).filter
if filter_upgrades then if filter_upgrades then
max_allowed = math.max(0, math.min(stack:get_count(), 5 - filter_upgrades)) max_allowed = math.max(0, math.min(stack:get_count(), 5 - filter_upgrades))
else else
max_allowed = math.min(stack:get_count(), 5) max_allowed = math.min(stack:get_count(), 5)
end end
elseif item == "microexpansion:upgrade_bulk" then elseif item == "microexpansion:upgrade_bulk" then
local bulk_upgrades = me.count_upgrades(minetest.get_meta(pos):get_inventory()).bulk local bulk_upgrades = me.count_upgrades(minetest.get_meta(pos):get_inventory()).bulk
if bulk_upgrades then if bulk_upgrades then
max_allowed = math.max(0, math.min(stack:get_count(), 10 - bulk_upgrades)) max_allowed = math.max(0, math.min(stack:get_count(), 10 - bulk_upgrades))
else else
max_allowed = math.min(stack:get_count(), 10) max_allowed = math.min(stack:get_count(), 10)
end end
else else
return 0 return 0
end end
end end
if not player then if not player then
return max_allowed return max_allowed
end end
local name = player:get_player_name() local name = player:get_player_name()
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if net then if net then
if net:get_access_level(name) < access_level.modify then if net:get_access_level(name) < access_level.modify then
return 0 return 0
end end
elseif minetest.is_protected(pos, name) then elseif minetest.is_protected(pos, name) then
--minetest.record_protection_violation(pos, name) --minetest.record_protection_violation(pos, name)
return 0 return 0
end end
if listname == "filter" then if listname == "filter" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local filter = stack:peek_item() local filter = stack:peek_item()
if inv:room_for_item(listname,filter) and not inv:contains_item(listname, filter) then if inv:room_for_item(listname,filter) and not inv:contains_item(listname, filter) then
inv:add_item(listname, filter) inv:add_item(listname, filter)
end end
return 0 return 0
else else
return max_allowed return max_allowed
end end
end, end,
allow_metadata_inventory_take = function(pos, listname, _, stack, player) allow_metadata_inventory_take = function(pos, listname, _, stack, player)
if not player then if not player then
return 0 return 0
end end
local name = player:get_player_name() local name = player:get_player_name()
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if net then if net then
if net:get_access_level(name) < access_level.modify then if net:get_access_level(name) < access_level.modify then
return 0 return 0
end end
elseif minetest.is_protected(pos, name) then elseif minetest.is_protected(pos, name) then
--minetest.record_protection_violation(pos, name) --minetest.record_protection_violation(pos, name)
return 0 return 0
end end
if listname == "filter" then if listname == "filter" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:remove_item(listname, stack) inv:remove_item(listname, stack)
return 0 return 0
else else
return stack:get_count() return stack:get_count()
end end
end, end,
allow_metadata_inventory_move = function(pos, from_list, _, to_list, _, count, player) allow_metadata_inventory_move = function(pos, from_list, _, to_list, _, count, player)
--perhaps allow filtering for upgrades and removing filters in this way --perhaps allow filtering for upgrades and removing filters in this way
if from_list ~= to_list then if from_list ~= to_list then
return 0 return 0
end end
return count return count
end, end,
} }
function item_transfer.register_io_device(itemstring, def) function item_transfer.register_io_device(itemstring, def)
for k,v in pairs(io_device_base) do for k,v in pairs(io_device_base) do
if def[k] == nil then if def[k] == nil then
def[k] = v def[k] = v
end end
end end
if not def.groups.me_connect then if not def.groups.me_connect then
def.groups.me_connect = 1 def.groups.me_connect = 1
end end
microexpansion.register_node(itemstring, def) microexpansion.register_node(itemstring, def)
end end

@ -5,53 +5,53 @@ local item_transfer = me.item_transfer
local access_level = microexpansion.constants.security.access_levels local access_level = microexpansion.constants.security.access_levels
local function exporter_timer(pos, elapsed) local function exporter_timer(pos, elapsed)
local net, cp = me.get_connected_network(pos) local net, cp = me.get_connected_network(pos)
if not net then if not net then
return false return false
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local target = vector.add(pos, microexpansion.facedir_to_right_dir(node.param2)) local target = vector.add(pos, microexpansion.facedir_to_right_dir(node.param2))
--TODO: allow setting list with control upgrade --TODO: allow setting list with control upgrade
--TODO: perhaps allow setting limits with control upgrade --TODO: perhaps allow setting limits with control upgrade
local list, inv = item_transfer.get_input_inventory(target) local list, inv = item_transfer.get_input_inventory(target)
if list then if list then
--TODO: move more with upgrades --TODO: move more with upgrades
local own_inv = minetest.get_meta(pos):get_inventory() local own_inv = minetest.get_meta(pos):get_inventory()
local upgrades = me.count_upgrades(own_inv) local upgrades = me.count_upgrades(own_inv)
local export_filter = upgrades.filter and function(stack) local export_filter = upgrades.filter and function(stack)
return not own_inv:contains_item("filter",stack:peek_item()) return not own_inv:contains_item("filter",stack:peek_item())
end end
local max_count = math.pow(2, upgrades.bulk or 0) local max_count = math.pow(2, upgrades.bulk or 0)
microexpansion.move_inv({inv=net:get_inventory(),name="main",huge=true}, {inv=inv,name=list}, max_count, export_filter) microexpansion.move_inv({inv=net:get_inventory(),name="main",huge=true}, {inv=inv,name=list}, max_count, export_filter)
--TODO: perhaps call allow_insert and on_insert callbacks --TODO: perhaps call allow_insert and on_insert callbacks
end end
return true return true
end end
-- [MicroExpansion Exporter] Register node -- [MicroExpansion Exporter] Register node
item_transfer.register_io_device("exporter", { item_transfer.register_io_device("exporter", {
description = "ME exporter", description = "ME exporter",
usedfor = "Exports items from ME Networks into machines", usedfor = "Exports items from ME Networks into machines",
tiles = { tiles = {
"exporter", "exporter",
"exporter", "exporter",
"interface", "interface",
"cable", "cable",
"microexpansion_exporter.png^[transform4", "microexpansion_exporter.png^[transform4",
"exporter", "exporter",
}, },
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
--perhaps convert to connectable --perhaps convert to connectable
type = "fixed", type = "fixed",
fixed = { fixed = {
{-0.5, -0.25, -0.25, 0.25, 0.25, 0.25}, {-0.5, -0.25, -0.25, 0.25, 0.25, 0.25},
{0.25, -0.375, -0.375, 0.5, 0.375, 0.375}, {0.25, -0.375, -0.375, 0.5, 0.375, 0.375},
}, },
}, },
connect_sides = { "left" }, connect_sides = { "left" },
recipe = { recipe = {
{ 1, { { 1, {
{"", "basic_materials:ic", microexpansion.iron_ingot_ingredient }, {"", "basic_materials:ic", microexpansion.iron_ingot_ingredient },
{"", "microexpansion:cable", "group:shovel" }, {"", "microexpansion:cable", "group:shovel" },
{"", "", microexpansion.iron_ingot_ingredient }, {"", "", microexpansion.iron_ingot_ingredient },
@ -64,30 +64,30 @@ item_transfer.register_io_device("exporter", {
}, },
} }
}, },
groups = { crumbly = 1 }, groups = { crumbly = 1 },
on_timer = exporter_timer, on_timer = exporter_timer,
on_construct = function(pos) on_construct = function(pos)
item_transfer.setup_io_device("ME Exporter",pos) item_transfer.setup_io_device("ME Exporter",pos)
me.send_event(pos,"connect") me.send_event(pos,"connect")
--perhaps write a propper update self function --perhaps write a propper update self function
item_transfer.update_timer_based(pos,nil,{type="construct"}) item_transfer.update_timer_based(pos,nil,{type="construct"})
end,
after_destruct = function(pos)
minetest.get_node_timer(pos):stop()
me.send_event(pos,"disconnect")
end, end,
on_metadata_inventory_put = function(pos, listname, _, stack, player) after_destruct = function(pos)
if listname == "upgrades" then minetest.get_node_timer(pos):stop()
item_transfer.setup_io_device("ME Exporter",pos) me.send_event(pos,"disconnect")
end end,
end, on_metadata_inventory_put = function(pos, listname, _, stack, player)
on_metadata_inventory_take = function(pos, listname, _, stack, player) if listname == "upgrades" then
if listname == "upgrades" then item_transfer.setup_io_device("ME Exporter",pos)
item_transfer.setup_io_device("ME Exporter",pos) end
end end,
end on_metadata_inventory_take = function(pos, listname, _, stack, player)
if listname == "upgrades" then
item_transfer.setup_io_device("ME Exporter",pos)
end
end
}) })
if me.uinv_category_enabled then if me.uinv_category_enabled then
unified_inventory.add_category_item("storage", "microexpansion:exporter") unified_inventory.add_category_item("storage", "microexpansion:exporter")
end end

@ -5,60 +5,60 @@ local item_transfer = me.item_transfer
local access_level = microexpansion.constants.security.access_levels local access_level = microexpansion.constants.security.access_levels
function importer_timer(pos, elapsed) function importer_timer(pos, elapsed)
local net, cp = me.get_connected_network(pos) local net, cp = me.get_connected_network(pos)
if not net then if not net then
return false return false
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local target = vector.add(pos, microexpansion.facedir_to_right_dir(node.param2)) local target = vector.add(pos, microexpansion.facedir_to_right_dir(node.param2))
--TODO: allow setting list with upgrade --TODO: allow setting list with upgrade
local list, inv = item_transfer.get_output_inventory(target) local list, inv = item_transfer.get_output_inventory(target)
if list then if list then
local own_inv = minetest.get_meta(pos):get_inventory() local own_inv = minetest.get_meta(pos):get_inventory()
local upgrades = me.count_upgrades(own_inv) local upgrades = me.count_upgrades(own_inv)
local count = math.min(net:get_inventory_space(),math.pow(2, upgrades.bulk or 0)) local count = math.min(net:get_inventory_space(),math.pow(2, upgrades.bulk or 0))
if count <= 0 then if count <= 0 then
return true return true
end end
local import_filter = function(stack) local import_filter = function(stack)
local stack_name = stack:get_name() local stack_name = stack:get_name()
if minetest.get_item_group(stack_name, "microexpansion_cell") > 0 then if minetest.get_item_group(stack_name, "microexpansion_cell") > 0 then
return true return true
end end
if upgrades.filter then if upgrades.filter then
return not own_inv:contains_item("filter",stack:peek_item()) return not own_inv:contains_item("filter",stack:peek_item())
end end
return false return false
end end
microexpansion.move_inv({inv=inv,name=list}, {inv=net:get_inventory(),name="main",huge=true}, count, import_filter) microexpansion.move_inv({inv=inv,name=list}, {inv=net:get_inventory(),name="main",huge=true}, count, import_filter)
net:set_storage_space(true) net:set_storage_space(true)
end end
return true return true
end end
-- [MicroExpansion Importer] Register node -- [MicroExpansion Importer] Register node
item_transfer.register_io_device("importer", { item_transfer.register_io_device("importer", {
description = "ME Importer", description = "ME Importer",
usedfor = "Imports items from machines into ME Networks", usedfor = "Imports items from machines into ME Networks",
tiles = { tiles = {
"importer", "importer",
"importer", "importer",
"interface", "interface",
"cable", "cable",
"microexpansion_importer.png^[transform4", "microexpansion_importer.png^[transform4",
"importer", "importer",
}, },
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-0.5, -0.25, -0.25, 0.25, 0.25, 0.25}, {-0.5, -0.25, -0.25, 0.25, 0.25, 0.25},
{0.25, -0.375, -0.375, 0.5, 0.375, 0.375}, {0.25, -0.375, -0.375, 0.5, 0.375, 0.375},
}, },
}, },
connect_sides = { "left" }, connect_sides = { "left" },
recipe = { recipe = {
{ 1, { { 1, {
{"", "basic_materials:ic", microexpansion.iron_ingot_ingredient }, {"", "basic_materials:ic", microexpansion.iron_ingot_ingredient },
{"", "microexpansion:cable", "group:hoe" }, {"", "microexpansion:cable", "group:hoe" },
{"", "", microexpansion.iron_ingot_ingredient }, {"", "", microexpansion.iron_ingot_ingredient },
@ -71,30 +71,30 @@ item_transfer.register_io_device("importer", {
}, },
} }
}, },
is_ground_content = false, is_ground_content = false,
groups = { crumbly = 1 }, groups = { crumbly = 1 },
on_timer = importer_timer, on_timer = importer_timer,
on_construct = function(pos) on_construct = function(pos)
item_transfer.setup_io_device("ME Importer",pos) item_transfer.setup_io_device("ME Importer",pos)
me.send_event(pos,"connect") me.send_event(pos,"connect")
item_transfer.update_timer_based(pos) item_transfer.update_timer_based(pos)
end,
after_destruct = function(pos)
minetest.get_node_timer(pos):stop()
me.send_event(pos,"disconnect")
end, end,
on_metadata_inventory_put = function(pos, listname, _, stack, player) after_destruct = function(pos)
if listname == "upgrades" then minetest.get_node_timer(pos):stop()
item_transfer.setup_io_device("ME Importer",pos) me.send_event(pos,"disconnect")
end end,
end, on_metadata_inventory_put = function(pos, listname, _, stack, player)
on_metadata_inventory_take = function(pos, listname, _, stack, player) if listname == "upgrades" then
if listname == "upgrades" then item_transfer.setup_io_device("ME Importer",pos)
item_transfer.setup_io_device("ME Importer",pos) end
end end,
end on_metadata_inventory_take = function(pos, listname, _, stack, player)
if listname == "upgrades" then
item_transfer.setup_io_device("ME Importer",pos)
end
end
}) })
if me.uinv_category_enabled then if me.uinv_category_enabled then
unified_inventory.add_category_item("storage", "microexpansion:importer") unified_inventory.add_category_item("storage", "microexpansion:importer")
end end

@ -8,9 +8,9 @@ microexpansion.require_module("network")
-- Iron Ingot Ingredient for MineClone2 -- Iron Ingot Ingredient for MineClone2
microexpansion.iron_ingot_ingredient = nil microexpansion.iron_ingot_ingredient = nil
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
microexpansion.iron_ingot_ingredient = "mcl_core:iron_ingot" microexpansion.iron_ingot_ingredient = "mcl_core:iron_ingot"
else else
microexpansion.iron_ingot_ingredient = "default:steel_ingot" microexpansion.iron_ingot_ingredient = "default:steel_ingot"
end end
-- Load API -- Load API

@ -6,62 +6,62 @@ local me = microexpansion
-- [register item] Upgrade Base -- [register item] Upgrade Base
me.register_item("upgrade_base", { me.register_item("upgrade_base", {
description = "Upgrade Base", description = "Upgrade Base",
usedfor = "the base for crafting upgrades", usedfor = "the base for crafting upgrades",
recipe = { recipe = {
{ 1, { { 1, {
{ "microexpansion:quartz_crystal" }, { "microexpansion:quartz_crystal" },
{ microexpansion.iron_ingot_ingredient }, { microexpansion.iron_ingot_ingredient },
}, },
}, },
}, },
}) })
-- [register item] Bulk Upgrade -- [register item] Bulk Upgrade
me.register_item("upgrade_bulk", { me.register_item("upgrade_bulk", {
description = "Bulk Upgrade", description = "Bulk Upgrade",
usedfor = "upgrades components to process more at the same time", usedfor = "upgrades components to process more at the same time",
recipe = { recipe = {
{ 1, { { 1, {
{"basic_materials:gold_wire"}, {"basic_materials:gold_wire"},
{"microexpansion:upgrade_base"} {"microexpansion:upgrade_base"}
}, },
}, },
{ 1, { { 1, {
{"microexpansion:gold_wire"}, {"microexpansion:gold_wire"},
{"microexpansion:upgrade_base"} {"microexpansion:upgrade_base"}
}, },
}, },
}, },
}) })
-- [register item] Filter Upgrade -- [register item] Filter Upgrade
me.register_item("upgrade_filter", { me.register_item("upgrade_filter", {
description = "Filter Upgrade", description = "Filter Upgrade",
usedfor = "allows setting up filters for components", usedfor = "allows setting up filters for components",
recipe = { recipe = {
{ 1, { { 1, {
{"microexpansion:quartz_crystal"}, {"microexpansion:quartz_crystal"},
{"microexpansion:upgrade_base"} {"microexpansion:upgrade_base"}
}, },
}, },
}, },
}) })
-- [register item] Control Upgrade -- [register item] Control Upgrade
me.register_item("upgrade_control", { me.register_item("upgrade_control", {
description = "Control Upgrade", description = "Control Upgrade",
usedfor = "allows more fine tuned control over components", usedfor = "allows more fine tuned control over components",
recipe = { recipe = {
{ 1, { { 1, {
{"basic_materials:ic"}, {"basic_materials:ic"},
{"microexpansion:upgrade_base"} {"microexpansion:upgrade_base"}
}, },
}, },
{ 1, { { 1, {
{"microexpansion:logic_chip"}, {"microexpansion:logic_chip"},
{"microexpansion:upgrade_base"} {"microexpansion:upgrade_base"}
}, },
}, },
}, },
}) })

@ -1,57 +1,57 @@
local me = microexpansion local me = microexpansion
if not me.constants then if not me.constants then
me.constants = {} me.constants = {}
end end
local constants = me.constants local constants = me.constants
local access_levels = { local access_levels = {
-- cannot interact at all with the network or it's components -- cannot interact at all with the network or it's components
blocked = 0, blocked = 0,
-- can only look into the network but not move, modify, etc. -- can only look into the network but not move, modify, etc.
view = 20, view = 20,
-- can use chests, craft terminals, etc. -- can use chests, craft terminals, etc.
interact = 40, interact = 40,
-- can use all components except security, can build and dig (except core) -- can use all components except security, can build and dig (except core)
modify = 60, modify = 60,
-- can use security terminal, can modify all players with less access -- can use security terminal, can modify all players with less access
manage = 80, manage = 80,
-- can modify all players with less access and self -- can modify all players with less access and self
full = 100 full = 100
} }
local access_level_descriptions = {} local access_level_descriptions = {}
access_level_descriptions[access_levels.blocked] = { access_level_descriptions[access_levels.blocked] = {
name = "Blocked", name = "Blocked",
color = "gray", color = "gray",
index = 1 index = 1
} }
access_level_descriptions[access_levels.view] = { access_level_descriptions[access_levels.view] = {
name = "View", name = "View",
color = "orange", color = "orange",
index = 2 index = 2
} }
access_level_descriptions[access_levels.interact] = { access_level_descriptions[access_levels.interact] = {
color = "yellow", color = "yellow",
name = "Interact", name = "Interact",
index = 3 index = 3
} }
access_level_descriptions[access_levels.modify] = { access_level_descriptions[access_levels.modify] = {
name = "Modify", name = "Modify",
color = "yellowgreen", color = "yellowgreen",
index = 4 index = 4
} }
access_level_descriptions[access_levels.manage] = { access_level_descriptions[access_levels.manage] = {
name = "Manage", name = "Manage",
color = "green", color = "green",
index = 5 index = 5
} }
access_level_descriptions[access_levels.full] = { access_level_descriptions[access_levels.full] = {
name = "Full", name = "Full",
color = "blue", color = "blue",
index = 6 index = 6
} }
constants.security = { constants.security = {
access_levels = access_levels, access_levels = access_levels,
access_level_descriptions = access_level_descriptions access_level_descriptions = access_level_descriptions
} }

@ -7,52 +7,52 @@ local access_level = microexpansion.constants.security.access_levels
local ctrl_recipe = nil local ctrl_recipe = nil
ctrl_recipe = { ctrl_recipe = {
{ 1, { { 1, {
{microexpansion.iron_ingot_ingredient, "microexpansion:steel_infused_obsidian_ingot", microexpansion.iron_ingot_ingredient}, {microexpansion.iron_ingot_ingredient, "microexpansion:steel_infused_obsidian_ingot", microexpansion.iron_ingot_ingredient},
{microexpansion.iron_ingot_ingredient, "microexpansion:machine_casing", microexpansion.iron_ingot_ingredient}, {microexpansion.iron_ingot_ingredient, "microexpansion:machine_casing", microexpansion.iron_ingot_ingredient},
{microexpansion.iron_ingot_ingredient, "microexpansion:cable", microexpansion.iron_ingot_ingredient}, {microexpansion.iron_ingot_ingredient, "microexpansion:cable", microexpansion.iron_ingot_ingredient},
}, },
} }
} }
-- [register node] Controller -- [register node] Controller
me.register_node("ctrl", { me.register_node("ctrl", {
description = "ME Controller", description = "ME Controller",
tiles = { tiles = {
"ctrl_sides", "ctrl_sides",
"ctrl_bottom", "ctrl_bottom",
"ctrl_sides", "ctrl_sides",
"ctrl_sides", "ctrl_sides",
"ctrl_sides", "ctrl_sides",
"ctrl_sides" "ctrl_sides"
}, },
recipe = ctrl_recipe, recipe = ctrl_recipe,
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-0.375, -0.375, -0.375, 0.375, 0.375, 0.375}, -- Core {-0.375, -0.375, -0.375, 0.375, 0.375, 0.375}, -- Core
{0.1875, -0.5, -0.5, 0.5, 0.5, -0.1875}, -- Corner1 {0.1875, -0.5, -0.5, 0.5, 0.5, -0.1875}, -- Corner1
{-0.5, -0.5, -0.5, -0.1875, 0.5, -0.1875}, -- Corner2 {-0.5, -0.5, -0.5, -0.1875, 0.5, -0.1875}, -- Corner2
{-0.5, -0.5, 0.1875, -0.1875, 0.5, 0.5}, -- Corner3 {-0.5, -0.5, 0.1875, -0.1875, 0.5, 0.5}, -- Corner3
{0.1875, -0.5, 0.1875, 0.5, 0.5, 0.5}, -- Corner4 {0.1875, -0.5, 0.1875, 0.5, 0.5, 0.5}, -- Corner4
{-0.5, -0.4375, -0.5, 0.5, -0.1875, 0.5}, -- Bottom {-0.5, -0.4375, -0.5, 0.5, -0.1875, 0.5}, -- Bottom
{-0.5, 0.1875, -0.5, 0.5, 0.5, -0.1875}, -- Top1 {-0.5, 0.1875, -0.5, 0.5, 0.5, -0.1875}, -- Top1
{0.1875, 0.1875, -0.5, 0.5, 0.5, 0.5}, -- Top2 {0.1875, 0.1875, -0.5, 0.5, 0.5, 0.5}, -- Top2
{-0.5, 0.1875, -0.5, -0.1875, 0.5, 0.5}, -- Top3 {-0.5, 0.1875, -0.5, -0.1875, 0.5, 0.5}, -- Top3
{-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- Top4 {-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- Top4
{-0.1875, -0.5, -0.1875, 0.1875, -0.25, 0.1875}, -- Bottom2 {-0.1875, -0.5, -0.1875, 0.1875, -0.25, 0.1875}, -- Bottom2
}, },
}, },
groups = { cracky = 1, me_connect = 1, }, groups = { cracky = 1, me_connect = 1, },
connect_sides = "nobottom", connect_sides = "nobottom",
me_update = function(pos,_,ev) me_update = function(pos,_,ev)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if meta:get_string("source") ~= "" then if meta:get_string("source") ~= "" then
return return
end end
local cnet = me.get_network(pos) local cnet = me.get_network(pos)
if cnet == nil then if cnet == nil then
microexpansion.log("no network for ctrl at pos "..minetest.pos_to_string(pos),"error") microexpansion.log("no network for ctrl at pos "..minetest.pos_to_string(pos),"error")
return return
@ -61,203 +61,202 @@ me.register_node("ctrl", {
end, end,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if net then if net then
meta:set_string("source", vector.to_string(cp)) meta:set_string("source", vector.to_string(cp))
else else
net = network.new({controller_pos = pos}) net = network.new({controller_pos = pos})
table.insert(me.networks,net) table.insert(me.networks,net)
end end
me.send_event(pos,"connect",{net=net}) me.send_event(pos,"connect",{net=net})
meta:set_string("infotext", "Network Controller") meta:set_string("infotext", "Network Controller")
end, end,
after_place_node = function(pos, player) after_place_node = function(pos, player)
local name = player:get_player_name() local name = player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Network Controller") meta:set_string("infotext", "Network Controller")
meta:set_string("owner", name) meta:set_string("owner", name)
local net,idx = me.get_network(pos) local net,idx = me.get_network(pos)
if net then if net then
net:set_access_level(name, me.constants.security.access_levels.full) net:set_access_level(name, me.constants.security.access_levels.full)
elseif meta:get_string("source") == "" then elseif meta:get_string("source") == "" then
me.log("no network after placing controller", "warning") me.log("no network after placing controller", "warning")
end end
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
if not player then if not player then
return false return false
end end
local name = player:get_player_name() local name = player:get_player_name()
if minetest.is_protected(pos, name) then if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return false return false
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local net local net
if meta:get_string("source") == "" then if meta:get_string("source") == "" then
net = me.get_network(pos) net = me.get_network(pos)
else else
net = me.get_connected_network(pos) net = me.get_connected_network(pos)
end end
if not net then if not net then
me.log("ME Network Controller without Network","error") me.log("ME Network Controller without Network","error")
return true return true
end end
return net:get_access_level(name) >= access_level.full return net:get_access_level(name) >= access_level.full
end, end,
on_destruct = function(pos) on_destruct = function(pos)
local net,idx = me.get_network(pos) local net,idx = me.get_network(pos)
--disconnect all those who need the network --disconnect all those who need the network
me.send_event(pos,"disconnect",{net=net}) me.send_event(pos,"disconnect",{net=net})
if net then if net then
if me.promote_controller(pos,net) then if me.promote_controller(pos,net) then
--reconnect with new controller --reconnect with new controller
me.send_event(pos,"reconnect",{net=net}) me.send_event(pos,"reconnect",{net=net})
else else
net:destruct() net:destruct()
if idx then if idx then
table.remove(me.networks,idx) table.remove(me.networks,idx)
end end
--disconnect all those that haven't realized the network is gone --disconnect all those that haven't realized the network is gone
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end end
else else
-- disconnect just in case -- disconnect just in case
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end end
end, end,
after_destruct = function(pos) after_destruct = function(pos)
--disconnect all those that haven't realized the controller was disconnected --disconnect all those that haven't realized the controller was disconnected
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end, end,
machine = { machine = {
type = "controller", type = "controller",
}, },
}) })
minetest.register_lbm({ minetest.register_lbm({
name = "microexpansion:update_network", name = "microexpansion:update_network",
label = "integrate new ME Network data", label = "integrate new ME Network data",
nodenames = {"microexpansion:ctrl"}, nodenames = {"microexpansion:ctrl"},
run_at_every_load = true, run_at_every_load = true,
action = function(pos) action = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local net,idx = me.get_network(pos) local net,idx = me.get_network(pos)
if not meta then if not meta then
me.log("activated controller before metadata was available", "warning") me.log("activated controller before metadata was available", "warning")
return return
end end
local source = meta:get_string("source") local source = meta:get_string("source")
if not net then if not net then
if source == "" then if source == "" then
me.log("activated controller without network", "warning") me.log("activated controller without network", "warning")
return return
else else
net = me.get_network(vector.from_string(source)) net = me.get_network(vector.from_string(source))
if not net then if not net then
me.log("activated controller that is linked to an unloaded controller", "info") me.log("activated controller that is linked to an unloaded controller", "info")
return return
end
end
end
if not net.access then
me.log("added access table to old network", "action")
net.access = {}
end
net:fallback_access()
end end
end
end
if not net.access then
me.log("added access table to old network", "action")
net.access = {}
end
net:fallback_access()
end
}) })
-- [register node] Cable -- [register node] Cable
me.register_machine("cable", { me.register_machine("cable", {
description = "ME Cable", description = "ME Cable",
tiles = { tiles = {
"cable", "cable",
}, },
recipe = { recipe = {
{ 12, "shapeless", { { 12, "shapeless", {
"microexpansion:steel_infused_obsidian_ingot", "microexpansion:machine_casing" "microexpansion:steel_infused_obsidian_ingot", "microexpansion:machine_casing"
}, },
} }
}, },
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
type = "connected", type = "connected",
fixed = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}, fixed = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
connect_top = {-0.25, -0.25, -0.25, 0.25, 0.5, 0.25}, -- y+ connect_top = {-0.25, -0.25, -0.25, 0.25, 0.5, 0.25}, -- y+
connect_bottom = {-0.25, -0.5, -0.25, 0.25, 0.25, 0.25}, -- y- connect_bottom = {-0.25, -0.5, -0.25, 0.25, 0.25, 0.25}, -- y-
connect_front = {-0.25, -0.25, -0.5, 0.25, 0.25, 0.25}, -- z- connect_front = {-0.25, -0.25, -0.5, 0.25, 0.25, 0.25}, -- z-
connect_back = {-0.25, -0.25, 0.25, 0.25, 0.25, 0.5 }, -- z+ connect_back = {-0.25, -0.25, 0.25, 0.25, 0.25, 0.5 }, -- z+
connect_left = {-0.5, -0.25, -0.25, 0.25, 0.25, 0.25}, -- x- connect_left = {-0.5, -0.25, -0.25, 0.25, 0.25, 0.25}, -- x-
connect_right = {-0.25, -0.25, -0.25, 0.5, 0.25, 0.25}, -- x+ connect_right = {-0.25, -0.25, -0.25, 0.5, 0.25, 0.25}, -- x+
}, },
paramtype = "light", paramtype = "light",
groups = { crumbly = 1, }, groups = { crumbly = 1, },
--TODO: move these functions into the registration --TODO: move these functions into the registration
can_dig = function(pos, player) can_dig = function(pos, player)
if not player then if not player then
return false return false
end end
local name = player:get_player_name() local name = player:get_player_name()
if minetest.is_protected(pos, name) then if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return false return false
end end
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if not net then if not net then
return true return true
end end
return net:get_access_level(name) >= access_level.modify return net:get_access_level(name) >= access_level.modify
end, end,
on_construct = function(pos) on_construct = function(pos)
--perhaps this needs to be done after the check if it can be placed --perhaps this needs to be done after the check if it can be placed
me.send_event(pos,"connect") me.send_event(pos,"connect")
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
if not placer then if not placer then
return false return false
end end
local name = placer:get_player_name() local name = placer:get_player_name()
if minetest.is_protected(pos, name) then if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
--protection probably handles this itself --protection probably handles this itself
--minetest.remove_node(pos) --minetest.remove_node(pos)
return true return true
end end
--TODO: prevent connecting multiple networks --TODO: prevent connecting multiple networks
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if not net then if not net then
return false return false
end end
if net:get_access_level(name) < access_level.modify then if net:get_access_level(name) < access_level.modify then
-- prevent placing cables on a network that a player doesn't have access to -- prevent placing cables on a network that a player doesn't have access to
minetest.remove_node(pos) minetest.remove_node(pos)
return true return true
end end
end, end,
after_destruct = function(pos) after_destruct = function(pos)
--FIXME: write drives before disconnecting --FIXME: write drives before disconnecting
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end, end,
me_update = function(pos,_,ev) me_update = function(pos,_,ev)
if ev then if ev then
if ev.type ~= "disconnect" then return end if ev.type ~= "disconnect" then return end
end end
--maybe this shouldn't be called on every update --maybe this shouldn't be called on every update
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if me.get_connected_network(pos) then if me.get_connected_network(pos) then
meta:set_string("infotext", "Network connected") meta:set_string("infotext", "Network connected")
else else
meta:set_string("infotext", "No Network") meta:set_string("infotext", "No Network")
end end
end, end,
machine = { machine = {
type = "conductor", type = "conductor",
}, },
}) })
if me.uinv_category_enabled then if me.uinv_category_enabled then
unified_inventory.add_category_item("storage", "microexpansion:ctrl") unified_inventory.add_category_item("storage", "microexpansion:ctrl")
unified_inventory.add_category_item("storage", "microexpansion:cable") unified_inventory.add_category_item("storage", "microexpansion:cable")
end end

@ -66,81 +66,81 @@ dofile(path.."/network.lua") -- Network Management
-- generate iterator to find all connected nodes -- generate iterator to find all connected nodes
function me.connected_nodes(start_pos,include_ctrl) function me.connected_nodes(start_pos,include_ctrl)
-- nodes to be checked -- nodes to be checked
local open_list = {{pos = start_pos}} local open_list = {{pos = start_pos}}
-- nodes that were checked -- nodes that were checked
local closed_set = {} local closed_set = {}
-- local connected nodes function to reduce table lookups -- local connected nodes function to reduce table lookups
local adjacent_connected_nodes = me.network.adjacent_connected_nodes local adjacent_connected_nodes = me.network.adjacent_connected_nodes
-- return the generated iterator -- return the generated iterator
return function () return function ()
-- start looking for next pos -- start looking for next pos
local open = false local open = false
-- pos to be checked -- pos to be checked
local current local current
-- find next unclosed -- find next unclosed
while not open do while not open do
-- get unchecked pos -- get unchecked pos
current = table.remove(open_list) current = table.remove(open_list)
-- none are left -- none are left
if current == nil then return end if current == nil then return end
-- assume it's open -- assume it's open
open = true open = true
-- check the closed positions -- check the closed positions
for _,closed in pairs(closed_set) do for _,closed in pairs(closed_set) do
-- if current is unclosed -- if current is unclosed
if vector.equals(closed,current.pos) then if vector.equals(closed,current.pos) then
--found one was closed --found one was closed
open = false open = false
end end
end end
end end
-- get all connected nodes -- get all connected nodes
local nodes = adjacent_connected_nodes(current.pos,include_ctrl) local nodes = adjacent_connected_nodes(current.pos,include_ctrl)
-- iterate through them -- iterate through them
for _,n in pairs(nodes) do for _,n in pairs(nodes) do
-- mark position to be checked -- mark position to be checked
table.insert(open_list,n) table.insert(open_list,n)
end end
-- add this one to the closed set -- add this one to the closed set
table.insert(closed_set,current.pos) table.insert(closed_set,current.pos)
-- return the one to be checked -- return the one to be checked
return current.pos,current.name return current.pos,current.name
end end
end end
-- get network connected to position -- get network connected to position
function me.get_connected_network(start_pos) function me.get_connected_network(start_pos)
for npos,nn in me.connected_nodes(start_pos,true) do for npos,nn in me.connected_nodes(start_pos,true) do
if nn == "microexpansion:ctrl" then if nn == "microexpansion:ctrl" then
local source = minetest.get_meta(npos):get_string("source") local source = minetest.get_meta(npos):get_string("source")
local network local network
if source == "" then if source == "" then
network = me.get_network(npos) network = me.get_network(npos)
else else
network = me.get_network(vector.from_string(source)) network = me.get_network(vector.from_string(source))
end end
if network then if network then
return network,npos return network,npos
end end
end end
end end
end end
function me.promote_controller(start_pos,net) function me.promote_controller(start_pos,net)
local promoted = false local promoted = false
for npos,nn in me.connected_nodes(start_pos,true) do for npos,nn in me.connected_nodes(start_pos,true) do
if nn == "microexpansion:ctrl" and npos ~= start_pos then if nn == "microexpansion:ctrl" and npos ~= start_pos then
if promoted then if promoted then
minetest.get_meta(npos):set_string("source", promoted) minetest.get_meta(npos):set_string("source", promoted)
else else
promoted = vector.to_string(npos) promoted = vector.to_string(npos)
minetest.get_meta(npos):set_string("source", "") minetest.get_meta(npos):set_string("source", "")
net.controller_pos = npos net.controller_pos = npos
end end
end end
end end
return promoted and true or false return promoted and true or false
end end
function me.update_connected_machines(start_pos,event,include_start) function me.update_connected_machines(start_pos,event,include_start)
@ -159,7 +159,7 @@ function me.update_connected_machines(start_pos,event,include_start)
if include_start or not vector.equals(npos,start_pos) then if include_start or not vector.equals(npos,start_pos) then
me.update_node(npos,ev) me.update_node(npos,ev)
end end
end end
end end
function me.send_event(spos,type,data) function me.send_event(spos,type,data)
@ -173,13 +173,13 @@ function me.send_event(spos,type,data)
end end
function me.get_network(pos) function me.get_network(pos)
for i,net in pairs(networks) do for i,net in pairs(networks) do
if net.controller_pos then if net.controller_pos then
if vector.equals(pos, net.controller_pos) then if vector.equals(pos, net.controller_pos) then
return net,i return net,i
end end
end end
end end
end end
dofile(path.."/ctrl.lua") -- Controller/wires dofile(path.."/ctrl.lua") -- Controller/wires
@ -187,30 +187,30 @@ dofile(path.."/security.lua") --Security Terminal
-- load networks -- load networks
function me.load() function me.load()
local res = storage:get_string("networks") local res = storage:get_string("networks")
if res == "" then if res == "" then
local f = io.open(me.worldpath.."/microexpansion_networks", "r") local f = io.open(me.worldpath.."/microexpansion_networks", "r")
if f then if f then
me.log("loading network data from file","action") me.log("loading network data from file","action")
res = minetest.deserialize(f:read("*all")) res = minetest.deserialize(f:read("*all"))
f:close() f:close()
else else
me.log("no network data loaded","action") me.log("no network data loaded","action")
return return
end end
else else
me.log("loading network data from mod storage","action") me.log("loading network data from mod storage","action")
res = minetest.deserialize(res) res = minetest.deserialize(res)
end end
if type(res) == "table" then if type(res) == "table" then
for _,n in pairs(res) do for _,n in pairs(res) do
local net = me.network.new(n) local net = me.network.new(n)
net:load() net:load()
table.insert(me.networks,net) table.insert(me.networks,net)
end end
else else
me.log("network data in unexpected format","error") me.log("network data in unexpected format","error")
end end
end end
-- load now -- load now
@ -222,35 +222,35 @@ function me.save()
for _,v in pairs(me.networks) do for _,v in pairs(me.networks) do
table.insert(data,v:serialize()) table.insert(data,v:serialize())
end end
if storage then if storage then
me.log("saving network data to mod storage","info") me.log("saving network data to mod storage","info")
storage:set_string("networks", minetest.serialize(data)) storage:set_string("networks", minetest.serialize(data))
else else
me.log("saving network data to file","info") me.log("saving network data to file","info")
local f = io.open(me.worldpath.."/microexpansion_networks", "w") local f = io.open(me.worldpath.."/microexpansion_networks", "w")
f:write(minetest.serialize(data)) f:write(minetest.serialize(data))
f:close() f:close()
end end
end end
function me.do_autosave() function me.do_autosave()
me.last_autosave = -1 me.last_autosave = -1
minetest.after(1, function() minetest.after(1, function()
--print("autosaving ME Networks") --print("autosaving ME Networks")
me.save() me.save()
me.last_autosave = minetest.get_server_uptime() me.last_autosave = minetest.get_server_uptime()
end) end)
end end
function me.autosave() function me.autosave()
--TODO: make max autosave interval settable --TODO: make max autosave interval settable
if not me.last_autosave then if not me.last_autosave then
me.do_autosave() me.do_autosave()
elseif me.last_autosave == -1 then elseif me.last_autosave == -1 then
return return
elseif minetest.get_server_uptime() - me.last_autosave >= 600 then elseif minetest.get_server_uptime() - me.last_autosave >= 600 then
me.do_autosave() me.do_autosave()
end end
end end
-- save on server shutdown -- save on server shutdown

@ -6,9 +6,9 @@
-- @field #number power_load the power currently provided to the network -- @field #number power_load the power currently provided to the network
-- @field #number power_storage the power that can be stored for the next tick -- @field #number power_storage the power that can be stored for the next tick
local network = { local network = {
default_access_level = microexpansion.constants.security.access_levels.view, default_access_level = microexpansion.constants.security.access_levels.view,
power_load = 0, power_load = 0,
power_storage = 0 power_storage = 0
} }
local me = microexpansion local me = microexpansion
me.network = network me.network = network
@ -20,7 +20,7 @@ local access_level = microexpansion.constants.security.access_levels
-- @param #table o the object to become a network or nil -- @param #table o the object to become a network or nil
-- @return #table the new network object -- @return #table the new network object
function network.new(o) function network.new(o)
return setmetatable(o or {}, {__index = network}) return setmetatable(o or {}, {__index = network})
end end
--- check if a node can be connected --- check if a node can be connected
@ -40,7 +40,7 @@ function network.can_connect(np)
nn = node.name nn = node.name
end end
end end
return minetest.get_item_group(nn, "me_connect") > 0 return minetest.get_item_group(nn, "me_connect") > 0
end end
--- get all adjacent connected nodes --- get all adjacent connected nodes
@ -49,103 +49,103 @@ end
-- @param #boolean include_ctrl whether to check for the controller -- @param #boolean include_ctrl whether to check for the controller
-- @return #table all nodes that have the group me_connect -- @return #table all nodes that have the group me_connect
function network.adjacent_connected_nodes(pos, include_ctrl) function network.adjacent_connected_nodes(pos, include_ctrl)
local adjacent = { local adjacent = {
{x=pos.x+1, y=pos.y, z=pos.z}, {x=pos.x+1, y=pos.y, z=pos.z},
{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-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},
{x=pos.x, y=pos.y, z=pos.z-1}, {x=pos.x, y=pos.y, z=pos.z-1},
} }
local nodes = {} local nodes = {}
for _,apos in pairs(adjacent) do for _,apos in pairs(adjacent) do
local napos = me.get_node(apos) local napos = me.get_node(apos)
local nn = napos.name local nn = napos.name
if network.can_connect(nn) then if network.can_connect(nn) then
if include_ctrl == false then if include_ctrl == false then
if nn ~= "microexpansion:ctrl" then if nn ~= "microexpansion:ctrl" then
table.insert(nodes,{pos = apos, name = nn}) table.insert(nodes,{pos = apos, name = nn})
end end
else else
table.insert(nodes,{pos = apos, name = nn}) table.insert(nodes,{pos = apos, name = nn})
end end
end end
end end
return nodes return nodes
end end
function network:get_access_level(player) function network:get_access_level(player)
local name local name
local has_bypass = minetest.check_player_privs(player, "protection_bypass") local has_bypass = minetest.check_player_privs(player, "protection_bypass")
if not player then if not player then
return self.default_access_level return self.default_access_level
elseif has_bypass then elseif has_bypass then
return me.constants.security.access_levels.full return me.constants.security.access_levels.full
elseif type(player) == "string" then elseif type(player) == "string" then
name = player name = player
else else
name = player:get_player_name() name = player:get_player_name()
end end
if not self.access and not has_bypass then if not self.access and not has_bypass then
return self.default_access_level return self.default_access_level
end end
return self.access[name] or self.default_access_level return self.access[name] or self.default_access_level
end end
function network:set_access_level(player, level) function network:set_access_level(player, level)
local name local name
if not player then if not player then
self.default_access_level = level self.default_access_level = level
elseif type(player) == "string" then elseif type(player) == "string" then
name = player name = player
else else
name = player:get_player_name() name = player:get_player_name()
end end
if not self.access then if not self.access then
self.access = {} self.access = {}
end end
self.access[name] = level self.access[name] = level
self:fallback_access() self:fallback_access()
-- autosave network data -- autosave network data
me.autosave() me.autosave()
end end
function network:fallback_access() function network:fallback_access()
local full_access = access_level.full local full_access = access_level.full
if not self.access then if not self.access then
--something must have gone badly wrong --something must have gone badly wrong
me.log("no network access table in fallback method","error") me.log("no network access table in fallback method","error")
self.access = {} self.access = {}
end end
for _,l in pairs(self.access) do for _,l in pairs(self.access) do
if l == full_access then if l == full_access then
return return
end end
end end
local meta = minetest.get_meta(self.controller_pos) local meta = minetest.get_meta(self.controller_pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if owner == "" then if owner == "" then
me.log("ME Network Controller without owner at: " .. vector.to_string(self.controller_pos), "warning") me.log("ME Network Controller without owner at: " .. vector.to_string(self.controller_pos), "warning")
else else
self.access[owner] = full_access self.access[owner] = full_access
end end
end end
function network:list_access() function network:list_access()
if not self.access then if not self.access then
self.access = {} self.access = {}
end end
return self.access return self.access
end end
--- provide power to the network --- provide power to the network
-- @function [parent=#network] provide -- @function [parent=#network] provide
-- @param #number power the amount of power provided -- @param #number power the amount of power provided
function network:provide(power) function network:provide(power)
self.power_load = self.power_load + power self.power_load = self.power_load + power
end end
--- demand power from the network --- demand power from the network
@ -153,35 +153,35 @@ end
-- @param #number power the amount of power demanded -- @param #number power the amount of power demanded
-- @return #boolean whether the power was provided -- @return #boolean whether the power was provided
function network:demand(power) function network:demand(power)
if self.power_load - power < 0 then if self.power_load - power < 0 then
return false return false
end end
self.power_load = self.power_load - power self.power_load = self.power_load - power
return true return true
end end
--- add power capacity to the network --- add power capacity to the network
-- @function [parent=#network] add_power_capacity -- @function [parent=#network] add_power_capacity
-- @param #number power the amount of power that can be stored -- @param #number power the amount of power that can be stored
function network:add_power_capacity(power) function network:add_power_capacity(power)
self.power_storage = self.power_storage + power self.power_storage = self.power_storage + power
end end
--- add power capacity to the network --- add power capacity to the network
-- @function [parent=#network] add_power_capacity -- @function [parent=#network] add_power_capacity
-- @param #number power the amount of power that can't be stored anymore -- @param #number power the amount of power that can't be stored anymore
function network:remove_power_capacity(power) function network:remove_power_capacity(power)
self.power_storage = self.power_storage - power self.power_storage = self.power_storage - power
if self.power_storage < 0 then if self.power_storage < 0 then
microexpansion.log("power storage of network "..self.." dropped below zero","warning") microexpansion.log("power storage of network "..self.." dropped below zero","warning")
end end
end end
--- remove overload --- remove overload
-- to be called by the controller every turn -- to be called by the controller every turn
-- @function [parent=#network] remove_overload -- @function [parent=#network] remove_overload
function network:remove_overload() function network:remove_overload()
self.power_load = math.min(self.power_load, self.power_storage) self.power_load = math.min(self.power_load, self.power_storage)
end end
--- get a drives item capacity --- get a drives item capacity
@ -189,27 +189,27 @@ end
-- @param #table pos the position of the drive -- @param #table pos the position of the drive
-- @return #number the number of items that can be stored in the drive -- @return #number the number of items that can be stored in the drive
local function get_drive_capacity(pos) local function get_drive_capacity(pos)
local cap = 0 local cap = 0
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
for i = 1, inv:get_size("main") do for i = 1, inv:get_size("main") do
cap = cap + me.get_cell_size(inv:get_stack("main", i):get_name()) cap = cap + me.get_cell_size(inv:get_stack("main", i):get_name())
end end
return cap return cap
end end
--- get the item capacity of a network --- get the item capacity of a network
-- @function [parent=#network] get_item_capacity -- @function [parent=#network] get_item_capacity
-- @return #number the total number of items that can be stored in the network -- @return #number the total number of items that can be stored in the network
function network:get_item_capacity() function network:get_item_capacity()
local cap = 0 local cap = 0
for npos in me.connected_nodes(self.controller_pos) do for npos in me.connected_nodes(self.controller_pos) do
if me.get_node(npos).name == "microexpansion:drive" then if me.get_node(npos).name == "microexpansion:drive" then
cap = cap + get_drive_capacity(npos) cap = cap + get_drive_capacity(npos)
end end
end end
self.capacity_cache = cap self.capacity_cache = cap
return cap return cap
end end
local function remove_slots(inv,ln,target,csize) local function remove_slots(inv,ln,target,csize)
@ -259,8 +259,8 @@ function network:set_storage_space(count,listname)
needed = needed + csize needed = needed + csize
remove_slots(inv,ln,needed,csize) remove_slots(inv,ln,needed,csize)
end end
-- autosave network data -- autosave network data
me.autosave() me.autosave()
end end
function network:update() function network:update()
@ -274,9 +274,9 @@ function network:get_inventory_name()
end end
function network:get_inventory_space(inv, list) function network:get_inventory_space(inv, list)
local inv = inv or self:get_inventory() local inv = inv or self:get_inventory()
local listname = list or "main" local listname = list or "main"
local max_slots = inv:get_size(listname) local max_slots = inv:get_size(listname)
local max_items = self.capacity_cache local max_items = self.capacity_cache
local slots, items = 0, 0 local slots, items = 0, 0
@ -297,9 +297,9 @@ local function create_inventory(net)
local invname = net:get_inventory_name() local invname = net:get_inventory_name()
net.inv = minetest.create_detached_inventory(invname, { net.inv = minetest.create_detached_inventory(invname, {
allow_put = function(inv, listname, index, stack, player) allow_put = function(inv, listname, index, stack, player)
if net:get_access_level(player) < access_level.interact then if net:get_access_level(player) < access_level.interact then
return 0 return 0
end end
local inside_stack = inv:get_stack(listname, index) local inside_stack = inv:get_stack(listname, index)
local stack_name = stack:get_name() local stack_name = stack:get_name()
if minetest.get_item_group(stack_name, "microexpansion_cell") > 0 then if minetest.get_item_group(stack_name, "microexpansion_cell") > 0 then
@ -333,9 +333,9 @@ local function create_inventory(net)
net:set_storage_space(true) net:set_storage_space(true)
end, end,
allow_take = function(_, _, _, stack, player) allow_take = function(_, _, _, stack, player)
if net:get_access_level(player) < access_level.interact then if net:get_access_level(player) < access_level.interact then
return 0 return 0
end end
return math.min(stack:get_count(),stack:get_stack_max()) return math.min(stack:get_count(),stack:get_stack_max())
end, end,
on_take = function() on_take = function()

@ -6,287 +6,287 @@ local access_desc = me.constants.security.access_level_descriptions
-- [me security] Get formspec -- [me security] Get formspec
local function security_formspec(pos, player, rule, q) local function security_formspec(pos, player, rule, q)
local list local list
local buttons local buttons
local logout = true local logout = true
local query = q or "" local query = q or ""
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if player and cp then if player and cp then
local access = net:get_access_level(player) local access = net:get_access_level(player)
if access < access_level.manage then -- Blocked dialog if access < access_level.manage then -- Blocked dialog
logout = false logout = false
list = "label[2.5,3;"..minetest.colorize("red", "Access Denied").."]" list = "label[2.5,3;"..minetest.colorize("red", "Access Denied").."]"
buttons = "button[3.5,6;2,1;logout;back]" buttons = "button[3.5,6;2,1;logout;back]"
elseif (not rule) or rule == "" then -- Main Screen elseif (not rule) or rule == "" then -- Main Screen
--TODO: show button or entry for default access level --TODO: show button or entry for default access level
list = "tablecolumns[color,span=1;text;color,span=1;text]" list = "tablecolumns[color,span=1;text;color,span=1;text]"
.. "table[0.5,2;6,7;access_table;" .. "table[0.5,2;6,7;access_table;"
local first = true local first = true
--TODO: filter --TODO: filter
local name_list = {} local name_list = {}
for p,l in pairs(net:list_access()) do for p,l in pairs(net:list_access()) do
if first then if first then
first = false first = false
else
list = list .. ","
end
table.insert(name_list, p)
local desc = access_desc[l] or {name = "Unknown", color = "red"}
list = list .. "cyan," .. p .. "," .. desc.color .. "," .. desc.name
end
list = list .. ";]"
minetest.get_meta(pos):set_string("table_index", minetest.serialize(name_list))
list = list .. [[
field[0.5,1;2,0.5;filter;;]]..query..[[]
button[3,1;0.8,0.5;search;?]
button[4,1;0.8,0.5;clear;X]
tooltip[search;Search]
tooltip[clear;Reset]
field_close_on_enter[filter;false]
]]
buttons = [[
button[7,7;1.5,0.8;new;new rule]
button[7,8;1.5,0.8;edit_sel;edit rule]
]]
--button[7,6;1.5,0.8;del_sel;delete rule]
elseif rule == "<new>" then -- Creation screen
logout = false
local players = ""
for _,p in pairs(minetest.get_connected_players()) do
if players ~= "" then
players = players .. ","
end
players = players .. p:get_player_name()
end
--TODO: add a text field (maybe toggelable)
list = [[
dropdown[3,2.75;5,0.5;new_player;]]..players..[[;]
label[1.5,3;rule for:]
]]
buttons = [[
button[2,6;2,0.8;edit;add/edit]
button[5,6;2,0.8;back;cancel]
]]
elseif (access < access_level.full and net:get_access_level(rule) >= access_level.manage) or (player ~= rule and access >= access_level.full and net:get_access_level(rule) >= access_level.full) then
-- low access dialog
list = "label[1,3;"..minetest.colorize("red", "You can only modify rules with lower access than yourself.").."]"
buttons = "button[3.5,6;2,1;back;back]"
else
local rule_level = net:get_access_level(rule)
local current = rule_level == access_level.blocked and "1" or
rule_level == access_level.view and "2" or
rule_level == access_level.interact and "3" or
rule_level == access_level.modify and "4" or
rule_level == access_level.manage and "5" or
rule_level == access_level.full and "6" or ""
list = [[
label[1,3;rule for:]].."\t"..minetest.colorize("cyan", rule)..[[]
label[1,4;access level:]
dropdown[3,3.75;2,0.5;access;Blocked,View,Interact,Modify,Manage,Full;]]..current..[[]
]]
buttons = [[
button[1,6;1,0.8;save;save]
button[3,6;2,0.8;reset;reset to default]
button[6,6;1,0.8;back;cancel]
]]
end
elseif cp then
logout = false
list = "label[2.5,3;Welcome to the security Terminal!]"
buttons = [[
button[3.5,6;2,1;login;login]
button_exit[8,0.5;0.5,0.5;close;x]
]]
else else
logout = false list = list .. ","
list = "label[2.5,3;" .. minetest.colorize("red", "No connected network!") .. "]"
buttons = "button_exit[3,6;2,1;close;close]"
end end
table.insert(name_list, p)
local desc = access_desc[l] or {name = "Unknown", color = "red"}
list = list .. "cyan," .. p .. "," .. desc.color .. "," .. desc.name
end
list = list .. ";]"
minetest.get_meta(pos):set_string("table_index", minetest.serialize(name_list))
return [[ list = list .. [[
formspec_version[2] field[0.5,1;2,0.5;filter;;]]..query..[[]
size[9,9.5] button[3,1;0.8,0.5;search;?]
]].. button[4,1;0.8,0.5;clear;X]
microexpansion.gui_bg .. tooltip[search;Search]
list .. tooltip[clear;Reset]
(logout and "button[7.5,0.5;1,0.5;logout;logout]" or "") .. field_close_on_enter[filter;false]
"label[0.5,0.5;ME Security Terminal]" .. ]]
buttons buttons = [[
button[7,7;1.5,0.8;new;new rule]
button[7,8;1.5,0.8;edit_sel;edit rule]
]]
--button[7,6;1.5,0.8;del_sel;delete rule]
elseif rule == "<new>" then -- Creation screen
logout = false
local players = ""
for _,p in pairs(minetest.get_connected_players()) do
if players ~= "" then
players = players .. ","
end
players = players .. p:get_player_name()
end
--TODO: add a text field (maybe toggelable)
list = [[
dropdown[3,2.75;5,0.5;new_player;]]..players..[[;]
label[1.5,3;rule for:]
]]
buttons = [[
button[2,6;2,0.8;edit;add/edit]
button[5,6;2,0.8;back;cancel]
]]
elseif (access < access_level.full and net:get_access_level(rule) >= access_level.manage) or (player ~= rule and access >= access_level.full and net:get_access_level(rule) >= access_level.full) then
-- low access dialog
list = "label[1,3;"..minetest.colorize("red", "You can only modify rules with lower access than yourself.").."]"
buttons = "button[3.5,6;2,1;back;back]"
else
local rule_level = net:get_access_level(rule)
local current = rule_level == access_level.blocked and "1" or
rule_level == access_level.view and "2" or
rule_level == access_level.interact and "3" or
rule_level == access_level.modify and "4" or
rule_level == access_level.manage and "5" or
rule_level == access_level.full and "6" or ""
list = [[
label[1,3;rule for:]].."\t"..minetest.colorize("cyan", rule)..[[]
label[1,4;access level:]
dropdown[3,3.75;2,0.5;access;Blocked,View,Interact,Modify,Manage,Full;]]..current..[[]
]]
buttons = [[
button[1,6;1,0.8;save;save]
button[3,6;2,0.8;reset;reset to default]
button[6,6;1,0.8;back;cancel]
]]
end
elseif cp then
logout = false
list = "label[2.5,3;Welcome to the security Terminal!]"
buttons = [[
button[3.5,6;2,1;login;login]
button_exit[8,0.5;0.5,0.5;close;x]
]]
else
logout = false
list = "label[2.5,3;" .. minetest.colorize("red", "No connected network!") .. "]"
buttons = "button_exit[3,6;2,1;close;close]"
end
return [[
formspec_version[2]
size[9,9.5]
]]..
microexpansion.gui_bg ..
list ..
(logout and "button[7.5,0.5;1,0.5;logout;logout]" or "") ..
"label[0.5,0.5;ME Security Terminal]" ..
buttons
end end
local function update_security(pos,_,ev) local function update_security(pos,_,ev)
--for now all events matter --for now all events matter
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if network == nil then if network == nil then
meta:set_string("editing_rule", "") meta:set_string("editing_rule", "")
meta:set_string("formspec", security_formspec(pos)) meta:set_string("formspec", security_formspec(pos))
end end
meta:set_string("formspec", security_formspec(pos)) meta:set_string("formspec", security_formspec(pos))
end end
local security_recipe = nil local security_recipe = nil
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
security_recipe = { security_recipe = {
{ 1, { { 1, {
{"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "mcl_copper:copper_ingot", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot", "microexpansion:machine_casing", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "microexpansion:machine_casing", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot", "microexpansion:cable", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "microexpansion:cable", "mcl_core:iron_ingot"},
}, },
} }
} }
else else
security_recipe = { security_recipe = {
{ 1, { { 1, {
{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"},
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot"}, {"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot"},
{"default:steel_ingot", "microexpansion:cable", "default:steel_ingot"}, {"default:steel_ingot", "microexpansion:cable", "default:steel_ingot"},
}, },
} }
} }
end end
-- [me chest] Register node -- [me chest] Register node
microexpansion.register_node("security", { microexpansion.register_node("security", {
description = "ME Security Terminal", description = "ME Security Terminal",
usedfor = "Allows controlling access to ME networks", usedfor = "Allows controlling access to ME networks",
tiles = { tiles = {
"security_bottom", "security_bottom",
"security_bottom", "security_bottom",
"chest_side", "chest_side",
"chest_side", "chest_side",
"chest_side", "chest_side",
"security_front", "security_front",
}, },
recipe = security_recipe, recipe = security_recipe,
is_ground_content = false, is_ground_content = false,
groups = { cracky = 1, me_connect = 1 }, groups = { cracky = 1, me_connect = 1 },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
me_update = update_security, me_update = update_security,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local net = me.get_connected_network(pos) local net = me.get_connected_network(pos)
me.send_event(pos,"connect",{net=net}) me.send_event(pos,"connect",{net=net})
update_security(pos) update_security(pos)
end, end,
after_destruct = function(pos) after_destruct = function(pos)
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end,
can_dig = function(pos, player)
if not player then
return false
end
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return false
end
local net,cp = me.get_connected_network(pos)
if not net then
return true
end
return net:get_access_level(name) >= access_level.manage
end, end,
can_dig = function(pos, player)
if not player then
return false
end
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return false
end
local net,cp = me.get_connected_network(pos)
if not net then
return true
end
return net:get_access_level(name) >= access_level.manage
end,
on_receive_fields = function(pos, _, fields, sender) on_receive_fields = function(pos, _, fields, sender)
if fields.close then if fields.close then
return return
end end
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if net then if net then
if cp then if cp then
microexpansion.log("network and ctrl_pos","info") microexpansion.log("network and ctrl_pos","info")
else else
microexpansion.log("network but no ctrl_pos","warning") microexpansion.log("network but no ctrl_pos","warning")
end end
else else
if cp then if cp then
microexpansion.log("no network but ctrl_pos","warning") microexpansion.log("no network but ctrl_pos","warning")
else else
microexpansion.log("no network and no ctrl_pos","info") microexpansion.log("no network and no ctrl_pos","info")
end end
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local name = sender:get_player_name() local name = sender:get_player_name()
if not net then if not net then
microexpansion.log("no network connected to security terminal","warning") microexpansion.log("no network connected to security terminal","warning")
return return
end end
if fields.logout then if fields.logout then
meta:set_string("formspec", security_formspec(pos)) meta:set_string("formspec", security_formspec(pos))
elseif fields.login or fields.back then elseif fields.login or fields.back then
-- carry over networks from old versions -- carry over networks from old versions
net:fallback_access() net:fallback_access()
meta:set_string("formspec", security_formspec(pos, name)) meta:set_string("formspec", security_formspec(pos, name))
elseif fields.search or fields.key_enter_field == "filter" then elseif fields.search or fields.key_enter_field == "filter" then
meta:set_string("formspec", security_formspec(pos, name), false, fields.filter) meta:set_string("formspec", security_formspec(pos, name), false, fields.filter)
elseif fields.clear then elseif fields.clear then
meta:set_string("formspec", security_formspec(pos, name)) meta:set_string("formspec", security_formspec(pos, name))
elseif fields.new then elseif fields.new then
meta:set_string("formspec", security_formspec(pos, name, "<new>")) meta:set_string("formspec", security_formspec(pos, name, "<new>"))
elseif fields.edit then elseif fields.edit then
local access = net:get_access_level(name) local access = net:get_access_level(name)
if not fields.new_player then if not fields.new_player then
me.log("edit button without new player field","warning") me.log("edit button without new player field","warning")
meta:set_string("formspec", security_formspec(pos, name)) meta:set_string("formspec", security_formspec(pos, name))
return return
end end
if net:get_access_level(fields.new_player) == nil then if net:get_access_level(fields.new_player) == nil then
if access >= access_level.manage then if access >= access_level.manage then
net:set_access_level(fields.new_player, net:get_access_level()) net:set_access_level(fields.new_player, net:get_access_level())
end end
end end
meta:set_string("editing_rule", fields.new_player) meta:set_string("editing_rule", fields.new_player)
meta:set_string("formspec", security_formspec(pos, name, fields.new_player)) meta:set_string("formspec", security_formspec(pos, name, fields.new_player))
elseif fields.edit_sel then elseif fields.edit_sel then
meta:set_string("formspec", security_formspec(pos, name, meta:get_string("editing_rule"))) meta:set_string("formspec", security_formspec(pos, name, meta:get_string("editing_rule")))
elseif fields.access_table then elseif fields.access_table then
local ev = minetest.explode_table_event(fields.access_table) local ev = minetest.explode_table_event(fields.access_table)
local table_index = minetest.deserialize(meta:get_string("table_index")) local table_index = minetest.deserialize(meta:get_string("table_index"))
local edit_player = table_index[ev.row] local edit_player = table_index[ev.row]
if net:get_access_level(edit_player) == nil then if net:get_access_level(edit_player) == nil then
me.log("playerlist changed before editing","warning") me.log("playerlist changed before editing","warning")
meta:set_string("formspec", security_formspec(pos, name)) meta:set_string("formspec", security_formspec(pos, name))
return return
else else
meta:set_string("editing_rule", edit_player) meta:set_string("editing_rule", edit_player)
if ev.type == "DCL" then if ev.type == "DCL" then
meta:set_string("formspec", security_formspec(pos, name, edit_player)) meta:set_string("formspec", security_formspec(pos, name, edit_player))
end end
end end
elseif fields.reset then elseif fields.reset then
local rule = meta:get_string("editing_rule") local rule = meta:get_string("editing_rule")
local access = net:get_access_level(name) local access = net:get_access_level(name)
local old_level = net:get_access_level(rule) local old_level = net:get_access_level(rule)
local new_level = net.default_access_level local new_level = net.default_access_level
if (access > old_level or name == rule) and (access > new_level or access >= access_level.full) then if (access > old_level or name == rule) and (access > new_level or access >= access_level.full) then
net:set_access_level(rule, nil) net:set_access_level(rule, nil)
--TODO: show fail dialog if access violation --TODO: show fail dialog if access violation
end end
meta:set_string("formspec", security_formspec(pos, name)) meta:set_string("formspec", security_formspec(pos, name))
elseif fields.save then elseif fields.save then
local rule = meta:get_string("editing_rule") local rule = meta:get_string("editing_rule")
local access = net:get_access_level(name) local access = net:get_access_level(name)
local old_level = net:get_access_level(rule) local old_level = net:get_access_level(rule)
local new_level = fields.access == "Blocked" and access_level.blocked or local new_level = fields.access == "Blocked" and access_level.blocked or
fields.access == "View" and access_level.view or fields.access == "View" and access_level.view or
fields.access == "Interact" and access_level.interact or fields.access == "Interact" and access_level.interact or
fields.access == "Modify" and access_level.modify or fields.access == "Modify" and access_level.modify or
fields.access == "Manage" and access_level.manage or fields.access == "Manage" and access_level.manage or
fields.access == "Full" and access_level.full fields.access == "Full" and access_level.full
if not new_level then if not new_level then
me.log("unknown access level selection " .. fields.access, "error") me.log("unknown access level selection " .. fields.access, "error")
--TODO: show fail dialog --TODO: show fail dialog
return return
end end
if (access > old_level or name == rule) and access > new_level then if (access > old_level or name == rule) and access > new_level then
net:set_access_level(rule, new_level) net:set_access_level(rule, new_level)
--TODO: show fail dialog if access violation --TODO: show fail dialog if access violation
end end
meta:set_string("formspec", security_formspec(pos, name)) meta:set_string("formspec", security_formspec(pos, name))
end end
end, end,
}) })

@ -15,71 +15,71 @@ local incranium_cracky = 3
local quartz_cracky = 3 local quartz_cracky = 3
if mcl_core_modpath then if mcl_core_modpath then
incranium_y_min = -55 incranium_y_min = -55
incranium_y_max = -20 incranium_y_max = -20
quartz_y_min = -50 quartz_y_min = -50
quartz_y_max = 0 quartz_y_max = 0
incranium_cracky = 3 incranium_cracky = 3
quartz_cracky = 3 quartz_cracky = 3
end end
local quartz_nodedef = { local quartz_nodedef = {
description = "Quartz Ore", description = "Quartz Ore",
tiles = { "default_stone.png^microexpansion_ore_quartz.png" }, tiles = { "default_stone.png^microexpansion_ore_quartz.png" },
is_ground_content = true, is_ground_content = true,
type = "ore", type = "ore",
groups = {cracky=quartz_cracky,material_stone=1, stone=1, pickaxey=3}, groups = {cracky=quartz_cracky,material_stone=1, stone=1, pickaxey=3},
drop = "microexpansion:quartz_crystal", drop = "microexpansion:quartz_crystal",
oredef = {{ oredef = {{
ore_type = "scatter", ore_type = "scatter",
wherein = stone_ingrediant, wherein = stone_ingrediant,
clust_scarcity = 10*10*10, clust_scarcity = 10*10*10,
clust_num_ores = 6, clust_num_ores = 6,
clust_size = 5, clust_size = 5,
y_min = quartz_y_min, y_min = quartz_y_min,
y_max = quartz_y_max, y_max = quartz_y_max,
}}, }},
} }
incranium_nodedef = { incranium_nodedef = {
description = "Incranium Ore", description = "Incranium Ore",
tiles = { "incranium" }, tiles = { "incranium" },
is_ground_content = true, is_ground_content = true,
groups = {cracky=incranium_cracky, material_stone=1, stone=1,pickaxey=3 }, groups = {cracky=incranium_cracky, material_stone=1, stone=1,pickaxey=3 },
type = "ore", type = "ore",
oredef = { oredef = {
{ {
ore_type = "blob", ore_type = "blob",
wherein = stone_ingrediant, wherein = stone_ingrediant,
clust_scarcity = 4*4*4, clust_scarcity = 4*4*4,
clust_num_ores = 4, clust_num_ores = 4,
clust_size = 3, clust_size = 3,
y_min = incranium_y_min, y_min = incranium_y_min,
y_max = incranium_y_max, y_max = incranium_y_max,
}, },
}, },
disabled = true, disabled = true,
} }
if mcl_core_modpath then if mcl_core_modpath then
quartz_nodedef._mcl_hardness = 3 quartz_nodedef._mcl_hardness = 3
quartz_nodedef._mcl_blast_resistance = 3 quartz_nodedef._mcl_blast_resistance = 3
quartz_nodedef._mcl_hardness = 3 quartz_nodedef._mcl_hardness = 3
quartz_nodedef._mcl_silk_touch_drop = true quartz_nodedef._mcl_silk_touch_drop = true
quartz_nodedef._mcl_fortune_drop = mcl_core.fortune_drop_ore quartz_nodedef._mcl_fortune_drop = mcl_core.fortune_drop_ore
incranium_nodedef._mcl_hardness = 3 incranium_nodedef._mcl_hardness = 3
incranium_nodedef._mcl_blast_resistance = 3 incranium_nodedef._mcl_blast_resistance = 3
incranium_nodedef._mcl_hardness = 3 incranium_nodedef._mcl_hardness = 3
incranium_nodedef._mcl_silk_touch_drop = true incranium_nodedef._mcl_silk_touch_drop = true
incranium_nodedef._mcl_fortune_drop = mcl_core.fortune_drop_ore incranium_nodedef._mcl_fortune_drop = mcl_core.fortune_drop_ore
end end
-- [register] Incranium Ore -- [register] Incranium Ore
me.register_node("incranium", incranium_nodedef) me.register_node("incranium", incranium_nodedef)
me.register_item("quartz_crystal", { me.register_item("quartz_crystal", {
description = "Quartz Crystal", description = "Quartz Crystal",
}) })

@ -4,101 +4,101 @@ local me = microexpansion
local fuel_fired_generator_recipe = nil local fuel_fired_generator_recipe = nil
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
fuel_fired_generator_recipe = { fuel_fired_generator_recipe = {
{ 1, { { 1, {
{ "mcl_core:iron_ingot", "mcl_furnaces:furnace", "mcl_core:iron_ingot" }, {"mcl_core:iron_ingot", "mcl_furnaces:furnace", "mcl_core:iron_ingot"},
{ "mcl_core:iron_ingot", "microexpansion:machine_casing", "mcl_core:iron_ingot" }, {"mcl_core:iron_ingot", "microexpansion:machine_casing", "mcl_core:iron_ingot"},
{ "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" }, {"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
}, },
} }
} }
else else
fuel_fired_generator_recipe = { fuel_fired_generator_recipe = {
{ 1, { { 1, {
{ "default:steel_ingot", "default:furnace", "default:steel_ingot" }, {"default:steel_ingot", "default:furnace", "default:steel_ingot"},
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" }, {"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot"},
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
}, },
} }
} }
end end
-- [register node] Fuel Fired Generator -- [register node] Fuel Fired Generator
me.register_machine("fuel_fired_generator", { me.register_machine("fuel_fired_generator", {
description = "Fuel-Fired Generator", description = "Fuel-Fired Generator",
tiles = { tiles = {
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"fuelgen_front", "fuelgen_front",
}, },
recipe = fuel_fired_generator_recipe, recipe = fuel_fired_generator_recipe,
groups = { cracky = 1 }, groups = { cracky = 1 },
connect_sides = "machine", connect_sides = "machine",
paramtype2 = "facedir", paramtype2 = "facedir",
status = "unstable", status = "unstable",
machine = { machine = {
type = "provider", type = "provider",
on_survey = function() -- args: pos on_survey = function() -- args: pos
--TODO: burn fuel --TODO: burn fuel
return 5 -- Generate 5 ME/tick return 5 -- Generate 5 ME/tick
end, end,
}, },
}) })
--[[register node] Super Smelter --[[register node] Super Smelter
me.register_node("super_smelter", { me.register_node("super_smelter", {
description = "Super Smelter", description = "Super Smelter",
tiles = { tiles = {
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"super_smelter_front", "super_smelter_front",
}, },
recipe = { recipe = {
{ 1, { { 1, {
{ "default:furnace", "default:furnace", "default:furnace" }, {"default:furnace", "default:furnace", "default:furnace"},
{ "default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" }, {"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot"},
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
}, },
}, },
}, },
groups = { cracky = 1, me_connect = 1, }, groups = { cracky = 1, me_connect = 1, },
connect_sides = "machine", connect_sides = "machine",
paramtype2 = "facedir", paramtype2 = "facedir",
status = "unstable", status = "unstable",
machine = { machine = {
type = "consumer", type = "consumer",
on_survey = function(pos) on_survey = function(pos)
return 5 -- Consume 5 ME/tick return 5 -- Consume 5 ME/tick
end, end,
}, },
}) })
-- [register item] Geothermal Generator -- [register item] Geothermal Generator
me.register_node("geo_generator", { me.register_node("geo_generator", {
description = "Geothermal Generator", description = "Geothermal Generator",
tiles = { tiles = {
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"machine_sides", "machine_sides",
"geogen_front", "geogen_front",
}, },
groups = { cracky = 1, me_connect = 1, }, groups = { cracky = 1, me_connect = 1, },
connect_sides = "machine", connect_sides = "machine",
paramtype2 = "facedir", paramtype2 = "facedir",
status = "unstable", status = "unstable",
machine = { machine = {
type = "provider", type = "provider",
on_survey = function(pos) on_survey = function(pos)
return 10 -- Generate 10 ME/tick return 10 -- Generate 10 ME/tick
end, end,
}, },
})]] })]]

@ -9,16 +9,16 @@ local power = me.power
-- [local function] Get netitem by position -- [local function] Get netitem by position
local function get_netitem_by_pos(list, pos) local function get_netitem_by_pos(list, pos)
for _, i in pairs(list) do for _, i in pairs(list) do
if vector.equals(pos, i.pos) then if vector.equals(pos, i.pos) then
return i return i
end end
end end
end end
-- [function] Generate new network ID -- [function] Generate new network ID
function power.new_id() function power.new_id()
return "network_"..#me.networks+1 return "network_"..#me.networks+1
end end
-- [function] Add machine to network -- [function] Add machine to network
@ -28,84 +28,84 @@ end
-- [function] Remove machine from network -- [function] Remove machine from network
function power.remove_machine(pos) function power.remove_machine(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("network_ignore", "true") meta:set_string("network_ignore", "true")
end end
-- [function] Trace network -- [function] Trace network
function power.trace(pos) function power.trace(pos)
local netpos = me.networks[minetest.get_meta(pos):get_string("network_id")] local netpos = me.networks[minetest.get_meta(pos):get_string("network_id")]
-- if no network, return -- if no network, return
if not netpos then if not netpos then
return return
end end
local meta = minetest.get_meta(netpos) local meta = minetest.get_meta(netpos)
local netid = meta:get_string("network_id") local netid = meta:get_string("network_id")
local list = {} local list = {}
local delete = false local delete = false
if meta:get_string("network_ignore") == "true" then if meta:get_string("network_ignore") == "true" then
delete = true delete = true
end end
-- [local function] Indexed -- [local function] Indexed
local function indexed(p) local function indexed(p)
for _, i in pairs(list) do for _, i in pairs(list) do
if vector.equals(p, i.pos) then if vector.equals(p, i.pos) then
return true return true
end end
end end
end end
-- [local function] Trace -- [local function] Trace
local function trace(nodes) local function trace(nodes)
for _, p in pairs(nodes) do for _, p in pairs(nodes) do
if not indexed(p) then if not indexed(p) then
local machine = minetest.get_meta(p) local machine = minetest.get_meta(p)
if machine:get_string("network_ignore") ~= "true" then if machine:get_string("network_ignore") ~= "true" then
local node = me.get_node(p).name local node = me.get_node(p).name
local desc = minetest.registered_nodes[node].description local desc = minetest.registered_nodes[node].description
if delete then if delete then
machine:set_string("network_id", nil) machine:set_string("network_id", nil)
machine:set_string("infotext", desc.."\nNo Network") machine:set_string("infotext", desc.."\nNo Network")
me.network_set_demand(p, 0) me.network_set_demand(p, 0)
else else
machine:set_string("network_id", netid) machine:set_string("network_id", netid)
machine:set_string("infotext", desc.."\nNetwork ID: "..netid) machine:set_string("infotext", desc.."\nNetwork ID: "..netid)
end end
list[#list + 1] = { pos = p, demand = machine:get_int("demand") } list[#list + 1] = { pos = p, demand = machine:get_int("demand") }
trace(power.get_connected_nodes(p, false)) trace(power.get_connected_nodes(p, false))
end end
end end
end end
end end
trace(power.get_connected_nodes(netpos)) trace(power.get_connected_nodes(netpos))
-- Check original list -- Check original list
local original = minetest.deserialize(meta:get_string("netitems")) local original = minetest.deserialize(meta:get_string("netitems"))
if original then if original then
for _, i in pairs(original) do for _, i in pairs(original) do
if not indexed(i.pos) then if not indexed(i.pos) then
local node = me.get_node(i.pos).name local node = me.get_node(i.pos).name
local desc = minetest.registered_nodes[node].description local desc = minetest.registered_nodes[node].description
local machine = minetest.get_meta(i.pos) local machine = minetest.get_meta(i.pos)
machine:set_string("network_id", nil) machine:set_string("network_id", nil)
machine:set_string("infotext", desc.."\nNo Network") machine:set_string("infotext", desc.."\nNo Network")
me.network_set_demand(pos, 0) me.network_set_demand(pos, 0)
end end
end end
end end
meta:set_string("netitems", minetest.serialize(list)) meta:set_string("netitems", minetest.serialize(list))
-- Update infotext -- Update infotext
meta:set_string("infotext", "Network Controller (owned by ".. meta:set_string("infotext", "Network Controller (owned by "..
meta:get_string("owner")..")\nNetwork ID: "..meta:get_string("network_id").. meta:get_string("owner")..")\nNetwork ID: "..meta:get_string("network_id")..
"\nDemand: "..dump(me.network_get_demand(netpos))) "\nDemand: "..dump(me.network_get_demand(netpos)))
end end
--- ---
@ -114,11 +114,11 @@ end
-- [function] Get load information -- [function] Get load information
function me.network_get_load(pos) function me.network_get_load(pos)
local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")] local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")]
if ctrl then if ctrl then
local meta = minetest.get_meta(ctrl) local meta = minetest.get_meta(ctrl)
local list = minetest.deserialize(meta:get_string("netitems")) local list = minetest.deserialize(meta:get_string("netitems"))
end end
end end
---- Generators ---- ---- Generators ----
@ -127,53 +127,53 @@ end
-- [function] Get total network demand -- [function] Get total network demand
function me.network_get_demand(pos) function me.network_get_demand(pos)
local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")] local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")]
-- if no network, return -- if no network, return
if not ctrl then if not ctrl then
return return
end end
local meta = minetest.get_meta(ctrl) local meta = minetest.get_meta(ctrl)
local list = minetest.deserialize(meta:get_string("netitems")) local list = minetest.deserialize(meta:get_string("netitems"))
local demand = 0 local demand = 0
for _, i in pairs(list) do for _, i in pairs(list) do
if i.demand then if i.demand then
demand = demand + i.demand demand = demand + i.demand
end end
end end
return demand return demand
end end
-- [function] Set demand for machine -- [function] Set demand for machine
function me.network_set_demand(pos, demand) function me.network_set_demand(pos, demand)
-- Update original metadata -- Update original metadata
minetest.get_meta(pos):set_int("demand", demand) minetest.get_meta(pos):set_int("demand", demand)
local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")] local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")]
-- if no network, return -- if no network, return
if not ctrl then if not ctrl then
return return
end end
local meta = minetest.get_meta(ctrl) local meta = minetest.get_meta(ctrl)
local list = minetest.deserialize(meta:get_string("netitems")) local list = minetest.deserialize(meta:get_string("netitems"))
local item = get_netitem_by_pos(list, pos) local item = get_netitem_by_pos(list, pos)
if not item then if not item then
return return
end end
item.demand = demand item.demand = demand
meta:set_string("netitems", minetest.serialize(list)) meta:set_string("netitems", minetest.serialize(list))
-- Update infotext -- Update infotext
meta:set_string("infotext", "Network Controller (owned by ".. meta:set_string("infotext", "Network Controller (owned by "..
meta:get_string("owner")..")\nNetwork ID: "..meta:get_string("network_id").. meta:get_string("owner")..")\nNetwork ID: "..meta:get_string("network_id")..
"\nDemand: "..dump(me.network_get_demand(pos))) "\nDemand: "..dump(me.network_get_demand(pos)))
end end
---- Storage ---- ---- Storage ----

@ -6,51 +6,51 @@ local BASENAME = "microexpansion"
-- [function] register cell -- [function] register cell
function microexpansion.register_cell(itemstring, def) function microexpansion.register_cell(itemstring, def)
if not def.inventory_image then if not def.inventory_image then
def.inventory_image = itemstring def.inventory_image = itemstring
end end
-- register craftitem -- register craftitem
minetest.register_craftitem(BASENAME..":"..itemstring, { minetest.register_craftitem(BASENAME..":"..itemstring, {
description = def.description, description = def.description,
inventory_image = BASENAME.."_"..def.inventory_image..".png", inventory_image = BASENAME.."_"..def.inventory_image..".png",
groups = {microexpansion_cell = 1}, groups = {microexpansion_cell = 1},
stack_max = 1, stack_max = 1,
microexpansion = { microexpansion = {
base_desc = def.description, base_desc = def.description,
drive = { drive = {
capacity = def.capacity or 5000, capacity = def.capacity or 5000,
}, },
}, },
}) })
-- if recipe, register recipe -- if recipe, register recipe
if def.recipe then if def.recipe then
microexpansion.register_recipe(BASENAME..":"..itemstring, def.recipe) microexpansion.register_recipe(BASENAME..":"..itemstring, def.recipe)
end end
if microexpansion.uinv_category_enabled then if microexpansion.uinv_category_enabled then
unified_inventory.add_category_item("storage", BASENAME..":"..itemstring) unified_inventory.add_category_item("storage", BASENAME..":"..itemstring)
end end
end end
-- [function] Get cell size -- [function] Get cell size
function microexpansion.get_cell_size(name) function microexpansion.get_cell_size(name)
if minetest.get_item_group(name, "microexpansion_cell") == 0 then if minetest.get_item_group(name, "microexpansion_cell") == 0 then
return 0 return 0
end end
local item = minetest.registered_craftitems[name] local item = minetest.registered_craftitems[name]
return item.microexpansion.drive.capacity return item.microexpansion.drive.capacity
end end
-- [function] Calculate max stacks -- [function] Calculate max stacks
function microexpansion.int_to_stacks(int) function microexpansion.int_to_stacks(int)
return math.ceil(int / 99) return math.ceil(int / 99)
end end
-- [function] Calculate number of pages -- [function] Calculate number of pages
function microexpansion.int_to_pagenum(int) function microexpansion.int_to_pagenum(int)
return math.floor(microexpansion.int_to_stacks(int) / 32) return math.floor(microexpansion.int_to_stacks(int) / 32)
end end
--[[ [function] Move items from inv to inv --[[ [function] Move items from inv to inv

@ -76,17 +76,17 @@ local function set_drive_controller(dpos,setd,cpos,i)
end end
local function write_to_cell(cell, items, item_count) local function write_to_cell(cell, items, item_count)
local size = microexpansion.get_cell_size(cell:get_name()) local size = microexpansion.get_cell_size(cell:get_name())
local item_meta = cell:get_meta() local item_meta = cell:get_meta()
--print(dump2(items,"cell_items")) --print(dump2(items,"cell_items"))
item_meta:set_string("items", minetest.serialize(items)) item_meta:set_string("items", minetest.serialize(items))
local base_desc = minetest.registered_craftitems[cell:get_name()].microexpansion.base_desc local base_desc = minetest.registered_craftitems[cell:get_name()].microexpansion.base_desc
-- Calculate Percentage -- Calculate Percentage
local percent = math.floor(item_count / size * 100) local percent = math.floor(item_count / size * 100)
-- Update description -- Update description
item_meta:set_string("description", base_desc.."\n".. item_meta:set_string("description", base_desc.."\n"..
minetest.colorize("grey", tostring(item_count).."/"..tostring(size).." Items ("..tostring(percent).."%)")) minetest.colorize("grey", tostring(item_count).."/"..tostring(size).." Items ("..tostring(percent).."%)"))
return cell return cell
end end
local function write_drive_cells(pos,network) local function write_drive_cells(pos,network)
@ -269,7 +269,7 @@ local function update_drive(pos,_,ev)
end end
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
drive_recipe = { drive_recipe = {
{ 1, { { 1, {
{"mcl_core:iron_ingot", "mcl_chests:chest", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "mcl_chests:chest", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot", "microexpansion:machine_casing", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "microexpansion:machine_casing", "mcl_core:iron_ingot"},
@ -278,7 +278,7 @@ if minetest.get_modpath("mcl_core") then
}} }}
else else
drive_recipe = { drive_recipe = {
{ 1, { { 1, {
{"default:steel_ingot", "default:chest", "default:steel_ingot" }, {"default:steel_ingot", "default:chest", "default:steel_ingot" },
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" }, {"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
@ -290,137 +290,137 @@ end
-- [me chest] Register node -- [me chest] Register node
microexpansion.register_node("drive", { microexpansion.register_node("drive", {
description = "ME Drive", description = "ME Drive",
usedfor = "Stores items into ME storage cells", usedfor = "Stores items into ME storage cells",
tiles = { tiles = {
"chest_top", "chest_top",
"chest_top", "chest_top",
"chest_side", "chest_side",
"chest_side", "chest_side",
"chest_side", "chest_side",
"drive_full", "drive_full",
}, },
recipe = drive_recipe, recipe = drive_recipe,
is_ground_content = false, is_ground_content = false,
groups = { cracky = 1, me_connect = 1 }, groups = { cracky = 1, me_connect = 1 },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
me_update = update_drive, me_update = update_drive,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", meta:set_string("formspec",
"size[9,9.5]".. "size[9,9.5]"..
microexpansion.gui_bg .. microexpansion.gui_bg ..
microexpansion.gui_slots .. microexpansion.gui_slots ..
[[ [[
label[0,-0.23;ME Drive] label[0,-0.23;ME Drive]
list[context;main;0,0.3;8,4] list[context;main;0,0.3;8,4]
list[current_player;main;0,5.5;8,1;] list[current_player;main;0,5.5;8,1;]
list[current_player;main;0,6.73;8,3;8] list[current_player;main;0,6.73;8,3;8]
listring[current_name;main] listring[current_name;main]
listring[current_player;main] listring[current_player;main]
field_close_on_enter[filter;false] field_close_on_enter[filter;false]
]]) ]])
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 10) inv:set_size("main", 10)
me.send_event(pos,"connect") me.send_event(pos,"connect")
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
if not player then if not player then
return false return false
end end
local name = player:get_player_name() local name = player:get_player_name()
if minetest.is_protected(pos, name) then if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return false return false
end end
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if not net then if not net then
return true return true
end end
if net:get_access_level(name) < access_level.modify then if net:get_access_level(name) < access_level.modify then
return false return false
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("main") return inv:is_empty("main")
end, end,
after_destruct = function(pos) after_destruct = function(pos)
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end, end,
allow_metadata_inventory_put = function(pos, _, _, stack, player) allow_metadata_inventory_put = function(pos, _, _, stack, player)
local name = player:get_player_name() local name = player:get_player_name()
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
if network then if network then
if network:get_access_level(player) < access_level.interact then if network:get_access_level(player) < access_level.interact then
return 0 return 0
end end
elseif minetest.is_protected(pos, name) then elseif minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return 0 return 0
end end
if minetest.get_item_group(stack:get_name(), "microexpansion_cell") == 0 then if minetest.get_item_group(stack:get_name(), "microexpansion_cell") == 0 then
return 0 return 0
else else
return 1 return 1
end end
end, end,
on_metadata_inventory_put = function(pos, _, _, stack) on_metadata_inventory_put = function(pos, _, _, stack)
me.send_event(pos,"item_cap") me.send_event(pos,"item_cap")
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
if network == nil then if network == nil then
return return
end end
local ctrl_inv = network:get_inventory() local ctrl_inv = network:get_inventory()
local items = minetest.deserialize(stack:get_meta():get_string("items")) local items = minetest.deserialize(stack:get_meta():get_string("items"))
if items == nil then if items == nil then
print("no items") print("no items")
me.send_event(pos,"items",{net=network}) me.send_event(pos,"items",{net=network})
return return
end end
network:set_storage_space(#items) network:set_storage_space(#items)
for _,s in pairs(items) do for _,s in pairs(items) do
me.insert_item(s, ctrl_inv, "main") me.insert_item(s, ctrl_inv, "main")
end end
me.send_event(pos,"items",{net=network}) me.send_event(pos,"items",{net=network})
end, end,
allow_metadata_inventory_take = function(pos,_,_,stack, player) --args: pos, listname, index, stack, player allow_metadata_inventory_take = function(pos,_,_,stack, player) --args: pos, listname, index, stack, player
local name = player:get_player_name() local name = player:get_player_name()
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
if network then if network then
write_drive_cells(pos,network) write_drive_cells(pos,network)
if network:get_access_level(player) < access_level.interact then if network:get_access_level(player) < access_level.interact then
return 0 return 0
end end
elseif minetest.is_protected(pos, name) then elseif minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return 0 return 0
end end
return stack:get_count() return stack:get_count()
end, end,
on_metadata_inventory_take = function(pos, _, _, stack) on_metadata_inventory_take = function(pos, _, _, stack)
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
if network == nil then if network == nil then
return return
end end
me.send_event(pos,"item_cap",{net=network}) me.send_event(pos,"item_cap",{net=network})
local ctrl_inv = network:get_inventory() local ctrl_inv = network:get_inventory()
local items = minetest.deserialize(stack:get_meta():get_string("items")) local items = minetest.deserialize(stack:get_meta():get_string("items"))
if items == nil then if items == nil then
network:update() network:update()
return return
end end
for _,ostack in pairs(items) do for _,ostack in pairs(items) do
--this returns 99 (max count) even if it removes more --this returns 99 (max count) even if it removes more
ctrl_inv:remove_item("main", ostack) ctrl_inv:remove_item("main", ostack)
end end
--print(stack:to_string()) --print(stack:to_string())
network:update() network:update()
me.send_event(pos,"items",{net=network}) me.send_event(pos,"items",{net=network})
end, end,
}) })
if me.uinv_category_enabled then if me.uinv_category_enabled then
unified_inventory.add_category_item("storage", "microexpansion:drive") unified_inventory.add_category_item("storage", "microexpansion:drive")
end end

@ -4,40 +4,40 @@
if minetest.get_modpath("mcl_core") then if minetest.get_modpath("mcl_core") then
microexpansion.register_cell("cell_1k", { microexpansion.register_cell("cell_1k", {
description = "1k ME Storage Cell", description = "1k ME Storage Cell",
capacity = 1000, capacity = 1000,
recipe = { recipe = {
{ 1, { { 1, {
{"moreores:tin_ingot", "mcl_copper:copper_ingot", "moreores:tin_ingot"}, {"moreores:tin_ingot", "mcl_copper:copper_ingot", "moreores:tin_ingot"},
{"mcl_copper:copper_ingot", "microexpansion:steel_infused_obsidian_ingot", "mcl_copper:copper_ingot"}, {"mcl_copper:copper_ingot", "microexpansion:steel_infused_obsidian_ingot", "mcl_copper:copper_ingot"},
{"moreores:tin_ingot", "mcl_copper:copper_ingot", "moreores:tin_ingot"} {"moreores:tin_ingot", "mcl_copper:copper_ingot", "moreores:tin_ingot"}
}}, }},
} },
}) })
microexpansion.register_cell("cell_2k", { microexpansion.register_cell("cell_2k", {
description = "2k ME Storage Cell", description = "2k ME Storage Cell",
capacity = 2000, capacity = 2000,
recipe = { recipe = {
{ 1, { { 1, {
{"mcl_copper:copper_ingot", "mcl_core:iron_ingot", "mcl_copper:copper_ingot"}, {"mcl_copper:copper_ingot", "mcl_core:iron_ingot", "mcl_copper:copper_ingot"},
{"mcl_core:iron_ingot", "mcl_core:obsidian", "mcl_core:iron_ingot"}, {"mcl_core:iron_ingot", "mcl_core:obsidian", "mcl_core:iron_ingot"},
{"mcl_copper:copper_ingot", "mcl_core:iron_ingot", "mcl_copper:copper_ingot"} {"mcl_copper:copper_ingot", "mcl_core:iron_ingot", "mcl_copper:copper_ingot"}
}}, }},
{ 1, "shapeless", {"microexpansion:cell_1k", "microexpansion:cell_1k"}} { 1, "shapeless", {"microexpansion:cell_1k", "microexpansion:cell_1k"}}
}, },
}) })
else else
-- [drive] 8k -- [drive] 8k
microexpansion.register_cell("cell_1k", { microexpansion.register_cell("cell_1k", {
description = "1k ME Storage Cell", description = "1k ME Storage Cell",
capacity = 1000, capacity = 1000,
recipe = { recipe = {
{ 1, { { 1, {
{"default:tin_ingot", "default:copper_ingot", "default:tin_ingot"}, {"default:tin_ingot", "default:copper_ingot", "default:tin_ingot"},
{"default:copper_ingot","microexpansion:steel_infused_obsidian_ingot","default:copper_ingot"}, {"default:copper_ingot", "microexpansion:steel_infused_obsidian_ingot", "default:copper_ingot"},
{"default:tin_ingot", "default:copper_ingot", "default:tin_ingot"}, {"default:tin_ingot", "default:copper_ingot", "default:tin_ingot"},
}, },
} }
}, },
@ -45,16 +45,16 @@ microexpansion.register_cell("cell_1k", {
-- [drive] 8k -- [drive] 8k
microexpansion.register_cell("cell_2k", { microexpansion.register_cell("cell_2k", {
description = "2k ME Storage Cell", description = "2k ME Storage Cell",
capacity = 2000, capacity = 2000,
recipe = { recipe = {
{ 1, { { 1, {
{"default:copper_ingot","default:steel_ingot", "default:copper_ingot"}, {"default:copper_ingot", "default:steel_ingot", "default:copper_ingot"},
{"default:steel_ingot", "default:obsidian_shard", "default:steel_ingot"}, {"default:steel_ingot", "default:obsidian_shard", "default:steel_ingot"},
{"default:copper_ingot","default:steel_ingot", "default:copper_ingot"}, {"default:copper_ingot", "default:steel_ingot", "default:copper_ingot"},
}, },
}, },
{ 1, "shapeless", {"microexpansion:cell_1k","microexpansion:cell_1k"}} { 1, "shapeless", {"microexpansion:cell_1k", "microexpansion:cell_1k"}}
}, },
}) })
@ -62,49 +62,49 @@ end
-- [drive] 16k -- [drive] 16k
microexpansion.register_cell("cell_4k", { microexpansion.register_cell("cell_4k", {
description = "4k ME Storage Cell", description = "4k ME Storage Cell",
capacity = 4000, capacity = 4000,
recipe = { recipe = {
{ 1, "shapeless", { { 1, "shapeless", {
"microexpansion:steel_infused_obsidian_ingot", "microexpansion:machine_casing", "microexpansion:steel_infused_obsidian_ingot" "microexpansion:steel_infused_obsidian_ingot", "microexpansion:machine_casing", "microexpansion:steel_infused_obsidian_ingot"
}, },
}, },
{ 1, "shapeless", {"microexpansion:cell_2k","microexpansion:cell_2k"}} { 1, "shapeless", {"microexpansion:cell_2k", "microexpansion:cell_2k"}}
}, },
}) })
-- [drive] 16k -- [drive] 16k
microexpansion.register_cell("cell_8k", { microexpansion.register_cell("cell_8k", {
description = "8k ME Storage Cell", description = "8k ME Storage Cell",
capacity = 8000, capacity = 8000,
recipe = { recipe = {
{ 1, "shapeless", {"microexpansion:cell_4k","microexpansion:cell_4k"}} { 1, "shapeless", {"microexpansion:cell_4k", "microexpansion:cell_4k"}}
}, },
}) })
-- [drive] 32k -- [drive] 32k
microexpansion.register_cell("cell_16k", { microexpansion.register_cell("cell_16k", {
description = "16k ME Storage Cell", description = "16k ME Storage Cell",
capacity = 16000, capacity = 16000,
recipe = { recipe = {
{ 1, "shapeless", {"microexpansion:cell_8k","microexpansion:cell_8k"}} { 1, "shapeless", {"microexpansion:cell_8k", "microexpansion:cell_8k"}}
}, },
}) })
-- [drive] 32k -- [drive] 32k
microexpansion.register_cell("cell_32k", { microexpansion.register_cell("cell_32k", {
description = "32k ME Storage Cell", description = "32k ME Storage Cell",
capacity = 32000, capacity = 32000,
recipe = { recipe = {
{ 1, "shapeless", {"microexpansion:cell_16k","microexpansion:cell_16k"}} { 1, "shapeless", {"microexpansion:cell_16k", "microexpansion:cell_16k"}}
}, },
}) })
-- [drive] 64k -- [drive] 64k
microexpansion.register_cell("cell_64k", { microexpansion.register_cell("cell_64k", {
description = "64k ME Storage Cell", description = "64k ME Storage Cell",
capacity = 64000, capacity = 64000,
recipe = { recipe = {
{ 1, "shapeless", {"microexpansion:cell_32k","microexpansion:cell_32k"}} { 1, "shapeless", {"microexpansion:cell_32k", "microexpansion:cell_32k"}}
}, },
}) })

@ -6,80 +6,80 @@ local access_level = microexpansion.constants.security.access_levels
-- [me chest] Get formspec -- [me chest] Get formspec
local function chest_formspec(pos, start_id, listname, page_max, q) local function chest_formspec(pos, start_id, listname, page_max, q)
local list local list
local page_number = "" local page_number = ""
local buttons = "" local buttons = ""
local query = q or "" local query = q or ""
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if cp then if cp then
if listname and net:get_item_capacity() > 0 then if listname and net:get_item_capacity() > 0 then
local ctrlinvname = net:get_inventory_name() local ctrlinvname = net:get_inventory_name()
if listname == "main" then if listname == "main" then
list = "list[detached:"..ctrlinvname..";" list = "list[detached:"..ctrlinvname..";"
.. listname .. ";0,0.3;8,4;" .. (start_id - 1) .. "]" .. listname .. ";0,0.3;8,4;" .. (start_id - 1) .. "]"
else else
list = "list[context;" .. listname .. ";0,0.3;8,4;" .. (start_id - 1) .. "]" list = "list[context;" .. listname .. ";0,0.3;8,4;" .. (start_id - 1) .. "]"
end end
list = list .. [[ list = list .. [[
list[current_player;main;0,5.5;8,1;] list[current_player;main;0,5.5;8,1;]
list[current_player;main;0,6.73;8,3;8] list[current_player;main;0,6.73;8,3;8]
listring[detached:]]..ctrlinvname..[[;main] listring[detached:]]..ctrlinvname..[[;main]
listring[current_player;main] listring[current_player;main]
]] ]]
buttons = [[ buttons = [[
button[3.56,4.35;1.8,0.9;tochest;To Drive] button[3.56,4.35;1.8,0.9;tochest;To Drive]
tooltip[tochest;Move everything from your inventory to the ME network.] tooltip[tochest;Move everything from your inventory to the ME network.]
button[5.4,4.35;0.8,0.9;prev;<] button[5.4,4.35;0.8,0.9;prev;<]
button[7.25,4.35;0.8,0.9;next;>] button[7.25,4.35;0.8,0.9;next;>]
tooltip[prev;Previous] tooltip[prev;Previous]
tooltip[next;Next] tooltip[next;Next]
field[0.29,4.6;2.2,1;filter;;]]..query..[[] field[0.29,4.6;2.2,1;filter;;]]..query..[[]
button[2.1,4.5;0.8,0.5;search;?] button[2.1,4.5;0.8,0.5;search;?]
button[2.75,4.5;0.8,0.5;clear;X] button[2.75,4.5;0.8,0.5;clear;X]
tooltip[search;Search] tooltip[search;Search]
tooltip[clear;Reset] tooltip[clear;Reset]
]] ]]
else else
list = "label[3,2;" .. minetest.colorize("red", "No connected drives!") .. "]" list = "label[3,2;" .. minetest.colorize("red", "No connected drives!") .. "]"
end end
else else
list = "label[3,2;" .. minetest.colorize("red", "No connected network!") .. "]" list = "label[3,2;" .. minetest.colorize("red", "No connected network!") .. "]"
end end
if page_max then if page_max then
page_number = "label[6.15,4.5;" .. math.floor((start_id / 32)) + 1 .. page_number = "label[6.15,4.5;" .. math.floor((start_id / 32)) + 1 ..
"/" .. page_max .."]" "/" .. page_max .."]"
end end
return [[ return [[
size[9,9.5] size[9,9.5]
]].. ]]..
microexpansion.gui_bg .. microexpansion.gui_bg ..
microexpansion.gui_slots .. microexpansion.gui_slots ..
list .. list ..
[[ [[
label[0,-0.23;ME Terminal] label[0,-0.23;ME Terminal]
field_close_on_enter[filter;false] field_close_on_enter[filter;false]
]].. ]]..
page_number .. page_number ..
buttons buttons
end end
local function update_chest(pos,_,ev) local function update_chest(pos,_,ev)
--for now all events matter --for now all events matter
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if network == nil then if network == nil then
meta:set_int("page", 1) meta:set_int("page", 1)
meta:set_string("formspec", chest_formspec(pos, 1)) meta:set_string("formspec", chest_formspec(pos, 1))
return return
end end
local size = network:get_item_capacity() local size = network:get_item_capacity()
local page_max = me.int_to_pagenum(size) + 1 local page_max = me.int_to_pagenum(size) + 1
meta:set_string("inv_name", "main") meta:set_string("inv_name", "main")
meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max)) meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max))
end end
local term_recipe = nil local term_recipe = nil
@ -107,95 +107,95 @@ end
-- [me chest] Register node -- [me chest] Register node
microexpansion.register_node("term", { microexpansion.register_node("term", {
description = "ME Terminal", description = "ME Terminal",
usedfor = "Can interact with storage cells in ME networks", usedfor = "Can interact with storage cells in ME networks",
tiles = { tiles = {
"chest_top", "chest_top",
"chest_top", "chest_top",
"chest_side", "chest_side",
"chest_side", "chest_side",
"chest_side", "chest_side",
"chest_front", "chest_front",
}, },
recipe = term_recipe, recipe = term_recipe,
is_ground_content = false, is_ground_content = false,
groups = { cracky = 1, me_connect = 1, tubedevice = 1, tubedevice_receiver = 1 }, groups = { cracky = 1, me_connect = 1, tubedevice = 1, tubedevice_receiver = 1 },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
me_update = update_chest, me_update = update_chest,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", chest_formspec(pos, 1)) meta:set_string("formspec", chest_formspec(pos, 1))
meta:set_string("inv_name", "none") meta:set_string("inv_name", "none")
meta:set_int("page", 1) meta:set_int("page", 1)
local own_inv = meta:get_inventory() local own_inv = meta:get_inventory()
own_inv:set_size("src", 1) own_inv:set_size("src", 1)
local net = me.get_connected_network(pos) local net = me.get_connected_network(pos)
me.send_event(pos,"connect",{net=net}) me.send_event(pos,"connect",{net=net})
if net then if net then
update_chest(pos) update_chest(pos)
end end
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
if not player then if not player then
return false return false
end end
local name = player:get_player_name() local name = player:get_player_name()
if minetest.is_protected(pos, name) then if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name) minetest.record_protection_violation(pos, name)
return false return false
end end
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if not net then if not net then
return true return true
end end
return net:get_access_level(name) >= access_level.modify return net:get_access_level(name) >= access_level.modify
end, end,
after_destruct = function(pos) after_destruct = function(pos)
me.send_event(pos,"disconnect") me.send_event(pos,"disconnect")
end, end,
allow_metadata_inventory_put = function(pos, _, _, stack, player) allow_metadata_inventory_put = function(pos, _, _, stack, player)
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
if network then if network then
if network:get_access_level(player) < access_level.interact then if network:get_access_level(player) < access_level.interact then
return 0 return 0
end end
elseif minetest.is_protected(pos, player) then elseif minetest.is_protected(pos, player) then
minetest.record_protection_violation(pos, player) minetest.record_protection_violation(pos, player)
return 0 return 0
end end
return stack:get_count() return stack:get_count()
end, end,
on_metadata_inventory_put = function(pos, listname, _, stack) on_metadata_inventory_put = function(pos, listname, _, stack)
local net = me.get_connected_network(pos) local net = me.get_connected_network(pos)
local inv = net:get_inventory() local inv = net:get_inventory()
me.insert_item(stack, inv, "main") me.insert_item(stack, inv, "main")
end, end,
allow_metadata_inventory_take = function(pos,_,_,stack, player) allow_metadata_inventory_take = function(pos,_,_,stack, player)
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
if network then if network then
if network:get_access_level(player) < access_level.interact then if network:get_access_level(player) < access_level.interact then
return 0 return 0
end end
elseif minetest.is_protected(pos, player) then elseif minetest.is_protected(pos, player) then
minetest.record_protection_violation(pos, player) minetest.record_protection_violation(pos, player)
return 0 return 0
end end
return math.min(stack:get_count(),stack:get_stack_max()) return math.min(stack:get_count(),stack:get_stack_max())
end, end,
on_metadata_inventory_take = function(pos, listname, _, stack) on_metadata_inventory_take = function(pos, listname, _, stack)
local net = me.get_connected_network(pos) local net = me.get_connected_network(pos)
local inv = net:get_inventory() local inv = net:get_inventory()
inv:remove_item("main", stack) inv:remove_item("main", stack)
end, end,
tube = { tube = {
can_insert = function(pos, _, stack) --pos, node, stack, direction can_insert = function(pos, _, stack) --pos, node, stack, direction
local net = me.get_connected_network(pos) local net = me.get_connected_network(pos)
if not net then if not net then
return false return false
end end
local inv = net:get_inventory() local inv = net:get_inventory()
local max_slots = inv:get_size("main") local max_slots = inv:get_size("main")
local max_items = net.capacity_cache local max_items = net.capacity_cache
@ -216,9 +216,9 @@ microexpansion.register_node("term", {
end, end,
insert_object = function(pos, _, stack) insert_object = function(pos, _, stack)
local net = me.get_connected_network(pos) local net = me.get_connected_network(pos)
if not net then if not net then
return stack return stack
end end
local inv = net:get_inventory() local inv = net:get_inventory()
me.insert_item(stack, inv, "main") me.insert_item(stack, inv, "main")
net:set_storage_space(true) net:set_storage_space(true)
@ -235,93 +235,93 @@ microexpansion.register_node("term", {
if cp then if cp then
microexpansion.log("network and ctrl_pos","info") microexpansion.log("network and ctrl_pos","info")
else else
microexpansion.log("network but no ctrl_pos","warning") microexpansion.log("network but no ctrl_pos","warning")
end end
else else
if cp then if cp then
microexpansion.log("no network but ctrl_pos","warning") microexpansion.log("no network but ctrl_pos","warning")
else else
microexpansion.log("no network and no ctrl_pos","info") microexpansion.log("no network and no ctrl_pos","info")
end end
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local page = meta:get_int("page") local page = meta:get_int("page")
local inv_name = meta:get_string("inv_name") local inv_name = meta:get_string("inv_name")
local own_inv = meta:get_inventory() local own_inv = meta:get_inventory()
local ctrl_inv local ctrl_inv
if cp then if cp then
ctrl_inv = net:get_inventory() ctrl_inv = net:get_inventory()
else else
microexpansion.log("no network connected","warning") microexpansion.log("no network connected","warning")
return return
end end
local inv local inv
if inv_name == "main" then if inv_name == "main" then
inv = ctrl_inv inv = ctrl_inv
assert(inv,"no control inv") assert(inv,"no control inv")
else else
inv = own_inv inv = own_inv
assert(inv,"no own inv") assert(inv,"no own inv")
end end
local page_max = math.floor(inv:get_size(inv_name) / 32) + 1 local page_max = math.floor(inv:get_size(inv_name) / 32) + 1
if inv_name == "none" then if inv_name == "none" then
return return
end end
if fields.next then if fields.next then
if page + 32 > inv:get_size(inv_name) then if page + 32 > inv:get_size(inv_name) then
return return
end end
meta:set_int("page", page + 32) meta:set_int("page", page + 32)
meta:set_string("formspec", chest_formspec(pos, page + 32, inv_name, page_max)) meta:set_string("formspec", chest_formspec(pos, page + 32, inv_name, page_max))
elseif fields.prev then elseif fields.prev then
if page - 32 < 1 then if page - 32 < 1 then
return return
end end
meta:set_int("page", page - 32) meta:set_int("page", page - 32)
meta:set_string("formspec", chest_formspec(pos, page - 32, inv_name, page_max)) meta:set_string("formspec", chest_formspec(pos, page - 32, inv_name, page_max))
elseif fields.search or fields.key_enter_field == "filter" then elseif fields.search or fields.key_enter_field == "filter" then
own_inv:set_size("search", 0) own_inv:set_size("search", 0)
if fields.filter == "" then if fields.filter == "" then
meta:set_int("page", 1) meta:set_int("page", 1)
meta:set_string("inv_name", "main") meta:set_string("inv_name", "main")
meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max)) meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max))
else else
local tab = {} local tab = {}
for i = 1, ctrl_inv:get_size("main") do for i = 1, ctrl_inv:get_size("main") do
local match = ctrl_inv:get_stack("main", i):get_name():find(fields.filter) local match = ctrl_inv:get_stack("main", i):get_name():find(fields.filter)
if match then if match then
tab[#tab + 1] = ctrl_inv:get_stack("main", i) tab[#tab + 1] = ctrl_inv:get_stack("main", i)
end end
end end
own_inv:set_list("search", tab) own_inv:set_list("search", tab)
meta:set_int("page", 1) meta:set_int("page", 1)
meta:set_string("inv_name", "search") meta:set_string("inv_name", "search")
meta:set_string("formspec", chest_formspec(pos, 1, "search", page_max, fields.filter)) meta:set_string("formspec", chest_formspec(pos, 1, "search", page_max, fields.filter))
end end
elseif fields.clear then elseif fields.clear then
own_inv:set_size("search", 0) own_inv:set_size("search", 0)
meta:set_int("page", 1) meta:set_int("page", 1)
meta:set_string("inv_name", "main") meta:set_string("inv_name", "main")
meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max)) meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max))
elseif fields.tochest then elseif fields.tochest then
if net:get_access_level(sender) < access_level.interact then if net:get_access_level(sender) < access_level.interact then
return return
end end
local pinv = minetest.get_inventory({type="player", name=sender:get_player_name()}) local pinv = minetest.get_inventory({type="player", name=sender:get_player_name()})
net:set_storage_space(pinv:get_size("main")) net:set_storage_space(pinv:get_size("main"))
local space = net:get_item_capacity() local space = net:get_item_capacity()
local contents = ctrl_inv:get_list("main") or {} local contents = ctrl_inv:get_list("main") or {}
for _,s in pairs(contents) do for _,s in pairs(contents) do
if not s:is_empty() then if not s:is_empty() then
space = space - s:get_count() space = space - s:get_count()
end end
end end
microexpansion.move_inv({ inv=pinv, name="main" }, { inv=ctrl_inv, name="main",huge=true }, space) microexpansion.move_inv({ inv=pinv, name="main" }, { inv=ctrl_inv, name="main",huge=true }, space)
net:set_storage_space(true) net:set_storage_space(true)
end end
end, end,
}) })
if me.uinv_category_enabled then if me.uinv_category_enabled then
unified_inventory.add_category_item("storage", "microexpansion:term") unified_inventory.add_category_item("storage", "microexpansion:term")
end end

@ -6,98 +6,98 @@ local me = microexpansion
local power = me.power local power = me.power
if me.uinv_category_enabled and unified_inventory.registered_categories then if me.uinv_category_enabled and unified_inventory.registered_categories then
if not unified_inventory.registered_categories["storage"] then if not unified_inventory.registered_categories["storage"] then
unified_inventory.register_category("storage", { unified_inventory.register_category("storage", {
symbol = "default:chest", symbol = "default:chest",
label = "Storage" label = "Storage"
}) })
end end
end end
-- [function] Register machine -- [function] Register machine
function me.register_machine(itemstring, def) function me.register_machine(itemstring, def)
-- Set after_place_node -- Set after_place_node
local def_afterplace = def.after_place_node local def_afterplace = def.after_place_node
def.after_place_node = function(pos, player) def.after_place_node = function(pos, player)
if def_afterplace then if def_afterplace then
def_afterplace(pos, player) def_afterplace(pos, player)
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local nodes = me.network.adjacent_connected_nodes(pos) local nodes = me.network.adjacent_connected_nodes(pos)
meta:set_string("infotext", def.description.."\nNo Network") meta:set_string("infotext", def.description.."\nNo Network")
for _, pos2 in pairs(nodes) do for _, pos2 in pairs(nodes) do
local id = minetest.get_meta(pos2):get_string("network_id") local id = minetest.get_meta(pos2):get_string("network_id")
if id ~= "" then if id ~= "" then
meta:set_string("infotext", def.description.."\nNetwork ID: "..id) meta:set_string("infotext", def.description.."\nNetwork ID: "..id)
meta:set_string("network_id", id) meta:set_string("network_id", id)
end end
end end
-- Trace Network -- Trace Network
--power.trace(pos) --power.trace(pos)
-- Set demand -- Set demand
if def.demand then if def.demand then
me.network_set_demand(pos, def.demand) me.network_set_demand(pos, def.demand)
end end
if type(def.machine) == "table" then if type(def.machine) == "table" then
if power then if power then
power.add_machine(pos, def.machine) power.add_machine(pos, def.machine)
end end
end end
end end
-- Set on_destruct -- Set on_destruct
local def_destruct = def.on_destruct local def_destruct = def.on_destruct
def.on_destruct = function(pos, player) def.on_destruct = function(pos, player)
if def_destruct then if def_destruct then
def_destruct(pos, player) def_destruct(pos, player)
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if meta:get_string("network_id") ~= "" then if meta:get_string("network_id") ~= "" then
-- Set demand -- Set demand
me.network_set_demand(pos, 0) me.network_set_demand(pos, 0)
-- Remove item from network -- Remove item from network
me.network_remove(pos) me.network_remove(pos)
-- Retrace Network -- Retrace Network
--power.trace(pos) --power.trace(pos)
end end
end end
-- Set connects_to -- Set connects_to
def.connects_to = {"group:me_connect"} def.connects_to = {"group:me_connect"}
-- Set me_connect group -- Set me_connect group
def.groups = def.groups or {} def.groups = def.groups or {}
def.groups.me_connect = 1 def.groups.me_connect = 1
me.register_node(itemstring, def) me.register_node(itemstring, def)
end end
-- [function] Get machine definition -- [function] Get machine definition
function me.get_def(name, key) function me.get_def(name, key)
if type(name) == "table" then if type(name) == "table" then
local node = me.get_node(name) local node = me.get_node(name)
if node then if node then
name = node.name name = node.name
end end
end end
local def = minetest.registered_nodes[name] local def = minetest.registered_nodes[name]
-- Check name and if registered -- Check name and if registered
if not name or not def then if not name or not def then
return return
end end
if key then if key then
return def[key] return def[key]
else else
return def return def
end end
end end
microexpansion.log("Machine Registration API loaded") microexpansion.log("Machine Registration API loaded")