饥荒Mod 开发(二二):显示物品信息
饥荒Mod 开发(二一):超大便携背包,超大物品栏,永久保鲜
饥荒Mod 开发(二三):显示物品栏详细信息
饥荒中的物品没有详细信息,基本上只有一个名字,所以很多物品的功能都不知道,比如浆果吃了也不知道恢复什么, 采集的胡萝卜也不知
道什么功效,可真是太不方便了,所以当我们把鼠标放在物品上面时需要显示物品的详细信息。
原理
widgets/hoverer 类用来显示鼠标悬浮的提示,所以我们需要拦截这个 悬浮的创建,设置需要显示的内容
显示自定义提示
在modmain.lua 文件中添加下面代码用来拦截 widgets/hoverer 创建,然后重写 SetString 方法
local round2 =function(num, idp)return GLOBAL.tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
--鼠标悬浮在物品上显示信息
AddClassPostConstruct("widgets/hoverer",function(self)local old_SetString = self.text.SetStringself.text.SetString = function(text,str)-- 获取鼠标下的世界实体local target = GLOBAL.TheInput:GetWorldEntityUnderMouse() -- 如果存在目标实体if target then-- 如果目标实体有预制体if target.prefab then-- 在字符串后添加预制体的代码str = str .. "\n代码: " .. target.prefabend-- 如果目标实体有可旅行组件if target.components.travelable then-- 在字符串后添加可旅行组件的名称str = str .."\n".. tostring(target.components.travelable.name)endif target.components then-- 如果目标实体有生命组件if target.components.health then-- 在字符串后添加生物的血量str = str.."\n"..math.ceil(target.components.health.currenthealth*10)/10 .."/"..math.ceil(target.components.health.maxhealth*10)/10end-- 如果目标实体有战斗组件,并且默认伤害大于0if target.components.combat and target.components.combat.defaultdamage > 0 then-- 在字符串后添加生物的攻击力str = str.."\n攻击力: "..target.components.combat.defaultdamageend-- 如果目标实体是温度计if target.prefab == "winterometer" then-- 获取当前温度local temp = GLOBAL.GetSeasonManager() and GLOBAL.GetSeasonManager():GetCurrentTemperature() or 30local high_temp = TUNING.OVERHEAT_TEMPlocal low_temp = 0-- 限制温度在最高温度和最低温度之间temp = math.min( math.max(low_temp, temp), high_temp)-- 在字符串后添加温度str = str.."\n温度: ".. tostring(math.floor(temp)) .. "\176C"end-- 检查目标实体是否有库存组件if target.components.inventory then-- 获取目标实体手部装备的物品local handitem = target.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)if handitem then-- 如果有手部装备的物品,可以在这里添加相关的处理代码end-- 获取目标实体头部装备的物品local headitem = target.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HEAD)if headitem then-- 如果头部装备的物品有防具组件if headitem.components.armor then-- 在字符串后添加头部防御的信息str = str.."\n头部防御: "..headitem.components.armor.absorb_percent*100 .."%"-- 在字符串后添加头部装备的耐久信息str = str.." 耐久: "..math.floor(headitem.components.armor:GetPercent() *100).."%"endend-- 获取目标实体身体装备的物品local bodyitem = target.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.BODY)if bodyitem then-- 如果身体装备的物品有防具组件if bodyitem.components.armor then-- 在字符串后添加身体防御的信息str = str.."\n身体防御: "..bodyitem.components.armor.absorb_percent*100 .."%"-- 在字符串后添加身体装备的耐久信息str = str.." 耐久: "..math.floor(bodyitem.components.armor:GetPercent() *100).."%"endendend-- 检查目标实体是否可以被驯养if target.components.domesticatable ~= nil then-- 如果目标实体有驯养和顺从的方法if target.components.domesticatable.GetDomestication and target.components.domesticatable.GetObedience ~= nil then-- 获取目标实体的饥饿值local hunger = target.components.hunger.current-- 获取目标实体的顺从值local obedience = target.components.domesticatable:GetObedience()-- 获取目标实体的驯养值local domestication = target.components.domesticatable:GetDomestication()-- 如果驯养值不为0if domestication ~= 0 then-- 在字符串后添加饥饿、顺从和驯养的信息str = str.."\n饥饿: "..round2(hunger).."\n顺从: "..round2(obedience*100,0).."%".."\n驯服: "..round2(domestication*100,0).."%"end-- 遍历目标实体的倾向for k,v in pairs(target.components.domesticatable.tendencies) do-- 默认倾向为"默认"local ten = "默认"-- 如果倾向为ORNERY,则设置为"战牛"if k == GLOBAL.TENDENCY.ORNERY thenten = "战牛"-- 如果倾向为RIDER,则设置为"行牛"elseif k == GLOBAL.TENDENCY.RIDER thenten = "行牛"-- 如果倾向为PUDGY,则设置为"肥牛"elseif k == GLOBAL.TENDENCY.PUDGY thenten = "肥牛"end-- 在字符串后添加倾向的信息str = str .. string.format("\n %s:%.2f", ten, v)endendend-- 检查目标实体是否可以被采摘,并且有目标时间if target.components.pickable and target.components.pickable.targettime then-- 在字符串后添加距离成长的时间(树枝、草、浆果、咖啡树)str = str .."\n距离成长: " .. tostring(math.ceil((target.components.pickable.targettime - GLOBAL.GetTime())/48)/10) .." 天"end-- 检查目标实体是否可以被砍伐,并且有目标时间if target.components.hackable and target.components.hackable.targettime then-- 在字符串后添加距离成长的时间(藤蔓、竹林)str = str.."\n距离成长: "..tostring(math.ceil((target.components.hackable.targettime - GLOBAL.GetTime())/48)/10).." 天"end-- 检查目标实体是否可以被部署,并且有生长时间if target.components.deployable and target.growtime then-- 在字符串后添加树苗的生长时间str = str.."\n树苗: "..tostring(math.ceil((target.growtime - GLOBAL.GetTime())/48)/10).." 天"end-- 检查目标实体是否可以成长,并且有目标时间if target.components.growable and target.components.growable.targettime then-- 在字符串后添加下一阶段的时间(树)str = str.."\n下一阶段: "..tostring( math.ceil((target.components.growable.targettime - GLOBAL.GetTime())/48)/10).." 天"end-- 检查目标实体是否有晾肉架组件,并且正在晾肉if target.components.dryer and target.components.dryer:IsDrying() then-- 如果正在晾肉,并且有获取晾肉时间的方法if target.components.dryer:IsDrying() and target.components.dryer.GetTimeToDry then-- 在字符串后添加剩余的晾肉时间str = str.."\n剩余: "..round2((target.components.dryer:GetTimeToDry()/TUNING.TOTAL_DAY_TIME)+0.1,1).." 天"endend-- 检查目标实体是否有烹饪组件,并且烹饪时间大于0if target.components.stewer and target.components.stewer:GetTimeToCook() > 0 then-- 计算剩余的烹饪时间local tm = math.ceil(target.components.stewer.targettime-GLOBAL.GetTime(),0)-- 获取烹饪的食物名称local cookname = GLOBAL.STRINGS.NAMES[string.upper(target.components.stewer.product)]-- 如果剩余时间小于0,则设置为0if tm <0 then tm=0 end-- 在字符串后添加正在烹饪的食物和剩余时间str = str .."\n正在烹饪: "..tostring(cookname).."\n剩余时间(秒): "..tmend-- 检查目标实体是否有农作物组件,并且有生长百分比if target.components.crop and target.components.crop.growthpercent then-- 如果有产品预制体if target.components.crop.product_prefab then-- 在字符串后添加产品的名称str = str.."\n"..(GLOBAL.STRINGS.NAMES[string.upper(target.components.crop.product_prefab)])end -- 如果生长百分比小于1if target.components.crop.growthpercent < 1 then-- 在字符串后添加距离成长的百分比str = str.."\n距离成长: "..math.ceil(target.components.crop.growthpercent*1000)/10 .."%" end end-- 检查目标实体是否有燃料组件,并且不是库存目标if target.components.fueled and not target.components.inventorytarget then-- 在字符串后添加燃料的百分比str = str.."\n燃料: "..math.ceil((target.components.fueled.currentfuel/target.components.fueled.maxfuel)*100) .."%" end-- 检查目标实体是否有追随者组件,并且有最大追随时间if target.components.follower and target.components.follower.maxfollowtime then-- 获取最大追随时间mx = target.components.follower.maxfollowtime-- 计算当前的忠诚百分比cur = math.floor(target.components.follower:GetLoyaltyPercent()*mx+0.5)-- 如果当前的忠诚百分比大于0if cur>0 then-- 在字符串后添加忠诚的百分比str = str.."\n忠诚: "..curendend-- 检查目标实体是否有船耐久组件if target.components.boathealth then-- 在字符串后添加船的当前耐久和最大耐久str = str.."\n船: "..math.ceil(target.components.boathealth.currenthealth).."/"..target.components.boathealth.maxhealthend-- 检查目标实体是否有有限使用组件if target.components.finiteuses then-- 如果有消耗属性if target.components.finiteuses.consumption thenlocal use = 1-- 遍历消耗属性for k,v in pairs(target.components.finiteuses.consumption) douse = vend-- 在字符串后添加耐久的当前值和总值str = str .."\n耐久: "..math.floor(target.components.finiteuses.current/use+.5).."/"..math.floor(target.components.finiteuses.total/use+.5)else-- 在字符串后添加耐久的当前值和总值str = str .."\n耐久: "..target.components.finiteuses.current.."/"..target.components.finiteuses.total end end-- 检查目标实体是否有可工作组件if target.components.workable then-- 获取工作动作local action = target.components.workable:GetWorkAction()-- 在字符串后添加工作动作str = str .."\n动作: ".. tostring(action.id)end-- 检查目标实体是否有生长组件if target.components.growth then-- 在字符串后添加等级和经验值str = str .. "\n等级:" .. target.components.growth:GetLevel() .. " (经验: "..target.components.growth:GetCurrentExp().."/"..target.components.growth:GetCurrentMaxExp() .. ")"endendendreturn old_SetString(text,str)end
end)
添加完上面代码之后就可以进入游戏测试,将鼠标放在物品上就会显示详细信息了


