2023-05-13 21:13:22 +02:00
|
|
|
local function get_energy_collector_formspec()
|
2023-06-10 22:55:47 +02:00
|
|
|
local formspec
|
2023-09-29 01:23:49 +02:00
|
|
|
if not exchangeclone.mcl then
|
2023-06-10 22:55:47 +02:00
|
|
|
formspec = {
|
2023-03-26 00:03:03 +01:00
|
|
|
"size[8,9]",
|
|
|
|
"label[3,2;Orb]",
|
2023-03-26 16:43:44 +02:00
|
|
|
"list[context;main;4,2;1,1;]",
|
2023-03-26 00:03:03 +01:00
|
|
|
"list[current_player;main;0,5;8,4;]",
|
2023-03-27 01:14:32 +02:00
|
|
|
"listring[current_player;main]",
|
|
|
|
"listring[context;main]"
|
2023-03-26 00:03:03 +01:00
|
|
|
}
|
|
|
|
else
|
2023-06-10 22:55:47 +02:00
|
|
|
formspec = {
|
2023-03-26 01:49:22 +01:00
|
|
|
"size[9,10]",
|
2023-03-26 00:03:03 +01:00
|
|
|
"label[3,2;Orb]",
|
2023-03-26 16:43:44 +02:00
|
|
|
"list[context;main;4,2;1,1;]",
|
2023-03-26 00:03:03 +01:00
|
|
|
mcl_formspec.get_itemslot_bg(4,2,1,1),
|
|
|
|
"list[current_player;main;0,5;9,3;9]",
|
|
|
|
mcl_formspec.get_itemslot_bg(0,5,9,3),
|
2023-03-26 00:12:29 +01:00
|
|
|
"list[current_player;main;0,8.5;9,1;]",
|
|
|
|
mcl_formspec.get_itemslot_bg(0,8.5,9,1),
|
2023-03-26 00:03:03 +01:00
|
|
|
"listring[current_player;main]",
|
2023-03-26 16:43:44 +02:00
|
|
|
"listring[context;main]"
|
2023-03-26 00:03:03 +01:00
|
|
|
}
|
|
|
|
end
|
2023-06-10 22:55:47 +02:00
|
|
|
return table.concat(formspec, "")
|
2021-12-30 22:45:58 +01:00
|
|
|
end
|
|
|
|
|
2023-10-07 17:26:21 +02:00
|
|
|
minetest.register_alias("exchangeclone:energy_collector", "exchangeclone:energy_collector_mk1")
|
|
|
|
|
|
|
|
-- Register LBM to update deconstructors
|
|
|
|
minetest.register_lbm({
|
|
|
|
name = "exchangeclone:collector_alert",
|
|
|
|
nodenames = {"exchangeclone:energy_collector_mk1"},
|
|
|
|
run_at_every_load = false,
|
|
|
|
action = function(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", "size[3,1]label[0,0;Break and replace.\nNothing will be lost.]")
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2023-10-06 02:19:48 +02:00
|
|
|
local check_positions = {
|
|
|
|
{x=0,y=0,z=1},
|
|
|
|
{x=0,y=0,z=-1},
|
|
|
|
{x=0,y=1,z=0},
|
|
|
|
{x=0,y=-1,z=0},
|
|
|
|
{x=1,y=0, z=0},
|
|
|
|
{x=-1,y=0,z=0},
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
for _, check_pos in ipairs(check_positions) do
|
|
|
|
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 can_dig(pos, player)
|
2023-09-29 01:23:49 +02:00
|
|
|
if exchangeclone.mcl then return true end
|
2021-12-30 22:45:58 +01:00
|
|
|
local meta = minetest.get_meta(pos);
|
|
|
|
local inv = meta:get_inventory()
|
2023-03-26 16:43:44 +02:00
|
|
|
return inv:is_empty("main")
|
2021-12-30 22:45:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
local using_orb = true
|
2023-03-26 16:43:44 +02:00
|
|
|
if inv:is_empty("main") then
|
2023-09-25 19:21:04 +02:00
|
|
|
using_orb = false
|
2021-12-30 22:45:58 +01:00
|
|
|
end
|
|
|
|
|
2023-10-04 02:08:07 +02:00
|
|
|
if minetest.get_natural_light(above) >= 14 then
|
2023-10-07 17:26:21 +02:00
|
|
|
if check_for_furnaces(pos, 1, true) then
|
2023-10-04 02:08:07 +02:00
|
|
|
-- do nothing, energy 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")
|
|
|
|
if using_orb then
|
|
|
|
local stored = exchangeclone.get_orb_energy(inv, "main", 1)
|
2023-10-06 02:19:48 +02:00
|
|
|
if stored + amount <= exchangeclone.orb_max then
|
2023-09-29 00:15:18 +02:00
|
|
|
stored = stored + amount
|
2023-10-06 02:19:48 +02:00
|
|
|
else
|
|
|
|
stored = math.max(stored, exchangeclone.orb_max)
|
2023-09-25 19:21:04 +02:00
|
|
|
end
|
2023-10-06 02:19:48 +02:00
|
|
|
exchangeclone.set_orb_energy(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
|
|
|
|
local player_energy = exchangeclone.get_player_energy(player)
|
2023-09-29 00:15:18 +02:00
|
|
|
exchangeclone.set_player_energy(player, player_energy + 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)
|
2021-12-30 22:45:58 +01:00
|
|
|
meta:set_string("formspec", get_energy_collector_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
|
2023-03-25 18:27:13 +01:00
|
|
|
if stack:get_name() == "exchangeclone:exchange_orb" 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
|
|
|
|
|
|
|
|
local function on_blast(pos)
|
|
|
|
local drops = {}
|
2023-05-13 21:13:22 +02:00
|
|
|
exchangeclone.get_inventory_drops(pos, "main", drops)
|
2023-03-25 18:27:13 +01:00
|
|
|
drops[#drops+1] = "exchangeclone:energy_collector"
|
2021-12-30 22:45:58 +01:00
|
|
|
minetest.remove_node(pos)
|
2023-10-04 02:08:07 +02:00
|
|
|
|
2021-12-30 22:45:58 +01:00
|
|
|
return drops
|
|
|
|
end
|
|
|
|
|
2023-06-21 23:45:22 +02:00
|
|
|
local function on_dig_node(pos, oldnode, oldmetadata, player)
|
2023-09-29 01:23:49 +02:00
|
|
|
if exchangeclone.mcl then
|
2023-05-13 21:13:22 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local meta2 = meta:to_table()
|
|
|
|
meta:from_table(oldmetadata)
|
|
|
|
local inv = meta:get_inventory()
|
2023-10-07 17:26:21 +02:00
|
|
|
local stack = inv:get_stack("main", 1)
|
|
|
|
if not stack:is_empty() then
|
|
|
|
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
|
|
|
minetest.add_item(p, stack)
|
2023-05-13 21:13:22 +02:00
|
|
|
end
|
|
|
|
meta:from_table(meta2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-09-29 00:15:18 +02:00
|
|
|
function exchangeclone.register_energy_collector(itemstring, name, amount, modifier, recipe)
|
2023-09-25 19:21:04 +02:00
|
|
|
minetest.register_node(itemstring, {
|
2023-10-04 02:08:07 +02:00
|
|
|
description = name,
|
2023-09-25 19:21:04 +02:00
|
|
|
tiles = {
|
|
|
|
"exchangeclone_energy_collector_up.png"..modifier,
|
|
|
|
"exchangeclone_energy_collector_down.png"..modifier,
|
|
|
|
"exchangeclone_energy_collector_right.png"..modifier,
|
|
|
|
"exchangeclone_energy_collector_right.png"..modifier,
|
|
|
|
"exchangeclone_energy_collector_right.png"..modifier,
|
|
|
|
"exchangeclone_energy_collector_right.png"..modifier
|
|
|
|
},
|
2023-10-04 02:08:07 +02:00
|
|
|
groups = {cracky = 2, container = 2, pickaxey = 2, energy_collector = amount},
|
2023-09-25 19:21:04 +02:00
|
|
|
_mcl_hardness = 3,
|
|
|
|
_mcl_blast_resistance = 6,
|
|
|
|
sounds = exchangeclone.sound_mod.node_sound_metal_defaults(),
|
|
|
|
is_ground_content = false,
|
|
|
|
can_dig = 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,
|
|
|
|
after_dig_node = on_dig_node,
|
|
|
|
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-09-25 19:21:04 +02:00
|
|
|
meta:set_string("infotext", name.."\nOwned by"..player_name)
|
2023-09-29 00:15:18 +02:00
|
|
|
end,
|
2023-09-25 19:21:04 +02:00
|
|
|
on_blast = on_blast,
|
|
|
|
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,
|
|
|
|
recipe = recipe
|
|
|
|
})
|
2023-09-25 19:21:04 +02:00
|
|
|
end
|
2021-12-30 22:45:58 +01:00
|
|
|
|
2023-05-13 21:13:22 +02:00
|
|
|
--[[if minetest.get_modpath("pipeworks") then
|
|
|
|
minetest.override_item("exchangeclone:energy_collector", {
|
|
|
|
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()
|
|
|
|
if stack:get_name() == "exchangeclone:exchange_orb" then
|
|
|
|
minetest.log(inv:room_for_item("main", stack))
|
|
|
|
return inv:room_for_item("main", stack)
|
|
|
|
else
|
|
|
|
minetest.log("failed")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
2023-06-21 23:45:22 +02:00
|
|
|
after_place_node = function(pos, player)
|
2023-05-13 21:13:22 +02:00
|
|
|
pipeworks.after_place(pos)
|
|
|
|
end,
|
|
|
|
after_dig_node = pipeworks.after_dig,
|
|
|
|
on_rotate = pipeworks.on_rotate,
|
|
|
|
})
|
|
|
|
end]]
|
|
|
|
|
2023-10-04 02:08:07 +02:00
|
|
|
local iron = "default:steelblock"
|
|
|
|
local glass = "default:glass"
|
|
|
|
local chest = "default:chest"
|
2023-03-25 18:27:13 +01:00
|
|
|
|
2023-09-29 01:23:49 +02:00
|
|
|
if exchangeclone.mcl then
|
2023-10-04 02:08:07 +02:00
|
|
|
iron = "mcl_core:ironblock"
|
|
|
|
glass = "mcl_core:glass"
|
|
|
|
chest = "mcl_chests:chest"
|
2023-03-25 18:27:13 +01:00
|
|
|
end
|
|
|
|
|
2023-10-07 17:26:21 +02:00
|
|
|
exchangeclone.register_energy_collector("exchangeclone:energy_collector_mk1", "Energy Collector MK1", 4, "", {
|
2023-10-04 02:08:07 +02:00
|
|
|
{glass, glass, glass},
|
|
|
|
{"exchangeclone:exchange_orb", chest, "exchangeclone:exchange_orb"},
|
|
|
|
{iron, iron, iron}
|
|
|
|
}
|
2023-10-07 17:26:21 +02:00
|
|
|
)
|
2023-10-04 02:08:07 +02:00
|
|
|
|
|
|
|
exchangeclone.register_energy_collector("exchangeclone:energy_collector_mk2", "Energy Collector MK2", 12, "^[multiply:#555555", {
|
|
|
|
{iron, iron, iron},
|
2023-10-07 17:26:21 +02:00
|
|
|
{"exchangeclone:energy_collector_mk1", "exchangeclone:energy_collector_mk1", "exchangeclone:energy_collector_mk1"},
|
2023-10-04 02:08:07 +02:00
|
|
|
{iron, iron, iron}
|
2021-12-30 22:45:58 +01:00
|
|
|
}
|
2023-10-07 17:26:21 +02:00
|
|
|
)
|
2023-10-04 02:08:07 +02:00
|
|
|
|
|
|
|
exchangeclone.register_energy_collector("exchangeclone:energy_collector_mk3", "Energy Collector MK3", 40, "^[multiply:#770000", {
|
|
|
|
{iron, iron, iron},
|
|
|
|
{"exchangeclone:energy_collector_mk2", "exchangeclone:energy_collector_mk2", "exchangeclone:energy_collector_mk2"},
|
|
|
|
{iron, iron, iron}
|
|
|
|
}
|
2023-10-07 17:26:21 +02:00
|
|
|
)
|
2023-10-04 02:08:07 +02:00
|
|
|
|
2023-10-06 02:19:48 +02:00
|
|
|
exchangeclone.register_energy_collector("exchangeclone:energy_collector_mk4", "Energy Collector MK4", 160, "^[multiply:#007700", {
|
2023-10-04 02:08:07 +02:00
|
|
|
{iron, iron, iron},
|
|
|
|
{"exchangeclone:energy_collector_mk3", "exchangeclone:energy_collector_mk3", "exchangeclone:energy_collector_mk3"},
|
|
|
|
{iron, iron, iron}
|
|
|
|
}
|
2023-10-07 17:26:21 +02:00
|
|
|
)
|
2023-10-04 02:08:07 +02:00
|
|
|
|
2023-10-06 02:19:48 +02:00
|
|
|
exchangeclone.register_energy_collector("exchangeclone:energy_collector_mk5", "Energy Collector MK5", 640, "^[multiply:#000077", {
|
2023-10-04 02:08:07 +02:00
|
|
|
{iron, iron, iron},
|
|
|
|
{"exchangeclone:energy_collector_mk4", "exchangeclone:energy_collector_mk4", "exchangeclone:energy_collector_mk4"},
|
|
|
|
{iron, iron, iron}
|
|
|
|
}
|
2023-10-07 17:26:21 +02:00
|
|
|
)
|