桃子起泡酒 发表于 2023-1-15 10:06:50

附加包教程:15.方块(四) - 教程中心 - Minecraft(我的世界)苦力怕论坛

<br /><br /><table cellspacing="0" class="t_table" ><tr><td><font size="6">前言<br /></font></td></tr><tr><td><br />上期,我们学习了所有我已知的方块事件方法。但我们还没有学习方块文档的高级写法——定义方块状态和方块状态决定的组件(方块排列)。这期,我们就来学习它们。<br /></td></tr><tr><td><img onerror="study_killerrpic(this)" id="aimg_zVHeX" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" src="https://klpbbs.com/static/image/hrline/line5.png" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="1" border="0" alt="" /></td></tr><tr><td><font size="6">基本结构<br /></font></td></tr><tr><td><br />它们分别使用description下states和与description同级的permutations决定。请看代码示例。<br /><ol><li><br /><li>{<br /><li>&nbsp;&nbsp;&quot;format_version&quot;: &quot;1.21.0&quot;,<br /><li>&nbsp;&nbsp;&quot;minecraft:block&quot;: {<br /><li>&nbsp; &nbsp; &quot;description&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;identifier&quot;: &quot;test_pack:test_block&quot;,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;states&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;test_pack:state_a&quot;: [ //这里的test_pack:state_a就是状态名称。状态有3种,这是第一种,布尔值,就是单纯的真或假。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; true, //真<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; false //假<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;],<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;test_pack:state_b&quot;: [ //这是第二种,指定文本。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &quot;option_a&quot;, //选项1<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &quot;option_b&quot;, //选项2<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &quot;option_c&quot; //选项3<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;],<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;test_pack:state_c&quot;: [ //这是第三种,指定数字。这时数字要介于0-15之间。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 1,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 2,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 3<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;]<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li>&nbsp; &nbsp; },<br /><li>&nbsp; &nbsp; &quot;components&quot;: {不要在意这些细节},<br /><li>&nbsp; &nbsp; &quot;events&quot;: {不要在意这些细节},<br /><li>&nbsp; &nbsp; &quot;permutations&quot;: [ //在意这里就对了!这里用于存放在哪个状态下方块该拥有哪个组件。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;{ //一个项目<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;condition&quot;: &quot;q.block_state('test_pack:state_a') == true&quot;, //条件,使用了Molang表达式,这个的意思是查询方块状态test_pack:state_a是否为真,如果是,就应用下面的这些组件来代替原本的组件。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;components&quot;: {...} //这里写在这个情形下的组件,用来代替原本的组件。如果原本有一个组件,这里有一个相同的组件,则后者覆盖前者。如果这里有一个原本没有的组件,会直接加上这个组件。如果原本有一个这里没有的组件,原本的组件继续生效。简而言之,这里只能替换和增加组件,不能删除原本的组件。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;},<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;{ //又一个项目<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;condition&quot;: &quot;q.block_state('test_pack:state_b') == 'option_a'&quot;, //意思是,查询方块状态test_pack:state_b是否是“option_a”,如果是,就应用下面的这些组件来代替原本的组件。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;components&quot;: {...}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;},<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;{ //又是一个项目<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;condition&quot;: &quot;q.block_state('test_pack:state_c') == 0&quot;, //意思是,查询方块状态test_pack:state_c是否为0,如果是,就应用下面的这些组件来代替原本的组件。<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;components&quot;: {...}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li>&nbsp; &nbsp; ]<br /><li>&nbsp;&nbsp;}<br /><li>}<br /><li></ol><br />以上就是状态和状态决定组件的用法了。<br /></td></tr><tr><td><img onerror="study_killerrpic(this)" id="aimg_fQ1FF" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" src="https://klpbbs.com/static/image/hrline/line1.png" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="1" border="0" alt="" /></td></tr><tr><td><font size="6">高级内容<br /></font></td></tr><tr><td><br />states和permutations只是固定的用法,这一段我们来说说Molang表达式。<br />所谓Molang,就是一种简单的基于表达式的语言,旨在运行时快速、数据驱动地计算值,并与游戏中的值和系统直接相连。它的重点是使像动画这样的低级系统支持内部和外部创作者的灵活的数据驱动行为,同时保持高性能。<font size="2">抄官网ing...</font><br />嗯,既然官网都说了Molang“是一种简单的基于表达式的语言”了,其实它还真的不怎么难。我们使用Molang时,大部分情况都是用“query.吧啦吧啦(吧啦吧啦a,吧啦吧啦b)”这种形式的查询函数,至于剩下的,那就是“variable.吧啦吧啦”在地物和实体动画文档里比较常见,还有“math.吧啦吧啦(吧啦吧啦a,吧啦吧啦b)”在动画文档里比较常见,“context.吧啦吧啦”在物品文档和动画文档里有点用,其他的似乎就没啥了。<br />其实重点只需要掌握a==b是a等于b,a!=b是a不等于b,还有什么+-*/这类的基础运算符就好了。然后就是疯狂翻官方文档。那里有一个<a href="https://learn.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/examples/molangconcepts/queryfunctions" rel="external nofollow" onClick="saya_extlink_golink('https://learn.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/examples/molangconcepts/queryfunctions');return false;" target="_blank">超级长的查询函数的列表</a>,从查询时间和天数,到查询物品耐久度,甚至是查询月相都有对应的函数,主要看看那里就好。不过那全是英文,还得找个好用的翻译器,有点不方便。<br /></td></tr><tr><td><img onerror="study_killerrpic(this)" id="aimg_z9L2o" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" src="https://klpbbs.com/static/image/hrline/line1.png" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="1" border="0" alt="" /></td></tr><tr><td><font size="6">总结<br /></font></td></tr><tr><td><br />这一期,我们学习了方块状态和它衍生出来的控制方块组件的功能。关于方块的学习即将结束,至于方块的实战运用,与物品大同小异,都是拼命地复制粘贴那些状态、组件和事件,我就不多说了。<br />从一开始以来,我们学习了配方、函数、功能域、迷雾、物品、方块、模型和战利品表,这么多内容。是时候了,我们下期就来学习子包。<br /><br /><br /><a href="https://klpbbs.com/thread-83028-1-1.html" target="_blank">第十四期</a> 第十五期 <a href="https://klpbbs.com/thread-83540-1-1.html" target="_blank">第十六期</a><br>来源:<a href="https://klpbbs.com/thread-83284-1-1.html" target="_blank">https://klpbbs.com/thread-83284-1-1.html</a><br>免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

娅静小仙女 发表于 2023-1-15 10:10:12

感谢分享
页: [1]
查看完整版本: 附加包教程:15.方块(四) - 教程中心 - Minecraft(我的世界)苦力怕论坛