UID 82897 性别 保密 经验 EP 铁粒 粒 回帖 0 主题 精华 在线时间 小时 注册时间 2021-7-23 最后登录 1970-1-1
本帖最后由 Cat_Anchor 于 2023-9-30 06:52 编辑 前言
上期,我们实现了主要功能。现在我们来解决那个漏洞。解决漏洞
这个漏洞的出现原因是播放时,原先的分数就被破坏掉了,因此只能想办法还原这个分数。上期,我们举例说有3个标记,播放前的分数是1,2,3,播放后就成了-2,-1,0。容易看出,两组中每个数字的差为3。所以把第二组的每个数字加3就可以还原出第一组的数据。那这个3是根据什么决定的?显然是标记数量。所以只要求出标记总数,然后把这个数字与每个标记的分数相加,再把结果赋值给标记的moving分数就好了。因此,end事件的代码如下。"end": { "run_command": { "command": [ "camera @p clear", //播放结束,首先清除玩家的相机,使相机回到正常状态 "camera @p[tag=fade] fade time 1.1 0.3 1.1", //淡入淡出功能 "scoreboard objectives add moving_temp dummy", //创建临时的计分板,用于获取标记数量 "scoreboard players operation @s moving_temp += * moving2", //计算标记数量 "scoreboard players operation @e[type=supplementary:moving_mark] moving += @s moving_temp", //把标记数量与moving的分数加起来,并将结果赋值给moving "scoreboard objectives remove moving_temp" //移除临时的计分板 ] } } 复制代码
到这里,这个实体算是正式制作完成了。不过还需要在资源包根目录下entity文件夹中创建相关文件,并定义材料、纹理、模型和渲染控制器才可以成功显示。为了省事,我直接用栓绳的材料和渲染控制器。{ "format_version": "1.10.0", "minecraft:client_entity": { "description": { "identifier": "supplementary:moving_mark", //命名空间ID "materials": { "default": "leash_knot" //材料 }, "textures": { "default": "textures/entity/moving_mark" //纹理 }, "geometry": { "default": "geometry.moving_mark" //模型 }, "render_controllers": [ "controller.render.leash_knot" //渲染控制器 ] } } } 复制代码
接着在/models/entity下定义模型。{"format_version":"1.12.0","minecraft:geometry":[{"description":{"identifier":"geometry.moving_mark","texture_width":32,"texture_height":32,"visible_bounds_width":2,"visible_bounds_height":2.5,"visible_bounds_offset":[0,0.75,0]},"bones":[{"name":"bb_main","pivot":[0,0,0],"cubes":[{"origin":[-4,3,-4],"size":[8,13,8],"uv":[0,0]}]}]}]} 复制代码
还需要纹理,不过这就简单多了。
总之,现在,基本的功能已经制作完成。还有些其他功能以及用物品执行命令来让操作简单易懂等,那就非常简单了。
最后的实体代码如下。{ "format_version": "1.20.10", "minecraft:entity": { "description": { "identifier": "supplementary:moving_mark", "is_spawnable": false, "is_summonable": true, "is_experimental": false }, "component_groups": { "speed3": { "minecraft:timer": { "looping": false, "time": 3, "randomInterval": false, "time_down_event": { "event": "camera" } } }, "speed4": { "minecraft:timer": { "looping": false, "time": 4, "randomInterval": false, "time_down_event": { "event": "camera" } } }, "speed5": { "minecraft:timer": { "looping": false, "time": 5, "randomInterval": false, "time_down_event": { "event": "camera" } } }, "speed6": { "minecraft:timer": { "looping": false, "time": 6, "randomInterval": false, "time_down_event": { "event": "camera" } } }, "speed7": { "minecraft:timer": { "looping": false, "time": 7, "randomInterval": false, "time_down_event": { "event": "camera" } } } }, "components": { "minecraft:tick_world": {}, "minecraft:persistent": {}, "minecraft:damage_sensor": { "triggers": { "cause": "all", "deals_damage": false } }, "minecraft:type_family": { "family": [ "inanimate" ] }, "minecraft:physics": { "has_gravity": false, "has_collision": false }, "minecraft:pushable": { "is_pushable": false, "is_pushable_by_piston": false }, "minecraft:fire_immune": true, "minecraft:nameable": { "allow_name_tag_renaming": false } }, "events": { "speed3": { "add": { "component_groups": [ "speed3" ] }, "run_command": { "command": "function moving_type3" } }, "speed4": { "add": { "component_groups": [ "speed4" ] }, "run_command": { "command": "function moving_type4" } }, "speed5": { "add": { "component_groups": [ "speed5" ] }, "run_command": { "command": "function moving_type5" } }, "speed6": { "add": { "component_groups": [ "speed6" ] }, "run_command": { "command": "function moving_type6" } }, "speed7": { "add": { "component_groups": [ "speed7" ] }, "run_command": { "command": "function moving_type7" } }, "start_moving": { "run_command": { "command": [ "function moving_speed", "execute if entity @p[tag=!show_mark] run effect @e[type=supplementary:moving_mark] invisibility 8 255 true", "execute if entity @p[tag=!show_player] run playanimation @a animation.player.hidden", "execute if entity @p[tag=auto_tp] run tp @p @s" ] } }, "minecraft:entity_spawned": { "run_command": { "command": [ "scoreboard objectives add moving dummy", "scoreboard objectives add moving2 dummy", "scoreboard players add @s moving2 1", "scoreboard players operation @s moving += * moving2" ] } }, "camera": { "remove": { "component_groups": [ "start_moving" ] }, "run_command": { "command": [ "scoreboard players remove @e[type=supplementary:moving_mark] moving 1", "event entity @e[type=supplementary:moving_mark,scores={moving=1}] start_moving", "execute unless entity @e[type=supplementary:moving_mark,scores={moving=1..},c=1] run execute as @e[type=supplementary:moving_mark,scores={moving=0},c=1] run event entity @s end" ] } }, "end": { "run_command": { "command": [ "camera @p clear", "camera @p[tag=fade] fade time 1.1 0.3 1.1", "scoreboard objectives add moving_temp dummy", "scoreboard players operation @s moving_temp += * moving2", "scoreboard players operation @e[type=supplementary:moving_mark] moving += @s moving_temp", "scoreboard objectives remove moving_temp" ] } } } } } 复制代码
后记
这一期,我们完成了一个实体的制作,这个实体是相机缓动的关键部分。
什么?模板包?直接去我开发的相机平滑移动 附加包就好了,这三篇教程中的所有代码都是那个附加包里的(作了一点小改动)。其实这里已经放出了大部分代码,还有模型、纹理等,直接复制也可以。