From 3c411555504b91324da9587f3b1a4ffeef0687dd Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Fri, 6 Aug 2021 21:46:27 -0400 Subject: [PATCH] Hint discovery by looktips No touching necessary anymore --- mods/nc_api_ents/falling_ent.lua | 4 +++- mods/nc_api_ents/item_ent.lua | 4 +++- mods/nc_api_hints/discover.lua | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/mods/nc_api_ents/falling_ent.lua b/mods/nc_api_ents/falling_ent.lua index 8c9da54e..711ab577 100644 --- a/mods/nc_api_ents/falling_ent.lua +++ b/mods/nc_api_ents/falling_ent.lua @@ -55,13 +55,15 @@ minetest.register_entity(":__builtin:falling_node", { on_activate = function(self, data) self.object:set_armor_groups({immortal = 1}) - return data_load(self, data) + data_load(self, data) + self.represents_item = self.node and self.node.name end, set_node = function(self, node, meta) if not node then return self.object:remove() end self.node = node + self.represents_item = self.node and self.node.name local def = minetest.registered_items[node.name] if def.falling_replacement then self.node.name = def.falling_replacement diff --git a/mods/nc_api_ents/item_ent.lua b/mods/nc_api_ents/item_ent.lua index 03b029a5..14e67909 100644 --- a/mods/nc_api_ents/item_ent.lua +++ b/mods/nc_api_ents/item_ent.lua @@ -31,7 +31,9 @@ minetest.register_entity(":__builtin:item", { }, set_item = function(self, item) - item = item and ItemStack(item):to_string() + local stack = ItemStack(item) + item = item and stack:to_string() + self.represents_item = stack:get_name() if item and item ~= self.itemstring then self.itemstring = item self.object:set_yaw(math_random() * math_pi * 2) diff --git a/mods/nc_api_hints/discover.lua b/mods/nc_api_hints/discover.lua index c7924d1b..87d0cb78 100644 --- a/mods/nc_api_hints/discover.lua +++ b/mods/nc_api_hints/discover.lua @@ -114,11 +114,12 @@ nodecore.register_on_chat_message("chat message stats", function(name, msg) end) ------------------------------------------------------------------------ --- PLAYER INVENTORY SCAN +-- PLAYER SCAN nodecore.register_playerstep({ label = "inv", - action = function(player) + action = function(player, data) + -- inventory local inv = player:get_inventory() local t = {} for i = 1, inv:get_size("main") do @@ -130,5 +131,23 @@ nodecore.register_playerstep({ for k in pairs(t) do discover(player, "inv:" .. k) end + + -- looking at + local pt = data.raycast() + if pt then + if pt.type == "node" then + local nn = minetest.get_node(pt.under).name + discover(player, "look:" .. nn) + local stack = nodecore.stack_get(pt.under) + if stack and not stack:is_empty() then + discover(player, "look:" .. stack:get_name()) + end + elseif pt.type == "object" then + local luaent = pt.ref:get_luaentity() + if luaent and luaent.represents_item then + discover(player, "look:" .. luaent.represents_item) + end + end + end end })