2023-10-06 02:19:48 +02:00
|
|
|
local function get_deconstructor_formspec()
|
2023-09-29 01:23:49 +02:00
|
|
|
if not exchangeclone.mcl then
|
2023-03-25 23:37:15 +01:00
|
|
|
local formspec = {
|
2023-03-25 18:58:08 +01:00
|
|
|
"size[8,9]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"label[2,1;Items]",
|
|
|
|
"list[context;src;2,2;1,1;]",
|
2023-03-25 18:58:08 +01:00
|
|
|
"label[5,1;Orb]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"list[context;fuel;5,2;1,1;]",
|
2023-03-25 23:37:15 +01:00
|
|
|
"list[current_player;main;0,5;8,4;]",
|
2023-03-27 01:30:29 +02:00
|
|
|
"listring[current_player;main]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"listring[context;src]",
|
2023-03-26 01:49:22 +01:00
|
|
|
"listring[current_player;main]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"listring[context;fuel]",
|
2023-03-25 23:37:15 +01:00
|
|
|
}
|
|
|
|
return table.concat(formspec, "")
|
2023-03-25 18:58:08 +01:00
|
|
|
else
|
2023-03-25 23:37:15 +01:00
|
|
|
local formspec = {
|
2023-03-26 00:12:29 +01:00
|
|
|
"size[9,10]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"label[2,1;Items]",
|
|
|
|
"list[context;src;2,2;1,1;]",
|
2023-03-25 23:37:15 +01:00
|
|
|
mcl_formspec.get_itemslot_bg(2,2,1,1),
|
|
|
|
"label[5,1;Orb]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"list[context;fuel;5,2;1,1;]",
|
2023-03-25 23:37:15 +01:00
|
|
|
mcl_formspec.get_itemslot_bg(5,2,1,1),
|
2023-03-26 00:03:03 +01:00
|
|
|
"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-27 01:30:29 +02:00
|
|
|
"listring[current_player;main]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"listring[context;src]",
|
2023-03-26 01:49:22 +01:00
|
|
|
"listring[current_player;main]",
|
2023-10-06 02:19:48 +02:00
|
|
|
"listring[context;fuel]"
|
2023-03-25 23:37:15 +01:00
|
|
|
}
|
|
|
|
return table.concat(formspec, "")
|
2023-03-25 18:58:08 +01:00
|
|
|
end
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
|
2023-10-07 17:26:21 +02:00
|
|
|
minetest.register_alias("exchangeclone:element_deconstructor", "exchangeclone:deconstructor")
|
|
|
|
|
2023-10-06 02:19:48 +02:00
|
|
|
-- Register LBM to update deconstructors
|
|
|
|
minetest.register_lbm({
|
|
|
|
name = "exchangeclone:deconstructor_alert",
|
|
|
|
nodenames = {"exchangeclone:deconstructor"},
|
2023-10-07 17:26:21 +02:00
|
|
|
run_at_every_load = false,
|
2023-10-06 02:19:48 +02:00
|
|
|
action = function(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2023-10-07 17:26:21 +02:00
|
|
|
meta:set_string("formspec", "size[3,1]label[0,0;Break and replace.\nNothing will be lost.]")
|
2023-10-06 02:19:48 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2021-08-25 18:01:36 +02:00
|
|
|
local function can_dig(pos, player)
|
2023-09-29 01:23:49 +02:00
|
|
|
if exchangeclone.mcl then return true end
|
2021-08-25 18:40:33 +02:00
|
|
|
local meta = minetest.get_meta(pos);
|
|
|
|
local inv = meta:get_inventory()
|
2023-10-06 02:19:48 +02:00
|
|
|
return inv:is_empty("src") and inv:is_empty("fuel") and inv:is_empty("main")
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
|
2023-10-06 02:19:48 +02:00
|
|
|
local function deconstructor_action(pos)
|
2023-10-07 17:26:21 +02:00
|
|
|
local limit = exchangeclone.orb_max
|
|
|
|
local using_orb = true
|
|
|
|
local player
|
2021-08-25 18:01:36 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2023-10-07 17:26:21 +02:00
|
|
|
if inv:get_stack("fuel", 1):get_name() ~= "exchangeclone:exchange_orb" then
|
|
|
|
limit = 2147483647
|
|
|
|
using_orb = false
|
|
|
|
player = minetest.get_player_by_name(meta:get_string("exchangeclone_placer"))
|
|
|
|
if not (player and player ~= "") then return end
|
|
|
|
end
|
2023-10-06 02:19:48 +02:00
|
|
|
local stack = inv:get_stack("src", 1)
|
|
|
|
local individual_energy_value = exchangeclone.get_item_energy(stack:get_name())
|
|
|
|
if individual_energy_value <= 0 then return end
|
|
|
|
local wear = stack:get_wear()
|
|
|
|
if wear and wear > 1 then
|
|
|
|
individual_energy_value = math.floor(individual_energy_value * (65536 / wear))
|
|
|
|
end
|
|
|
|
if stack:get_name() == "exchangeclone:exchange_orb" then
|
|
|
|
individual_energy_value = individual_energy_value + exchangeclone.get_orb_itemstack_energy(stack)
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
2023-10-07 17:26:21 +02:00
|
|
|
local current_energy
|
|
|
|
if using_orb then
|
|
|
|
current_energy = exchangeclone.get_orb_energy(inv, "fuel", 1)
|
|
|
|
else
|
|
|
|
current_energy = exchangeclone.get_player_energy(player)
|
|
|
|
end
|
|
|
|
local max_count = math.floor((limit - current_energy)/individual_energy_value)
|
2023-10-06 02:19:48 +02:00
|
|
|
local add_count = math.min(max_count, stack:get_count())
|
|
|
|
local energy_value = individual_energy_value * add_count
|
2023-10-07 17:26:21 +02:00
|
|
|
local result = current_energy + energy_value
|
|
|
|
if result < 0 or result > limit then return end
|
|
|
|
if using_orb then
|
|
|
|
exchangeclone.set_orb_energy(inv, "fuel", 1, result)
|
|
|
|
else
|
|
|
|
exchangeclone.set_player_energy(player, result)
|
|
|
|
end
|
2023-10-06 02:19:48 +02:00
|
|
|
stack:set_count(stack:get_count() - add_count)
|
|
|
|
if stack:get_count() == 0 then stack = ItemStack("") end
|
|
|
|
inv:set_stack("src", 1, stack)
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_construct(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2023-10-06 02:19:48 +02:00
|
|
|
inv:set_size("src", 1)
|
|
|
|
inv:set_size("fuel", 1)
|
|
|
|
meta:set_string("formspec", get_deconstructor_formspec())
|
|
|
|
meta:set_string("infotext", "Deconstructor")
|
|
|
|
deconstructor_action(pos, 0)
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
2023-10-06 02:19:48 +02:00
|
|
|
|
2021-08-25 18:40:33 +02:00
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
2023-10-06 02:19:48 +02:00
|
|
|
if listname == "fuel" then
|
2023-03-25 18:27:13 +01:00
|
|
|
if stack:get_name() == "exchangeclone:exchange_orb" then
|
2021-08-25 18:01:36 +02:00
|
|
|
return stack:get_count()
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
2023-10-06 02:19:48 +02:00
|
|
|
elseif listname == "src" then
|
2021-08-25 18:01:36 +02:00
|
|
|
return stack:get_count()
|
2023-10-06 02:19:48 +02:00
|
|
|
else
|
|
|
|
return 0
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
2021-08-25 18:40:33 +02:00
|
|
|
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)
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
2021-08-25 18:40:33 +02:00
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
2021-08-25 18:01:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_blast(pos)
|
|
|
|
local drops = {}
|
2023-10-06 02:19:48 +02:00
|
|
|
exchangeclone.get_inventory_drops(pos, "src", drops)
|
|
|
|
exchangeclone.get_inventory_drops(pos, "fuel", drops)
|
|
|
|
drops[#drops+1] = "exchangeclone:deconstructor"
|
2021-08-25 18:01:36 +02:00
|
|
|
minetest.remove_node(pos)
|
|
|
|
return drops
|
|
|
|
end
|
|
|
|
|
2023-10-06 02:19:48 +02:00
|
|
|
minetest.register_node("exchangeclone:deconstructor", {
|
|
|
|
description = "Deconstructor",
|
2021-12-30 18:51:45 +01:00
|
|
|
tiles = {
|
2023-05-23 16:53:45 +02:00
|
|
|
"exchangeclone_deconstructor_up.png",
|
|
|
|
"exchangeclone_deconstructor_down.png",
|
|
|
|
"exchangeclone_deconstructor_right.png",
|
|
|
|
"exchangeclone_deconstructor_right.png",
|
|
|
|
"exchangeclone_deconstructor_right.png",
|
|
|
|
"exchangeclone_deconstructor_right.png"
|
2021-12-30 18:51:45 +01:00
|
|
|
},
|
2023-10-06 02:19:48 +02:00
|
|
|
groups = {cracky = 2, container = 4, pickaxey = 2},
|
2023-05-26 18:55:55 +02:00
|
|
|
_mcl_hardness = 3,
|
|
|
|
_mcl_blast_resistance = 6,
|
2023-09-25 16:41:23 +02:00
|
|
|
sounds = exchangeclone.sound_mod.node_sound_metal_defaults(),
|
2021-08-25 18:40:33 +02:00
|
|
|
is_ground_content = false,
|
2023-03-27 01:30:29 +02:00
|
|
|
can_dig = can_dig,
|
2023-06-21 23:45:22 +02:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, player)
|
2023-09-29 01:23:49 +02:00
|
|
|
if exchangeclone.mcl then
|
2023-03-27 00:44:47 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local meta2 = meta:to_table()
|
|
|
|
meta:from_table(oldmetadata)
|
|
|
|
local inv = meta:get_inventory()
|
2023-10-06 02:19:48 +02:00
|
|
|
for _, listname in ipairs({"src", "fuel"}) do
|
2023-03-27 00:44:47 +02:00
|
|
|
local stack = inv:get_stack(listname, 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)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
meta:from_table(meta2)
|
|
|
|
end
|
2023-03-27 00:19:19 +02:00
|
|
|
end,
|
2023-10-07 17:26:21 +02:00
|
|
|
after_place_node = function(pos, player, itemstack, pointed_thing)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("exchangeclone_placer", player:get_player_name())
|
|
|
|
end,
|
2023-10-06 02:19:48 +02:00
|
|
|
on_timer = deconstructor_action,
|
2021-08-25 18:40:33 +02:00
|
|
|
on_construct = on_construct,
|
2023-10-06 02:19:48 +02:00
|
|
|
on_metadata_inventory_move = deconstructor_action,
|
|
|
|
on_metadata_inventory_put = deconstructor_action,
|
2023-10-07 17:26:21 +02:00
|
|
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
|
|
if listname == "fuel" then return end
|
|
|
|
deconstructor_action(pos)
|
|
|
|
end,
|
2021-08-25 18:01:36 +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,
|
|
|
|
})
|
2021-08-26 16:10:40 +02:00
|
|
|
|
2023-03-25 18:27:13 +01:00
|
|
|
local recipe_ingredient = "default:furnace"
|
|
|
|
|
2023-09-29 01:23:49 +02:00
|
|
|
if exchangeclone.mcl then
|
2023-03-25 18:27:13 +01:00
|
|
|
recipe_ingredient = "mcl_furnaces:furnace"
|
|
|
|
end
|
|
|
|
|
2021-08-26 16:10:40 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
type = "shaped",
|
2023-10-06 02:19:48 +02:00
|
|
|
output = "exchangeclone:deconstructor",
|
2021-08-26 16:10:40 +02:00
|
|
|
recipe = {
|
2023-03-25 18:27:13 +01:00
|
|
|
{"", "exchangeclone:exchange_orb",""},
|
2023-05-24 17:08:10 +02:00
|
|
|
{"", recipe_ingredient, ""},
|
2023-03-25 18:27:13 +01:00
|
|
|
{"", "exchangeclone:exchange_orb", ""}
|
2021-08-26 16:10:40 +02:00
|
|
|
}
|
2023-10-06 02:19:48 +02:00
|
|
|
})
|