相关文章:
饥荒Mod 开发(二二):显示物品信息
饥荒Mod 开发(二一):超大便携背包,超大物品栏,永久保鲜 饥荒Mod 开发(二三):显示物品栏详细信息 饥荒中的物品没有详细信息,基本上只有一个名字,所以很多物品的功能都不知道,比如浆果吃了也不知…...
Microsoft Edge使用方法和心得
Microsoft Edge使用方法和心得 大家好,我是豪哥,一名来自杭州的Java程序员,今天我想分享一下我对Microsoft Edge的使用方法和心得。作为一名热爱编程的程序员,我发现一个高效的浏览器对于我们的工作和学习至关重要。而Microsoft …...
Kafka操作指令笔记
查堆积用命令查: ./kafka-consumer-groups.sh --bootstrap-server {kafka集群地址} --describe --group {消费组名称}bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --all-groups #查看所有组别的积压情况可以通过grep、awk或其他文…...
WAVE SUMMIT+ 2023倒计时2天,传文心一言将曝最新进展!
传文心一言将曝最新进展! 亮点一:趋势引领,“扛把子”文心一言将曝新进展亮点二:干货十足,硬核低门槛开发秘籍大放送亮点三:蓄势待发,大模型赋能产业正当时亮点四:群星闪耀ÿ…...
Crow:Middlewares 庖丁解牛5 context
Crow:Middlewares 庖丁解牛4 partial_context-CSDN博客 基于partial_context再来解释context namespace detail {template<typename... Middlewares>struct partial_context : public pop_back<Middlewares...>::template rebind<partial_context>, public…...
CentOS 7 设置网络
CentOS 7 设置网络 正常情况 ①登陆进去之后使用下面的命令修改文件 echo ONBOOTyes >> /etc/sysconfig/network-scripts/ifcfg-ens33②如果是虚拟机重启后使用如下命令进行查看IP地址 ip addr注:到这里如果显示有两部分,则代表网络设置成功&a…...
装饰器模式(Decorator)
装饰器模式(Decorator Pattern)是一种结构型设计模式,用于动态地给一个对象添加额外的职责。装饰器提供了一个灵活的替代扩展功能的方案,相比继承更加灵活。 在Java中,装饰器模式通常涉及以下几个部分: 组件(Component):定义一个对象接口,可以给这些对象动态添加职责…...
关于“Python”的核心知识点整理大全34
目录 第13 章 外星人 13.1 回顾项目 game_functions.py 13.2 创建第一个外星人 13.2.1 创建 Alien 类 alien.py 13.2.2 创建 Alien 实例 alien_invasion.py 13.2.3 让外星人出现在屏幕上 game_functions.py 13.3 创建一群外星人 13.3.1 确定一行可容纳…...
设计模式--抽象工厂模式
实验4:抽象工厂模式 本次实验属于模仿型实验,通过本次实验学生将掌握以下内容: 1、理解抽象工厂模式的动机,掌握该模式的结构; 2、能够利用抽象工厂模式解决实际问题。 [实验任务]:人与肤色 使用抽象…...
浅析海博深造
文章目录 深造作用 留学种类 选专业 择校 申请流程 申请方式 深造作用 1、个人能力提升(学术专业、语言、新文化或新生活方式) 2、更好的职业发展(起点更高、结交新朋友或扩大社交圈) 3、北京上海落户优惠 4、海外居留福…...
【Hive_05】企业调优1(资源配置、explain、join优化)
1、 计算资源配置1.1 Yarn资源配置1.2 MapReduce资源配置 2、 Explain查看执行计划(重点)2.1 Explain执行计划概述2.2 基本语法2.3 案例实操 3、分组聚合优化3.1 优化说明(1)map-side 聚合相关的参数 3.2 优化案例 4、join优化4.1…...
synchronized
⭐ 作者:小胡_不糊涂 🌱 作者主页:小胡_不糊涂的个人主页 📀 收录专栏:JavaEE 💖 持续更文,关注博主少走弯路,谢谢大家支持 💖 synchronized 1. 特性1.1 互斥1.2 可重入 …...
Vue在页面上添加水印
第一步:在自己的项目里创建一个js文件;如图所示我在在watermark文件中创建了一个名为waterMark.js文件。 waterMark.js /** 水印添加方法 */ let setWatermark (str1, str2) > {let id 1.23452384164.123412415if (document.getElementById(id) …...
SQL server 数据库练习题及答案(练习2)
使用你的名字创建一个数据库 创建表: 数据库中有三张表,分别为student,course,SC(即学生表,课程表,选课表) 问题: --1.分别查询学生表和学生修课表中的全部数据。--2.查询成绩在70到80分之间…...
minicube搭建golang容器服务
引言 最近在自己电脑上搭建一个小型k8s环境,以学习云原生相关内容。这里我主要分为三部分记录: 容器及容器编排理论环境安装相关rpcx服务实战 还在调试中,先总结整理下,这里后续补充上我的github工程链接。 一、容器及容器编排理…...
图片批量处理:图片批量缩放,高效调整尺寸的技巧
在数字媒体时代,图片处理已是日常生活和工作中不可或缺的一部分。有时候要批量处理图片,如缩放图片尺寸,以满足不同的应用需求。现在一起来看看办公提效式具如何高效的将图片批量处理方法,快速、准确地批量调整图片尺寸操作。 下…...
直接插入排序【从0-1学数据结构】
文章目录 💗 直接插入排序Java代码C代码JavaScript代码稳定性时间复杂度空间复杂度 我们先来学习 直接插入排序, 直接排序算是所有排序中最简单的了,代码也非常好实现,尽管直接插入排序很简单,但是我们依旧不可以上来就直接写代码,一定要分析之后才开始写,这样可以提…...
C++/CLI——1简介
C/CLI——1简介 如果你是.net程序员,不免会用到C/C写的库。对于简单的调用,可以直接使用DllImport来完成就可以,详情可参考C#调用C/C从零深入讲解。但是对于复杂的C类和对象,尤其是类似于OCC的大型C项目,DllImport可能…...
C#实现串口通讯
1、官网下载Launch Virtual Serial Port Driver Virtual Serial Port Driver - create and emulate virtual COM port,开个虚拟串口: Pair模式(一对,成双成对的意思,就是COM1向COM2传或者COM2向COM1,好比两台机器的CO…...
NLP论文阅读记录 - 以大语言模型为参考学习总结
文章目录 前言0、论文摘要一、Introduction1.1目标问题1.2相关的尝试1.3本文贡献 二.相关工作2.1文本生成模型的训练方法2.2 基于LLM的自动评估2.3 LLM 蒸馏和基于 LLM 的数据增强 三.本文方法3.1 Summarize as Large Language Models3.1.1 前提3.1.2 大型语言模型作为参考具有…...
零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?
一、核心优势:专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发,是一款收费低廉但功能全面的Windows NAS工具,主打“无学习成本部署” 。与其他NAS软件相比,其优势在于: 无需硬件改造:将任意W…...
【ROS】Nav2源码之nav2_behavior_tree-行为树节点列表
1、行为树节点分类 在 Nav2(Navigation2)的行为树框架中,行为树节点插件按照功能分为 Action(动作节点)、Condition(条件节点)、Control(控制节点) 和 Decorator(装饰节点) 四类。 1.1 动作节点 Action 执行具体的机器人操作或任务,直接与硬件、传感器或外部系统…...
【单片机期末】单片机系统设计
主要内容:系统状态机,系统时基,系统需求分析,系统构建,系统状态流图 一、题目要求 二、绘制系统状态流图 题目:根据上述描述绘制系统状态流图,注明状态转移条件及方向。 三、利用定时器产生时…...
QT: `long long` 类型转换为 `QString` 2025.6.5
在 Qt 中,将 long long 类型转换为 QString 可以通过以下两种常用方法实现: 方法 1:使用 QString::number() 直接调用 QString 的静态方法 number(),将数值转换为字符串: long long value 1234567890123456789LL; …...
在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?
uni-app 中 Web-view 与 Vue 页面的通讯机制详解 一、Web-view 简介 Web-view 是 uni-app 提供的一个重要组件,用于在原生应用中加载 HTML 页面: 支持加载本地 HTML 文件支持加载远程 HTML 页面实现 Web 与原生的双向通讯可用于嵌入第三方网页或 H5 应…...
iview框架主题色的应用
1.下载 less要使用3.0.0以下的版本 npm install less2.7.3 npm install less-loader4.0.52./src/config/theme.js文件 module.exports {yellow: {theme-color: #FDCE04},blue: {theme-color: #547CE7} }在sass中使用theme配置的颜色主题,无需引入,直接可…...
Vue 模板语句的数据来源
🧩 Vue 模板语句的数据来源:全方位解析 Vue 模板(<template> 部分)中的表达式、指令绑定(如 v-bind, v-on)和插值({{ }})都在一个特定的作用域内求值。这个作用域由当前 组件…...
Unity中的transform.up
2025年6月8日,周日下午 在Unity中,transform.up是Transform组件的一个属性,表示游戏对象在世界空间中的“上”方向(Y轴正方向),且会随对象旋转动态变化。以下是关键点解析: 基本定义 transfor…...
算术操作符与类型转换:从基础到精通
目录 前言:从基础到实践——探索运算符与类型转换的奥秘 算术操作符超级详解 算术操作符:、-、*、/、% 赋值操作符:和复合赋值 单⽬操作符:、--、、- 前言:从基础到实践——探索运算符与类型转换的奥秘 在先前的文…...
比特币:固若金汤的数字堡垒与它的四道防线
第一道防线:机密信函——无法破解的哈希加密 将每一笔比特币交易比作一封在堡垒内部传递的机密信函。 解释“哈希”(Hashing)就是一种军事级的加密术(SHA-256),能将信函内容(交易细节…...
