Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
MotionDetectorBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 public static int Index = 179;
7
9
11
13
14 public override void Initialize() {
15 Model model = ContentManager.Get<Model>("Models/MotionDetector");
16 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("MotionDetector").ParentBone);
17 for (int i = 0; i < 6; i++) {
18 int num = i;
19 Matrix m = i >= 4
20 ? i != 4
21 ? Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)
22 : Matrix.CreateTranslation(0.5f, 0f, 0.5f)
23 : Matrix.CreateRotationX((float)Math.PI / 2f)
24 * Matrix.CreateTranslation(0f, 0f, -0.5f)
25 * Matrix.CreateRotationY(i * (float)Math.PI / 2f)
26 * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f);
27 m_blockMeshesByData[num] = new BlockMesh();
29 .AppendModelMeshPart(
30 model.FindMesh("MotionDetector").MeshParts[0],
31 boneAbsoluteTransform * m,
32 false,
33 false,
34 false,
35 false,
37 );
38 m_collisionBoxesByData[num] = [m_blockMeshesByData[num].CalculateBoundingBox()];
39 }
40 Matrix m2 = Matrix.CreateRotationY(-(float)Math.PI / 2f) * Matrix.CreateRotationZ((float)Math.PI / 2f);
41 m_standaloneBlockMesh.AppendModelMeshPart(
42 model.FindMesh("MotionDetector").MeshParts[0],
43 boneAbsoluteTransform * m2,
44 false,
45 false,
46 false,
47 false,
49 );
50 }
51
52 public override int GetFace(int value) => Terrain.ExtractData(value) & 7;
53
54 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain,
55 ComponentMiner componentMiner,
56 int value,
57 TerrainRaycastResult raycastResult) {
58 BlockPlacementData result = default;
59 result.Value = Terrain.ReplaceData(value, raycastResult.CellFace.Face);
60 result.CellFace = raycastResult.CellFace;
61 return result;
62 }
63
64 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
65 int num = Terrain.ExtractData(value);
66 if (num >= m_collisionBoxesByData.Length) {
67 return null;
68 }
69 return m_collisionBoxesByData[num];
70 }
71
72 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
73 int num = Terrain.ExtractData(value);
74 if (num < m_blockMeshesByData.Length) {
75 generator.GenerateMeshVertices(
76 this,
77 x,
78 y,
79 z,
82 null,
83 geometry.SubsetOpaque
84 );
85 generator.GenerateWireVertices(
86 value,
87 x,
88 y,
89 z,
90 GetFace(value),
91 0.25f,
93 geometry.SubsetOpaque
94 );
95 }
96 }
97
98 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
99 int value,
100 Color color,
101 float size,
102 ref Matrix matrix,
103 DrawBlockEnvironmentData environmentData) {
104 BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, color, 2f * size, ref matrix, environmentData);
105 }
106
107 public override ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z) =>
108 new MotionDetectorElectricElement(subsystemElectricity, new CellFace(x, y, z, GetFace(value)));
109
111 int value,
112 int face,
113 int connectorFace,
114 int x,
115 int y,
116 int z) {
117 int face2 = GetFace(value);
118 if (face == face2
119 && SubsystemElectricity.GetConnectorDirection(face2, 0, connectorFace).HasValue) {
120 return ElectricConnectorType.Output;
121 }
122 return null;
123 }
124 }
125}
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)
virtual void GenerateWireVertices(int value, int x, int y, int z, int mountingFace, float centerBoxSize, Vector2 centerOffset, TerrainGeometrySubset subset)
static Matrix GetBoneAbsoluteTransform(ModelBone modelBone)
static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
static object Get(Type type, string name)
override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
方块放置方向
override ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, 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 void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
override? ElectricConnectorType GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
override int GetFace(int value)
static ? ElectricConnectorDirection GetConnectorDirection(int mountingFace, int rotation, int connectorFace)
TerrainGeometrySubset SubsetOpaque
static int ReplaceData(int value, int data)
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