added EMC generator, needs texture

This commit is contained in:
unknown 2015-07-31 06:24:47 -04:00
parent 8936015a56
commit bbd003bd46
3 changed files with 57 additions and 15 deletions

@ -1,4 +1,3 @@
-- Registering Craft Items -- -- Registering Craft Items --
minetest.register_craftitem("equivalent_exchange:alchemy_bag_white", { minetest.register_craftitem("equivalent_exchange:alchemy_bag_white", {

@ -1,12 +1,16 @@
equivalent_exchange = { condenser = {
convert = function(pos) convert = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory() local inventory = meta:get_inventory()
local target = inventory:get_stack("to", 1) 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 if not inventory:room_for_item("from", target:get_name()) then return end
target = target:to_table() 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 if not target_emc then return end
local emc = meta:get_int("emc") local emc = meta:get_int("emc")
local size = inventory:get_size("from") local size = inventory:get_size("from")
@ -14,7 +18,7 @@ equivalent_exchange = {
local stack = inventory:get_stack("from", i) local stack = inventory:get_stack("from", i)
if not stack:is_empty() then if not stack:is_empty() then
stack = stack:to_table() 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 if local_emc ~= nil then
emc = emc + local_emc * stack.count emc = emc + local_emc * stack.count
inventory:set_stack("from", i, {}) inventory:set_stack("from", i, {})
@ -26,11 +30,13 @@ equivalent_exchange = {
emc = emc - timesOver * target_emc emc = emc - timesOver * target_emc
meta:set_int("emc", emc) meta:set_int("emc", emc)
inventory:add_item("from", {name=target.name, count = timesOver}) 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, end,
get_emc = function(name) get_emc = function(name)
return minetest.registered_items[name].emc return minetest.registered_items[name].emc
end, end,
get_formspec = function(emc, target) get_formspec = function(emc, target)
return "size[13,13]".. return "size[13,13]"..
"label[0,0;Energy Condenser]".. "label[0,0;Energy Condenser]"..
@ -42,7 +48,16 @@ equivalent_exchange = {
"label[10.5,0.5;Current EMC: ".. emc .."\nNeeded EMC: ".. (target - emc).."]" "label[10.5,0.5;Current EMC: ".. emc .."\nNeeded EMC: ".. (target - emc).."]"
end, 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 -- -- Registering Nodes --
minetest.register_node("equivalent_exchange:condenser", { minetest.register_node("equivalent_exchange:condenser", {
@ -61,8 +76,9 @@ minetest.register_node("equivalent_exchange:condenser", {
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(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("infotext", "Energy Condenser")
meta:set_string("emc_storable", "true")
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("to", 1) inv:set_size("to", 1)
inv:set_size("from", 13*7) inv:set_size("from", 13*7)
@ -78,11 +94,11 @@ minetest.register_node("equivalent_exchange:condenser", {
return true return true
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
equivalent_exchange.convert(pos) condenser.convert(pos)
return stack:get_count() return stack:get_count()
end, end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) 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 return count
end, end,
emc = 42,011 emc = 42,011
@ -93,8 +109,8 @@ minetest.register_node("equivalent_exchange:condenser", {
minetest.register_craft({ minetest.register_craft({
output = "equivalent_exchange:condenser", output = "equivalent_exchange:condenser",
recipe = { recipe = {
{"default:obsidian", "default:diamond", "default:obsidian"}, {"default:obsidian", "default:mese", "default:obsidian"},
{"default:diamond", "equivalent_exchange:alchemical_chest", "default:diamond"}, {"default:mese", "equivalent_exchange:alchemical_chest", "default:mese"},
{"default:obsidian", "default:diamond", "default:obsidian"} {"default:obsidian", "default:mese", "default:obsidian"}
} }
}) })

@ -1,9 +1,9 @@
emc_gather = function(orig_emc, type) emc_gather = function(orig_emc, type)
return orig_emc + (10^(type - 1)) return orig_emc + (10^(type - 1))
end, end
-- Registering ABMs -- -- Registering ABMs --
minetest.register_abm({ minetest.register_abm({
nodenames = {"equivalent_exchange:energy_collector_mk1"}, nodenames = {"equivalent_exchange:energy_collector_mk1"},
interval = 1.0, interval = 1.0,
@ -17,6 +17,33 @@ minetest.register_abm({
"label[4,0;EMC Stored: "..emc_gather(emc,1).."]".. "label[4,0;EMC Stored: "..emc_gather(emc,1).."]"..
"list[current_name;container;0,0.5;6,1;]") "list[current_name;container;0,0.5;6,1;]")
meta:set_int("emc",emc_gather(emc,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, end,
}) })