找回密码
 初始化身份识别芯片
查看: 825|回复: 2

关于CargoAPI里getQuantity函数的疑问

[复制链接]

势力巨擘

译码专家

发表于 2025-4-14 01:51:00 | 显示全部楼层 |阅读模式
如题,本人参考补给制造mod统计舰队货舱内锻炉数量的代码写了如下代码,希望能实现相同的统计功能,但返回值始终是0。




public float iCalculateBonus(CargoAPI cargo) {
        float iCorrupted = cargo.getQuantity(CargoItemType.SPECIAL, Items.CORRUPTED_NANOFORGE);
        float iPristine = cargo.getQuantity(CargoItemType.SPECIAL, Items.PRISTINE_NANOFORGE);
               
        float iMaxBonus = PristineForgeMultiplier;
        float iBonus = CorruptedForgeMultiplier * iCorrupted + PristineForgeMultiplier * iPristine;
        if (iBonus > iMaxBonus) {
            iBonus = iMaxBonus;
        };

               
        Global.getSector().getCampaignUI().addMessage("iBonus: " + iBonus, Misc.getTextColor());
        Global.getSector().getCampaignUI().addMessage("iPristine: " + iPristine, Misc.getTextColor());
        Global.getSector().getCampaignUI().addMessage("iCorrupted: " + iCorrupted, Misc.getTextColor());


               
        return iBonus+1;
    }


翻看API文件内函数输入值的要求是  float getQuantity(CargoItemType paramCargoItemType, Object paramObject);
如果直接照抄原代码的话会出现Cannot determine simple type name "SpecialItemData"的数据类型报错
本人对Java语法的了解十分浅薄,还望大佬们不吝赐教
Eyes to the sky, and may the stars bring the light.

星域军阀

高级机师

发表于 2025-4-14 03:01:55 | 显示全部楼层
第二个参数填String是不行的,纳米熔炉这种你得new一个SpecialItemData的实例对象
SpecialItemData只要id和param一致,哈希值就是一样的,用==比较使用同一个id来new的两个SpecialItemData是能通过的

点评

谢谢cjy大佬,我检查了几遍发现是漏import了一个东西,现在解决了  详情 回复 发表于 2025-4-14 11:39

势力巨擘

译码专家

 楼主| 发表于 2025-4-14 11:39:50 | 显示全部楼层
cjy4312 发表于 2025-4-14 03:01
第二个参数填String是不行的,纳米熔炉这种你得new一个SpecialItemData的实例对象
SpecialItemData只要id和 ...

谢谢cjy大佬,我检查了几遍发现是漏import了一个东西,现在解决了
Eyes to the sky, and may the stars bring the light.

本版积分规则

Archiver|手机版|小黑屋|远行星号中文论坛

GMT+8, 2025-12-6 06:23

Powered by Discuz! X3.5

© 2001-2077 Tencent Cloud | Durian Software Studio

快速回复 返回顶部 返回列表