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