cleaned up energy collector, fixed last commit

This commit is contained in:
unknown 2015-08-02 10:57:34 -04:00
parent d852645950
commit d57f817a0c
11 changed files with 69 additions and 218 deletions

@ -25,17 +25,17 @@ condenser = {
emc = emc + local_emc * stack.count emc = emc + local_emc * stack.count
inventory:set_stack("from", i, {}) inventory:set_stack("from", i, {})
end end
--print(dump(stack))
end end
end end
local timesOver = math.floor(emc / target_emc) local generate_amount = math.floor(emc / target_emc)
emc = emc - timesOver * target_emc local times_over = math.floor(generate_amount / 99)
emc = emc - generate_amount * target_emc
meta:set_int("emc", emc) meta:set_int("emc", emc)
for i = 1, timesOver do for i = 1, times_over do
inventory:add_item("from", {name = target.name, count = 99}) inventory:add_item("from", {name = target.name, count = 99})
end end
if timesOver % 99 > 0 then if generate_amount % 99 > 0 then
inventory:add_item("from", {name = target.name, count = timesOver % 99}) inventory:add_item("from", {name = target.name, count = generate_amount % 99})
end end
meta:set_string("formspec", condenser.get_formspec(emc, target_emc)) meta:set_string("formspec", condenser.get_formspec(emc, target_emc))
end, end,

@ -25,36 +25,35 @@ collector = {
end end
if emc_transferable_nodes_length == 0 then if emc_transferable_nodes_length == 0 then
local generate_amount = math.floor(emc / 10) local generate_amount = math.floor(emc / 10)
local timesOver = math.floor(generate_amount / 99) local times_over = math.floor(generate_amount / 99)
local inventory = meta:get_inventory() local inventory = meta:get_inventory()
local size = inventory:get_size("container") local size = inventory:get_size("container")
if emc >= 10 then if emc >= 10 then
meta:set_int("emc", emc - 10*generate_amount) meta:set_int("emc", emc - 10*generate_amount)
if mark == 4 then if mark == 4 then
meta:set_string("formspec", meta:set_string("formspec",
"size[8,7.5]".. "size[8,7.4]"..
"label[0,0;Antimatter Collector]".. "label[0,0;Antimatter Collector]"..
"label[4,0;EMC Stored: "..emc - 10*generate_amount.."]".. "label[4,0;EMC Stored: "..emc - 10*generate_amount.."]"..
"list[current_name;container;0,0.5;8,7;]") "list[current_name;container;0,0.5;8,7;]")
else else
meta:set_string("formspec", meta:set_string("formspec",
"size[8,7.5]".. "size[8,7.4]"..
"label[0,0;Energy Collector Mark "..mark.."]".. "label[0,0;Energy Collector Mark "..mark.."]"..
"label[4,0;EMC Stored: "..emc - 10*generate_amount.."]".. "label[4,0;EMC Stored: "..emc - 10*generate_amount.."]"..
"list[current_name;container;0,0.5;8,7;]") "list[current_name;container;0,0.5;8,7;]")
end end
for i = 1, timesOver do for i = 1, times_over do
inventory:add_item("container", {name = modname.."klein_star", count = 99}) inventory:add_item("container", {name = modname.."klein_star", count = 99})
end end
if timesOver % 99 > 0 then if generate_amount % 99 > 0 then
inventory:add_item("container", {name = modname.."klein_star", count = timesOver % 99}) inventory:add_item("container", {name = modname.."klein_star", count = generate_amount % 99})
end end
end end
end end
local newemc = (collector.emc_gather(emc, mark, multiplier)) local newemc = (collector.emc_gather(emc, mark, multiplier))
local distribution = math.floor(newemc / emc_transferable_nodes_length) local distribution = math.floor(newemc / emc_transferable_nodes_length)
for j = 1,emc_transferable_nodes_length do for j = 1,emc_transferable_nodes_length do
print(mark)
if mark == 4 then if mark == 4 then
meta:set_string("formspec", meta:set_string("formspec",
"size[8,7.5]".. "size[8,7.5]"..
@ -81,91 +80,43 @@ collector = {
end, end,
} }
local register_name = {"mk1","mk2","mk3","antimatter_collector"}
local item_name = {"Energy Collector Mark 1","Energy Collector Mark 2","Energy Collector Mark 3", "Antimatter Collector"}
for i = 1,4 do
-- Registering ABMs -- -- Registering ABMs --
minetest.register_abm({ minetest["register_abm"]({
nodenames = {modname.."mk1"}, nodenames = {modname..register_name[i]},
interval = 1.0, interval = 1.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local emc = meta:get_int("emc") local emc = meta:get_int("emc")
local multiplier = collector.check_multiplier(pos) local multiplier = collector.check_multiplier(pos)
local emc_per = collector.emc_gather(emc,i,multiplier)
meta:set_string("formspec", meta:set_string("formspec",
"size[8,7.5]".. "size[8,7.4]"..
"label[0,0;Energy Collector Mark 1]".. "label[0,0;"..item_name[i].."]"..
"label[4,0;EMC Stored: "..collector.emc_gather(emc,1,multiplier).."]".. "label[4,0;EMC Stored: "..emc_per.."]"..
"list[current_name;container;0,0.5;8,7;]") "list[current_name;container;0,0.5;8,7;]")
meta:set_int("emc",collector.emc_gather(emc,1,multiplier)) meta:set_int("emc", emc_per)
collector.emc_transfer(1,pos,multiplier) collector.emc_transfer(i,pos,multiplier)
end, end,
}) })
minetest.register_abm({
nodenames = {modname.."mk2"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local emc = meta:get_int("emc")
local multiplier = collector.check_multiplier(pos)
meta:set_string("formspec",
"size[8,7.5]"..
"label[0,0;Energy Collector Mark 2]"..
"label[4,0;EMC Stored: "..collector.emc_gather(emc,2,multiplier).."]"..
"list[current_name;container;0,0.5;8,7;]")
meta:set_int("emc",collector.emc_gather(emc,2,multiplier))
collector.emc_transfer(2,pos,multiplier)
end,
})
minetest.register_abm({
nodenames = {modname.."mk3"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local emc = meta:get_int("emc")
local multiplier = collector.check_multiplier(pos)
meta:set_string("formspec",
"size[8,7.5]"..
"label[0,0;Energy Collector Mark 3]"..
"label[4,0;EMC Stored: "..collector.emc_gather(emc,3,multiplier).."]"..
"list[current_name;container;0,0.5;8,7;]")
meta:set_int("emc",collector.emc_gather(emc,3,multiplier))
collector.emc_transfer(3,pos,multiplier)
end,
})
minetest.register_abm({
nodenames = {modname.."antimatter_collector"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local emc = meta:get_int("emc")
local multiplier = collector.check_multiplier(pos)
meta:set_string("formspec",
"size[8,7.5]"..
"label[0,0;Antimatter Collector]"..
"label[4,0;EMC Stored: "..collector.emc_gather(emc,4,multiplier).."]"..
"list[current_name;container;0,0.5;8,7;]")
meta:set_int("emc",collector.emc_gather(emc,4,multiplier))
collector.emc_transfer(4,pos,multiplier)
end,
})
-- Registering Nodes -- -- Registering Nodes --
minetest.register_node(modname.."mk1", { minetest["register_node"](":"..modname..register_name[i], {
description = "Energy Collector Mark 1", description = item_name[i],
tiles = { tiles = {
"ee_energy_collectors_energy_collector_mk1_top.png", "ee_energy_collectors_"..register_name[i].."_top.png",
"ee_energy_collectors_energy_collector_mk1_bottom.png", "ee_energy_collectors_"..register_name[i].."_bottom.png",
"ee_energy_collectors_energy_collector_mk1_side.png", "ee_energy_collectors_"..register_name[i].."_side.png",
"ee_energy_collectors_energy_collector_mk1_side.png", "ee_energy_collectors_"..register_name[i].."_side.png",
"ee_energy_collectors_energy_collector_mk1_side.png", "ee_energy_collectors_"..register_name[i].."_side.png",
"ee_energy_collectors_energy_collector_mk1_side.png", "ee_energy_collectors_"..register_name[i].."_side.png",
}, },
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky = 2}, groups = {cracky = 2},
@ -174,124 +125,24 @@ minetest.register_node(modname.."mk1", {
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[8,7.5]".. "size[8,7.4]"..
"label[0,0;Energy Collector Mark 1]".. "label[0,0;"..item_name[i].."]"..
"label[4,0;EMC Stored: 0]".. "label[4,0;EMC Stored: 0]"..
"list[current_name;container;0,0.5;8,7;]") "list[current_name;container;0,0.5;8,7;]")
meta:set_string("infotext", "Energy Collector Mark 1") meta:set_string("infotext", item_name[i])
meta:set_int("emc", 0) meta:set_int("emc", 0)
local inv = meta:get_inventory() local inventory = meta:get_inventory()
inv:set_size("container", 8*7) inventory:set_size("container", 8*7)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("container") return inv:is_empty("container")
end, end,
emc = 529605 --emc = emc[i]
}) })
minetest.register_node(modname.."mk2", { end
description = "Energy Collector Mark 2",
tiles = {
"ee_energy_collectors_energy_collector_mk2_top.png",
"ee_energy_collectors_energy_collector_mk2_bottom.png",
"ee_energy_collectors_energy_collector_mk2_side.png",
"ee_energy_collectors_energy_collector_mk2_side.png",
"ee_energy_collectors_energy_collector_mk2_side.png",
"ee_energy_collectors_energy_collector_mk2_side.png",
},
paramtype2 = "facedir",
groups = {cracky = 2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,7.5]"..
"label[0,0;Energy Collector Mark 2]"..
"label[4,0;EMC Stored: 0]"..
"list[current_name;container;0,0.5;8,7;]")
meta:set_string("infotext", "Energy Collector Mark 2")
meta:set_int("emc", 0)
local inv = meta:get_inventory()
inv:set_size("container", 8*7)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("container")
end,
emc = 529605
})
minetest.register_node(modname.."mk3", {
description = "Energy Collector Mark 3",
tiles = {
"ee_energy_collectors_energy_collector_mk3_top.png",
"ee_energy_collectors_energy_collector_mk3_bottom.png",
"ee_energy_collectors_energy_collector_mk3_side.png",
"ee_energy_collectors_energy_collector_mk3_side.png",
"ee_energy_collectors_energy_collector_mk3_side.png",
"ee_energy_collectors_energy_collector_mk3_side.png",
},
paramtype2 = "facedir",
groups = {cracky = 2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,7.5]"..
"label[0,0;Energy Collector Mark 3]"..
"label[4,0;EMC Stored: 0]"..
"list[current_name;container;0,0.5;8,7;]")
meta:set_string("infotext", "Energy Collector Mark 3")
meta:set_int("emc", 0)
local inv = meta:get_inventory()
inv:set_size("container", 8*7)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("container")
end,
emc = 529605
})
minetest.register_node(modname.."antimatter_collector", {
description = "Antimatter Collector",
tiles = {
"ee_energy_collectors_antimatter_collector_top.png",
"ee_energy_collectors_antimatter_collector_bottom.png",
"ee_energy_collectors_antimatter_collector_side.png",
"ee_energy_collectors_antimatter_collector_side.png",
"ee_energy_collectors_antimatter_collector_side.png",
"ee_energy_collectors_antimatter_collector_side.png",
},
paramtype2 = "facedir",
groups = {cracky = 2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,7.5]"..
"label[0,0;Antimatter Collector]"..
"label[4,0;EMC Stored: 0]"..
"list[current_name;container;0,0.5;8,7;]")
meta:set_string("infotext", "Antimatter Collector")
meta:set_int("emc", 0)
local inv = meta:get_inventory()
inv:set_size("container", 8*7)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("container")
end,
emc = 269554885
})
minetest.register_node(modname.."interdiction_stone", { minetest.register_node(modname.."interdiction_stone", {
description = "Interdiction Stone", description = "Interdiction Stone",