Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemEggBlockBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
13 public Random m_random = new();
14
15 public const string fName = "SubsystemEggBlockBehavior";
16
17 public override int[] HandledBlocks => [];
18
19 public override bool OnHitAsProjectile(CellFace? cellFace, ComponentBody componentBody, WorldItem worldItem) {
20 int data = Terrain.ExtractData(worldItem.Value);
21 bool isCooked = EggBlock.GetIsCooked(data);
22 bool isLaid = EggBlock.GetIsLaid(data);
23 if (!isCooked
24 && (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative || m_random.Float(0f, 1f) <= (isLaid ? 0.15f : 1f))) {
25 try {
26 EggBlock.EggType eggType = m_eggBlock.GetEggType(data);
27 Entity entity = DatabaseManager.CreateEntity(Project, eggType.TemplateName, true);
28 entity.FindComponent<ComponentBody>(true).Position = worldItem.Position;
31 m_random.Float(0f, (float)Math.PI * 2f)
32 );
33 entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0.25f;
34 Project.AddEntity(entity);
35 }
36 catch (Exception e) {
37 Log.Error($"Spawning creature from egg (index: {(data >> 4) & 0xFFF}) error: {e}");
38 if (worldItem is Projectile projectile) {
39 ComponentGui componentGui = projectile.Owner?.Entity.FindComponent<ComponentGui>();
40 if (componentGui != null) {
41 componentGui.DisplaySmallMessage(LanguageControl.Get(fName, "1"), Color.White, true, false);
42 }
43 }
44 }
45 }
46 return true;
47 }
48
49 public override void Load(ValuesDictionary valuesDictionary) {
50 base.Load(valuesDictionary);
51 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
53 }
54 }
55}
static void Error(object message)
定义 Log.cs:80
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
static Entity CreateEntity(Project project, SpawnEntityData spawnEntityData, bool throwIfNotFound)
static bool GetIsLaid(int data)
static bool GetIsCooked(int data)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
override void Load(ValuesDictionary valuesDictionary)
override bool OnHitAsProjectile(CellFace? cellFace, ComponentBody componentBody, WorldItem worldItem)
static int ExtractData(int value)
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary
static Color White
static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
static readonly Vector3 UnitY