Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SeaUrchinBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 public new const int Index = 226;
7
8 public BlockMesh[] m_blockMeshes = new BlockMesh[24];
9
11
13
14 public static Color[] m_colors = [new(20, 20, 20), new(50, 20, 20), new(80, 30, 30), new(20, 20, 40)];
15
16 public static Vector2[] m_offsets = [
17 0.15f * new Vector2(-0.8f, -1f), 0.15f * new Vector2(1f, -0.75f), 0.15f * new Vector2(-0.65f, 1f), 0.15f * new Vector2(0.9f, 0.7f)
18 ];
19
20 public override void Initialize() {
21 Model model = ContentManager.Get<Model>("Models/SeaUrchin");
22 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Urchin").ParentBone);
23 Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Bottom").ParentBone);
24 for (int i = 0; i < 6; i++) {
25 for (int j = 0; j < 4; j++) {
26 Vector2 zero = Vector2.Zero;
27 if (i < 4) {
28 zero.Y = i * (float)Math.PI / 2f;
29 }
30 else {
31 zero.X = i == 4 ? -(float)Math.PI / 2f : (float)Math.PI / 2f;
32 }
33 Matrix m = Matrix.CreateRotationX((float)Math.PI / 2f)
34 * Matrix.CreateRotationZ(0.3f + 2f * j)
35 * Matrix.CreateTranslation(m_offsets[j].X, m_offsets[j].Y, -0.49f)
38 * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f);
39 int num = 4 * i + j;
40 m_blockMeshes[num] = new BlockMesh();
41 m_blockMeshes[num]
42 .AppendModelMeshPart(
43 model.FindMesh("Urchin").MeshParts[0],
44 boneAbsoluteTransform * m,
45 false,
46 false,
47 false,
48 false,
50 );
51 m_collisionBoxes[num] = [m_blockMeshes[num].CalculateBoundingBox()];
52 }
53 }
55 m_standaloneBlockMesh.AppendModelMeshPart(
56 model.FindMesh("Urchin").MeshParts[0],
57 boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.1f, 0f),
58 false,
59 false,
60 false,
61 false,
63 );
64 m_standaloneBlockMesh.AppendModelMeshPart(
65 model.FindMesh("Bottom").MeshParts[0],
66 boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.1f, 0f),
67 false,
68 false,
69 false,
70 false,
72 );
73 base.Initialize();
74 }
75
76 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
77 int data = Terrain.ExtractData(value);
78 int face = GetFace(data);
79 int subvariant = GetSubvariant(data);
80 return m_collisionBoxes[4 * face + subvariant];
81 }
82
83 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
84 int data = Terrain.ExtractData(value);
85 int face = GetFace(data);
86 int subvariant = GetSubvariant(data);
87 Color color = m_colors[subvariant];
88 generator.GenerateMeshVertices(
89 this,
90 x,
91 y,
92 z,
93 m_blockMeshes[4 * face + subvariant],
94 color,
95 null,
96 geometry.SubsetOpaque
97 );
98 base.GenerateTerrainVertices(generator, geometry, value, x, y, z);
99 }
100
101 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
102 int value,
103 Color color,
104 float size,
105 ref Matrix matrix,
106 DrawBlockEnvironmentData environmentData) {
108 primitivesRenderer,
110 color * new Color(40, 40, 40),
111 3f * size,
112 ref matrix,
113 environmentData
114 );
115 }
116
118 Vector3 position,
119 int value,
120 float strength) => new(subsystemTerrain, position, 0.75f * strength, DestructionDebrisScale, new Color(64, 64, 64), DefaultTextureSlot);
121 }
122}
Engine.Color Color
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
virtual void GenerateMeshVertices(Block block, int x, int y, int z, BlockMesh blockMesh, Color color, Matrix? matrix, TerrainGeometrySubset subset)
float DestructionDebrisScale
int DefaultTextureSlot
static Matrix GetBoneAbsoluteTransform(ModelBone modelBone)
static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
static int GetSubvariant(int data)
static object Get(Type type, string name)
BoundingBox[][] m_collisionBoxes
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
static Vector2[] m_offsets
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)
TerrainGeometrySubset SubsetOpaque
static int ExtractData(int value)
static Color White
static Matrix CreateRotationX(float radians)
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreateRotationZ(float radians)
static Matrix CreateRotationY(float radians)
static readonly Vector2 Zero