From bbd003bd46b5567144d7ba83fe0ef3987aba6ca8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 31 Jul 2015 06:24:47 -0400 Subject: [PATCH] added EMC generator, needs texture --- alchemy_bag.lua | 1 - condenser.lua | 40 ++++++++++++++++++++++++++++------------ energy_collector.lua | 31 +++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/alchemy_bag.lua b/alchemy_bag.lua index 1f9be94..238f346 100644 --- a/alchemy_bag.lua +++ b/alchemy_bag.lua @@ -1,4 +1,3 @@ - -- Registering Craft Items -- minetest.register_craftitem("equivalent_exchange:alchemy_bag_white", { diff --git a/condenser.lua b/condenser.lua index 8caaa36..7b07725 100644 --- a/condenser.lua +++ b/condenser.lua @@ -1,12 +1,16 @@ -equivalent_exchange = { +condenser = { convert = function(pos) local meta = minetest.get_meta(pos) local inventory = meta:get_inventory() local target = inventory:get_stack("to", 1) - if target:is_empty() then return end + local emc = meta:get_int("emc") + if target:is_empty() then + meta:set_string("formspec", condenser.get_formspec(emc, 0)) + return + end if not inventory:room_for_item("from", target:get_name()) then return end target = target:to_table() - local target_emc = equivalent_exchange.get_emc(target.name) + local target_emc = condenser.get_emc(target.name) if not target_emc then return end local emc = meta:get_int("emc") local size = inventory:get_size("from") @@ -14,7 +18,7 @@ equivalent_exchange = { local stack = inventory:get_stack("from", i) if not stack:is_empty() then stack = stack:to_table() - local local_emc = equivalent_exchange.get_emc(stack.name) + local local_emc = condenser.get_emc(stack.name) if local_emc ~= nil then emc = emc + local_emc * stack.count inventory:set_stack("from", i, {}) @@ -26,11 +30,13 @@ equivalent_exchange = { emc = emc - timesOver * target_emc meta:set_int("emc", emc) inventory:add_item("from", {name=target.name, count = timesOver}) - meta:set_string("formspec", equivalent_exchange.get_formspec(emc, target_emc)) + meta:set_string("formspec", condenser.get_formspec(emc, target_emc)) end, + get_emc = function(name) return minetest.registered_items[name].emc end, + get_formspec = function(emc, target) return "size[13,13]".. "label[0,0;Energy Condenser]".. @@ -42,7 +48,16 @@ equivalent_exchange = { "label[10.5,0.5;Current EMC: ".. emc .."\nNeeded EMC: ".. (target - emc).."]" end, } +-- Registering ABMs -- +minetest.register_abm({ + nodenames = {"equivalent_exchange:condenser"}, + interval = 1.5, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + condenser.convert(pos) + end, +}) -- Registering Nodes -- minetest.register_node("equivalent_exchange:condenser", { @@ -61,12 +76,13 @@ minetest.register_node("equivalent_exchange:condenser", { sounds = default.node_sound_stone_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", equivalent_exchange.get_formspec(0, 0)) + meta:set_string("formspec", condenser.get_formspec(0, 0)) meta:set_string("infotext", "Energy Condenser") + meta:set_string("emc_storable", "true") local inv = meta:get_inventory() inv:set_size("to", 1) inv:set_size("from", 13*7) - end, + end, can_dig = function(pos,player) local meta = minetest.get_meta(pos); local inv = meta:get_inventory() @@ -78,11 +94,11 @@ minetest.register_node("equivalent_exchange:condenser", { return true end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - equivalent_exchange.convert(pos) + condenser.convert(pos) return stack:get_count() end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - equivalent_exchange.convert(pos) + condenser.convert(pos) return count end, emc = 42,011 @@ -93,8 +109,8 @@ minetest.register_node("equivalent_exchange:condenser", { minetest.register_craft({ output = "equivalent_exchange:condenser", recipe = { - {"default:obsidian", "default:diamond", "default:obsidian"}, - {"default:diamond", "equivalent_exchange:alchemical_chest", "default:diamond"}, - {"default:obsidian", "default:diamond", "default:obsidian"} + {"default:obsidian", "default:mese", "default:obsidian"}, + {"default:mese", "equivalent_exchange:alchemical_chest", "default:mese"}, + {"default:obsidian", "default:mese", "default:obsidian"} } }) \ No newline at end of file diff --git a/energy_collector.lua b/energy_collector.lua index 4c05197..ec9cca0 100644 --- a/energy_collector.lua +++ b/energy_collector.lua @@ -1,9 +1,9 @@ - emc_gather = function(orig_emc, type) return orig_emc + (10^(type - 1)) -end, +end -- Registering ABMs -- + minetest.register_abm({ nodenames = {"equivalent_exchange:energy_collector_mk1"}, interval = 1.0, @@ -17,6 +17,33 @@ minetest.register_abm({ "label[4,0;EMC Stored: "..emc_gather(emc,1).."]".. "list[current_name;container;0,0.5;6,1;]") meta:set_int("emc",emc_gather(emc,1)) + local newemc = (emc_gather(emc,1)) + local surrounding_nodes = { + minetest.get_meta({x = pos.x + 1, y = pos.y, z = pos.z}), + minetest.get_meta({x = pos.x - 1, y = pos.y, z = pos.z}), + minetest.get_meta({x = pos.x, y = pos.y + 1, z = pos.z}), + minetest.get_meta({x = pos.x, y = pos.y - 1, z = pos.z}), + minetest.get_meta({x = pos.x, y = pos.y, z = pos.z + 1}), + minetest.get_meta({x = pos.x, y = pos.y, z = pos.z - 1}) + } + local emc_transferable_nodes = {} + local emc_transferable_nodes_length = 0 + for i = 1,6 do + if surrounding_nodes[i]:get_string("emc_storable") == "true" then + table.insert(emc_transferable_nodes,surrounding_nodes[i]) + emc_transferable_nodes_length = emc_transferable_nodes_length + 1 + end + end + local distribution = math.floor(newemc / emc_transferable_nodes_length) + for j = 1,emc_transferable_nodes_length do + meta:set_string("formspec", + "size[6,1.5]".. + "label[0,0;Energy Collector Mark 1]".. + "label[4,0;EMC Stored: "..(newemc - distribution).."]".. + "list[current_name;container;0,0.5;6,1;]") + meta:set_int("emc",(newemc - distribution)) + emc_transferable_nodes[j]:set_int("emc", (emc_transferable_nodes[j]:get_int("emc") + distribution)) + end end, })