Minecraft(我的世界)中文论坛

 找回密码
 注册(register)

!header_login!

只需一步,立刻登录

查看: 91|回复: 7

[mod安装&应用] CraftTweaker 合成相关 每次合成物品都会扣除玩家的饥饿值

[复制链接]
xiaoxi喵 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
590
钻石
性别
保密
注册时间
2019-2-5
查看详细资料
 楼主| 发表于 2020-3-27 01:10:21 | 显示全部楼层 |阅读模式
40金粒
本帖最后由 1398671127 于 2020-3-27 06:44 编辑

如何实现合成物品会扣除玩家的饥饿值,最近有了新的想法可是不会CraftTweaker的高级用法
呜呜呜,我知道40金粒有点少

最佳答案

查看完整内容

特定的合成 [markdown] ```javascript recipes.addShapeless("experiencestone",,[,], function(out,ins,info) { if (isNull(info.player) || info.player.isFake()) return out; // 如果由机器合成跳过处理 return info.player.foodStats.foodLevel > 1 ? out : null; }, //IRecipeAction function(out,cInfo,player){ if (isNull(player) || player.isFake() || player.world.remote) return; // 如果由机器合成 ...
当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
8928
钻石
性别
保密
注册时间
2016-1-27
查看详细资料
发表于 2020-3-27 01:10:22 | 显示全部楼层
本帖最后由 友 于 2020-3-29 21:42 编辑

特定的合成
recipes.addShapeless("experiencestone",<item:minecraft:iron_ingot>,[<minecraft:dirt>,<minecraft:dirt>],
function(out,ins,info) {   
    if (isNull(info.player) || info.player.isFake()) return out; // 如果由机器合成跳过处理
    return info.player.foodStats.foodLevel > 1 ? out : null;
},
//IRecipeAction
function(out,cInfo,player){
    if (isNull(player) || player.isFake() || player.world.remote) return; // 如果由机器合成跳过处理
    if (player.foodStats.saturationLevel > 0.15) {
        player.foodStats.saturationLevel -= 0.15;
    } else {
        player.foodStats.foodLevel -= 1;
    }
});



所有合成
import crafttweaker.events.IEventManager;
import crafttweaker.event.PlayerCraftedEvent;
import crafttweaker.player.IPlayer;

events.onPlayerCrafted(function(event as PlayerCraftedEvent) {
    val player as IPlayer = event.player;
    if (isNull(player) || player.isFake() || player.world.remote) return;
    if (player.foodStats.saturationLevel > 0.15) {
        player.foodStats.saturationLevel -= 0.15;
    } else {
        val foodLevel as int = player.foodStats.foodLevel;
        player.foodStats.foodLevel = max(0, foodLevel - 1);
    }
});


需要安装ctutils模组



回复

使用道具 举报

折叠 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
10828
钻石
性别
保密
注册时间
2020-2-21
查看详细资料
发表于 2020-3-27 01:21:34 | 显示全部楼层
recipes.addShapeless("experiencestone",输出物品,[合成物,合成物,合成物,合成物],
function(out,ins,cInfo){
    return out;
},
//IRecipeAction
function(out,cInfo,player){
    player.foodStats -= 1;
});

试试?
回复

使用道具 举报

xiaoxi喵 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
590
钻石
性别
保密
注册时间
2019-2-5
查看详细资料
 楼主| 发表于 2020-3-27 02:21:01 来自手机 | 显示全部楼层
本帖最后由 1398671127 于 2020-3-27 06:37 编辑
折叠 发表于 2020-3-27 01:21
recipes.addShapeless("experiencestone",输出物品,[合成物,合成物,合成物,合成物],
function(out,ins,cInf ...

不行,会报错,突然断网了,明天我再发报错吧.
神奇的是检查语法没错
  1. [PREINITIALIZATION][CLIENT][INFO] Current loaders after merging: [[preinit]]
  2. [PREINITIALIZATION][CLIENT][INFO] Loading scripts for loader with names [preinit]
  3. [PREINITIALIZATION][CLIENT][INFO] [preinit | SIDE_CLIENT]: Skipping file {[0:crafttweaker]: xiaoxi.zs} as we are currently loading with a different loader
  4. [PREINITIALIZATION][CLIENT][INFO] Completed script loading in: 2ms
  5. [PREINITIALIZATION][CLIENT][INFO] Current loaders after merging: [[preinit], [contenttweaker]]
  6. [PREINITIALIZATION][CLIENT][INFO] Loading scripts for loader with names [contenttweaker]
  7. [PREINITIALIZATION][CLIENT][INFO] [contenttweaker | SIDE_CLIENT]: Skipping file {[0:crafttweaker]: xiaoxi.zs} as we are currently loading with a different loader
  8. [PREINITIALIZATION][CLIENT][INFO] Completed script loading in: 0ms
  9. [PREINITIALIZATION][CLIENT][INFO] Current loaders after merging: [[preinit], [contenttweaker], [gregtech]]
  10. [PREINITIALIZATION][CLIENT][INFO] Loading scripts for loader with names [gregtech]
  11. [PREINITIALIZATION][CLIENT][INFO] [gregtech | SIDE_CLIENT]: Skipping file {[0:crafttweaker]: xiaoxi.zs} as we are currently loading with a different loader
  12. [PREINITIALIZATION][CLIENT][INFO] Completed script loading in: 0ms
  13. [INITIALIZATION][CLIENT][INFO] CraftTweaker: Building registry
  14. [INITIALIZATION][CLIENT][INFO] CraftTweaker: Successfully built item registry
  15. [INITIALIZATION][CLIENT][INFO] Current loaders after merging: [[preinit], [contenttweaker], [gregtech], [recipeevent | crafttweaker]]
  16. [INITIALIZATION][CLIENT][INFO] Loading scripts for loader with names [crafttweaker | recipeevent]
  17. [INITIALIZATION][CLIENT][INFO] [crafttweaker | SIDE_CLIENT]: Loading Script: {[0:crafttweaker]: xiaoxi.zs}
  18. [INITIALIZATION][CLIENT][ERROR] [crafttweaker]: Error executing {[0:crafttweaker]: xiaoxi.zs}: null
  19. java.lang.NullPointerException
  20.         at stanhebben.zenscript.type.natives.JavaMethod.rematch(JavaMethod.java:135)
  21.         at stanhebben.zenscript.expression.ExpressionCallVirtual.<init>(ExpressionCallVirtual.java:26)
  22.         at stanhebben.zenscript.type.natives.ZenNativeMember$InstanceGetValue.assign(ZenNativeMember.java:89)
  23.         at stanhebben.zenscript.parser.expression.ParsedExpressionAssign.compile(ParsedExpressionAssign.java:26)
  24.         at stanhebben.zenscript.statements.StatementExpression.compile(StatementExpression.java:27)
  25.         at stanhebben.zenscript.statements.StatementExpression.compile(StatementExpression.java:19)
  26.         at stanhebben.zenscript.expression.ExpressionJavaLambda.compile(ExpressionJavaLambda.java:75)
  27.         at stanhebben.zenscript.expression.ExpressionCallVirtual.compile(ExpressionCallVirtual.java:41)
  28.         at stanhebben.zenscript.statements.StatementExpression.compile(StatementExpression.java:27)
  29.         at stanhebben.zenscript.statements.StatementExpression.compile(StatementExpression.java:19)
  30.         at stanhebben.zenscript.ZenModule.compileScripts(ZenModule.java:152)
  31.         at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:215)
  32.         at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:105)
  33.         at crafttweaker.mc1120.events.CommonEventHandler.registerRecipes(CommonEventHandler.java:69)
  34.         at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_695_CommonEventHandler_registerRecipes_Register.invoke(.dynamic)
  35.         at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
  36.         at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
  37.         at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
  38.         at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:857)
  39.         at net.minecraftforge.common.crafting.CraftingHelper.loadRecipes(CraftingHelper.java:636)
  40.         at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:747)
  41.         at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:336)
  42.         at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:535)
  43.         at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)
  44.         at net.minecraft.client.main.Main.main(SourceFile:123)
  45.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  46.         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  47.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  48.         at java.lang.reflect.Method.invoke(Unknown Source)
  49.         at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
  50.         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
  51. [INITIALIZATION][CLIENT][INFO] Completed script loading in: 230ms
  52. [POSTINITIALIZATION][CLIENT][INFO] Removing recipes for various outputs
  53. [AVAILABLE][CLIENT][INFO] Fixed the RecipeBook
复制代码


回复

使用道具 举报

Remooonant 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
329
钻石
性别
保密
注册时间
2019-11-5
查看详细资料
发表于 2020-3-27 06:22:33 | 显示全部楼层
看看这个行不行
回复

使用道具 举报

xiaoxi喵 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
590
钻石
性别
保密
注册时间
2019-2-5
查看详细资料
 楼主| 发表于 2020-3-27 06:35:35 | 显示全部楼层
本帖最后由 1398671127 于 2020-3-27 07:32 编辑

可以发代码吗,图片有点难受
无效的
  1. SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:6 > No such member: playerCraftedEvent
  2. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:6 > Not a valid type
  3. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:8 > could not find type PlayerCraftedEvent
  4. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:9 > No such member in java.lang.Object: player
  5. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:10 > No such member in java.lang.Object: player
  6. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:11 > No such member in java.lang.Object: player
  7. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:13 > No such member in java.lang.Object: player
  8. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:13 > No such member in java.lang.Object: player
  9. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:13 > not a valid lvalue
  10. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:15 > No such member in java.lang.Object: player
  11. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:15 > not a valid lvalue
  12. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:16 > No such member in java.lang.Object: player
  13. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:16 > No such member in java.lang.Object: player
  14. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:16 > not a valid lvalue
  15. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:19 > No such member in java.lang.Object: player
  16. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:20 > No such member in java.lang.Object: player
  17. [SERVER_STARTED][SERVER][ERROR] xiaoxi.zs:20 > not a valid lvalue
复制代码

回复

使用道具 举报

GiNYAi 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
8543
钻石
性别
保密
注册时间
2012-3-31
查看详细资料
发表于 2020-3-27 09:50:43 | 显示全部楼层
似乎稍微慢了那么一点

  1. val stone = <minecraft:stone>;
  2. val apple = <minecraft:apple>;
  3. recipes.addShapeless("stone_apple", apple, [stone, stone],
  4.     function(out,ins,cInfo){
  5.         val player = cInfo.player;
  6.         val foodStats = player.foodStats;
  7.         if (foodStats.saturationLevel > 0) {
  8.             foodStats.saturationLevel = max( foodStats.saturationLevel - 2.5, 0);
  9.             return out;
  10.         } else if (foodStats.foodLevel > 0){
  11.             foodStats.foodLevel = max( foodStats.foodLevel - 4, 0);
  12.             return out;
  13.         }
  14.         return null;
  15.     } as crafttweaker.recipes.IRecipeFunction
  16. );
复制代码
回复

使用道具 举报

xiaoxi喵 当前离线
帖子
主题
精华
贡献
最后登录
1970-1-1
爱心
积分
590
钻石
性别
保密
注册时间
2019-2-5
查看详细资料
 楼主| 发表于 2020-3-27 09:54:55 | 显示全部楼层
GiNYAi 发表于 2020-3-27 09:50
似乎稍微慢了那么一点

是的大佬
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册(register)

本版积分规则

Archiver|小黑屋|Mcbbs.net ( 京ICP备15023768号-1 ) | 京公网安备 11010502037624号 | 手机版

GMT+8, 2020-4-10 08:18 , Processed in 0.037426 second(s), Total 15, Slave 14 queries, Release: Build.2020.04.01.1425, Gzip On, MemCached On.

"Minecraft"以及"我的世界"为Mojang Synergies AB的商标 本站与Mojang以及微软公司没有从属关系

© 2010-2020 我的世界中文论坛 版权所有 本站原创图文内容版权属于原创作者,未经许可不得转载

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