Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions nodes/node_battery_holder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,11 @@ local def = {
-- Allow all items with energy storage to be placed in the inventory
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
if listname == "batteries" then
if not minetest.global_exists("technic") then
return 0
end

local node_name = stack:get_name()

-- Allow all items with energy storage from technic mod
if technic.power_tools[node_name] ~= nil then
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
if digtron.check_protected_and_record(pos, player) then
return 0
end
return stack:get_count()
else
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
if digtron.check_protected_and_record(pos, player) then
return 0
end
else
return 0
return stack:get_count()
end
end
return 0
Expand Down Expand Up @@ -116,12 +99,9 @@ local def = {
return inv:add_item("batteries", stack)
end,
can_insert = function(pos, _, stack)
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
meta = minetest.get_meta(pos)
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the previous comment about -- Disregard empty batteries, the player should know better to justify the charge > 0 check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is back.
Anyway I was wondering if it would be better to accept empty batteries (seems more usual).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be logically equivalent to allow_metadata_inventory_put. The player (automated or manual action) should be made aware that the battery is not usable as-is. Some feedback is needed for them, and rejecting the movement transaction is about the most simple approach to do that.
Anyway. I think this should be kept.

local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("batteries", stack)
end
Expand Down
9 changes: 3 additions & 6 deletions util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,14 @@ digtron.tap_batteries = function(battery_positions, target, test)
end

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