Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemGrassBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
10 public Dictionary<Point3, int> m_toUpdate = [];
11
12 public Random m_random = new();
13
14 public override int[] HandledBlocks => [8];
15
17
18 public override void OnPoll(int value, int x, int y, int z, int pollPass) {
19 if (Terrain.ExtractData(value) != 0
20 || m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0) {
21 return;
22 }
24 if (num == 0) {
25 m_toUpdate[new Point3(x, y, z)] = Terrain.ReplaceContents(value, 8);
26 }
27 if (num < 13) {
28 return;
29 }
30 for (int i = x - 1; i <= x + 1; i++) {
31 for (int j = z - 1; j <= z + 1; j++) {
32 for (int k = y - 2; k <= y + 1; k++) {
33 int cellValue = SubsystemTerrain.Terrain.GetCellValue(i, k, j);
34 if (Terrain.ExtractContents(cellValue) != 2) {
35 continue;
36 }
37 int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(i, k + 1, j);
38 if (KillsGrassIfOnTopOfIt(cellValue2)
39 || Terrain.ExtractLight(cellValue2) < 13
40 || !(m_random.Float(0f, 1f) < 0.1f)) {
41 continue;
42 }
43 int num2 = Terrain.ReplaceContents(cellValue, 8);
44 m_toUpdate[new Point3(i, k, j)] = num2;
45 if (Terrain.ExtractContents(cellValue2) == 0) {
46 int temperature = SubsystemTerrain.Terrain.GetTemperature(i, j);
47 int humidity = SubsystemTerrain.Terrain.GetHumidity(i, j);
48 int num3 = PlantsManager.GenerateRandomPlantValue(m_random, num2, temperature, humidity, k + 1);
49 if (num3 != 0) {
50 m_toUpdate[new Point3(i, k + 1, j)] = num3;
51 }
52 }
53 }
54 }
55 }
56 }
57
58 public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ) {
59 int cellValue = SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z);
60 if (Terrain.ExtractContents(cellValue) == 61) {
61 int cellValueFast = SubsystemTerrain.Terrain.GetCellValueFast(x, y, z);
62 cellValueFast = Terrain.ReplaceData(cellValueFast, 1);
63 SubsystemTerrain.ChangeCell(x, y, z, cellValueFast);
64 }
65 else {
66 int cellValueFast2 = SubsystemTerrain.Terrain.GetCellValueFast(x, y, z);
67 cellValueFast2 = Terrain.ReplaceData(cellValueFast2, 0);
68 SubsystemTerrain.ChangeCell(x, y, z, cellValueFast2);
69 }
70 if (KillsGrassIfOnTopOfIt(cellValue)) {
72 }
73 }
74
75 public override void OnExplosion(int value, int x, int y, int z, float damage) {
76 if (damage > BlocksManager.Blocks[8].ExplosionResilience * m_random.Float(0f, 1f)) {
78 }
79 }
80
81 public override void Load(ValuesDictionary valuesDictionary) {
82 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
83 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
84 base.Load(valuesDictionary);
85 }
86
87 public virtual void Update(float dt) {
88 if (m_subsystemTime.PeriodicGameTimeEvent(60.0, 0.0)) {
89 foreach (KeyValuePair<Point3, int> item in m_toUpdate) {
90 if (Terrain.ExtractContents(item.Value) == 8) {
91 if (SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y, item.Key.Z) != 2) {
92 continue;
93 }
94 }
95 else {
96 int cellContents = SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y - 1, item.Key.Z);
97 if ((cellContents != 8 && cellContents != 2)
98 || SubsystemTerrain.Terrain.GetCellContents(item.Key.X, item.Key.Y, item.Key.Z) != 0) {
99 continue;
100 }
101 }
102 SubsystemTerrain.ChangeCell(item.Key.X, item.Key.Y, item.Key.Z, item.Value);
103 }
104 m_toUpdate.Clear();
105 }
106 }
107
108 public bool KillsGrassIfOnTopOfIt(int value) {
109 int num = Terrain.ExtractContents(value);
110 Block block = BlocksManager.Blocks[num];
111 if (!(block is FluidBlock)) {
112 if (!block.IsFaceTransparent(SubsystemTerrain, 5, value)) {
113 return block.IsCollidable_(value);
114 }
115 return false;
116 }
117 return true;
118 }
119 }
120}
float ExplosionResilience
virtual bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
virtual bool IsCollidable_(int value)
static int GenerateRandomPlantValue(Random random, int groundValue, int temperature, int humidity, int y)
override void OnExplosion(int value, int x, int y, int z, float damage)
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)
override void Load(ValuesDictionary valuesDictionary)
static int ExtractContents(int value)
static int ReplaceData(int value, int data)
virtual int GetCellValueFast(int x, int y, int z)
virtual int GetHumidity(int x, int z)
virtual int GetCellValue(int x, int y, int z)
virtual int GetCellContents(int x, int y, int z)
static int ExtractLight(int value)
static int ReplaceContents(int value, int contents)
方块值的最低10位,替换为目标Content
static int MakeBlockValue(int contents)
static int ExtractData(int value)
virtual int GetTemperature(int x, int z)
ValuesDictionary ValuesDictionary