Skip to content

Commit

Permalink
Log every inventory action (#360)
Browse files Browse the repository at this point in the history
Co-authored-by: OgelGames <[email protected]>
  • Loading branch information
Emojigit and OgelGames authored Jun 12, 2024
1 parent 3809c48 commit be25d97
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 2 deletions.
6 changes: 6 additions & 0 deletions technic/machines/HV/nuclear_reactor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ minetest.register_node("technic:hv_nuclear_reactor_core", {
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
technic_run = run,
})

Expand Down Expand Up @@ -521,6 +524,9 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", {
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
technic_run = run,
technic_on_disable = function(pos, node)
local timer = minetest.get_node_timer(pos)
Expand Down
3 changes: 3 additions & 0 deletions technic/machines/HV/quarry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ minetest.register_node("technic:quarry", {
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
return player_allowed(pos, player:get_player_name()) and stack:get_count() or 0
end,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
mesecons = {
effector = {
action_on = function(pos)
Expand Down
3 changes: 3 additions & 0 deletions technic/machines/MV/tool_workshop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ minetest.register_node("technic:tool_workshop", {
can_dig = technic.machine_can_dig,
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
tube = {
can_insert = function (pos, node, stack, direction)
return minetest.get_meta(pos):get_inventory():room_for_item("src", stack)
Expand Down
6 changes: 6 additions & 0 deletions technic/machines/other/coal_alloy_furnace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ minetest.register_node("technic:coal_alloy_furnace", {
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
})

minetest.register_node("technic:coal_alloy_furnace_active", {
Expand All @@ -92,6 +95,9 @@ minetest.register_node("technic:coal_alloy_furnace_active", {
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
})

minetest.register_abm({
Expand Down
6 changes: 6 additions & 0 deletions technic/machines/other/constructor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ local function make_constructor(mark, length)
allow_metadata_inventory_put = allow_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
on_rotate = function(pos, node, user, mode, new_param2)
if mode ~= 1 then
return false
Expand All @@ -231,6 +234,9 @@ local function make_constructor(mark, length)
allow_metadata_inventory_put = allow_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
on_rotate = false
})
end
Expand Down
3 changes: 3 additions & 0 deletions technic/machines/other/injector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ minetest.register_node("technic:injector", {
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig
})
Expand Down
3 changes: 3 additions & 0 deletions technic/machines/register/battery_box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ function technic.register_battery_box(nodename, data)
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
technic_run = run,
on_timer = on_timer,
on_rightclick = function(pos) update_node(pos, true) end,
Expand Down
28 changes: 28 additions & 0 deletions technic/machines/register/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,31 @@ function technic.machine_inventory_move(pos, from_list, from_index,
local stack = minetest.get_meta(pos):get_inventory():get_stack(from_list, from_index)
return inv_change(pos, player, count, from_list, to_list, stack)
end

function technic.machine_on_inventory_put(pos, listname, index, stack, player)
minetest.log("action", string.format("%s puts %s into %s at %s",
player:get_player_name(),
stack:to_string(),
minetest.get_node(pos).name,
minetest.pos_to_string(pos)
))
end

function technic.machine_on_inventory_take(pos, listname, index, stack, player)
minetest.log("action", string.format("%s takes %s from %s at %s",
player:get_player_name(),
stack:to_string(),
minetest.get_node(pos).name,
minetest.pos_to_string(pos)
))
end

function technic.machine_on_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local stack = minetest.get_meta(pos):get_inventory():get_stack(to_list, to_index)
minetest.log("action", string.format("%s moves %s in %s at %s",
player:get_player_name(),
stack:to_string(),
minetest.get_node(pos).name,
minetest.pos_to_string(pos)
))
end
6 changes: 6 additions & 0 deletions technic/machines/register/machine_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ function technic.register_base_machine(nodename, data)
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
technic_run = run,
after_place_node = def.tube and pipeworks.after_place,
after_dig_node = technic.machine_after_dig_node,
Expand Down Expand Up @@ -265,6 +268,9 @@ function technic.register_base_machine(nodename, data)
allow_metadata_inventory_put = technic.machine_inventory_put,
allow_metadata_inventory_take = technic.machine_inventory_take,
allow_metadata_inventory_move = technic.machine_inventory_move,
on_metadata_inventory_move = technic.machine_on_inventory_move,
on_metadata_inventory_put = technic.machine_on_inventory_put,
on_metadata_inventory_take = technic.machine_on_inventory_take,
technic_run = run,
technic_disabled_machine_name = nodename,
on_receive_fields = function(pos, formname, fields, sender)
Expand Down
15 changes: 15 additions & 0 deletions technic_chests/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,18 @@ function technic.chests.log_inv_change(pos, name, change, items)
minetest.log("action", name.." takes "..items.." from chest at "..spos)
end
end

function technic.chests.log_fast_move(pos, name, change, items)
local spos = minetest.pos_to_string(pos)
local itemlist = {}
for _, stack in ipairs(items) do
table.insert(itemlist, stack.name.." "..stack.count)
end
if change == "put" then
minetest.log("action", string.format("%s puts items into chest at %s: %s",
name, spos, table.concat(itemlist, ", ")))
elseif change == "take" then
minetest.log("action", string.format("%s takes items from chest at %s: %s",
name, spos, table.concat(itemlist, ", ")))
end
end
4 changes: 2 additions & 2 deletions technic_chests/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function technic.chests.register_chest(nodename, data)
if data.digilines and meta:get_int("send_take") == 1 then
technic.chests.send_digiline_message(pos, "take", player, moved_items)
end
technic.chests.log_inv_change(pos, player:get_player_name(), "take", "stuff")
technic.chests.log_fast_move(pos, player:get_player_name(), "take", moved_items)
return 0
end
return count
Expand All @@ -160,7 +160,7 @@ function technic.chests.register_chest(nodename, data)
if data.digilines and meta:get_int("send_put") == 1 then
technic.chests.send_digiline_message(pos, "put", player, moved_items)
end
technic.chests.log_inv_change(pos, player:get_player_name(), "put", "stuff")
technic.chests.log_fast_move(pos, player:get_player_name(), "put", moved_items)
return 0
end
return stack:get_count()
Expand Down
11 changes: 11 additions & 0 deletions technic_cnc/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ function technic_cnc.register_cnc_machine(nodename, def)
groups.tubedevice_receiver = 1
end

-- Only do logging when technic is enabled to avoid duplicating code
local on_metadata_inventory_move = technic_cnc.use_technic and technic.machine_on_inventory_move or nil
local on_metadata_inventory_put = technic_cnc.use_technic and technic.machine_on_inventory_put or nil
local on_metadata_inventory_take = technic_cnc.use_technic and technic.machine_on_inventory_take or nil

-- Inactive state CNC machine
minetest.register_node(":" .. nodename, {
description = def.description,
Expand Down Expand Up @@ -412,6 +417,9 @@ function technic_cnc.register_cnc_machine(nodename, def)
allow_metadata_inventory_put = def.allow_metadata_inventory_put or allow_metadata_inventory_put,
allow_metadata_inventory_take = def.allow_metadata_inventory_take or allow_metadata_inventory_take,
allow_metadata_inventory_move = def.allow_metadata_inventory_move or allow_metadata_inventory_move,
on_metadata_inventory_move = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_inventory_take,
on_receive_fields = on_receive_fields,
technic_run = def.technic_run or technic_run,
})
Expand All @@ -436,6 +444,9 @@ function technic_cnc.register_cnc_machine(nodename, def)
allow_metadata_inventory_put = def.allow_metadata_inventory_put or allow_metadata_inventory_put,
allow_metadata_inventory_take = def.allow_metadata_inventory_take or allow_metadata_inventory_take,
allow_metadata_inventory_move = def.allow_metadata_inventory_move or allow_metadata_inventory_move,
on_metadata_inventory_move = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_inventory_take,
on_receive_fields = on_receive_fields,
technic_run = def.technic_run or technic_run,
technic_disabled_machine_name = nodename,
Expand Down

0 comments on commit be25d97

Please sign in to comment.