2017-10-10 21:02:35 +02:00
|
|
|
-- internationalization boilerplate
|
2023-11-17 11:55:41 +01:00
|
|
|
local S = digtron.S
|
|
|
|
-- local MP = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
-- local S = dofile(MP.."/intllib.lua")
|
2017-10-10 21:02:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Battery storage. Controller node draws electrical power from here.
|
|
|
|
-- Note that batttery boxes are digtron group 7.
|
|
|
|
|
2017-10-22 06:29:18 +02:00
|
|
|
local battery_holder_formspec_string = "size[8,9.3]" ..
|
2017-10-10 21:02:35 +02:00
|
|
|
default.gui_bg ..
|
|
|
|
default.gui_bg_img ..
|
|
|
|
default.gui_slots ..
|
|
|
|
"label[0,0;" .. S("Batteries") .. "]" ..
|
|
|
|
"list[current_name;batteries;0,0.6;8,4;]" ..
|
|
|
|
"list[current_player;main;0,5.15;8,1;]" ..
|
|
|
|
"list[current_player;main;0,6.38;8,3;8]" ..
|
|
|
|
"listring[current_name;batteries]" ..
|
|
|
|
"listring[current_player;main]" ..
|
|
|
|
default.get_hotbar_bg(0,5.15)
|
|
|
|
|
2023-06-19 07:44:40 +02:00
|
|
|
local battery_holder_formspec = function()
|
2017-10-22 06:29:18 +02:00
|
|
|
return battery_holder_formspec_string
|
|
|
|
end
|
2017-10-10 21:02:35 +02:00
|
|
|
|
2017-10-11 04:33:56 +02:00
|
|
|
local holder_groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 7, tubedevice = 1, tubedevice_receiver = 1}
|
|
|
|
if not minetest.get_modpath("technic") then
|
|
|
|
-- if technic isn't installed there's no point in offering battery holders.
|
|
|
|
-- leave them registered, though, in case technic is being removed from an existing server.
|
|
|
|
holder_groups.not_in_creative_inventory = 1
|
|
|
|
end
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2024-07-14 11:50:23 +02:00
|
|
|
local def = {
|
2017-10-10 21:02:35 +02:00
|
|
|
description = S("Digtron Battery Holder"),
|
|
|
|
_doc_items_longdesc = digtron.doc.battery_holder_longdesc,
|
|
|
|
_doc_items_usagehelp = digtron.doc.battery_holder_usagehelp,
|
|
|
|
_digtron_formspec = battery_holder_formspec,
|
2017-10-11 04:33:56 +02:00
|
|
|
groups = holder_groups,
|
2017-10-10 21:02:35 +02:00
|
|
|
drop = "digtron:battery_holder",
|
|
|
|
sounds = digtron.metal_sounds,
|
|
|
|
paramtype2= "facedir",
|
|
|
|
drawtype = "nodebox",
|
2017-10-25 05:16:37 +02:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
},
|
|
|
|
},
|
2017-10-10 21:02:35 +02:00
|
|
|
paramtype = "light",
|
|
|
|
is_ground_content = false,
|
|
|
|
tiles = {
|
|
|
|
"digtron_plate.png^digtron_crossbrace.png^digtron_battery.png",
|
|
|
|
"digtron_plate.png^digtron_crossbrace.png^digtron_battery.png",
|
|
|
|
"digtron_plate.png^digtron_crossbrace.png^digtron_battery.png^digtron_storage.png",
|
|
|
|
"digtron_plate.png^digtron_crossbrace.png^digtron_battery.png^digtron_storage.png",
|
|
|
|
"digtron_plate.png^digtron_crossbrace.png^digtron_battery.png^digtron_storage.png",
|
|
|
|
"digtron_plate.png^digtron_crossbrace.png^digtron_battery.png^digtron_storage.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2017-10-22 06:29:18 +02:00
|
|
|
meta:set_string("formspec", battery_holder_formspec(pos, meta))
|
2017-10-10 21:02:35 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("batteries", 8*4)
|
|
|
|
end,
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2019-07-20 01:42:47 +02:00
|
|
|
-- Allow all items with energy storage to be placed in the inventory
|
2024-08-22 06:32:24 +02:00
|
|
|
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
|
2017-10-10 21:02:35 +02:00
|
|
|
if listname == "batteries" then
|
2024-07-14 11:49:07 +02:00
|
|
|
if not minetest.global_exists("technic") then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2017-10-10 21:02:35 +02:00
|
|
|
local node_name = stack:get_name()
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2019-07-20 01:42:47 +02:00
|
|
|
-- Allow all items with energy storage from technic mod
|
2023-06-19 07:44:40 +02:00
|
|
|
if technic.power_tools[node_name] ~= nil then
|
2017-10-10 21:02:35 +02:00
|
|
|
local meta = stack:get_metadata()
|
|
|
|
local md = minetest.deserialize(meta)
|
|
|
|
-- And specifically if they hold any charge
|
|
|
|
-- Disregard empty batteries, the player should know better
|
2017-10-11 04:33:56 +02:00
|
|
|
if md and md.charge > 0 then
|
2024-08-22 06:32:24 +02:00
|
|
|
if digtron.check_protected_and_record(pos, player) then
|
|
|
|
return 0
|
|
|
|
end
|
2023-06-19 07:44:40 +02:00
|
|
|
return stack:get_count()
|
2017-10-10 21:02:35 +02:00
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end,
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2024-08-22 06:32:24 +02:00
|
|
|
allow_metadata_inventory_move = digtron.protected_allow_metadata_inventory_move,
|
|
|
|
|
|
|
|
allow_metadata_inventory_take = digtron.protected_allow_metadata_inventory_take,
|
|
|
|
|
2023-06-19 07:44:40 +02:00
|
|
|
|
|
|
|
can_dig = function(pos)
|
2017-10-10 21:02:35 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:is_empty("batteries")
|
|
|
|
end,
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2017-10-10 21:02:35 +02:00
|
|
|
-- Pipeworks compatibility
|
|
|
|
-- Because who wouldn't send batteries through pipes if he could?
|
|
|
|
-----------------------------------------------------------------
|
|
|
|
|
|
|
|
tube = (function() if minetest.get_modpath("pipeworks") then return {
|
2023-06-19 07:44:40 +02:00
|
|
|
insert_object = function(pos, _, stack)
|
2017-10-11 04:33:56 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:add_item("batteries", stack)
|
2017-10-10 21:02:35 +02:00
|
|
|
end,
|
2023-06-19 07:44:40 +02:00
|
|
|
can_insert = function(pos, _, stack)
|
2017-10-11 04:33:56 +02:00
|
|
|
local meta = stack:get_metadata()
|
|
|
|
local md = minetest.deserialize(meta)
|
|
|
|
-- And specifically if they hold any charge
|
|
|
|
-- Disregard empty batteries, the player should know better
|
|
|
|
if md and md.charge > 0 then
|
2023-06-19 07:44:40 +02:00
|
|
|
meta = minetest.get_meta(pos)
|
2017-10-10 21:02:35 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:room_for_item("batteries", stack)
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end,
|
|
|
|
input_inventory = "batteries",
|
|
|
|
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
|
|
|
|
} end end)(),
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2017-10-10 21:02:35 +02:00
|
|
|
after_place_node = (function() if minetest.get_modpath("pipeworks") then return pipeworks.after_place end end)(),
|
|
|
|
after_dig_node = (function() if minetest.get_modpath("pipeworks")then return pipeworks.after_dig end end)()
|
2024-07-14 11:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default.set_inventory_action_loggers(def, "digtron battery holder")
|
|
|
|
|
|
|
|
minetest.register_node("digtron:battery_holder", def)
|