= 创作分享 =
你问我答
1.12.2【CraftTweaker】if 判断时的问题
QQ酱593674

1.12.2【CraftTweaker】if 判断时的问题

QQ酱593674 于 2024-4-3 03:17 ( 1月前 ) [复制链接] [只看楼主] [打印]
177 1
20RF
import crafttweaker.event.IPlayerEvent;
import crafttweaker.block.IBlock;
import crafttweaker.player.IPlayer;
import crafttweaker.event.IEventCancelable;
import crafttweaker.event.PlayerInteractBlockEvent;//导包

#右键板条箱时提示
events.onPlayerInteractBlock(function(tishi as crafttweaker.event.PlayerInteractBlockEvent){
        var block as IBlock  = tishi.block;
        var player as IPlayer = tishi.player;
       
        for i in 0 to 5 {
                if (!isNull(block) && block.definition.id == <variedcommodities:crate>.definition.makeStack(i)){
                        tishi.cancel();
                        tishi.player.sendStatusMessage(format.red("里面似乎装着什么,试试把他砸碎。"));}
                        }
});

问提:橙色部分是我需要填入方块ID的部分(他有枚举值),我用了遍历的方法,但是提示我要填入字符串,这部分可以用数组之类的方法优雅填入吗?试过"variedcommodities:crate:*"也不行

发表于 2024-4-3 03:17:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

回复 | 举报

该帖共收到 1 条回复!
5中生有
没看懂,.definition.makeStack(meta)返回的是一个IItemstack吧,block.definition.id返回的是一个string,或许应该用
  1. .definition.makeStack(meta).definition.id
复制代码


不过这有点麻烦啊,你是要判断是不是指定方块吗?我看别人是这样写的
  1. if (block.definition.id == "minecraft:wool" && block.meta == 13) { // 检测方块ID与metadata
复制代码


关于Metadata:https://youyi580.gitbook.io/zentutorial/easy/crafting-table/metadata
修改方块掉落物:https://youyi580.gitbook.io/zentutorial/actual-combat/events/tweaking-block-drops
发表于 2024-4-19 03:11:07 | 只看该作者

回复 | 举报

百科目前不允许匿名发帖哦~ 请先 [ 登陆 ][ 注册 ] 吧~

本版积分规则

发新帖
  • 回复
  • 点评
  • 评分

[ MC百科(mcmod.cn) 除另有声明,所有开放公共编辑的内容均使用 BY-NC-SA 3.0 协议 ]

Minecraft百科CC协议
快速回复 返回顶部 返回列表