Skip to content

Commit

Permalink
DevTest: Cleanup callback logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 authored and sfan5 committed Oct 23, 2022
1 parent 9e186a4 commit 7a8ac00
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion games/devtest/mods/callbacks/entities.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Entities that test their callbacks

local message = function(msg)
minetest.log("action", msg)
minetest.log("action", "[callbacks] "..msg)
minetest.chat_send_all(msg)
end

Expand Down
22 changes: 14 additions & 8 deletions games/devtest/mods/callbacks/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
-- Item callbacks
--

local function print_to_everything(msg)
minetest.log("action", "[callbacks] " .. msg)
minetest.chat_send_all(msg)
end

minetest.register_craftitem("callbacks:callback_item_1", {
description = "Callback Test Item 1".."\n"..
"Tests callbacks: on_secondary_use, on_drop, on_pickup, on_use, after_use".."\n"..
Expand All @@ -12,7 +17,7 @@ minetest.register_craftitem("callbacks:callback_item_1", {
groups = { callback_test = 1 },

on_secondary_use = function(itemstack, user, pointed_thing)
minetest.log("[callbacks:callback_item_1 on_secondary_use] " .. itemstack:get_name())
print_to_everything("[callbacks:callback_item_1 on_secondary_use] " .. itemstack:get_name())
local ctrl = user and user:get_player_control() or {}
if ctrl.sneak then
itemstack = ItemStack(itemstack)
Expand All @@ -22,7 +27,7 @@ minetest.register_craftitem("callbacks:callback_item_1", {
end,

on_drop = function(itemstack, dropper, pos)
minetest.log("[callbacks:callback_item_1 on_drop] " .. itemstack:get_name())
print_to_everything("[callbacks:callback_item_1 on_drop] " .. itemstack:get_name())
local ctrl = dropper and dropper:get_player_control() or {}
if ctrl.sneak then
itemstack = ItemStack(itemstack)
Expand All @@ -33,12 +38,13 @@ minetest.register_craftitem("callbacks:callback_item_1", {
end,

on_pickup = function(itemstack, picker, pointed_thing, ...)
minetest.log("[callbacks:callback_item_1 on_pickup]")
print_to_everything("[callbacks:callback_item_1 on_pickup]")
assert(pointed_thing.ref:get_luaentity().name == "__builtin:item")
local ctrl = picker and picker:get_player_control() or {}
if ctrl.aux1 then
-- Debug message
minetest.log(dump({...}))
print_to_everything("on_pickup dump:")
print_to_everything(dump({...}))
end
if ctrl.sneak then
-- Pick up one item of the other kind at once
Expand All @@ -61,7 +67,7 @@ minetest.register_craftitem("callbacks:callback_item_1", {
end,

on_use = function(itemstack, user, pointed_thing)
minetest.log("[callbacks:callback_item_1 on_use] " .. itemstack:get_name())
print_to_everything("[callbacks:callback_item_1 on_use] " .. itemstack:get_name())
local ctrl = user and user:get_player_control() or {}
if ctrl.sneak then
itemstack = ItemStack(itemstack)
Expand All @@ -71,7 +77,7 @@ minetest.register_craftitem("callbacks:callback_item_1", {
end,

after_use = function(itemstack, user, node, digparams) -- never called
minetest.log("[callbacks:callback_item_1 after_use]")
print_to_everything("[callbacks:callback_item_1 after_use]")
local ctrl = user and user:get_player_control() or {}
if ctrl.up then
itemstack = ItemStack(itemstack)
Expand All @@ -89,7 +95,7 @@ minetest.register_craftitem("callbacks:callback_item_2", {
groups = { callback_test = 1 },

on_use = function(itemstack, user, pointed_thing)
minetest.log("[callbacks:callback_item_2 on_use]")
print_to_everything("[callbacks:callback_item_2 on_use]")
itemstack = ItemStack(itemstack)
itemstack:set_name("callbacks:callback_item_1")
return itemstack
Expand All @@ -103,7 +109,7 @@ minetest.register_on_item_pickup(function(itemstack, picker, pointed_thing, time
if item_name ~= "callbacks:callback_item_1" and item_name ~= "callbacks:callback_item_2" then
return
end
minetest.log("["..item_name.." register_on_item_pickup]")
print_to_everything("["..item_name.." register_on_item_pickup]")

local ctrl = picker and picker:get_player_control() or {}
if item_name == "callbacks:callback_item_2" and not ctrl.sneak then
Expand Down
2 changes: 1 addition & 1 deletion games/devtest/mods/callbacks/nodes.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local function print_to_everything(msg)
minetest.log("action", msg)
minetest.log("action", "[callbacks] " .. msg)
minetest.chat_send_all(msg)
end

Expand Down

0 comments on commit 7a8ac00

Please sign in to comment.