Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemMagnetBlockBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
9 public DynamicArray<Vector3> m_magnets = [];
10
11 public const int MaxMagnets = 8;
12
13 public override int[] HandledBlocks => [167];
14
15 public int MagnetsCount => m_magnets.Count;
16
17 public Vector3 FindNearestCompassTarget(Vector3 compassPosition) {
18 if (m_magnets.Count > 0) {
19 float num = float.MaxValue;
21 for (int i = 0; i < m_magnets.Count && i < 8; i++) {
22 Vector3 vector = m_magnets.Array[i];
23 float num2 = Vector3.DistanceSquared(compassPosition, vector);
24 if (num2 < num) {
25 num = num2;
26 v = vector;
27 }
28 }
29 return v + new Vector3(0.5f);
30 }
31 float num3 = float.MaxValue;
32 Vector3 v2 = Vector3.Zero;
33 foreach (PlayerData playersDatum in m_subsystemPlayers.PlayersData) {
34 Vector3 spawnPosition = playersDatum.SpawnPosition;
35 float num4 = Vector3.DistanceSquared(compassPosition, spawnPosition);
36 if (num4 < num3) {
37 num3 = num4;
38 v2 = spawnPosition;
39 }
40 }
41 return v2 + new Vector3(0.5f);
42 }
43
44 public override void Load(ValuesDictionary valuesDictionary) {
45 base.Load(valuesDictionary);
46 m_subsystemPlayers = Project.FindSubsystem<SubsystemPlayers>(true);
47 string value = valuesDictionary.GetValue<string>("Magnets");
48 m_magnets = new DynamicArray<Vector3>((IEnumerable<Vector3>)HumanReadableConverter.ValuesListFromString<Vector3>(';', value));
49 }
50
51 public override void Save(ValuesDictionary valuesDictionary) {
52 base.Save(valuesDictionary);
53 string value = HumanReadableConverter.ValuesListToString(';', m_magnets.ToArray());
54 valuesDictionary.SetValue("Magnets", value);
55 }
56
57 public override void OnBlockAdded(int value, int oldValue, int x, int y, int z) {
58 m_magnets.Add(new Vector3(x, y, z));
59 }
60
61 public override void OnBlockRemoved(int value, int newValue, int x, int y, int z) {
62 m_magnets.Remove(new Vector3(x, y, z));
63 }
64
65 public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ) {
66 int cellValue = SubsystemTerrain.Terrain.GetCellValue(x, y - 1, z);
67 if (BlocksManager.Blocks[Terrain.ExtractContents(cellValue)].IsNonAttachable(cellValue)) {
68 SubsystemTerrain.DestroyCell(
69 0,
70 x,
71 y,
72 z,
73 0,
74 false,
75 false
76 );
77 }
78 }
79 }
80}
Engine.Vector3 Vector3
virtual bool IsNonAttachable(int value)
override void OnBlockAdded(int value, int oldValue, int x, int y, int z)
override void Load(ValuesDictionary valuesDictionary)
override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
override void Save(ValuesDictionary valuesDictionary)
override void OnBlockRemoved(int value, int newValue, int x, int y, int z)
Vector3 FindNearestCompassTarget(Vector3 compassPosition)
static int ExtractContents(int value)
ValuesDictionary ValuesDictionary
static float DistanceSquared(Vector3 v1, Vector3 v2)
static readonly Vector3 Zero