Skip to content

Commit

Permalink
Not returning function and handle cases where technic is not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Emojigit committed Jun 4, 2024
1 parent 7ce02f3 commit 02ef499
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 81 deletions.
16 changes: 6 additions & 10 deletions technic/machines/HV/nuclear_reactor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,6 @@ local digiline_def = function(pos, _, channel, msg)
end
end

local on_metadata_inventory_move = technic.machine_on_inventory_move("technic:hv_nuclear_reactor_core")
local on_metadata_inventory_put = technic.machine_on_inventory_put("technic:hv_nuclear_reactor_core")
local on_metadata_inventory_take = technic.machine_on_inventory_take("technic:hv_nuclear_reactor_core")

minetest.register_node("technic:hv_nuclear_reactor_core", {
description = reactor_desc,
tiles = {
Expand Down Expand Up @@ -484,9 +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 = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_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,
technic_run = run,
})

Expand Down Expand Up @@ -528,9 +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 = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_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,
technic_run = run,
technic_on_disable = function(pos, node)
local timer = minetest.get_node_timer(pos)
Expand Down
6 changes: 3 additions & 3 deletions technic/machines/MV/tool_workshop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +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("technic:tool_workshop"),
on_metadata_inventory_put = technic.machine_on_inventory_put("technic:tool_workshop"),
on_metadata_inventory_take = technic.machine_on_inventory_take("technic:tool_workshop"),
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
11 changes: 3 additions & 8 deletions technic/machines/register/battery_box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,6 @@ function technic.register_battery_box(nodename, data)
return true
end

-- This nodename is not an actual nodename - it is the base nodename.
local on_metadata_inventory_move = technic.machine_on_inventory_move(nodename)
local on_metadata_inventory_put = technic.machine_on_inventory_put(nodename)
local on_metadata_inventory_take = technic.machine_on_inventory_take(nodename)

for i = 0, 8 do
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
technic_machine=1, ["technic_"..ltier]=1, axey=2, handy=1}
Expand Down Expand Up @@ -394,9 +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 = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_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,
technic_run = run,
on_timer = on_timer,
on_rightclick = function(pos) update_node(pos, true) end,
Expand Down
63 changes: 30 additions & 33 deletions technic/machines/register/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,41 +191,38 @@ function technic.machine_inventory_move(pos, from_list, from_index,
return inv_change(pos, player, count, from_list, to_list, stack)
end

function technic.machine_on_inventory_put(nodename)
return function(pos, listname, index, stack, player)
minetest.log("action", string.format(
"%s put %s into %s[%u] of %s at %s",
player:is_player() and player:get_player_name() or "A mod",
stack:to_string(),
listname, index,
nodename,
minetest.pos_to_string(pos)
))
end
function technic.machine_on_inventory_put(pos, listname, index, stack, player)
local nodename = minetest.get_node(pos).name
minetest.log("action", string.format(
"%s put %s into %s[%u] of %s at %s",
player:is_player() and player:get_player_name() or "A mod",
stack:to_string(),
listname, index,
nodename,
minetest.pos_to_string(pos)
))
end

function technic.machine_on_inventory_take(nodename)
return function(pos, listname, index, stack, player)
minetest.log("action", string.format(
"%s took %s from %s[%u] of %s at %s",
player:is_player() and player:get_player_name() or "A mod",
stack:to_string(),
listname, index,
nodename,
minetest.pos_to_string(pos)
))
end
function technic.machine_on_inventory_take(pos, listname, index, stack, player)
local nodename = minetest.get_node(pos).name
minetest.log("action", string.format(
"%s took %s from %s[%u] of %s at %s",
player:is_player() and player:get_player_name() or "A mod",
stack:to_string(),
listname, index,
nodename,
minetest.pos_to_string(pos)
))
end

function technic.machine_on_inventory_move(nodename)
return function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", string.format(
"%s moved item from %s[%u] to %s[%u] of %s at %s",
player:is_player() and player:get_player_name() or "A mod",
from_list, from_index,
to_list, to_index,
nodename,
minetest.pos_to_string(pos)
))
end
function technic.machine_on_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local nodename = minetest.get_node(pos).name
minetest.log("action", string.format(
"%s moved item from %s[%u] to %s[%u] of %s at %s",
player:is_player() and player:get_player_name() or "A mod",
from_list, from_index,
to_list, to_index,
nodename,
minetest.pos_to_string(pos)
))
end
16 changes: 6 additions & 10 deletions technic/machines/register/machine_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ function technic.register_base_machine(nodename, data)
tentry = ""
end

