Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
IvyBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class IvyBlock : Block {
6 public static int Index = 197;
7
9 new BoundingBox[]
10 [] { [
11 new BoundingBox(new Vector3(0f, 0f, 0.9375f), new Vector3(1f, 1f, 1f))
12 ], [new BoundingBox(new Vector3(0.9375f, 0f, 0f), new Vector3(1f, 1f, 1f))], [
13 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0.0625f))
14 ], [new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.0625f, 1f, 1f))]
15 };
16
17 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
18 int face = GetFace(Terrain.ExtractData(value));
19 if (face >= 0
20 && face < 4) {
21 return m_boundingBoxes[face];
22 }
23 return base.GetCustomCollisionBoxes(terrain, value);
24 }
25
26 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain,
27 ComponentMiner componentMiner,
28 int value,
29 TerrainRaycastResult raycastResult) {
30 BlockPlacementData result = default;
31 if (raycastResult.CellFace.Face < 4) {
32 result.CellFace = raycastResult.CellFace;
33 result.Value = Terrain.MakeBlockValue(197, 0, SetFace(0, CellFace.OppositeFace(raycastResult.CellFace.Face)));
34 }
35 return result;
36 }
37
38 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
39 TerrainGeometrySubset subsetAlphaTest = geometry.SubsetAlphaTest;
40 DynamicArray<TerrainVertex> vertices = subsetAlphaTest.Vertices;
41 TerrainGeometryDynamicArray<int> indices = subsetAlphaTest.Indices;
42 int count = vertices.Count;
43 int data = Terrain.ExtractData(value);
44 int num = Terrain.ExtractLight(value);
45 int face = GetFace(data);
47 Color color = BlockColorsMap.Ivy.Lookup(generator.Terrain, x, y, z) * s;
48 color.A = byte.MaxValue;
49 switch (face) {
50 case 0:
51 vertices.Count += 4;
53 x,
54 y,
55 z + 1,
56 color,
58 0,
59 ref vertices.Array[count]
60 );
62 x + 1,
63 y,
64 z + 1,
65 color,
67 1,
68 ref vertices.Array[count + 1]
69 );
71 x + 1,
72 y + 1,
73 z + 1,
74 color,
76 2,
77 ref vertices.Array[count + 2]
78 );
80 x,
81 y + 1,
82 z + 1,
83 color,
85 3,
86 ref vertices.Array[count + 3]
87 );
88 indices.Add(count);
89 indices.Add(count + 1);
90 indices.Add(count + 2);
91 indices.Add(count + 2);
92 indices.Add(count + 1);
93 indices.Add(count);
94 indices.Add(count + 2);
95 indices.Add(count + 3);
96 indices.Add(count);
97 indices.Add(count);
98 indices.Add(count + 3);
99 indices.Add(count + 2);
100 break;
101 case 1:
102 vertices.Count += 4;
104 x + 1,
105 y,
106 z,
107 color,
109 0,
110 ref vertices.Array[count]
111 );
113 x + 1,
114 y + 1,
115 z,
116 color,
118 3,
119 ref vertices.Array[count + 1]
120 );
122 x + 1,
123 y + 1,
124 z + 1,
125 color,
127 2,
128 ref vertices.Array[count + 2]
129 );
131 x + 1,
132 y,
133 z + 1,
134 color,
136 1,
137 ref vertices.Array[count + 3]
138 );
139 indices.Add(count);
140 indices.Add(count + 1);
141 indices.Add(count + 2);
142 indices.Add(count + 2);
143 indices.Add(count + 1);
144 indices.Add(count);
145 indices.Add(count + 2);
146 indices.Add(count + 3);
147 indices.Add(count);
148 indices.Add(count);
149 indices.Add(count + 3);
150 indices.Add(count + 2);
151 break;
152 case 2:
153 vertices.Count += 4;
155 x,
156 y,
157 z,
158 color,
160 0,
161 ref vertices.Array[count]
162 );
164 x + 1,
165 y,
166 z,
167 color,
169 1,
170 ref vertices.Array[count + 1]
171 );
173 x + 1,
174 y + 1,
175 z,
176 color,
178 2,
179 ref vertices.Array[count + 2]
180 );
182 x,
183 y + 1,
184 z,
185 color,
187 3,
188 ref vertices.Array[count + 3]
189 );
190 indices.Add(count);
191 indices.Add(count + 2);
192 indices.Add(count + 1);
193 indices.Add(count + 1);
194 indices.Add(count + 2);
195 indices.Add(count);
196 indices.Add(count + 2);
197 indices.Add(count);
198 indices.Add(count + 3);
199 indices.Add(count + 3);
200 indices.Add(count);
201 indices.Add(count + 2);
202 break;
203 case 3:
204 vertices.Count += 4;
206 x,
207 y,
208 z,
209 color,
211 0,
212 ref vertices.Array[count]
213 );
215 x,
216 y + 1,
217 z,
218 color,
220 3,
221 ref vertices.Array[count + 1]
222 );
224 x,
225 y + 1,
226 z + 1,
227 color,
229 2,
230 ref vertices.Array[count + 2]
231 );
233 x,
234 y,
235 z + 1,
236 color,
238 1,
239 ref vertices.Array[count + 3]
240 );
241 indices.Add(count);
242 indices.Add(count + 2);
243 indices.Add(count + 1);
244 indices.Add(count + 1);
245 indices.Add(count + 2);
246 indices.Add(count);
247 indices.Add(count + 2);
248 indices.Add(count);
249 indices.Add(count + 3);
250 indices.Add(count + 3);
251 indices.Add(count);
252 indices.Add(count + 2);
253 break;
254 }
255 }
256
257 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
258 int value,
259 Color color,
260 float size,
261 ref Matrix matrix,
262 DrawBlockEnvironmentData environmentData) {
263 color *= BlockColorsMap.Ivy.Lookup(environmentData.Temperature, environmentData.Humidity);
265 primitivesRenderer,
266 value,
267 size,
268 ref matrix,
269 null,
270 color,
271 false,
272 environmentData
273 );
274 }
275
277 Vector3 position,
278 int value,
279 float strength) {
281 subsystemTerrain.Terrain,
282 Terrain.ToCell(position.X),
283 Terrain.ToCell(position.Y),
284 Terrain.ToCell(position.Z)
285 );
286 return new BlockDebrisParticleSystem(subsystemTerrain, position, strength, DestructionDebrisScale, color, DefaultTextureSlot);
287 }
288
289 public static int GetFace(int data) => data & 3;
290
291 public static int SetFace(int data, int face) => (data & -4) | (face & 3);
292
293 public static bool IsGrowthStopCell(int x, int y, int z) => MathUtils.Hash((uint)(x + y * 451 + z * 77437)) % 5u == 0;
294 }
295}
Engine.Vector3 Vector3
static int Hash(int key)
static BlockColorsMap Ivy
Color Lookup(int temperature, int humidity)
static void SetupLitCornerVertex(float x, float y, float z, Color color, int textureSlot, int corner, ref TerrainVertex vertex)
float DestructionDebrisScale
int DefaultTextureSlot
static void DrawFlatOrImageExtrusionBlock(PrimitivesRenderer3D primitivesRenderer, int value, float size, ref Matrix matrix, Texture2D texture, Color color, bool isEmissive, DrawBlockEnvironmentData environmentData)
BoundingBox[][] m_boundingBoxes
static int GetFace(int data)
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
static int Index
static int SetFace(int data, int face)
override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
方块放置方向
static bool IsGrowthStopCell(int x, int y, int z)
override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
static readonly float[] LightIntensityByLightValueAndFace
TerrainGeometrySubset SubsetAlphaTest
TerrainGeometryDynamicArray< TerrainVertex > Vertices
TerrainGeometryDynamicArray< int > Indices
static int ToCell(float x)
static int ExtractLight(int value)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static int OppositeFace(int face)