Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
FireworksBlock.cs
浏览该文件的文档.
1using System.Globalization;
2using Engine;
4
5namespace Game {
6 public class FireworksBlock : Block {
7 [Flags]
18
19 public static int Index = 215;
20
22
24
26
27 public static readonly string[] HeadNames = [
28 "HeadConeSmall",
29 "HeadConeLarge",
30 "HeadCylinderSmall",
31 "HeadCylinderLarge",
32 "HeadSphere",
33 "HeadDiamondSmall",
34 "HeadDiamondLarge",
35 "HeadCylinderFlat"
36 ];
37
38 public static readonly Color[] FireworksColors = [
39 new(255, 255, 255),
40 new(85, 255, 255),
41 new(255, 85, 85),
42 new(85, 85, 255),
43 new(255, 255, 85),
44 new(85, 255, 85),
45 new(255, 170, 0),
46 new(255, 85, 255)
47 ];
48
49 public override void Initialize() {
50 Model model = ContentManager.Get<Model>("Models/Fireworks");
51 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Body").ParentBone);
52 Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Fins").ParentBone);
53 for (int i = 0; i < 64; i++) {
54 int num = i / 8;
55 int num2 = i % 8;
56 Color color = FireworksColors[num2];
57 color *= 0.75f;
58 color.A = byte.MaxValue;
59 Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(HeadNames[num]).ParentBone);
62 .AppendModelMeshPart(
63 model.FindMesh(HeadNames[num]).MeshParts[0],
64 boneAbsoluteTransform3 * Matrix.CreateTranslation(0f, -0.25f, 0f),
65 false,
66 false,
67 false,
68 false,
69 color
70 );
71 }
72 for (int j = 0; j < 2; j++) {
73 float num3 = 0.5f + j * 0.5f;
74 Matrix m = Matrix.CreateScale(new Vector3(num3, 1f, num3));
77 .AppendModelMeshPart(
78 model.FindMesh("Body").MeshParts[0],
79 boneAbsoluteTransform * m * Matrix.CreateTranslation(0f, -0.25f, 0f),
80 false,
81 false,
82 false,
83 false,
85 );
86 }
87 for (int k = 0; k < 2; k++) {
90 .AppendModelMeshPart(
91 model.FindMesh("Fins").MeshParts[0],
92 boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.25f, 0f),
93 false,
94 false,
95 false,
96 false,
97 k == 0 ? Color.White : new Color(224, 0, 0)
98 );
99 }
100 base.Initialize();
101 }
102
103 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) { }
104
105 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
106 int value,
107 Color color,
108 float size,
109 ref Matrix matrix,
110 DrawBlockEnvironmentData environmentData) {
111 int data = Terrain.ExtractData(value);
112 int color2 = GetColor(data);
113 Shape shape = GetShape(data);
114 int altitude = GetAltitude(data);
115 bool flickering = GetFlickering(data);
117 primitivesRenderer,
118 m_headBlockMeshes[(int)shape * 8 + color2],
119 color,
120 2f * size,
121 ref matrix,
122 environmentData
123 );
124 BlocksManager.DrawMeshBlock(primitivesRenderer, m_bodyBlockMeshes[altitude], color, 2f * size, ref matrix, environmentData);
125 BlocksManager.DrawMeshBlock(primitivesRenderer, m_finsBlockMeshes[flickering ? 1 : 0], color, 2f * size, ref matrix, environmentData);
126 }
127
128 public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
129 int data = Terrain.ExtractData(value);
130 int color = GetColor(data);
131 Shape shape = GetShape(data);
132 int altitude = GetAltitude(data);
133 bool flickering = GetFlickering(data);
134 return string.Format(
135 LanguageControl.GetFireworks("Other", "1"),
136 LanguageControl.GetFireworks("FireworksColorDisplayNames", color.ToString()),
137 flickering ? LanguageControl.GetFireworks("Other", "2") : null,
138 LanguageControl.GetFireworks("ShapeDisplayNames", ((int)shape).ToString()),
139 altitude == 0 ? LanguageControl.GetFireworks("Other", "3") : LanguageControl.GetFireworks("Other", "4")
140 );
141 }
142
143 public override IEnumerable<int> GetCreativeValues() {
144 int color = 0;
145 while (color < 8) {
146 int num;
147 for (int altitude = 0; altitude < 2; altitude = num) {
148 for (int flickering = 0; flickering < 2; flickering = num) {
149 for (int shape = 0; shape < 8; shape = num) {
150 yield return Terrain.MakeBlockValue(
151 215,
152 0,
153 SetColor(SetAltitude(SetShape(SetFlickering(0, flickering != 0), (Shape)shape), altitude), color)
154 );
155 num = shape + 1;
156 }
157 num = flickering + 1;
158 }
159 num = altitude + 1;
160 }
161 num = color + 1;
162 color = num;
163 }
164 }
165
166 public override IEnumerable<CraftingRecipe> GetProceduralCraftingRecipes() {
167 int shape = 0;
168 while (shape < 8) {
169 int num;
170 for (int altitude = 0; altitude < 2; altitude = num) {
171 for (int flickering = 0; flickering < 2; flickering = num) {
172 for (int color = 0; color < 8; color = num) {
173 CraftingRecipe craftingRecipe = new() {
174 ResultCount = 20,
175 ResultValue = Terrain.MakeBlockValue(
176 215,
177 0,
178 SetColor(SetAltitude(SetShape(SetFlickering(0, flickering != 0), (Shape)shape), altitude), color)
179 ),
180 RemainsCount = 1,
181 RemainsValue = Terrain.MakeBlockValue(90),
182 RequiredHeatLevel = 0f,
183 Description = LanguageControl.GetFireworks("CRDescription", null)
184 };
185 if (shape == 0) {
186 craftingRecipe.Ingredients[0] = null;
187 craftingRecipe.Ingredients[1] = "sulphurchunk";
188 craftingRecipe.Ingredients[2] = null;
189 }
190 if (shape == 1) {
191 craftingRecipe.Ingredients[0] = "sulphurchunk";
192 craftingRecipe.Ingredients[1] = "coalchunk";
193 craftingRecipe.Ingredients[2] = "sulphurchunk";
194 }
195 if (shape == 2) {
196 craftingRecipe.Ingredients[0] = "sulphurchunk";
197 craftingRecipe.Ingredients[1] = null;
198 craftingRecipe.Ingredients[2] = "sulphurchunk";
199 }
200 if (shape == 3) {
201 craftingRecipe.Ingredients[0] = "sulphurchunk";
202 craftingRecipe.Ingredients[1] = "sulphurchunk";
203 craftingRecipe.Ingredients[2] = "sulphurchunk";
204 }
205 if (shape == 4) {
206 craftingRecipe.Ingredients[0] = "coalchunk";
207 craftingRecipe.Ingredients[1] = "coalchunk";
208 craftingRecipe.Ingredients[2] = "coalchunk";
209 }
210 if (shape == 5) {
211 craftingRecipe.Ingredients[0] = null;
212 craftingRecipe.Ingredients[1] = "saltpeterchunk";
213 craftingRecipe.Ingredients[2] = null;
214 }
215 if (shape == 6) {
216 craftingRecipe.Ingredients[0] = "sulphurchunk";
217 craftingRecipe.Ingredients[1] = "saltpeterchunk";
218 craftingRecipe.Ingredients[2] = "sulphurchunk";
219 }
220 if (shape == 7) {
221 craftingRecipe.Ingredients[0] = "coalchunk";
222 craftingRecipe.Ingredients[1] = "saltpeterchunk";
223 craftingRecipe.Ingredients[2] = "coalchunk";
224 }
225 if (flickering == 0) {
226 craftingRecipe.Ingredients[3] = "canvas";
227 craftingRecipe.Ingredients[5] = "canvas";
228 }
229 if (flickering == 1) {
230 craftingRecipe.Ingredients[3] = "gunpowder";
231 craftingRecipe.Ingredients[5] = "gunpowder";
232 }
233 if (altitude == 0) {
234 craftingRecipe.Ingredients[6] = "gunpowder";
235 craftingRecipe.Ingredients[7] = null;
236 craftingRecipe.Ingredients[8] = "gunpowder";
237 }
238 if (altitude == 1) {
239 craftingRecipe.Ingredients[6] = "gunpowder";
240 craftingRecipe.Ingredients[7] = "gunpowder";
241 craftingRecipe.Ingredients[8] = "gunpowder";
242 }
243 craftingRecipe.Ingredients[4] = $"paintbucket:{(color != 7 ? color : 10).ToString(CultureInfo.InvariantCulture)}";
244 yield return craftingRecipe;
245 num = color + 1;
246 }
247 num = flickering + 1;
248 }
249 num = altitude + 1;
250 }
251 num = shape + 1;
252 shape = num;
253 }
254 }
255
256 public static Shape GetShape(int data) => (Shape)(data & 7);
257
258 public static int SetShape(int data, Shape shape) => (data & -8) | (int)(shape & Shape.FlatTrails);
259
260 public static int GetAltitude(int data) => (data >> 3) & 1;
261
262 public static int SetAltitude(int data, int altitude) => (data & -9) | ((altitude & 1) << 3);
263
264 public static bool GetFlickering(int data) => ((data >> 4) & 1) != 0;
265
266 public static int SetFlickering(int data, bool flickering) => (data & -17) | ((flickering ? 1 : 0) << 4);
267
268 public static int GetColor(int data) => (data >> 5) & 7;
269
270 public static int SetColor(int data, int color) => (data & -225) | ((color & 7) << 5);
271 }
272}
Engine.Vector3 Vector3
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
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)
static int SetFlickering(int data, bool flickering)
static bool GetFlickering(int data)
static Shape GetShape(int data)
static int SetColor(int data, int color)
static readonly Color[] FireworksColors
override IEnumerable< CraftingRecipe > GetProceduralCraftingRecipes()
override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
static int GetAltitude(int data)
static int SetAltitude(int data, int altitude)
static int GetColor(int data)
static readonly string[] HeadNames
static int SetShape(int data, Shape shape)
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 IEnumerable< int > GetCreativeValues()
static string GetFireworks(string name, string prop)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static Color White
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreateScale(float scale)