Skip to content

Commit be25d97

Browse files
EmojigitOgelGames
andauthored
Log every inventory action (#360)
Co-authored-by: OgelGames <[email protected]>
1 parent 3809c48 commit be25d97

File tree

12 files changed

+92
-2
lines changed

12 files changed

+92
-2
lines changed

technic/machines/HV/nuclear_reactor.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ minetest.register_node("technic:hv_nuclear_reactor_core", {
480480
allow_metadata_inventory_put = technic.machine_inventory_put,
481481
allow_metadata_inventory_take = technic.machine_inventory_take,
482482
allow_metadata_inventory_move = technic.machine_inventory_move,
483+
on_metadata_inventory_move = technic.machine_on_inventory_move,
484+
on_metadata_inventory_put = technic.machine_on_inventory_put,
485+
on_metadata_inventory_take = technic.machine_on_inventory_take,
483486
technic_run = run,
484487
})
485488

@@ -521,6 +524,9 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", {
521524
allow_metadata_inventory_put = technic.machine_inventory_put,
522525
allow_metadata_inventory_take = technic.machine_inventory_take,
523526
allow_metadata_inventory_move = technic.machine_inventory_move,
527+
on_metadata_inventory_move = technic.machine_on_inventory_move,
528+
on_metadata_inventory_put = technic.machine_on_inventory_put,
529+
on_metadata_inventory_take = technic.machine_on_inventory_take,
524530
technic_run = run,
525531
technic_on_disable = function(pos, node)
526532
local timer = minetest.get_node_timer(pos)

technic/machines/HV/quarry.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ minetest.register_node("technic:quarry", {
554554
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
555555
return player_allowed(pos, player:get_player_name()) and stack:get_count() or 0
556556
end,
557+
on_metadata_inventory_move = technic.machine_on_inventory_move,
558+
on_metadata_inventory_put = technic.machine_on_inventory_put,
559+
on_metadata_inventory_take = technic.machine_on_inventory_take,
557560
mesecons = {
558561
effector = {
559562
action_on = function(pos)

technic/machines/MV/tool_workshop.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ minetest.register_node("technic:tool_workshop", {
131131
can_dig = technic.machine_can_dig,
132132
allow_metadata_inventory_put = technic.machine_inventory_put,
133133
allow_metadata_inventory_take = technic.machine_inventory_take,
134+
on_metadata_inventory_move = technic.machine_on_inventory_move,
135+
on_metadata_inventory_put = technic.machine_on_inventory_put,
136+
on_metadata_inventory_take = technic.machine_on_inventory_take,
134137
tube = {
135138
can_insert = function (pos, node, stack, direction)
136139
return minetest.get_meta(pos):get_inventory():room_for_item("src", stack)

technic/machines/other/coal_alloy_furnace.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ minetest.register_node("technic:coal_alloy_furnace", {
7272
allow_metadata_inventory_put = technic.machine_inventory_put,
7373
allow_metadata_inventory_take = technic.machine_inventory_take,
7474
allow_metadata_inventory_move = technic.machine_inventory_move,
75+
on_metadata_inventory_move = technic.machine_on_inventory_move,
76+
on_metadata_inventory_put = technic.machine_on_inventory_put,
77+
on_metadata_inventory_take = technic.machine_on_inventory_take,
7578
})
7679

7780
minetest.register_node("technic:coal_alloy_furnace_active", {
@@ -92,6 +95,9 @@ minetest.register_node("technic:coal_alloy_furnace_active", {
9295
allow_metadata_inventory_put = technic.machine_inventory_put,
9396
allow_metadata_inventory_take = technic.machine_inventory_take,
9497
allow_metadata_inventory_move = technic.machine_inventory_move,
98+
on_metadata_inventory_move = technic.machine_on_inventory_move,
99+
on_metadata_inventory_put = technic.machine_on_inventory_put,
100+
on_metadata_inventory_take = technic.machine_on_inventory_take,
95101
})
96102

97103
minetest.register_abm({

technic/machines/other/constructor.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ local function make_constructor(mark, length)
205205
allow_metadata_inventory_put = allow_inventory_put,
206206
allow_metadata_inventory_take = technic.machine_inventory_take,
207207
allow_metadata_inventory_move = technic.machine_inventory_move,
208+
on_metadata_inventory_move = technic.machine_on_inventory_move,
209+
on_metadata_inventory_put = technic.machine_on_inventory_put,
210+
on_metadata_inventory_take = technic.machine_on_inventory_take,
208211
on_rotate = function(pos, node, user, mode, new_param2)
209212
if mode ~= 1 then
210213
return false
@@ -231,6 +234,9 @@ local function make_constructor(mark, length)
231234
allow_metadata_inventory_put = allow_inventory_put,
232235
allow_metadata_inventory_take = technic.machine_inventory_take,
233236
allow_metadata_inventory_move = technic.machine_inventory_move,
237+
on_metadata_inventory_move = technic.machine_on_inventory_move,
238+
on_metadata_inventory_put = technic.machine_on_inventory_put,
239+
on_metadata_inventory_take = technic.machine_on_inventory_take,
234240
on_rotate = false
235241
})
236242
end

technic/machines/other/injector.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ minetest.register_node("technic:injector", {
152152
allow_metadata_inventory_put = technic.machine_inventory_put,
153153
allow_metadata_inventory_take = technic.machine_inventory_take,
154154
allow_metadata_inventory_move = technic.machine_inventory_move,
155+
on_metadata_inventory_move = technic.machine_on_inventory_move,
156+
on_metadata_inventory_put = technic.machine_on_inventory_put,
157+
on_metadata_inventory_take = technic.machine_on_inventory_take,
155158
after_place_node = pipeworks.after_place,
156159
after_dig_node = pipeworks.after_dig
157160
})

technic/machines/register/battery_box.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ function technic.register_battery_box(nodename, data)
389389
allow_metadata_inventory_put = technic.machine_inventory_put,
390390
allow_metadata_inventory_take = technic.machine_inventory_take,
391391
allow_metadata_inventory_move = technic.machine_inventory_move,
392+
on_metadata_inventory_move = technic.machine_on_inventory_move,
393+
on_metadata_inventory_put = technic.machine_on_inventory_put,
394+
on_metadata_inventory_take = technic.machine_on_inventory_take,
392395
technic_run = run,
393396
on_timer = on_timer,
394397
on_rightclick = function(pos) update_node(pos, true) end,

technic/machines/register/common.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,31 @@ function technic.machine_inventory_move(pos, from_list, from_index,
190190
local stack = minetest.get_meta(pos):get_inventory():get_stack(from_list, from_index)
191191
return inv_change(pos, player, count, from_list, to_list, stack)
192192
end
193+
194+
function technic.machine_on_inventory_put(pos, listname, index, stack, player)
195+
minetest.log("action", string.format("%s puts %s into %s at %s",
196+
player:get_player_name(),
197+
stack:to_string(),
198+
minetest.get_node(pos).name,
199+
minetest.pos_to_string(pos)
200+
))
201+
end
202+
203+
function technic.machine_on_inventory_take(pos, listname, index, stack, player)
204+
minetest.log("action", string.format("%s takes %s from %s at %s",
205+
player:get_player_name(),
206+
stack:to_string(),
207+
minetest.get_node(pos).name,
208+
minetest.pos_to_string(pos)
209+
))
210+
end
211+
212+
function technic.machine_on_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
213+
local stack = minetest.get_meta(pos):get_inventory():get_stack(to_list, to_index)
214+
minetest.log("action", string.format("%s moves %s in %s at %s",
215+
player:get_player_name(),
216+
stack:to_string(),
217+
minetest.get_node(pos).name,
218+
minetest.pos_to_string(pos)
219+
))
220+
end

technic/machines/register/machine_base.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ function technic.register_base_machine(nodename, data)
216216
allow_metadata_inventory_put = technic.machine_inventory_put,
217217
allow_metadata_inventory_take = technic.machine_inventory_take,
218218
allow_metadata_inventory_move = technic.machine_inventory_move,
219+
on_metadata_inventory_move = technic.machine_on_inventory_move,
220+
on_metadata_inventory_put = technic.machine_on_inventory_put,
221+
on_metadata_inventory_take = technic.machine_on_inventory_take,
219222
technic_run = run,
220223
after_place_node = def.tube and pipeworks.after_place,
221224
after_dig_node = technic.machine_after_dig_node,
@@ -265,6 +268,9 @@ function technic.register_base_machine(nodename, data)
265268
allow_metadata_inventory_put = technic.machine_inventory_put,
266269
allow_metadata_inventory_take = technic.machine_inventory_take,
267270
allow_metadata_inventory_move = technic.machine_inventory_move,
271+
on_metadata_inventory_move = technic.machine_on_inventory_move,
272+
on_metadata_inventory_put = technic.machine_on_inventory_put,
273+
on_metadata_inventory_take = technic.machine_on_inventory_take,
268274
technic_run = run,
269275
technic_disabled_machine_name = nodename,
270276
on_receive_fields = function(pos, formname, fields, sender)

technic_chests/inventory.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,18 @@ function technic.chests.log_inv_change(pos, name, change, items)
176176
minetest.log("action", name.." takes "..items.." from chest at "..spos)
177177
end
178178
end
179+
180+
function technic.chests.log_fast_move(pos, name, change, items)
181+
local spos = minetest.pos_to_string(pos)
182+
local itemlist = {}
183+
for _, stack in ipairs(items) do
184+
table.insert(itemlist, stack.name.." "..stack.count)
185+
end
186+
if change == "put" then
187+
minetest.log("action", string.format("%s puts items into chest at %s: %s",
188+
name, spos, table.concat(itemlist, ", ")))
189+
elseif change == "take" then
190+
minetest.log("action", string.format("%s takes items from chest at %s: %s",
191+
name, spos, table.concat(itemlist, ", ")))
192+
end
193+
end

0 commit comments

Comments
 (0)