暴风湛娟 发表于 2023-1-11 09:50:30

附加包教程:9.物品(四) - 教程中心 - Minecraft(我的世界)苦力怕论坛

<br /><br /><table cellspacing="0" class="t_table" ><tr><td><font size="6">前言<br /></font></td></tr><tr><td>上期,我们学习了所有我已知的物品事件方法。也就是说,我们已经学完了物品相关知识。这一期,我们要进行实战演练。<br /></td></tr><tr><td><img onerror="study_killerrpic(this)" id="aimg_rWpsq" 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 />目标:一把剑(命名空间ID:test_pack:test_sword),伤害为26,创造模式下不能拿着它破坏方块,有附魔闪光(即使还没有附魔),附魔能力是70,耐久是5000,掉耐久几率是50%,潜行打到生物会造成范围5格伤害并掉5点耐久,潜行打破方块会有4分之1几率给持有者清除所有状态效果,然后增加状态效果(力量5、急迫5,都是30秒),然后掉5点耐久,不会刷新掉,可以放在副手。<br /></td></tr><tr><td><img onerror="study_killerrpic(this)" id="aimg_gtFU3" 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 />既然是一把剑,那么首先在components里添加:<br /><ol><li>&quot;tag:minecraft:sword&quot;</ol><br />伤害是26,创造模式下不能拿着它破坏方块,有附魔闪光。这3个条件分别代表3个组件,继续添加:<br /><ol><li>&quot;minecraft:damage&quot;: 26,<br /><li>&quot;minecraft:can_destroy_in_creative&quot;: false,<br /><li>&quot;minecraft:glint&quot;: true<br /><li></ol><br />附魔能力是70,可以用minecraft:enchantable解决。<br /><ol><li>&quot;minecraft:enchantable&quot;:{&quot;value&quot;:70,&quot;slot&quot;:&quot;sword&quot;}</ol><br />耐久是5000,掉耐久几率是50%,可以用minecraft:durability解决。<br /><ol><li>&quot;minecraft:durability&quot;:{&quot;damage_chance&quot;:0.5,&quot;max_durability&quot;:5000}</ol><br />接下来的一些功能有些复杂,我们先看最后的“不会刷新掉,可以放在副手”,可以用2个组件解决。<br /><ol><li>&quot;minecraft:should_despawn&quot;: false<br /><li>&quot;minecraft:allow_off_hand&quot;: true</ol><br />然后,让我们看看题目里的隐藏要求。既然是剑,那么应该是破坏蜘蛛网和竹子很快,而且是装备,所以要装备在手上,最大堆叠数量应该是1。后者可以很简单地解决,前者则需要一点点功夫。剑没有效率附魔,所以use_efficiency应该是false。然后还得定义一个耐久下降的事件。<br /><ol><li>&quot;minecraft:hand_equipped&quot;:true,&quot;minecraft:max_stack_size&quot;:1,&quot;minecraft:digger&quot;:{&quot;use_efficiency&quot;:false,&quot;destroy_speeds&quot;:[{&quot;block&quot;:&quot;minecraft:web&quot;,&quot;speed&quot;:30,&quot;on_dig&quot;:{&quot;event&quot;:&quot;damage&quot;}},{&quot;block&quot;:&quot;minecraft:bamboo&quot;,&quot;speed&quot;:30,&quot;on_dig&quot;:{&quot;event&quot;:&quot;damage&quot;}}]}<br /><li>//上面是组件,下面是事件<br /><li>&quot;damage&quot;:{&quot;damage&quot;:{&quot;type&quot;:&quot;durability&quot;,&quot;amount&quot;:1,&quot;target&quot;:&quot;self&quot;}}</ol><br />还有,剑应该能被修复,而且应该放在创造模式物品栏的“剑”这一类里。新版本中,同类自定义物品的修复无需额外组件。<br /><ol><li>&quot;minecraft:creative_category&quot;: {&quot;parent&quot;:&quot;itemGroup.name.sword&quot;}</ol><br />最后是最难的地方。“潜行打到生物会造成范围5格伤害并掉5点耐久,潜行打破方块会有4分之1几率给持有者清除所有状态效果,然后增加状态效果(力量5、急迫5,都是30秒),然后掉5点耐久。”<br />这一堆东西可以用一个组件搞定,主要是事件怎么写。组件如下。<br /><ol><li>&quot;minecraft:weapon&quot;:{<br /><li>&nbsp;&nbsp;&quot;on_hit_block&quot;: &quot;destroy&quot;,<br /><li>&nbsp;&nbsp;&quot;on_hurt_entity&quot;: &quot;hurt&quot;,<br /><li>&nbsp;&nbsp;&quot;on_not_hurt_entity&quot;: &quot;damage&quot;<br /><li>} //注:1.20.40.21中移除了这个组件。</ol><br />然后再运用sequence和randomize写一下事件。这个有点长,为了便于理解,我还没有像上面一样压缩代码,所以用折叠块折起来。<br /><input type="button" class="yc" value="点击展开折叠内容" onClick="n = this.parentNode.parentNode.lastChild;if(n.style.display == 'none') {n.style.display = 'block';this.value='点击折叠展开内容';} else {n.style.display = 'none';this.value='点击展开折叠内容';} return false;"/> <table style="word-break:break-all;word-wrap:break-all;"><td><ol><li>&quot;hurt&quot;: {<br /><li>&nbsp;&nbsp;&quot;sequence&quot;: [<br /><li>&nbsp; &nbsp; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;damage&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;type&quot;: &quot;durability&quot;,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;amount&quot;: 5,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;target&quot;: &quot;self&quot;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li>&nbsp; &nbsp; },<br /><li>&nbsp; &nbsp; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;condition&quot;: &quot;q.is_sneaking&quot;,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;run_command&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;command&quot;: &quot;damage @e 26 entity_attack entity @p&quot;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li>&nbsp; &nbsp; }<br /><li>&nbsp;&nbsp;]<br /><li>},<br /><li>&quot;destroy&quot;: {<br /><li>&nbsp;&nbsp;&quot;randomize&quot;: [<br /><li>&nbsp; &nbsp; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;weight&quot;: 3,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;sequence&quot;: [<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &quot;run_command&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&quot;command&quot;: &quot;effect @p clear&quot;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;},<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &quot;run_command&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&quot;command&quot;: [<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;effect @p strength 30 4&quot;,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&quot;effect @p haste 30 4&quot;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;]<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;},<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &quot;damage&quot;: {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&quot;type&quot;: &quot;durability&quot;,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&quot;amount&quot;: 5,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&quot;target&quot;: &quot;self&quot;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;]<br /><li>&nbsp; &nbsp; },<br /><li>&nbsp; &nbsp; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&quot;weight&quot;: 1<br /><li>&nbsp; &nbsp; }<br /><li>&nbsp;&nbsp;]<br /><li>}</ol></td></table><br />最后,把以上写的一大堆东西结合在一起,成为一个文件,游戏内就可以起效了!<br /></td></tr><tr><td><img onerror="study_killerrpic(this)" id="aimg_G2MM0" 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 /><a href="https://klpbbs.com/forum.php?mod=attachment&amp;aid=MjQ3NDAyfGJkNmJjNTJhfDE3MTc5MjQxMjl8MHw4MjA3Nw%3D%3D" target="_blank">test_sword.json</a><br /><br /><br /><a href="https://klpbbs.com/thread-82050-1-1.html" target="_blank">第八期</a> 第九期 <a href="https://klpbbs.com/thread-82444-1-1.html" target="_blank">第十期</a><br>来源:<a href="https://klpbbs.com/thread-82077-1-7.html" target="_blank">https://klpbbs.com/thread-82077-1-7.html</a><br>免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

