Skip to content

Commit 3d391a0

Browse files
authored
Fix battery holder not accepting technic batteries (#115)
1 parent be49b92 commit 3d391a0

File tree

2 files changed

+8
-31
lines changed

2 files changed

+8
-31
lines changed

nodes/node_battery_holder.lua

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,11 @@ local def = {
6767
-- Allow all items with energy storage to be placed in the inventory
6868
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
6969
if listname == "batteries" then
70-
if not minetest.global_exists("technic") then
71-
return 0
72-
end
73-
74-
local node_name = stack:get_name()
75-
76-
-- Allow all items with energy storage from technic mod
77-
if technic.power_tools[node_name] ~= nil then
78-
local meta = stack:get_metadata()
79-
local md = minetest.deserialize(meta)
80-
-- And specifically if they hold any charge
81-
-- Disregard empty batteries, the player should know better
82-
if md and md.charge > 0 then
83-
if digtron.check_protected_and_record(pos, player) then
84-
return 0
85-
end
86-
return stack:get_count()
87-
else
70+
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
71+
if digtron.check_protected_and_record(pos, player) then
8872
return 0
8973
end
90-
else
91-
return 0
74+
return stack:get_count()
9275
end
9376
end
9477
return 0
@@ -116,12 +99,9 @@ local def = {
11699
return inv:add_item("batteries", stack)
117100
end,
118101
can_insert = function(pos, _, stack)
119-
local meta = stack:get_metadata()
120-
local md = minetest.deserialize(meta)
121-
-- And specifically if they hold any charge
122102
-- Disregard empty batteries, the player should know better
123-
if md and md.charge > 0 then
124-
meta = minetest.get_meta(pos)
103+
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
104+
local meta = minetest.get_meta(pos)
125105
local inv = meta:get_inventory()
126106
return inv:room_for_item("batteries", stack)
127107
end

util.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,14 @@ digtron.tap_batteries = function(battery_positions, target, test)
262262
end
263263

264264
for _, itemstack in pairs(invlist) do
265-
local meta = minetest.deserialize(itemstack:get_metadata())
266-
if (meta ~= nil) then
267-
local power_available = math.floor(meta.charge / digtron.config.power_ratio)
265+
if minetest.global_exists("technic") then
266+
local power_available = math.floor(technic.get_charge(itemstack) / digtron.config.power_ratio)
268267
if power_available ~= 0 then
269268
local actual_burned = power_available -- we just take all we have from the battery, since they aren't stackable
270269
-- don't bother recording the items if we're just testing, nothing is actually being removed.
271270
if test ~= true then
272271
-- since we are taking everything, the wear and charge can both be set to 0
273-
itemstack:set_wear(0)
274-
meta.charge = 0
275-
itemstack:set_metadata(minetest.serialize(meta))
272+
technic.set_charge(itemstack, 0)
276273
end
277274
current_burned = current_burned + actual_burned
278275
end

0 commit comments

Comments
 (0)