Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ChristmasTreeBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 public static int Index = 63;
7
9
11
13
15
17
18 public override void Initialize() {
19 Model model = ContentManager.Get<Model>("Models/ChristmasTree");
20 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StandTrunk").ParentBone);
21 Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Leaves").ParentBone);
22 Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Decorations").ParentBone);
24 m_leavesBlockMesh.AppendModelMeshPart(
25 model.FindMesh("Leaves").MeshParts[0],
26 boneAbsoluteTransform2 * Matrix.CreateTranslation(0.5f, 0f, 0.5f),
27 false,
28 false,
29 true,
30 false,
32 );
33 m_standTrunkBlockMesh.AppendModelMeshPart(
34 model.FindMesh("StandTrunk").MeshParts[0],
35 boneAbsoluteTransform * Matrix.CreateTranslation(0.5f, 0f, 0.5f),
36 false,
37 false,
38 false,
39 false,
41 );
42 m_decorationsBlockMesh.AppendModelMeshPart(
43 model.FindMesh("Decorations").MeshParts[0],
44 boneAbsoluteTransform3 * Matrix.CreateTranslation(0.5f, 0f, 0.5f),
45 false,
46 false,
47 false,
48 false,
50 );
51 m_litDecorationsBlockMesh.AppendModelMeshPart(
52 model.FindMesh("Decorations").MeshParts[0],
53 boneAbsoluteTransform3 * Matrix.CreateTranslation(0.5f, 0f, 0.5f),
54 true,
55 false,
56 false,
57 false,
59 );
60 m_standaloneBlockMesh.AppendModelMeshPart(
61 model.FindMesh("StandTrunk").MeshParts[0],
62 boneAbsoluteTransform * Matrix.CreateTranslation(0f, -1f, 0f),
63 false,
64 false,
65 false,
66 false,
68 );
69 m_standaloneBlockMesh.AppendModelMeshPart(
70 model.FindMesh("Leaves").MeshParts[0],
71 boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -1f, 0f),
72 false,
73 false,
74 true,
75 false,
76 color
77 );
78 m_standaloneBlockMesh.AppendModelMeshPart(
79 model.FindMesh("Decorations").MeshParts[0],
80 boneAbsoluteTransform3 * Matrix.CreateTranslation(0f, -1f, 0f),
81 false,
82 false,
83 false,
84 false,
86 );
87 base.Initialize();
88 }
89
90 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
91 Color color = BlockColorsMap.SpruceLeaves.Lookup(generator.Terrain, x, y, z);
92 if (GetLightState(Terrain.ExtractData(value))) {
93 generator.GenerateMeshVertices(
94 this,
95 x,
96 y,
97 z,
100 null,
101 geometry.SubsetOpaque
102 );
103 generator.GenerateMeshVertices(
104 this,
105 x,
106 y,
107 z,
109 Color.White,
110 null,
111 geometry.SubsetOpaque
112 );
113 generator.GenerateMeshVertices(
114 this,
115 x,
116 y,
117 z,
119 color,
120 null,
121 geometry.SubsetAlphaTest
122 );
123 }
124 else {
125 generator.GenerateMeshVertices(
126 this,
127 x,
128 y,
129 z,
131 Color.White,
132 null,
133 geometry.SubsetOpaque
134 );
135 generator.GenerateMeshVertices(
136 this,
137 x,
138 y,
139 z,
141 Color.White,
142 null,
143 geometry.SubsetOpaque
144 );
145 generator.GenerateMeshVertices(
146 this,
147 x,
148 y,
149 z,
151 color,
152 null,
153 geometry.SubsetAlphaTest
154 );
155 }
156 generator.GenerateWireVertices(
157 value,
158 x,
159 y,
160 z,
161 4,
162 0.01f,
164 geometry.SubsetOpaque
165 );
166 }
167
168 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
169 int value,
170 Color color,
171 float size,
172 ref Matrix matrix,
173 DrawBlockEnvironmentData environmentData) {
174 BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, color, size, ref matrix, environmentData);
175 }
176
178 Vector3 position,
179 int value,
180 float strength) {
182 subsystemTerrain.Terrain,
183 Terrain.ToCell(position.X),
184 Terrain.ToCell(position.Y),
185 Terrain.ToCell(position.Z)
186 );
187 return new BlockDebrisParticleSystem(subsystemTerrain, position, strength, DestructionDebrisScale, color, DefaultTextureSlot);
188 }
189
190 public override int GetEmittedLightAmount(int value) {
191 if (!GetLightState(Terrain.ExtractData(value))) {
192 return 0;
193 }
195 }
196
197 public override int GetShadowStrength(int value) {
198 if (!GetLightState(Terrain.ExtractData(value))) {
200 }
201 return -99;
202 }
203
204 public static bool GetLightState(int data) => (data & 1) != 0;
205
206 public static int SetLightState(int data, bool state) {
207 if (!state) {
208 return data & -2;
209 }
210 return data | 1;
211 }
212
213 public ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z) =>
214 new ChristmasTreeElectricElement(subsystemElectricity, new CellFace(x, y, z, 4), value);
215
217 int value,
218 int face,
219 int connectorFace,
220 int x,
221 int y,
222 int z) {
223 if (face == 4
224 && SubsystemElectricity.GetConnectorDirection(4, 0, connectorFace).HasValue) {
225 return ElectricConnectorType.Input;
226 }
227 return null;
228 }
229
230 public int GetConnectionMask(int value) => int.MaxValue;
231 }
232}
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
Color Lookup(int temperature, int humidity)
static BlockColorsMap SpruceLeaves
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)
int DefaultEmittedLightAmount
float DestructionDebrisScale
int DefaultTextureSlot
int DefaultShadowStrength
static Matrix GetBoneAbsoluteTransform(ModelBone modelBone)
static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
ElectricConnectorType? GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
static int SetLightState(int data, bool state)
static bool GetLightState(int data)
override int GetEmittedLightAmount(int value)
override int GetShadowStrength(int value)
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)
ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z)
static object Get(Type type, string name)
static ? ElectricConnectorDirection GetConnectorDirection(int mountingFace, int rotation, int connectorFace)
TerrainGeometrySubset SubsetAlphaTest
TerrainGeometrySubset SubsetOpaque
static int ToCell(float x)
static int ExtractData(int value)
static Color White
static Matrix CreateTranslation(float x, float y, float z)
static readonly Vector2 Zero