Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ThermometerBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 public static int Index = 120;
7
8 public BlockMesh m_caseMesh = new();
9
10 public BlockMesh m_fluidMesh = new();
11
12 public Matrix[] m_matricesByData = new Matrix[4];
13
15
17
18 public override void Initialize() {
19 Model model = ContentManager.Get<Model>("Models/Thermometer");
20 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Case").ParentBone);
21 Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Fluid").ParentBone);
22 m_caseMesh.AppendModelMeshPart(
23 model.FindMesh("Case").MeshParts[0],
24 boneAbsoluteTransform,
25 false,
26 false,
27 true,
28 false,
30 );
31 m_fluidMesh.AppendModelMeshPart(
32 model.FindMesh("Fluid").MeshParts[0],
33 boneAbsoluteTransform2,
34 false,
35 false,
36 false,
37 false,
39 );
40 for (int i = 0; i < 4; i++) {
42 * Matrix.CreateTranslation(0.95f, 0.15f, 0.5f)
43 * Matrix.CreateTranslation(-0.5f, 0f, -0.5f)
44 * Matrix.CreateRotationY((i + 1) * (float)Math.PI / 2f)
45 * Matrix.CreateTranslation(0.5f, 0f, 0.5f);
46 m_collisionBoxesByData[i] = [m_caseMesh.CalculateBoundingBox(m_matricesByData[i])];
47 }
48 m_fluidBottomPosition = m_fluidMesh.Vertices.Min(v => v.Position.Y);
49 base.Initialize();
50 }
51
52 public ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z) {
53 int num = Terrain.ExtractData(value);
54 return new ThermometerElectricElement(subsystemElectricity, new CellFace(x, y, z, num & 3));
55 }
56
58 int value,
59 int face,
60 int connectorFace,
61 int x,
62 int y,
63 int z) {
64 if ((Terrain.ExtractData(value) & 3) == face) {
65 return ElectricConnectorType.Output;
66 }
67 return null;
68 }
69
70 public int GetConnectionMask(int value) => int.MaxValue;
71
72 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
73 int num = Terrain.ExtractData(value);
74 if (num < m_collisionBoxesByData.Length) {
75 return m_collisionBoxesByData[num];
76 }
77 return null;
78 }
79
80 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain,
81 ComponentMiner componentMiner,
82 int value,
83 TerrainRaycastResult raycastResult) {
84 int value2 = 0;
85 if (raycastResult.CellFace.Face == 0) {
87 }
88 if (raycastResult.CellFace.Face == 1) {
90 }
91 if (raycastResult.CellFace.Face == 2) {
93 }
94 if (raycastResult.CellFace.Face == 3) {
96 }
97 BlockPlacementData result = default;
98 result.Value = value2;
99 result.CellFace = raycastResult.CellFace;
100 return result;
101 }
102
103 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
104 int num = Terrain.ExtractData(value);
105 if (num < m_matricesByData.Length) {
106 int num2 = generator.SubsystemMetersBlockBehavior?.GetThermometerReading(x, y, z) ?? 8;
107 float y2 = MathUtils.Lerp(1.02f, 3.91f, MathUtils.Saturate(num2 / 20f));
108 Matrix matrix = m_matricesByData[num];
110 * Matrix.CreateScale(1f, y2, 1f)
112 * matrix;
113 generator.GenerateMeshVertices(
114 this,
115 x,
116 y,
117 z,
119 Color.White,
120 matrix,
121 geometry.SubsetOpaque
122 );
123 generator.GenerateMeshVertices(
124 this,
125 x,
126 y,
127 z,
129 Color.White,
130 value2,
131 geometry.SubsetOpaque
132 );
133 generator.GenerateWireVertices(
134 value,
135 x,
136 y,
137 z,
138 num & 3,
139 0.2f,
141 geometry.SubsetOpaque
142 );
143 }
144 }
145
146 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
147 int value,
148 Color color,
149 float size,
150 ref Matrix matrix,
151 DrawBlockEnvironmentData environmentData) {
152 Matrix matrix2 = Matrix.CreateScale(3f * size) * Matrix.CreateTranslation(0f, -0.15f, 0f) * matrix;
153 BlocksManager.DrawMeshBlock(primitivesRenderer, m_caseMesh, color, 1f, ref matrix2, environmentData);
154 if (environmentData.EnvironmentTemperature.HasValue) {
155 float y = MathUtils.Lerp(1.02f, 3.91f, MathUtils.Saturate(environmentData.EnvironmentTemperature.Value / 20f));
157 * Matrix.CreateScale(1f, y, 1f)
159 * matrix2;
160 BlocksManager.DrawMeshBlock(primitivesRenderer, m_fluidMesh, color, 1f, ref matrix3, environmentData);
161 }
162 }
163 }
164}
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
static float Saturate(float x)
static float Lerp(float x1, float x2, float f)
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)
SubsystemMetersBlockBehavior SubsystemMetersBlockBehavior
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)
TerrainGeometrySubset SubsetOpaque
static int ReplaceData(int value, int data)
static int ReplaceContents(int value, int contents)
方块值的最低10位,替换为目标Content
static int ExtractData(int value)
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)
方块放置方向
BoundingBox[][] m_collisionBoxesByData
ElectricConnectorType? GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z)
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
static Color White
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreateRotationY(float radians)
static Matrix CreateScale(float scale)
static readonly Vector2 Zero