Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemDeciduousLeavesBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 struct LeafParticles {
7 public double Time;
8
10 }
11
13
15
17
19
21
23
25
27
28 DynamicArray<LeafParticles> m_leafParticles = [];
29
30 DynamicArray<LeafParticles> m_tmpLeafParticles = [];
31
32 public override int[] HandledBlocks => [];
33
35
36 public void CreateFallenLeaves(Point3 p, bool applyImmediately) {
37 int? num = null;
38 while (p.Y >= 1
39 && p.Y < 256) {
40 int cellValue = m_subsystemTerrain.Terrain.GetCellValue(p.X, p.Y, p.Z);
41 if (num.HasValue) {
44 m_subsystemCellChangeQueue.QueueCellChange(p.X, p.Y + 1, p.Z, Terrain.MakeBlockValue(261), applyImmediately);
45 break;
46 }
48 break;
49 }
50 }
51 num = cellValue;
52 p.Y--;
53 }
54 }
55
56 public override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded) {
57 UpdateTimeOfYear(value, x, y, z, true);
58 QueueLeafParticles(value, x, y, z);
59 }
60
61 public override void OnPoll(int value, int x, int y, int z, int pollPass) {
62 UpdateTimeOfYear(value, x, y, z, false);
63 QueueLeafParticles(value, x, y, z);
64 }
65
66 public override void Load(ValuesDictionary valuesDictionary) {
67 base.Load(valuesDictionary);
68 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
69 m_subsystemSeasons = Project.FindSubsystem<SubsystemSeasons>(true);
70 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
71 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
73 m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(true);
75 }
76
77 void IUpdateable.Update(float dt) {
78 if (!m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0)) {
79 return;
80 }
81 foreach (LeafParticles leafParticle in m_leafParticles) {
82 if (m_subsystemTime.GameTime >= leafParticle.Time) {
83 if (m_subsystemGameWidgets.CalculateDistanceFromNearestView(new Vector3(leafParticle.Position)) < 32f) {
84 int cellValue = m_subsystemTerrain.Terrain.GetCellValue(
85 leafParticle.Position.X,
86 leafParticle.Position.Y,
87 leafParticle.Position.Z
88 );
89 int num = Terrain.ExtractContents(cellValue);
90 if (BlocksManager.Blocks[num] is DeciduousLeavesBlock deciduousLeavesBlock
91 && deciduousLeavesBlock.GetLeafDropProbability(cellValue) > 0f) {
92 m_subsystemParticles.AddParticleSystem(
93 new LeavesParticleSystem(m_subsystemTerrain, leafParticle.Position, m_random.Int(1, 2), true, false, cellValue)
94 );
95 }
96 }
97 }
98 else {
99 m_tmpLeafParticles.Add(leafParticle);
100 }
101 }
103 m_tmpLeafParticles.Clear();
104 }
105
106 void UpdateTimeOfYear(int value, int x, int y, int z, bool applyImmediately) {
107 float num = 0.03f * MathUtils.Hash((uint)(x + y * 59 + z * 3319)) / 4.2949673E+09f;
108 float timeOfYear = IntervalUtils.Normalize(m_subsystemGameInfo.WorldSettings.TimeOfYear + num);
110 int num2 = Terrain.ExtractData(value);
111 int num3 = obj.SetTimeOfYear(num2, timeOfYear);
112 if (num3 != num2) {
113 int value2 = Terrain.ReplaceData(value, num3);
114 m_subsystemCellChangeQueue.QueueCellChange(x, y, z, value2, applyImmediately);
116 if (DeciduousLeavesBlock.GetSeason(num3) == Season.Winter
117 && season != Season.Winter) {
118 CreateFallenLeaves(new Point3(x, y, z), applyImmediately);
119 }
120 }
121 }
122
123 void QueueLeafParticles(int value, int x, int y, int z) {
125 if (m_leafParticles.Count < 30000
126 && m_random.Bool(deciduousLeavesBlock.GetLeafDropProbability(value) / 60f * 60f)
127 && m_subsystemGameWidgets.CalculateDistanceFromNearestView(new Vector3(x, y, z)) < 128f) {
128 m_leafParticles.Add(new LeafParticles { Position = new Point3(x, y, z), Time = m_subsystemTime.GameTime + m_random.Float(0f, 60f) });
129 }
130 }
131 }
132}
static int Hash(int key)
virtual int SetTimeOfYear(int data, float timeOfYear)
virtual float GetLeafDropProbability(int value)
static float Normalize(float t)
override void Load(ValuesDictionary valuesDictionary)
void UpdateTimeOfYear(int value, int x, int y, int z, bool applyImmediately)
override void OnPoll(int value, int x, int y, int z, int pollPass)
override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded)
static int ExtractContents(int value)
static int ReplaceData(int value, int data)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
UpdateOrder UpdateOrder
void Update(float dt)