mirror of
https://github.com/ZNixian/equivalent_exchange.git
synced 2024-12-25 22:52:23 +01:00
added EMC generator, needs texture
This commit is contained in:
parent
8936015a56
commit
bbd003bd46
@ -1,4 +1,3 @@
|
||||
|
||||
-- Registering Craft Items --
|
||||
|
||||
minetest.register_craftitem("equivalent_exchange:alchemy_bag_white", {
|
||||
|
@ -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"}
|
||||
}
|
||||
})
|
@ -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,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user