2013-07-17 21:34:35 +02:00
|
|
|
|
2017-03-28 20:04:04 +02:00
|
|
|
local digilines_path = minetest.get_modpath("digilines")
|
|
|
|
|
2013-10-30 18:45:32 +01:00
|
|
|
local S = technic.getter
|
2017-04-11 13:48:46 +02:00
|
|
|
local tube_entry = "^pipeworks_tube_connection_metallic.png"
|
2017-04-13 00:50:50 +02:00
|
|
|
local cable_entry = "^technic_cable_connection_overlay.png"
|
2013-07-17 21:34:35 +02:00
|
|
|
|
2017-04-11 09:37:42 +02:00
|
|
|
local fs_helpers = pipeworks.fs_helpers
|
|
|
|
|
2013-11-27 22:17:19 +01:00
|
|
|
technic.register_power_tool("technic:battery", 10000)
|
2013-12-04 03:52:27 +01:00
|
|
|
technic.register_power_tool("technic:red_energy_crystal", 50000)
|
|
|
|
technic.register_power_tool("technic:green_energy_crystal", 150000)
|
|
|
|
technic.register_power_tool("technic:blue_energy_crystal", 450000)
|
2013-11-27 22:17:19 +01:00
|
|
|
|
2017-06-05 16:56:51 +02:00
|
|
|
-- Battery recipes:
|
|
|
|
-- Tin-copper recipe:
|
2013-11-27 22:17:19 +01:00
|
|
|
minetest.register_craft({
|
2017-06-05 16:56:51 +02:00
|
|
|
output = "technic:battery",
|
2013-11-27 22:17:19 +01:00
|
|
|
recipe = {
|
2023-12-27 18:11:42 +01:00
|
|
|
{"group:wood", technic.compat.copper_ingredient, "group:wood"},
|
2018-07-21 19:11:12 +02:00
|
|
|
{"group:wood", "default:tin_ingot", "group:wood"},
|
2023-12-27 18:11:42 +01:00
|
|
|
{"group:wood", technic.compat.copper_ingredient, "group:wood"},
|
2017-06-05 16:56:51 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
-- Sulfur-lead-water recipes:
|
|
|
|
-- With sulfur lumps:
|
|
|
|
-- With water:
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "technic:battery",
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "technic:sulfur_lump", "group:wood"},
|
|
|
|
{"technic:lead_ingot", "bucket:bucket_water", "technic:lead_ingot"},
|
|
|
|
{"group:wood", "technic:sulfur_lump", "group:wood"},
|
|
|
|
},
|
|
|
|
replacements = {
|
|
|
|
{"bucket:bucket_water", "bucket:bucket_empty"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
-- With oil extract:
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "technic:battery",
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "technic:sulfur_lump", "group:wood"},
|
|
|
|
{"technic:lead_ingot", "homedecor:oil_extract", "technic:lead_ingot"},
|
|
|
|
{"group:wood", "technic:sulfur_lump", "group:wood"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
-- With sulfur dust:
|
|
|
|
-- With water:
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "technic:battery",
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "technic:sulfur_dust", "group:wood"},
|
|
|
|
{"technic:lead_ingot", "bucket:bucket_water", "technic:lead_ingot"},
|
|
|
|
{"group:wood", "technic:sulfur_dust", "group:wood"},
|
|
|
|
},
|
|
|
|
replacements = {
|
|
|
|
{"bucket:bucket_water", "bucket:bucket_empty"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
-- With oil extract:
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "technic:battery",
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "technic:sulfur_dust", "group:wood"},
|
|
|
|
{"technic:lead_ingot", "homedecor:oil_extract", "technic:lead_ingot"},
|
|
|
|
{"group:wood", "technic:sulfur_dust", "group:wood"},
|
2013-11-27 22:17:19 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_tool("technic:battery", {
|
|
|
|
description = S("RE Battery"),
|
|
|
|
inventory_image = "technic_battery.png",
|
Genericise handling of multiple meanings of wear
The tool workshop is meant to repair mechanical damage to tools, so
is at risk of `repairing' tools that use the wear bar to represent
something other than mechanical wear. It had special-case recognition
of the water and lava cans, which use the wear bar to represent how much
content they're carrying, and wouldn't repair them. But it didn't avoid
`repairing' RE chargeable items, which use the wear bar to represent
how much energy they have stored. It would modify the wear bar without
actually affecting the charge, so the wear bar would jump back to the
correct place when the next charging or discharging event occurred.
To genericise, introduce a new item property, "wear_represents", which
indicates how the wear bar is used for this item. Currently defined
values are "mechanical_wear" (straightforward damage to tools that
start out perfect), "technic_RE_charge" (electrical energy, canonically
represented in the meta rather than the wear bar), and "content_level"
(how full a container is). For backcompat, nil is interpreted as
"mechanical_wear". The tool workshop will only repair "mechanical_wear"
tools. As a bonus, set_RE_wear() will only set the wear bar for
"technic_RE_charge" items: this means developers will notice if they
forget to declare wear_represents, but also means that with no further
changes it's possible to have an RE chargeable item that uses its wear
bar to represent something else.
2014-04-28 11:44:07 +02:00
|
|
|
wear_represents = "technic_RE_charge",
|
2014-04-30 11:49:54 +02:00
|
|
|
on_refill = technic.refill_RE_charge,
|
2013-11-27 22:17:19 +01:00
|
|
|
tool_capabilities = {
|
|
|
|
charge = 0,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
fleshy = {times={}, uses=10000, maxlevel=0}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-04-14 10:29:56 +02:00
|
|
|
-- x+2 + (z+2)*2
|
|
|
|
local dirtab = {
|
|
|
|
[4] = 2,
|
|
|
|
[5] = 3,
|
|
|
|
[7] = 1,
|
|
|
|
[8] = 0
|
|
|
|
}
|
|
|
|
|
2014-05-23 19:51:23 +02:00
|
|
|
local tube = {
|
|
|
|
insert_object = function(pos, node, stack, direction)
|
2017-04-14 10:29:56 +02:00
|
|
|
print(minetest.pos_to_string(direction), dirtab[direction.x+2+(direction.z+2)*2], node.param2)
|
|
|
|
if direction.y == 1
|
|
|
|
or (direction.y == 0 and dirtab[direction.x+2+(direction.z+2)*2] == node.param2) then
|
2014-05-23 19:51:23 +02:00
|
|
|
return stack
|
|
|
|
end
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2017-04-14 10:29:56 +02:00
|
|
|
if direction.y == 0 then
|
2014-05-23 19:51:23 +02:00
|
|
|
return inv:add_item("src", stack)
|
|
|
|
else
|
|
|
|
return inv:add_item("dst", stack)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
2017-04-14 10:29:56 +02:00
|
|
|
print(minetest.pos_to_string(direction), dirtab[direction.x+2+(direction.z+2)*2], node.param2)
|
|
|
|
if direction.y == 1
|
|
|
|
or (direction.y == 0 and dirtab[direction.x+2+(direction.z+2)*2] == node.param2) then
|
2014-05-23 19:51:23 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2017-04-14 10:29:56 +02:00
|
|
|
if direction.y == 0 then
|
2017-04-11 09:37:42 +02:00
|
|
|
if meta:get_int("split_src_stacks") == 1 then
|
|
|
|
stack = stack:peek_item(1)
|
|
|
|
end
|
|
|
|
return inv:room_for_item("src", stack)
|
2014-05-23 19:51:23 +02:00
|
|
|
else
|
2017-04-11 09:37:42 +02:00
|
|
|
if meta:get_int("split_dst_stacks") == 1 then
|
|
|
|
stack = stack:peek_item(1)
|
|
|
|
end
|
|
|
|
return inv:room_for_item("dst", stack)
|
2014-05-23 19:51:23 +02:00
|
|
|
end
|
|
|
|
end,
|
2017-04-14 10:29:56 +02:00
|
|
|
connect_sides = {left=1, right=1, back=1, top=1},
|
2014-05-23 19:51:23 +02:00
|
|
|
}
|
2013-11-27 22:17:19 +01:00
|
|
|
|
2017-04-11 09:37:42 +02:00
|
|
|
local function add_on_off_buttons(meta, ltier, charge_percent)
|
2019-01-26 14:14:45 +01:00
|
|
|
local formspec = "image[1,1;1,2;technic_power_meter_bg.png"
|
2017-04-11 09:37:42 +02:00
|
|
|
.."^[lowpart:"..charge_percent
|
2019-01-26 14:14:45 +01:00
|
|
|
..":technic_power_meter_fg.png]"
|
|
|
|
if ltier == "mv" or ltier == "hv" then
|
|
|
|
formspec = formspec..
|
2017-04-11 09:37:42 +02:00
|
|
|
fs_helpers.cycling_button(
|
|
|
|
meta,
|
|
|
|
"image_button[3,2.0;1,0.6",
|
|
|
|
"split_src_stacks",
|
|
|
|
{
|
2017-04-12 01:16:50 +02:00
|
|
|
pipeworks.button_off,
|
|
|
|
pipeworks.button_on
|
2017-04-11 09:37:42 +02:00
|
|
|
}
|
|
|
|
).."label[3.9,2.01;Allow splitting incoming 'charge' stacks from tubes]"..
|
|
|
|
fs_helpers.cycling_button(
|
|
|
|
meta,
|
|
|
|
"image_button[3,2.5;1,0.6",
|
|
|
|
"split_dst_stacks",
|
|
|
|
{
|
2017-04-12 01:16:50 +02:00
|
|
|
pipeworks.button_off,
|
|
|
|
pipeworks.button_on
|
2017-04-11 09:37:42 +02:00
|
|
|
}
|
|
|
|
).."label[3.9,2.51;Allow splitting incoming 'discharge' stacks]"
|
|
|
|
end
|
|
|
|
return formspec
|
|
|
|
end
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
function technic.register_battery_box(data)
|
|
|
|
local tier = data.tier
|
|
|
|
local ltier = string.lower(tier)
|
|
|
|
|
2013-11-26 22:53:52 +01:00
|
|
|
local formspec =
|
2017-03-28 20:04:04 +02:00
|
|
|
"size[8,9]"..
|
2013-10-30 18:45:32 +01:00
|
|
|
"image[1,1;1,2;technic_power_meter_bg.png]"..
|
2017-03-28 20:04:04 +02:00
|
|
|
"list[context;src;3,1;1,1;]"..
|
2013-10-30 18:45:32 +01:00
|
|
|
"image[4,1;1,1;technic_battery_reload.png]"..
|
2017-03-28 20:04:04 +02:00
|
|
|
"list[context;dst;5,1;1,1;]"..
|
2013-10-30 18:45:32 +01:00
|
|
|
"label[0,0;"..S("%s Battery Box"):format(tier).."]"..
|
|
|
|
"label[3,0;"..S("Charge").."]"..
|
|
|
|
"label[5,0;"..S("Discharge").."]"..
|
|
|
|
"label[1,3;"..S("Power level").."]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"list[current_player;main;0,5;8,4;]"..
|
2017-03-28 20:04:04 +02:00
|
|
|
"listring[context;dst]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"listring[current_player;main]"..
|
2017-03-28 20:04:04 +02:00
|
|
|
"listring[context;src]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"listring[current_player;main]"
|
2017-04-11 09:37:42 +02:00
|
|
|
|
2017-03-28 20:04:04 +02:00
|
|
|
if digilines_path then
|
|
|
|
formspec = formspec.."button[0.6,3.7;2,1;edit_channel;edit Channel]"
|
|
|
|
end
|
2015-06-18 04:09:27 +02:00
|
|
|
|
2014-05-23 19:51:23 +02:00
|
|
|
if data.upgrade then
|
|
|
|
formspec = formspec..
|
2017-03-28 20:04:04 +02:00
|
|
|
"list[context;upgrade1;3.5,3;1,1;]"..
|
|
|
|
"list[context;upgrade2;4.5,3;1,1;]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"label[3.5,4;"..S("Upgrade Slots").."]"..
|
2017-03-28 20:04:04 +02:00
|
|
|
"listring[context;upgrade1]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"listring[current_player;main]"..
|
2017-03-28 20:04:04 +02:00
|
|
|
"listring[context;upgrade2]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"listring[current_player;main]"
|
2014-05-23 19:51:23 +02:00
|
|
|
end
|
2013-10-30 18:45:32 +01:00
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
local run = function(pos, node)
|
2022-10-29 21:36:48 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2022-11-24 21:49:20 +01:00
|
|
|
local network_id = tonumber(meta:get_string(tier.."_network"))
|
2017-04-13 02:21:20 +02:00
|
|
|
|
2022-10-29 21:36:48 +02:00
|
|
|
if not technic.networks[network_id] then
|
2017-04-13 02:21:20 +02:00
|
|
|
meta:set_string("infotext", S("%s Battery Box Has No Network"):format(tier))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
local eu_input = meta:get_int(tier.."_EU_input")
|
|
|
|
local current_charge = meta:get_int("internal_EU_charge")
|
|
|
|
|
|
|
|
local EU_upgrade, tube_upgrade = 0, 0
|
|
|
|
if data.upgrade then
|
|
|
|
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
|
|
|
|
end
|
|
|
|
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
|
2017-03-28 20:04:04 +02:00
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
-- Charge/discharge the battery with the input EUs
|
|
|
|
if eu_input >= 0 then
|
|
|
|
current_charge = math.min(current_charge + eu_input, max_charge)
|
|
|
|
else
|
|
|
|
current_charge = math.max(current_charge + eu_input, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Charging/discharging tools here
|
|
|
|
local tool_full, tool_empty
|
|
|
|
current_charge, tool_full = technic.charge_tools(meta,
|
|
|
|
current_charge, data.charge_step)
|
|
|
|
current_charge, tool_empty = technic.discharge_tools(meta,
|
|
|
|
current_charge, data.discharge_step,
|
|
|
|
max_charge)
|
2017-03-28 20:04:04 +02:00
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
if data.tube then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
technic.handle_machine_pipeworks(pos, tube_upgrade,
|
|
|
|
function(pos, x_velocity, z_velocity)
|
|
|
|
if tool_full and not inv:is_empty("src") then
|
|
|
|
technic.send_items(pos, x_velocity, z_velocity, "src")
|
|
|
|
elseif tool_empty and not inv:is_empty("dst") then
|
|
|
|
technic.send_items(pos, x_velocity, z_velocity, "dst")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- We allow batteries to charge on less than the demand
|
|
|
|
meta:set_int(tier.."_EU_demand",
|
|
|
|
math.min(data.charge_rate, max_charge - current_charge))
|
|
|
|
meta:set_int(tier.."_EU_supply",
|
|
|
|
math.min(data.discharge_rate, current_charge))
|
|
|
|
meta:set_int("internal_EU_charge", current_charge)
|
|
|
|
|
|
|
|
-- Select node textures
|
|
|
|
local charge_count = math.ceil((current_charge / max_charge) * 8)
|
|
|
|
charge_count = math.min(charge_count, 8)
|
|
|
|
charge_count = math.max(charge_count, 0)
|
|
|
|
local last_count = meta:get_float("last_side_shown")
|
|
|
|
if charge_count ~= last_count then
|
|
|
|
technic.swap_node(pos,"technic:"..ltier.."_battery_box"..charge_count)
|
|
|
|
meta:set_float("last_side_shown", charge_count)
|
|
|
|
end
|
|
|
|
|
|
|
|
local charge_percent = math.floor(current_charge / max_charge * 100)
|
2017-04-11 09:37:42 +02:00
|
|
|
meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, charge_percent))
|
2018-07-16 17:26:39 +02:00
|
|
|
local infotext = S("@1 Battery Box: @2 / @3", tier,
|
|
|
|
technic.EU_string(current_charge),
|
|
|
|
technic.EU_string(max_charge))
|
2014-07-11 11:00:46 +02:00
|
|
|
if eu_input == 0 then
|
|
|
|
infotext = S("%s Idle"):format(infotext)
|
|
|
|
end
|
|
|
|
meta:set_string("infotext", infotext)
|
|
|
|
end
|
2017-03-28 20:04:04 +02:00
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
for i = 0, 8 do
|
2016-03-20 02:34:56 +01:00
|
|
|
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
|
|
|
|
technic_machine=1, ["technic_"..ltier]=1}
|
2013-07-17 21:34:35 +02:00
|
|
|
if i ~= 0 then
|
|
|
|
groups.not_in_creative_inventory = 1
|
|
|
|
end
|
2017-03-28 20:04:04 +02:00
|
|
|
|
2014-05-23 19:51:23 +02:00
|
|
|
if data.tube then
|
|
|
|
groups.tubedevice = 1
|
|
|
|
groups.tubedevice_receiver = 1
|
|
|
|
end
|
2017-03-28 20:04:04 +02:00
|
|
|
|
2017-04-13 02:29:22 +02:00
|
|
|
local top_tex = "technic_"..ltier.."_battery_box_top.png"..tube_entry
|
2017-04-13 00:50:50 +02:00
|
|
|
local front_tex = "technic_"..ltier.."_battery_box_front.png^technic_power_meter"..i..".png"
|
2017-04-13 02:29:22 +02:00
|
|
|
local side_tex = "technic_"..ltier.."_battery_box_side.png"..tube_entry
|
2017-04-14 10:29:56 +02:00
|
|
|
local bottom_tex = "technic_"..ltier.."_battery_box_bottom.png"..cable_entry
|
2017-04-13 00:50:50 +02:00
|
|
|
|
2017-04-11 13:48:46 +02:00
|
|
|
if ltier == "lv" then
|
2017-04-13 02:29:22 +02:00
|
|
|
top_tex = "technic_"..ltier.."_battery_box_top.png"
|
2017-04-13 00:50:50 +02:00
|
|
|
front_tex = "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"
|
2017-04-13 02:29:22 +02:00
|
|
|
side_tex = "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"
|
2017-04-11 13:48:46 +02:00
|
|
|
end
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
minetest.register_node("technic:"..ltier.."_battery_box"..i, {
|
2013-10-30 18:45:32 +01:00
|
|
|
description = S("%s Battery Box"):format(tier),
|
2017-03-28 20:04:04 +02:00
|
|
|
tiles = {
|
2017-04-13 02:29:22 +02:00
|
|
|
top_tex,
|
|
|
|
bottom_tex,
|
|
|
|
side_tex,
|
|
|
|
side_tex,
|
|
|
|
side_tex,
|
2017-04-13 00:50:50 +02:00
|
|
|
front_tex},
|
2013-07-17 21:34:35 +02:00
|
|
|
groups = groups,
|
2016-03-20 02:34:56 +01:00
|
|
|
connect_sides = {"bottom"},
|
2014-05-23 19:51:23 +02:00
|
|
|
tube = data.tube and tube or nil,
|
|
|
|
paramtype2 = "facedir",
|
2023-12-27 18:11:42 +01:00
|
|
|
sounds = technic.compat.wood_sounds,
|
2013-07-17 21:34:35 +02:00
|
|
|
drop = "technic:"..ltier.."_battery_box0",
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2022-06-06 21:04:13 +02:00
|
|
|
local EU_upgrade, _ = 0
|
2017-04-11 09:37:42 +02:00
|
|
|
if data.upgrade then
|
2022-06-06 21:04:13 +02:00
|
|
|
EU_upgrade, _ = technic.handle_machine_upgrades(meta)
|
2017-04-11 09:37:42 +02:00
|
|
|
end
|
|
|
|
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
|
|
|
|
local charge = meta:get_int("internal_EU_charge")
|
|
|
|
local cpercent = math.floor(charge / max_charge * 100)
|
2013-07-17 21:34:35 +02:00
|
|
|
local inv = meta:get_inventory()
|
2013-11-26 22:53:52 +01:00
|
|
|
meta:set_string("infotext", S("%s Battery Box"):format(tier))
|
2017-04-11 09:37:42 +02:00
|
|
|
meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, cpercent))
|
2017-03-28 20:04:04 +02:00
|
|
|
meta:set_string("channel", ltier.."_battery_box"..minetest.pos_to_string(pos))
|
2013-11-26 22:53:52 +01:00
|
|
|
meta:set_int(tier.."_EU_demand", 0)
|
|
|
|
meta:set_int(tier.."_EU_supply", 0)
|
|
|
|
meta:set_int(tier.."_EU_input", 0)
|
2013-07-17 21:34:35 +02:00
|
|
|
meta:set_float("internal_EU_charge", 0)
|
|
|
|
inv:set_size("src", 1)
|
|
|
|
inv:set_size("dst", 1)
|
2014-05-23 19:51:23 +02:00
|
|
|
inv:set_size("upgrade1", 1)
|
|
|
|
inv:set_size("upgrade2", 1)
|
2013-07-17 21:34:35 +02:00
|
|
|
end,
|
2013-11-27 18:28:56 +01:00
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2014-07-11 11:00:46 +02:00
|
|
|
technic_run = run,
|
2017-04-14 10:29:56 +02:00
|
|
|
on_rotate = screwdriver.rotate_simple,
|
2015-03-08 02:45:57 +01:00
|
|
|
after_place_node = data.tube and pipeworks.after_place,
|
2017-03-28 20:04:04 +02:00
|
|
|
after_dig_node = technic.machine_after_dig_node,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
2017-04-11 13:45:31 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2017-04-11 09:37:42 +02:00
|
|
|
if fields.edit_channel then
|
|
|
|
minetest.show_formspec(sender:get_player_name(),
|
2017-03-28 20:04:04 +02:00
|
|
|
"technic:battery_box_edit_channel"..minetest.pos_to_string(pos),
|
|
|
|
"field[channel;Digiline Channel;"..meta:get_string("channel").."]")
|
2017-04-11 09:37:42 +02:00
|
|
|
elseif fields["fs_helpers_cycling:0:split_src_stacks"]
|
|
|
|
or fields["fs_helpers_cycling:0:split_dst_stacks"]
|
|
|
|
or fields["fs_helpers_cycling:1:split_src_stacks"]
|
|
|
|
or fields["fs_helpers_cycling:1:split_dst_stacks"] then
|
2020-06-12 20:39:00 +02:00
|
|
|
meta = minetest.get_meta(pos)
|
2017-04-11 09:37:42 +02:00
|
|
|
if not pipeworks.may_configure(pos, sender) then return end
|
|
|
|
fs_helpers.on_receive_fields(pos, fields)
|
2022-06-06 21:04:13 +02:00
|
|
|
local EU_upgrade, _ = 0
|
2017-04-11 09:37:42 +02:00
|
|
|
if data.upgrade then
|
2022-06-06 21:04:13 +02:00
|
|
|
EU_upgrade, _ = technic.handle_machine_upgrades(meta)
|
2017-04-11 09:37:42 +02:00
|
|
|
end
|
|
|
|
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
|
|
|
|
local charge = meta:get_int("internal_EU_charge")
|
|
|
|
local cpercent = math.floor(charge / max_charge * 100)
|
|
|
|
meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, cpercent))
|
|
|
|
end
|
2017-03-28 20:04:04 +02:00
|
|
|
end,
|
|
|
|
digiline = {
|
|
|
|
receptor = {action = function() end},
|
|
|
|
effector = {
|
|
|
|
action = function(pos, node, channel, msg)
|
|
|
|
if msg ~= "GET" and msg ~= "get" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if channel ~= meta:get_string("channel") then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
digilines.receptor_send(pos, digilines.rules.default, channel, {
|
|
|
|
demand = meta:get_int(tier.."_EU_demand"),
|
|
|
|
supply = meta:get_int(tier.."_EU_supply"),
|
|
|
|
input = meta:get_int(tier.."_EU_input"),
|
|
|
|
charge = meta:get_int("internal_EU_charge"),
|
|
|
|
max_charge = data.max_charge * (1 + technic.handle_machine_upgrades(meta) / 10),
|
|
|
|
src = inv:get_stack("src", 1):to_table(),
|
|
|
|
dst = inv:get_stack("dst", 1):to_table(),
|
|
|
|
upgrade1 = inv:get_stack("upgrade1", 1):to_table(),
|
|
|
|
upgrade2 = inv:get_stack("upgrade2", 1):to_table()
|
|
|
|
})
|
|
|
|
end
|
|
|
|
},
|
|
|
|
},
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Register as a battery type
|
|
|
|
-- Battery type machines function as power reservoirs and can both receive and give back power
|
|
|
|
for i = 0, 8 do
|
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_battery_box"..i, technic.battery)
|
|
|
|
end
|
|
|
|
|
|
|
|
end -- End registration
|
|
|
|
|
2017-03-28 20:04:04 +02:00
|
|
|
minetest.register_on_player_receive_fields(
|
|
|
|
function(player, formname, fields)
|
|
|
|
if formname:sub(1, 32) ~= "technic:battery_box_edit_channel" or
|
|
|
|
not fields.channel then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pos = minetest.string_to_pos(formname:sub(33))
|
|
|
|
local plname = player:get_player_name()
|
|
|
|
if minetest.is_protected(pos, plname) then
|
|
|
|
minetest.record_protection_violation(pos, plname)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("channel", fields.channel)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2022-06-06 18:53:50 +02:00
|
|
|
local function default_get_charge(itemstack)
|
|
|
|
-- check if is chargable
|
|
|
|
local tool_name = itemstack:get_name()
|
|
|
|
if not technic.power_tools[tool_name] then
|
|
|
|
return 0, 0
|
|
|
|
end
|
|
|
|
-- Set meta data for the tool if it didn't do it itself
|
|
|
|
local item_meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
|
|
|
if not item_meta.charge then
|
|
|
|
item_meta.charge = 0
|
|
|
|
end
|
|
|
|
return item_meta.charge, technic.power_tools[tool_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
local function default_set_charge(itemstack, charge)
|
|
|
|
local tool_name = itemstack:get_name()
|
|
|
|
if technic.power_tools[tool_name] then
|
|
|
|
technic.set_RE_wear(itemstack, charge, technic.power_tools[tool_name])
|
|
|
|
end
|
|
|
|
local item_meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
|
|
|
item_meta.charge = charge
|
|
|
|
itemstack:set_metadata(minetest.serialize(item_meta))
|
|
|
|
end
|
|
|
|
|
2013-10-19 04:22:39 +02:00
|
|
|
function technic.charge_tools(meta, batt_charge, charge_step)
|
2013-07-17 21:34:35 +02:00
|
|
|
local inv = meta:get_inventory()
|
2013-10-19 04:22:39 +02:00
|
|
|
if inv:is_empty("src") then
|
2014-05-23 19:51:23 +02:00
|
|
|
return batt_charge, false
|
2013-10-19 04:22:39 +02:00
|
|
|
end
|
2014-12-15 23:47:07 +01:00
|
|
|
local src_stack = inv:get_stack("src", 1)
|
2013-10-19 04:22:39 +02:00
|
|
|
|
2022-06-06 18:53:50 +02:00
|
|
|
-- get callbacks
|
|
|
|
local src_def = src_stack:get_definition()
|
|
|
|
local technic_get_charge = src_def.technic_get_charge or default_get_charge
|
|
|
|
local technic_set_charge = src_def.technic_set_charge or default_set_charge
|
|
|
|
|
|
|
|
-- get tool charge
|
|
|
|
local tool_charge, item_max_charge = technic_get_charge(src_stack)
|
|
|
|
if item_max_charge==0 then
|
2014-05-23 19:51:23 +02:00
|
|
|
return batt_charge, false
|
2013-10-19 04:22:39 +02:00
|
|
|
end
|
2022-06-06 18:53:50 +02:00
|
|
|
|
2013-10-19 04:22:39 +02:00
|
|
|
-- Do the charging
|
2014-05-23 19:51:23 +02:00
|
|
|
if tool_charge >= item_max_charge then
|
|
|
|
return batt_charge, true
|
|
|
|
elseif batt_charge <= 0 then
|
|
|
|
return batt_charge, false
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
2013-10-19 04:22:39 +02:00
|
|
|
charge_step = math.min(charge_step, batt_charge)
|
|
|
|
charge_step = math.min(charge_step, item_max_charge - tool_charge)
|
|
|
|
tool_charge = tool_charge + charge_step
|
|
|
|
batt_charge = batt_charge - charge_step
|
2022-06-06 18:53:50 +02:00
|
|
|
technic_set_charge(src_stack, tool_charge)
|
2014-12-15 23:47:07 +01:00
|
|
|
inv:set_stack("src", 1, src_stack)
|
2014-05-23 19:51:23 +02:00
|
|
|
return batt_charge, (tool_charge == item_max_charge)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-19 04:22:39 +02:00
|
|
|
function technic.discharge_tools(meta, batt_charge, charge_step, max_charge)
|
2013-07-17 21:34:35 +02:00
|
|
|
local inv = meta:get_inventory()
|
2013-10-19 04:22:39 +02:00
|
|
|
if inv:is_empty("dst") then
|
2014-05-23 19:51:23 +02:00
|
|
|
return batt_charge, false
|
2013-10-19 04:22:39 +02:00
|
|
|
end
|
2022-06-06 18:53:50 +02:00
|
|
|
local src_stack = inv:get_stack("dst", 1)
|
|
|
|
|
|
|
|
-- get callbacks
|
|
|
|
local src_def = src_stack:get_definition()
|
|
|
|
local technic_get_charge = src_def.technic_get_charge or default_get_charge
|
|
|
|
local technic_set_charge = src_def.technic_set_charge or default_set_charge
|
|
|
|
|
|
|
|
-- get tool charge
|
|
|
|
local tool_charge, item_max_charge = technic_get_charge(src_stack)
|
|
|
|
if item_max_charge==0 then
|
2014-05-23 19:51:23 +02:00
|
|
|
return batt_charge, false
|
2013-10-19 04:22:39 +02:00
|
|
|
end
|
2013-07-17 21:34:35 +02:00
|
|
|
|
2013-10-19 04:22:39 +02:00
|
|
|
-- Do the discharging
|
2014-05-23 19:51:23 +02:00
|
|
|
if tool_charge <= 0 then
|
|
|
|
return batt_charge, true
|
|
|
|
elseif batt_charge >= max_charge then
|
|
|
|
return batt_charge, false
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
2013-10-19 04:22:39 +02:00
|
|
|
charge_step = math.min(charge_step, max_charge - batt_charge)
|
|
|
|
charge_step = math.min(charge_step, tool_charge)
|
|
|
|
tool_charge = tool_charge - charge_step
|
|
|
|
batt_charge = batt_charge + charge_step
|
2022-06-06 18:53:50 +02:00
|
|
|
technic_set_charge(src_stack, tool_charge)
|
|
|
|
inv:set_stack("dst", 1, src_stack)
|
2014-05-23 19:51:23 +02:00
|
|
|
return batt_charge, (tool_charge == 0)
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|