2023-11-19 01:48:35 +01:00
|
|
|
local S = minetest.get_translator()
|
|
|
|
|
|
|
|
local formspec =
|
|
|
|
"size["..(exchangeclone.mcl and 9 or 8)..",9]"..
|
2024-02-12 19:02:52 +01:00
|
|
|
"label[3,2;"..S("Star").."]"..
|
2023-11-19 01:48:35 +01:00
|
|
|
"list[context;main;4,2;1,1;]"..
|
|
|
|
exchangeclone.inventory_formspec(0,5)..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[context;main]"..
|
2023-11-20 01:01:56 +01:00
|
|
|
(exchangeclone.mcl and mcl_formspec.get_itemslot_bg(4,2,1,1) or "")
|
2021-12-30 22:45:58 +01:00
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
minetest.register_alias("exchangeclone:energy_collector", "exchangeclone:basic_collector")
|
2023-10-07 17:26:21 +02:00
|
|
|
|
|
|
|
local function check_for_furnaces(pos, set_furnace, start)
|
2023-10-06 02:19:48 +02:00
|
|
|
local found = false
|
2023-12-21 01:52:46 +01:00
|
|
|
for _, check_pos in pairs(exchangeclone.neighbors) do
|
2023-10-06 02:19:48 +02:00
|
|
|
local new_pos = vector.add(pos, check_pos)
|
|
|
|
local node = minetest.get_node(new_pos)
|
2023-10-07 17:26:21 +02:00
|
|
|
local furnace = minetest.get_item_group(node.name, "exchangeclone_furnace")
|
|
|
|
if furnace > 0 then
|
2023-10-06 02:19:48 +02:00
|
|
|
found = true
|
2023-10-07 17:26:21 +02:00
|
|
|
if start then
|
|
|
|
local timer = minetest.get_node_timer(new_pos)
|
|
|
|
if not timer:is_started() then
|
|
|
|
if furnace == 1 then -- Dark Matter
|
|
|
|
timer:start(0.45)
|
|
|
|
elseif furnace == 2 then -- Red Matter
|
|
|
|
timer:start(0.16)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-10-06 02:19:48 +02:00
|
|
|
if set_furnace ~= nil then
|
|
|
|
local meta = minetest.get_meta(new_pos)
|
|
|
|
meta:set_int("using_collector", set_furnace)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return found
|
|
|
|
end
|
|
|
|
|
2021-12-30 22:45:58 +01:00
|
|
|
local function on_timer(pos, elapsed)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2023-10-04 02:08:07 +02:00
|
|
|
|
2021-12-30 22:45:58 +01:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
|
2023-08-07 22:56:29 +02:00
|
|
|
-- get node above
|
2023-10-04 02:08:07 +02:00
|
|
|
local above = vector.add({x=0,y=1,z=0}, pos)
|
2023-09-25 19:21:04 +02:00
|
|
|
|
2024-02-12 19:02:52 +01:00
|
|
|
local using_star = true
|
2023-03-26 16:43:44 +02:00
|
|
|
if inv:is_empty("main") then
|
2024-02-12 19:02:52 +01:00
|
|
|
using_star = false
|
2021-12-30 22:45:58 +01:00
|
|
|
end
|
|
|
|
|
2023-11-21 08:54:58 +01:00
|
|
|
local light = minetest.get_natural_light(above)
|
|
|
|
|
|
|
|
if light and light >= 14 then
|
2023-10-07 17:26:21 +02:00
|
|
|
if check_for_furnaces(pos, 1, true) then
|
2024-02-14 02:12:48 +01:00
|
|
|
-- do nothing, emc is being used for the furnace.
|
2023-10-07 17:26:21 +02:00
|
|
|
return true
|
2023-10-04 02:08:07 +02:00
|
|
|
end
|
2023-09-25 19:21:04 +02:00
|
|
|
local amount = meta:get_int("collector_amount")
|
2024-02-12 19:02:52 +01:00
|
|
|
if using_star then
|
|
|
|
local max = exchangeclone.get_star_max(inv:get_stack("main", 1))
|
2024-02-13 22:51:51 +01:00
|
|
|
local stored = exchangeclone.get_star_emc(inv, "main", 1)
|
2024-02-12 19:02:52 +01:00
|
|
|
if stored + amount <= max then
|
2023-09-29 00:15:18 +02:00
|
|
|
stored = stored + amount
|
2023-10-06 02:19:48 +02:00
|
|
|
else
|
2024-02-12 19:02:52 +01:00
|
|
|
stored = math.max(stored, max)
|
2023-09-25 19:21:04 +02:00
|
|
|
end
|
2024-02-13 22:51:51 +01:00
|
|
|
exchangeclone.set_star_emc(inv, "main", 1, stored)
|
2023-09-25 19:21:04 +02:00
|
|
|
else
|
2023-10-07 17:26:21 +02:00
|
|
|
local placer = meta:get_string("exchangeclone_placer")
|
2023-09-25 19:21:04 +02:00
|
|
|
if placer and placer ~= "" then
|
2023-09-29 00:15:18 +02:00
|
|
|
local player = minetest.get_player_by_name(placer)
|
2023-09-25 19:21:04 +02:00
|
|
|
if player then
|
2024-03-04 02:46:39 +01:00
|
|
|
player:_add_emc(amount)
|
2023-09-25 19:21:04 +02:00
|
|
|
end
|
|
|
|
end
|
2023-09-25 16:41:23 +02:00
|
|
|
end
|
2023-09-29 00:15:18 +02:00
|
|
|
else
|
2023-10-06 02:19:48 +02:00
|
|
|
check_for_furnaces(pos, 0)
|
2021-12-30 22:45:58 +01:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_construct(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2023-03-26 16:43:44 +02:00
|
|
|
inv:set_size("main", 1)
|
2023-11-19 01:48:35 +01:00
|
|
|
meta:set_string("formspec", formspec)
|
2023-09-29 00:15:18 +02:00
|
|
|
minetest.get_node_timer(pos):start(1)
|
2021-12-30 22:45:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
2023-03-26 16:43:44 +02:00
|
|
|
if listname == "main" then
|
2024-02-12 19:02:52 +01:00
|
|
|
if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then
|
2021-12-30 22:45:58 +01:00
|
|
|
return stack:get_count()
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local stack = inv:get_stack(from_list, from_index)
|
|
|
|
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
function exchangeclone.register_energy_collector(itemstring, name, amount, texture, recipe, glow)
|
2023-09-25 19:21:04 +02:00
|
|
|
minetest.register_node(itemstring, {
|
2024-02-14 02:12:48 +01:00
|
|
|
description = name.."\nGenerates "..exchangeclone.format_number(amount).." EMC/second",
|
2024-03-04 00:02:22 +01:00
|
|
|
tiles = {texture},
|
2024-02-23 19:53:21 +01:00
|
|
|
groups = {
|
|
|
|
cracky = 2,
|
|
|
|
pickaxey = 1,
|
|
|
|
handy = 1,
|
|
|
|
oddly_breakable_by_hand = 2,
|
|
|
|
material_glass = 1,
|
|
|
|
energy_collector = 1,
|
|
|
|
container = 2,
|
|
|
|
tubedevice = 1,
|
2024-03-04 00:02:22 +01:00
|
|
|
tubedevice_receiver = 1,
|
2024-02-23 19:53:21 +01:00
|
|
|
},
|
|
|
|
light_source = glow,
|
|
|
|
_mcl_hardness = 1,
|
|
|
|
_mcl_blast_resistance = 1,
|
|
|
|
sounds = exchangeclone.sound_mod.node_sound_glass_defaults(),
|
2023-09-25 19:21:04 +02:00
|
|
|
is_ground_content = false,
|
2023-12-25 16:57:42 +01:00
|
|
|
can_dig = exchangeclone.can_dig,
|
2023-09-29 00:15:18 +02:00
|
|
|
on_timer = on_timer,
|
2023-09-25 19:21:04 +02:00
|
|
|
on_construct = on_construct,
|
2023-12-25 16:57:42 +01:00
|
|
|
after_dig_node = exchangeclone.drop_after_dig({"main"}),
|
2023-09-25 19:21:04 +02:00
|
|
|
on_metadata_inventory_move = function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
|
|
|
end,
|
|
|
|
on_metadata_inventory_put = function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
|
|
|
end,
|
|
|
|
on_metadata_inventory_take = function(pos)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
|
|
|
end,
|
2023-10-06 02:19:48 +02:00
|
|
|
on_destruct = function(pos, large)
|
|
|
|
check_for_furnaces(pos, 0)
|
|
|
|
end,
|
2023-09-25 19:21:04 +02:00
|
|
|
after_place_node = function(pos, player, itemstack, pointed_thing)
|
|
|
|
local player_name = player:get_player_name()
|
2023-09-29 00:15:18 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2023-09-25 19:21:04 +02:00
|
|
|
meta:set_int("collector_amount", amount)
|
2023-10-07 17:26:21 +02:00
|
|
|
meta:set_string("exchangeclone_placer", player_name)
|
2023-11-19 01:48:35 +01:00
|
|
|
meta:set_string("infotext", name.."\n"..S("Owned by ")..player_name)
|
2023-11-20 01:01:56 +01:00
|
|
|
if exchangeclone.pipeworks then
|
|
|
|
pipeworks.after_place(pos, player, itemstack, pointed_thing)
|
|
|
|
end
|
2023-09-29 00:15:18 +02:00
|
|
|
end,
|
2023-12-25 16:57:42 +01:00
|
|
|
on_blast = exchangeclone.on_blast({"main"}),
|
2023-09-25 19:21:04 +02:00
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
|
|
|
})
|
2023-10-07 17:26:21 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = itemstring,
|
2024-03-04 00:02:22 +01:00
|
|
|
type = recipe[2] or "shaped",
|
|
|
|
recipe = recipe[1]
|
2023-10-07 17:26:21 +02:00
|
|
|
})
|
2021-12-30 22:45:58 +01:00
|
|
|
|
2023-11-20 01:01:56 +01:00
|
|
|
if exchangeclone.pipeworks then
|
|
|
|
minetest.override_item(itemstring, {
|
|
|
|
tube = {
|
|
|
|
input_inventory = "main",
|
|
|
|
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1},
|
|
|
|
insert_object = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:add_item("main", stack)
|
|
|
|
end,
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2024-02-12 19:02:52 +01:00
|
|
|
if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then
|
2023-11-20 01:01:56 +01:00
|
|
|
return inv:room_for_item("main", stack)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
on_rotate = pipeworks.on_rotate,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2023-05-13 21:13:22 +02:00
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
local collectors = {
|
|
|
|
"Basic",
|
|
|
|
"Dark",
|
|
|
|
"Red",
|
|
|
|
"Magenta",
|
|
|
|
"Pink",
|
|
|
|
"Purple",
|
|
|
|
"Violet",
|
|
|
|
"Blue",
|
|
|
|
"Cyan",
|
|
|
|
"Green",
|
|
|
|
"Lime",
|
|
|
|
"Yellow",
|
|
|
|
"Orange",
|
|
|
|
"White",
|
|
|
|
}
|
2023-10-04 02:08:07 +02:00
|
|
|
|
2024-03-25 07:13:23 +01:00
|
|
|
local ingredient = exchangeclone.itemstrings.collector_ingredient
|
2023-12-18 23:57:30 +01:00
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
exchangeclone.register_energy_collector(
|
|
|
|
"exchangeclone:basic_collector",
|
|
|
|
S("Basic Collector [MK 1]"),
|
|
|
|
4,
|
|
|
|
"exchangeclone_basic_collector.png",
|
|
|
|
{{
|
|
|
|
{ingredient, exchangeclone.itemstrings.glass, ingredient},
|
|
|
|
{ingredient, "exchangeclone:aeternalis_fuel_block", ingredient},
|
2024-03-25 07:13:23 +01:00
|
|
|
{ingredient, exchangeclone.itemstrings.furnace, ingredient},
|
2023-12-18 23:57:30 +01:00
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
}},
|
|
|
|
5
|
2023-12-18 23:57:30 +01:00
|
|
|
)
|
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
minetest.register_alias("exchangeclone:energy_collector_mk1", "exchangeclone:basic_collector")
|
2023-12-18 23:57:30 +01:00
|
|
|
|
2024-03-04 00:02:22 +01:00
|
|
|
for i = 2, #collectors do
|
|
|
|
local collector = collectors[i]
|
|
|
|
local codified = collector:lower().."_collector"
|
|
|
|
local previous = "exchangeclone:"..collectors[i-1]:lower().."_collector"
|
|
|
|
exchangeclone.register_energy_collector(
|
|
|
|
"exchangeclone:"..codified,
|
2024-03-04 02:46:39 +01:00
|
|
|
S(collector.." Collector [MK"..i.."]"),
|
2024-03-04 00:02:22 +01:00
|
|
|
4*math.pow(6,i-1),
|
|
|
|
"exchangeclone_"..codified..".png",
|
|
|
|
{
|
|
|
|
{
|
|
|
|
previous,
|
|
|
|
"exchangeclone:"..collector:lower().."_matter"
|
|
|
|
},
|
|
|
|
"shapeless"
|
|
|
|
},
|
|
|
|
5+i
|
|
|
|
)
|
|
|
|
minetest.register_alias("exchangeclone:energy_collector_mk"..i, "exchangeclone:"..codified)
|
|
|
|
end
|