Merge remote-tracking branch 'poikilos/master'

This commit is contained in:
bri cassa 2024-09-15 09:21:21 +02:00
commit 3bc8ee4d1f

126
init.lua
View File

@ -2,7 +2,7 @@
-- Metadata Tools -- Metadata Tools
-- --
-- A mod providing write and read access to a nodes' metadata using commands -- A mod providing write and read access to a nodes' metadata using commands
-- (c) 2015-2016 ßÿ Lymkwi/LeMagnesium/Mg and Paly2; (c) 2017-2022 Poikilos -- (c) 2015-2016 ßÿ Lymkwi/LeMagnesium/Mg and Paly2; & (c) 2017-2024 Poikilos
-- License: [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/) -- License: [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/)
-- --
-- Version: Poikilos fork of 1.2.2 -- Version: Poikilos fork of 1.2.2
@ -307,7 +307,10 @@ minetest.register_craftitem("metatools:stick",{
"[metatools::stick] You pointed at nothing." "[metatools::stick] You pointed at nothing."
) )
return return
elseif pointed_thing.type == "object" then elseif pointed_thing.type == "object" and pointed_thing.ref and pointed_thing.ref:get_luaentity() then
-- It must be a mob
-- (Otherwise [if not get_luaentity(),] it must be a player character,
-- so see next elseif case
local pointedObjRef = pointed_thing.ref local pointedObjRef = pointed_thing.ref
-- local objAsStr = minetest.serialize(pointedObjRef) -- local objAsStr = minetest.serialize(pointedObjRef)
-- ^ if param is pointed_thing or pointed_thing.ref, minetest.serialize causes "2021-11-14 16:45:39: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'metatools' in callback item_OnUse(): /home/owner/minetest/bin/../builtin/common/serialize.lua:151: Can't serialize data of type userdata" -- ^ if param is pointed_thing or pointed_thing.ref, minetest.serialize causes "2021-11-14 16:45:39: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'metatools' in callback item_OnUse(): /home/owner/minetest/bin/../builtin/common/serialize.lua:151: Can't serialize data of type userdata"
@ -331,7 +334,8 @@ minetest.register_craftitem("metatools:stick",{
-- end -- end
-- minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr) -- minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr)
local luaEntity = pointedObjRef:get_luaentity() local luaEntity = pointedObjRef:get_luaentity()
-- INFO: For player name, use user:get_player_name() -- NOTE: For player name, use user:get_player_name()
-- NOTE: luaEntity is nil when clicking player!
minetest.chat_send_player( minetest.chat_send_player(
username, username,
" LuaEntity.name: " .. luaEntity.name " LuaEntity.name: " .. luaEntity.name
@ -364,8 +368,122 @@ minetest.register_craftitem("metatools:stick",{
-- username, -- username,
-- yamlSerializeTable(animation.range, " range") -- yamlSerializeTable(animation.range, " range")
-- ) -- )
-- else type is usually "node" -- else will return early (See "if not nodepos or ..." below)!
elseif pointed_thing.type == "object" and pointed_thing.ref and pointed_thing.ref:is_player() then
-- NOTE pointed_thing.ref.get_luaentity() is nil in this and all successive cases
-- local pointedObjRef = pointed_thing.ref
local player = pointed_thing.ref
local inv = player:get_inventory()
if pointed_thing.ref:get_player_name() then
minetest.chat_send_player(
username,
" player name: " .. pointed_thing.ref:get_player_name()
)
else
minetest.chat_send_player(
username,
" player name: nil"
)
end end
if pointed_thing.ref:get_entity_name() then
minetest.chat_send_player(
username,
" entity name: " .. pointed_thing.ref:get_entity_name()
)
end
minetest.chat_send_player(
username,
" inventories:"
)
-- local pointedEntitySAO = player:getluaobject()
-- local pointedPlayerSAO = player:getplayersao()
-- local pointedRemotePlayer = player:getplayer()
local inventories = {
["main"] = 32, -- The regular inventory grid
["hand"] = 1, -- item shown in hand in 3D (?)
["craft"] = 9, -- the 3x3 area for crafting
["craftpreview"] = 1, -- you can see but not take from preview
["craftresult"] = 1, -- you take the item from this to craft it
["bag1"] = 1, -- For bag itself (bag item placed here enables bag1contents)
["bag1contents"] = 32, -- The items in the bag
["bag2"] = 1,
["bag2contents"] = 32,
["bag3"] = 1,
["bag3contents"] = 32,
["bag4"] = 1,
["bag4contents"] = 32,
["more_chests:wifi"] = 32, -- on player since all chests are shared
["enderchest"] = 32 -- legacy, TM Mojang. See wifi instead.
}
-- NOTE: "hunger" is also an inventory but it is used as a savable variable
for inv_name, inv_max in pairs(inventories) do
local i = 0
local inv_count = 0
local inv_block_text = ""
for y=1,4,1 do
local sep = ""
local line = ""
local cols = 8
if inv_max == 9 then
cols = 3
end
for x=1,cols,1 do
i = i + 1 -- 1 to 32
if i > inv_max then
break
end
line = line .. sep .. inv:get_stack(inv_name, i):get_name()
if inv:get_stack(inv_name, i):get_count() > 0 then
line = line .. " " .. inv:get_stack(inv_name, i):get_count()
inv_count = inv_count + 1
end
sep = ", "
end -- end for column
if i > inv_max then
break
end
inv_block_text = inv_block_text .. " - " .. line .. "\n"
end -- end for row (newline)
if inv_count > 0 then
minetest.chat_send_player(
username,
" " .. inv_name .." inventory:\n" .. inv_block_text
)
end
end
-- Next get player metadata "3d_armor_inventory" (contains a Lua return statement returning the 3d_armor table for the player)
local known_metas = {"3d_armor_inventory", "unified_inventory:bags", "sethome:home"}
for _, meta_name in pairs(known_metas) do
local attribute_meta = player:get_meta() -- see also 3d_armor init.lua
-- Other attributes: local known_metas = {"hbsprint:sprinting", "hbsprint:stamina", "homedecor:player_skin", "hunger_ng:eating_timestamp", "hunger_ng:hunger", "hunger_ng:hunger_bar", "skinsdb:skin_key", "sprinting", "stamina"}
local content_lua = attribute_meta:get_string(meta_name)
if content_lua and content_lua ~= "" then
minetest.chat_send_player(
username,
" " .. meta_name .. " = " .. content_lua
)
end
end
elseif pointed_thing.type == "object" and pointed_thing.ref then
-- NOTE pointed_thing.ref.get_luaentity() is nil in this and all successive cases
-- local pointedObjRef = pointed_thing.ref
minetest.chat_send_player(
username,
"A non-player non-Lua ObjRef was clicked (NotImplemented in this version of metatools):"
)
if pointed_thing.ref:get_entity_name() then
minetest.chat_send_player(
username,
" entity name: " .. pointed_thing.ref:get_entity_name()
)
else
minetest.chat_send_player(
username,
" entity name: nil"
)
end
end
local nodepos = pointed_thing.under local nodepos = pointed_thing.under
-- > * `under` refers to the node position behind the pointed face -- > * `under` refers to the node position behind the pointed face
-- > * `above` refers to the node position in front of the pointed face. -- > * `above` refers to the node position in front of the pointed face.