Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemSoilBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
8 public Random m_random = new();
9
10 public Dictionary<Point3, bool> m_toDegrade = [];
11
12 public Dictionary<Point3, bool> m_toHydrate = [];
13
14 public override int[] HandledBlocks => [168];
15
17
18 public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody) {
19 if (componentBody.Mass > 20f
20 && !componentBody.IsCrouching) {
21 Vector3 velocity2 = componentBody.Velocity;
22 if (velocity2.Y < -3f
23 || (velocity2.Y < 0f && m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta && velocity2.LengthSquared() > 1f)) {
24 m_toDegrade[cellFace.Point] = true;
25 }
26 }
27 }
28
29 public override void OnPoll(int value, int x, int y, int z, int pollPass) {
30 bool hydration = SoilBlock.GetHydration(Terrain.ExtractData(value));
31 if (DetermineHydration(x, y, z, 3)) {
32 if (!hydration) {
33 m_toHydrate[new Point3(x, y, z)] = true;
34 }
35 }
36 else if (hydration) {
37 m_toHydrate[new Point3(x, y, z)] = false;
38 }
39 }
40
41 public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ) {
42 int cellValue = SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z);
43 if (DegradesSoilIfOnTopOfIt(cellValue)) {
44 int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(x, y, z);
45 SubsystemTerrain.ChangeCell(x, y, z, Terrain.ReplaceContents(cellValue2, 2));
46 }
47 }
48
49 public override void Load(ValuesDictionary valuesDictionary) {
50 base.Load(valuesDictionary);
51 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
52 }
53
54 public virtual void Update(float dt) {
55 if (m_subsystemTime.PeriodicGameTimeEvent(2.5, 0.0)) {
56 foreach (Point3 key2 in m_toDegrade.Keys) {
57 if (SubsystemTerrain.Terrain.GetCellContents(key2.X, key2.Y, key2.Z) == 168) {
58 int cellValue = SubsystemTerrain.Terrain.GetCellValue(key2.X, key2.Y, key2.Z);
59 SubsystemTerrain.ChangeCell(key2.X, key2.Y, key2.Z, Terrain.ReplaceContents(cellValue, 2));
60 }
61 }
62 m_toDegrade.Clear();
63 }
64 if (m_subsystemTime.PeriodicGameTimeEvent(10.0, 0.0)) {
65 foreach (KeyValuePair<Point3, bool> item in m_toHydrate) {
66 Point3 key = item.Key;
67 bool value = item.Value;
68 int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z);
69 if (Terrain.ExtractContents(cellValue2) == 168) {
70 int data = SoilBlock.SetHydration(Terrain.ExtractData(cellValue2), value);
71 int value2 = Terrain.ReplaceData(cellValue2, data);
72 SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, value2);
73 }
74 }
75 m_toHydrate.Clear();
76 }
77 }
78
79 public bool DegradesSoilIfOnTopOfIt(int value) {
80 int num = Terrain.ExtractContents(value);
81 Block block = BlocksManager.Blocks[num];
82 if (!block.IsFaceTransparent(SubsystemTerrain, 5, value)) {
83 return block.IsCollidable_(value);
84 }
85 return false;
86 }
87
88 public bool DetermineHydration(int x, int y, int z, int steps) {
89 if (steps > 0
90 && y > 0
91 && y < 254) {
92 if (DetermineHydrationHelper(x - 1, y, z, steps - 1)) {
93 return true;
94 }
95 if (DetermineHydrationHelper(x + 1, y, z, steps - 1)) {
96 return true;
97 }
98 if (DetermineHydrationHelper(x, y, z - 1, steps - 1)) {
99 return true;
100 }
101 if (DetermineHydrationHelper(x, y, z + 1, steps - 1)) {
102 return true;
103 }
104 if (steps >= 2) {
105 if (DetermineHydrationHelper(x, y - 1, z, steps - 2)) {
106 return true;
107 }
108 if (DetermineHydrationHelper(x, y + 1, z, steps - 2)) {
109 return true;
110 }
111 }
112 }
113 return false;
114 }
115
116 public bool DetermineHydrationHelper(int x, int y, int z, int steps) {
117 int cellValueFast = SubsystemTerrain.Terrain.GetCellValueFast(x, y, z);
118 int num = Terrain.ExtractContents(cellValueFast);
119 int data = Terrain.ExtractData(cellValueFast);
120 switch (num) {
121 case 18: return true;
122 case 168:
123 if (SoilBlock.GetHydration(data)) {
124 return DetermineHydration(x, y, z, steps);
125 }
126 break;
127 }
128 if (num == 2) {
129 return DetermineHydration(x, y, z, steps);
130 }
131 return false;
132 }
133 }
134}
virtual bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
virtual bool IsCollidable_(int value)
static int SetHydration(int data, bool hydration)
static bool GetHydration(int data)
override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)
bool DetermineHydration(int x, int y, int z, int steps)
bool DetermineHydrationHelper(int x, int y, int z, int steps)
override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
override void Load(ValuesDictionary valuesDictionary)
override void OnPoll(int value, int x, int y, int z, int pollPass)
virtual void ChangeCell(int x, int y, int z, int value, bool updateModificationCounter=true, MovingBlock movingBlock=null)
static int ExtractContents(int value)
static int ReplaceData(int value, int data)
virtual int GetCellValueFast(int x, int y, int z)
virtual int GetCellValue(int x, int y, int z)
virtual int GetCellContents(int x, int y, int z)
static int ReplaceContents(int value, int contents)
方块值的最低10位,替换为目标Content
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
float LengthSquared()