Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
StairsBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public abstract class StairsBlock : Block, IPaintableBlock {
6 [Flags]
12
14
16
18
20
22
24
25 public StairsBlock(int coloredTextureSlot) => m_coloredTextureSlot = coloredTextureSlot;
26
27 public override void Initialize() {
28 Model model = ContentManager.Get<Model>("Models/Stairs");
29 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Stairs").ParentBone);
30 Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StairsOuterCorner").ParentBone);
31 Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StairsInnerCorner").ParentBone);
32 for (int i = 0; i < 24; i++) {
33 int rotation = GetRotation(i);
34 bool isUpsideDown = GetIsUpsideDown(i);
35 CornerType cornerType = GetCornerType(i);
36 Matrix m = !isUpsideDown
37 ? Matrix.CreateRotationY(rotation * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f)
38 : Matrix.CreateRotationY(rotation * (float)Math.PI / 2f)
39 * Matrix.CreateTranslation(0.5f, -0.5f, 0.5f)
40 * Matrix.CreateScale(1f, -1f, 1f)
41 * Matrix.CreateTranslation(0f, 0.5f, 0f);
42 BlockMesh blockMesh = new();
43 switch (cornerType) {
44 case CornerType.None:
45 blockMesh.AppendModelMeshPart(
46 model.FindMesh("Stairs").MeshParts[0],
47 boneAbsoluteTransform * m,
48 false,
49 isUpsideDown,
50 false,
51 false,
53 ); break;
54 case CornerType.OneQuarter:
55 blockMesh.AppendModelMeshPart(
56 model.FindMesh("StairsOuterCorner").MeshParts[0],
57 boneAbsoluteTransform2 * m,
58 false,
59 isUpsideDown,
60 false,
61 false,
63 ); break;
64 case CornerType.ThreeQuarters:
65 blockMesh.AppendModelMeshPart(
66 model.FindMesh("StairsInnerCorner").MeshParts[0],
67 boneAbsoluteTransform3 * m,
68 false,
69 isUpsideDown,
70 false,
71 false,
73 ); break;
74 }
75 float num = isUpsideDown ? rotation : -rotation;
77 Matrix.CreateTranslation(-0.03125f, -0.03125f, 0f)
78 * Matrix.CreateRotationZ(num * (float)Math.PI / 2f)
79 * Matrix.CreateTranslation(0.03125f, 0.03125f, 0f),
80 16
81 );
83 Matrix.CreateTranslation(-0.03125f, -0.03125f, 0f)
84 * Matrix.CreateRotationZ((0f - num) * (float)Math.PI / 2f)
85 * Matrix.CreateTranslation(0.03125f, 0.03125f, 0f),
86 32
87 );
88 if (isUpsideDown) {
90 Matrix.CreateTranslation(-0.03125f, -0.03125f, 0f)
91 * Matrix.CreateScale(1f, -1f, 1f)
92 * Matrix.CreateTranslation(0.03125f, 0.03125f, 0f)
93 );
94 }
96 m_coloredBlockMeshes[i].AppendBlockMesh(blockMesh);
98 .TransformTextureCoordinates(Matrix.CreateTranslation(m_coloredTextureSlot % 16 / 16f, m_coloredTextureSlot / 16 / 16f, 0f));
99 m_coloredBlockMeshes[i].GenerateSidesData();
101 m_uncoloredBlockMeshes[i].AppendBlockMesh(blockMesh);
103 .TransformTextureCoordinates(Matrix.CreateTranslation(DefaultTextureSlot % 16 / 16f, DefaultTextureSlot / 16 / 16f, 0f));
104 m_uncoloredBlockMeshes[i].GenerateSidesData();
105 }
106 m_standaloneUncoloredBlockMesh.AppendModelMeshPart(
107 model.FindMesh("Stairs").MeshParts[0],
108 boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f),
109 false,
110 false,
111 false,
112 false,
114 );
115 m_standaloneUncoloredBlockMesh.TransformTextureCoordinates(
117 );
118 m_standaloneColoredBlockMesh.AppendModelMeshPart(
119 model.FindMesh("Stairs").MeshParts[0],
120 boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f),
121 false,
122 false,
123 false,
124 false,
126 );
127 m_standaloneColoredBlockMesh.TransformTextureCoordinates(
129 );
130 m_collisionBoxes[0] = [
131 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0.5f)),
132 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f))
133 ];
134 m_collisionBoxes[1] = [
135 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 1f, 1f)),
136 new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 0.5f, 1f))
137 ];
138 m_collisionBoxes[2] = [
139 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)),
140 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 1f, 1f))
141 ];
142 m_collisionBoxes[3] = [
143 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 1f)),
144 new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 1f, 1f))
145 ];
146 m_collisionBoxes[4] = [
147 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0.5f)),
148 new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f))
149 ];
150 m_collisionBoxes[5] = [
151 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 1f, 1f)),
152 new BoundingBox(new Vector3(0.5f, 0.5f, 0f), new Vector3(1f, 1f, 1f))
153 ];
154 m_collisionBoxes[6] = [
155 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)),
156 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 1f, 1f))
157 ];
158 m_collisionBoxes[7] = [
159 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 1f, 1f)),
160 new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 1f, 1f))
161 ];
162 m_collisionBoxes[8] = [
163 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
164 new BoundingBox(new Vector3(0.5f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f))
165 ];
166 m_collisionBoxes[9] = [
167 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
168 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 1f, 0.5f))
169 ];
170 m_collisionBoxes[10] = [
171 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
172 new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(0.5f, 1f, 1f))
173 ];
174 m_collisionBoxes[11] = [
175 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
176 new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f))
177 ];
178 m_collisionBoxes[12] = [
179 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
180 new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f))
181 ];
182 m_collisionBoxes[13] = [
183 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
184 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f))
185 ];
186 m_collisionBoxes[14] = [
187 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
188 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(0.5f, 0.5f, 1f))
189 ];
190 m_collisionBoxes[15] = [
191 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
192 new BoundingBox(new Vector3(0.5f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f))
193 ];
194 m_collisionBoxes[16] = [
195 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
196 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)),
197 new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f))
198 ];
199 m_collisionBoxes[17] = [
200 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
201 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)),
202 new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(0.5f, 1f, 1f))
203 ];
204 m_collisionBoxes[18] = [
205 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
206 new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)),
207 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 1f, 0.5f))
208 ];
209 m_collisionBoxes[19] = [
210 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)),
211 new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)),
212 new BoundingBox(new Vector3(0.5f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f))
213 ];
214 m_collisionBoxes[20] = [
215 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
216 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)),
217 new BoundingBox(new Vector3(0.5f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f))
218 ];
219 m_collisionBoxes[21] = [
220 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
221 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)),
222 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(0.5f, 0.5f, 1f))
223 ];
224 m_collisionBoxes[22] = [
225 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
226 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)),
227 new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f))
228 ];
229 m_collisionBoxes[23] = [
230 new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)),
231 new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)),
232 new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f))
233 ];
234 base.Initialize();
235 }
236
237 public override IEnumerable<int> GetCreativeValues() {
238 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetColor(0, null));
239 int i = 0;
240 while (i < 16) {
241 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetColor(0, i));
242 int num = i + 1;
243 i = num;
244 }
245 }
246
247 public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value) {
248 int data = Terrain.ExtractData(value);
249 bool isUpsideDown = GetIsUpsideDown(data);
250 switch (face) {
251 case 4: return !isUpsideDown;
252 case 5: return isUpsideDown;
253 default:
254 switch (GetCornerType(data)) {
255 case CornerType.None: {
256 int rotation2 = GetRotation(data);
257 return face != ((rotation2 + 2) & 3);
258 }
259 case CornerType.OneQuarter: return true;
260 default: {
261 int rotation = GetRotation(data);
262 if (face != ((rotation + 1) & 3)) {
263 return face != ((rotation + 2) & 3);
264 }
265 return false;
266 }
267 }
268 }
269 }
270
271 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
272 int data = Terrain.ExtractData(value);
273 int? color = GetColor(data);
274 if (color.HasValue) {
276 this,
277 x,
278 y,
279 z,
281 SubsystemPalette.GetColor(generator, color),
282 null,
283 null,
284 geometry.SubsetOpaque
285 );
286 }
287 else {
289 this,
290 x,
291 y,
292 z,
294 Color.White,
295 null,
296 null,
297 geometry.SubsetOpaque
298 );
299 }
300 }
301
302 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain,
303 ComponentMiner componentMiner,
304 int value,
305 TerrainRaycastResult raycastResult) {
307 float num = Vector3.Dot(forward, Vector3.UnitZ);
308 float num2 = Vector3.Dot(forward, Vector3.UnitX);
309 float num3 = Vector3.Dot(forward, -Vector3.UnitZ);
310 float num4 = Vector3.Dot(forward, -Vector3.UnitX);
311 int rotation = 0;
312 if (num == MathUtils.Max(num, num2, num3, num4)) {
313 rotation = 2;
314 }
315 else if (num2 == MathUtils.Max(num, num2, num3, num4)) {
316 rotation = 3;
317 }
318 else if (num3 == MathUtils.Max(num, num2, num3, num4)) {
319 rotation = 0;
320 }
321 else if (num4 == MathUtils.Max(num, num2, num3, num4)) {
322 rotation = 1;
323 }
324 bool isUpsideDown = raycastResult.CellFace.Face == 5;
325 int data = Terrain.ExtractData(value);
326 BlockPlacementData result = default;
327 result.Value = Terrain.MakeBlockValue(BlockIndex, 0, SetIsUpsideDown(SetRotation(data, rotation), isUpsideDown));
328 result.CellFace = raycastResult.CellFace;
329 return result;
330 }
331
332 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
333 int data = Terrain.ExtractData(value);
334 return m_collisionBoxes[GetVariant(data)];
335 }
336
337 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
338 int value,
339 Color color,
340 float size,
341 ref Matrix matrix,
342 DrawBlockEnvironmentData environmentData) {
343 int? color2 = GetColor(Terrain.ExtractData(value));
344 if (color2.HasValue) {
346 primitivesRenderer,
348 color * SubsystemPalette.GetColor(environmentData, color2),
349 size,
350 ref matrix,
351 environmentData
352 );
353 }
354 else {
355 BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneUncoloredBlockMesh, color, size, ref matrix, environmentData);
356 }
357 }
358
359 public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
360 int? color = GetColor(Terrain.ExtractData(value));
361 return SubsystemPalette.GetName(subsystemTerrain, color, base.GetDisplayName(subsystemTerrain, value));
362 }
363
364 public override string GetCategory(int value) {
365 if (!GetColor(Terrain.ExtractData(value)).HasValue) {
366 return base.GetCategory(value);
367 }
368 return "Painted";
369 }
370
371 public override void GetDropValues(SubsystemTerrain subsystemTerrain,
372 int oldValue,
373 int newValue,
374 int toolLevel,
375 List<BlockDropValue> dropValues,
376 out bool showDebris) {
377 showDebris = true;
378 int data = Terrain.ExtractData(oldValue);
379 int data2 = SetColor(0, GetColor(data));
380 int value = Terrain.MakeBlockValue(BlockIndex, 0, data2);
381 dropValues.Add(new BlockDropValue { Value = value, Count = 1 });
382 }
383
385 Vector3 position,
386 int value,
387 float strength) {
388 int? color = GetColor(Terrain.ExtractData(value));
389 if (color.HasValue) {
390 return new BlockDebrisParticleSystem(
391 subsystemTerrain,
392 position,
393 strength,
395 SubsystemPalette.GetColor(subsystemTerrain, color),
397 );
398 }
399 return new BlockDebrisParticleSystem(
400 subsystemTerrain,
401 position,
402 strength,
404 Color.White,
405 base.GetFaceTextureSlot(0, value)
406 );
407 }
408
409 public virtual int? GetPaintColor(int value) => GetColor(Terrain.ExtractData(value));
410
411 public virtual int Paint(SubsystemTerrain terrain, int value, int? color) =>
413
414 public static Point3 RotationToDirection(int rotation) => CellFace.FaceToPoint3((rotation + 2) % 4);
415
416 public static int GetRotation(int data) => data & 3;
417
418 public static int SetRotation(int data, int rotation) => (data & -4) | (rotation & 3);
419
420 public static bool GetIsUpsideDown(int data) => (data & 4) != 0;
421
422 public static int SetIsUpsideDown(int data, bool isUpsideDown) {
423 if (isUpsideDown) {
424 return data | 4;
425 }
426 return data & -5;
427 }
428
429 public static CornerType GetCornerType(int data) => (CornerType)((data >> 3) & 3);
430
431 public static int SetCornerType(int data, CornerType cornerType) => (data & -25) | ((int)(cornerType & (CornerType)3) << 3);
432
433 public static int? GetColor(int data) {
434 if ((data & 0x20) != 0) {
435 return (data >> 6) & 0xF;
436 }
437 return null;
438 }
439
440 public static int SetColor(int data, int? color) {
441 if (color.HasValue) {
442 return (data & -993) | 0x20 | ((color.Value & 0xF) << 6);
443 }
444 return data & -993;
445 }
446
447 public static int GetVariant(int data) => data & 0x1F;
448 }
449}
Engine.Vector3 Vector3
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
static int Max(int x1, int x2)
virtual void GenerateShadedMeshVertices(Block block, int x, int y, int z, BlockMesh blockMesh, Color color, Matrix? matrix, int[] facesMap, TerrainGeometrySubset subset)
int BlockIndex
定义 Block.cs:6
float DestructionDebrisScale
int DefaultTextureSlot
virtual void TransformTextureCoordinates(Matrix matrix, int facesMask=-1)
static Matrix GetBoneAbsoluteTransform(ModelBone modelBone)
virtual void AppendModelMeshPart(ModelMeshPart meshPart, Matrix matrix, bool makeEmissive, bool flipWindingOrder, bool doubleSided, bool flipNormals, Color color)
static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
ComponentCreatureModel ComponentCreatureModel
ComponentCreature ComponentCreature
static object Get(Type type, string name)
override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
方块放置方向
static CornerType GetCornerType(int data)
StairsBlock(int coloredTextureSlot)
static int SetRotation(int data, int rotation)
static int SetIsUpsideDown(int data, bool isUpsideDown)
BlockMesh[] m_uncoloredBlockMeshes
BoundingBox[][] m_collisionBoxes
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
static bool GetIsUpsideDown(int data)
BlockMesh m_standaloneColoredBlockMesh
BlockMesh[] m_coloredBlockMeshes
override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
static ? int GetColor(int data)
override string GetCategory(int value)
static int GetRotation(int data)
override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
static int SetCornerType(int data, CornerType cornerType)
static int GetVariant(int data)
static int SetColor(int data, int? color)
override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
override void Initialize()
virtual ? int GetPaintColor(int value)
override IEnumerable< int > GetCreativeValues()
override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List< BlockDropValue > dropValues, out bool showDebris)
virtual int Paint(SubsystemTerrain terrain, int value, int? color)
static Point3 RotationToDirection(int rotation)
override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
BlockMesh m_standaloneUncoloredBlockMesh
TerrainGeometrySubset SubsetOpaque
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static Color White
static Matrix CreateFromQuaternion(Quaternion quaternion)
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreateRotationZ(float radians)
static Matrix CreateRotationY(float radians)
Vector3 Forward
static Matrix CreateScale(float scale)
static readonly Vector3 UnitX
static readonly Vector3 UnitZ
static float Dot(Vector3 v1, Vector3 v2)
static Point3 FaceToPoint3(int face)