附加包教程:38.实体(四)
本帖最后由 Cat_Anchor 于 2023-9-30 06:52 编辑前言
上期,我们实现了主要功能。现在我们来解决那个漏洞。
https://klpbbs.com/static/image/hrline/line5.png
解决漏洞
这个漏洞的出现原因是播放时,原先的分数就被破坏掉了,因此只能想办法还原这个分数。上期,我们举例说有3个标记,播放前的分数是1,2,3,播放后就成了-2,-1,0。容易看出,两组中每个数字的差为3。所以把第二组的每个数字加3就可以还原出第一组的数据。那这个3是根据什么决定的?显然是标记数量。所以只要求出标记总数,然后把这个数字与每个标记的分数相加,再把结果赋值给标记的moving分数就好了。因此,end事件的代码如下。
"end": {
"run_command": {
"command": [
"camera @p clear", //播放结束,首先清除玩家的相机,使相机回到正常状态
"camera @p 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 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":},"bones":[{"name":"bb_main","pivot":,"cubes":[{"origin":[-4,3,-4],"size":,"uv":}]}]}]}
还需要纹理,不过这就简单多了。
https://pic.imgdb.cn/item/64aa75081ddac507cc3e7c6a.png
总之,现在,基本的功能已经制作完成。还有些其他功能以及用物品执行命令来让操作简单易懂等,那就非常简单了。
最后的实体代码如下。
{
"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 run effect @e invisibility 8 255 true",
"execute if entity @p run playanimation @a animation.player.hidden",
"execute if entity @p 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 moving 1",
"event entity @e start_moving",
"execute unless entity @e run execute as @e run event entity @s end"
]
}
},
"end": {
"run_command": {
"command": [
"camera @p clear",
"camera @p 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 moving += @s moving_temp",
"scoreboard objectives remove moving_temp"
]
}
}
}
}
}
https://klpbbs.com/static/image/hrline/line2.png
后记
这一期,我们完成了一个实体的制作,这个实体是相机缓动的关键部分。
什么?模板包?直接去我开发的相机平滑移动附加包就好了,这三篇教程中的所有代码都是那个附加包里的(作了一点小改动)。其实这里已经放出了大部分代码,还有模型、纹理等,直接复制也可以。
第三十七期 第三十八期 第三十九期 感谢作者大大的一系列教程 本帖最后由 Po_Cu 于 2023-9-30 12:39 编辑
作者,附加包能不能改玩家的各项属性?(比如伤害值) 本帖最后由 Cat_Anchor 于 2023-9-30 13:44 编辑
Po_Cu 发表于 2023-9-30 12:27
作者,附加包能不能改玩家的各项属性?(比如伤害值)
可以改,例如要改玩家的伤害就是在entities文件夹下player.json里改这个地方
"minecraft:attack": {
"damage": 1 //伤害值
}
页: [1]