偷喝汽水 发表于 2023-1-11 09:55:26

感谢分享

软芙朵朵 发表于 2023-1-11 09:57:39

教程相当高产(

小鱼偶偶泡 发表于 2024-2-16 13:38:43

<br /><br />请问潜行打到实体的事件里,第13行的entity @p用意何在? 当我触发这个事件时,我自己也会受到伤害..<br />如果我想要这个范围内除了攻击发出者之外的其他实体受到伤害呢?<br />

櫻花射手 发表于 2024-2-16 17:34:44

<br />命令/damage格式:/damage &lt;目标&gt; &lt;伤害&gt; &lt;伤害来源&gt; entity &lt;施加者&gt;。所以entity @p的意思是伤害是玩家造成的,不加这个就不会掉经验。不过也确实会对自己造成伤害,可以改成/damage @e 26 entity_attack entity @p。指定一个最小范围,可以防止选择器选择到自己。

布丁果沙 发表于 2024-2-16 18:12:04

<br />感谢分享..这样的话攻击范围就是一个&quot;空心圆&quot;了,这样也会产生一个小小的问题,就是在一个微乎其微的情况下,想要攻击的对象和自己重合在一起,它就不会受到伤害,不过毕竟是小概率事件,就不考虑了,这里让我好奇,r能取什么值?因为这里出现了0.1,它还能是0.01之类的吗,因为我了解一个物品的伤害和实体的生命值都必须是整数<br />
页: [1]
查看完整版本: 附加包教程:9.物品(四) - 教程中心 - Minecraft(我的世界)苦力怕论坛