Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemSaddleBlockBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
9 public Random m_random = new();
10
11 public override int[] HandledBlocks => [158];
12
13 public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) {
14 BodyRaycastResult? bodyRaycastResult = componentMiner.Raycast<BodyRaycastResult>(ray, RaycastMode.Interaction);
15 if (bodyRaycastResult.HasValue) {
16 ComponentHealth componentHealth = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent<ComponentHealth>();
17 if (componentHealth == null
18 || componentHealth.Health > 0f) {
19 string entityTemplateName = $"{bodyRaycastResult.Value.ComponentBody.Entity.ValuesDictionary.DatabaseObject.Name}_Saddled";
20 Entity entity = DatabaseManager.CreateEntity(Project, entityTemplateName, false);
21 if (entity != null) {
22 ComponentBody componentBody = entity.FindComponent<ComponentBody>(true);
23 componentBody.Position = bodyRaycastResult.Value.ComponentBody.Position;
24 componentBody.Rotation = bodyRaycastResult.Value.ComponentBody.Rotation;
25 componentBody.Velocity = bodyRaycastResult.Value.ComponentBody.Velocity;
26 entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
27 Project.RemoveEntity(bodyRaycastResult.Value.ComponentBody.Entity, true);
28 Project.AddEntity(entity);
29 m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, true);
30 componentMiner.RemoveActiveTool(1);
31 }
32 }
33 return true;
34 }
35 return false;
36 }
37
38 public override void Load(ValuesDictionary valuesDictionary) {
39 base.Load(valuesDictionary);
40 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
41 }
42 }
43}
virtual void RemoveActiveTool(int removeCount)
virtual object Raycast(Ray3 ray, RaycastMode mode, bool raycastTerrain=true, bool raycastBodies=true, bool raycastMovingBlocks=true, float? Reach=null)
发出射线检测,检测玩家点击到的目标
static Entity CreateEntity(Project project, SpawnEntityData spawnEntityData, bool throwIfNotFound)
override void Load(ValuesDictionary valuesDictionary)
override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary
Vector3 Position
定义 Ray3.cs:3