local on_metadata_inventory_move = technic.machine_on_inventory_move(nodename)
local on_metadata_inventory_put = technic.machine_on_inventory_put(nodename)
local on_metadata_inventory_take = technic.machine_on_inventory_take(nodename)

minetest.register_node(colon..nodename, {
description = def.description,
tiles = {
Expand Down Expand Up @@ -220,9 +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 = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_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,
technic_run = run,
after_place_node = def.tube and pipeworks.after_place,
after_dig_node = technic.machine_after_dig_node,
Expand Down Expand Up @@ -272,9 +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 = on_metadata_inventory_move,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_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,
technic_run = run,
technic_disabled_machine_name = nodename,
on_receive_fields = function(pos, formname, fields, sender)
Expand Down
5 changes: 0 additions & 5 deletions technic_chests/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ function technic.chests.move_inv(from_inv, to_inv, filter)
return moved_items
end

-- DEPRECATED: use technic.machine_on_inventory_* instead.
---@deprecated
---@see technic.machine_on_inventory_put
---@see technic.machine_on_inventory_take
---@see technic.machine_on_inventory_move
function technic.chests.log_inv_change(pos, name, change, items)
local spos = minetest.pos_to_string(pos)
if change == "move" then
Expand Down
26 changes: 17 additions & 9 deletions technic_chests/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ function technic.chests.register_chest(nodename, data)
data.digilines = nil
end

local on_metadata_inventory_move = technic.machine_on_inventory_move(nodename)
local on_metadata_inventory_put = technic.machine_on_inventory_put(nodename)
local on_metadata_inventory_take = technic.machine_on_inventory_take(nodename)

data.formspec = technic.chests.get_formspec(data)
local def = {
description = data.description,
Expand Down Expand Up @@ -148,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_fast_move(pos, player:get_player_name(), nodename, "take", moved_items)
technic.chests.log_inv_change(pos, player:get_player_name(), "take", "stuff")
return 0
end
return count
Expand All @@ -164,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_fast_move(pos, player:get_player_name(), nodename, "put", moved_items)
technic.chests.log_inv_change(pos, player:get_player_name(), "put", "stuff")
return 0
end
return stack:get_count()
Expand All @@ -175,9 +171,21 @@ function technic.chests.register_chest(nodename, data)
end
return stack:get_count()
end,
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_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
technic.chests.log_inv_change(pos, player:get_player_name(), "move", "stuff")
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if data.digilines and minetest.get_meta(pos):get_int("send_put") == 1 then
technic.chests.send_digiline_message(pos, "put", player, {stack:to_table()})
end
technic.chests.log_inv_change(pos, player:get_player_name(), "put", stack:get_name())
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
if data.digilines and minetest.get_meta(pos):get_int("send_take") == 1 then
technic.chests.send_digiline_message(pos, "take", player, {stack:to_table()})
end
technic.chests.log_inv_change(pos, player:get_player_name(), "take", stack:get_name())
end,
on_blast = function(pos)
if data.locked or data.protected then
return
Expand Down
7 changes: 4 additions & 3 deletions technic_cnc/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,10 @@ function technic_cnc.register_cnc_machine(nodename, def)
groups.tubedevice_receiver = 1
end

local on_metadata_inventory_move = technic.machine_on_inventory_move(nodename)
local on_metadata_inventory_put = technic.machine_on_inventory_put(nodename)
local on_metadata_inventory_take = technic.machine_on_inventory_take(nodename)
-- Only do logging when technic is loaded... I don't wanna duplicate code
local on_metadata_inventory_move = technic_cnc.use_technic and technic.machine_on_inventory_move
local on_metadata_inventory_put = technic_cnc.use_technic and technic.machine_on_inventory_put
local on_metadata_inventory_take = technic_cnc.use_technic and technic.machine_on_inventory_take

-- Inactive state CNC machine
minetest.register_node(":" .. nodename, {
Expand Down

0 comments on commit 02ef499

Please sign in to comment.