Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ArrowBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class ArrowBlock : Block {
6 [Flags]
18
19 public static int Index = 192;
20
21 public List<BlockMesh> m_standaloneBlockMeshes = [];
22
23 public static int[] m_order = [
24 0,
25 1,
26 8,
27 2,
28 3,
29 4,
30 5,
31 6,
32 7
33 ];
34
35 public static string[] m_tipNames = [
36 "ArrowTip",
37 "ArrowTip",
38 "ArrowTip",
39 "ArrowTip",
40 "ArrowFireTip",
41 "BoltTip",
42 "BoltTip",
43 "BoltExplosiveTip",
44 "ArrowTip"
45 ];
46
47 public static int[] m_tipTextureSlots = [
48 47,
49 1,
50 63,
51 182,
52 62,
53 63,
54 182,
55 183,
56 79
57 ];
58
59 public static string[] m_shaftNames = [
60 "ArrowShaft",
61 "ArrowShaft",
62 "ArrowShaft",
63 "ArrowShaft",
64 "ArrowShaft",
65 "BoltShaft",
66 "BoltShaft",
67 "BoltShaft",
68 "ArrowShaft"
69 ];
70
71 public static int[] m_shaftTextureSlots = [
72 4,
73 4,
74 4,
75 4,
76 4,
77 63,
78 63,
79 63,
80 4
81 ];
82
83 public static string[] m_stabilizerNames = [
84 "ArrowStabilizer",
85 "ArrowStabilizer",
86 "ArrowStabilizer",
87 "ArrowStabilizer",
88 "ArrowStabilizer",
89 "BoltStabilizer",
90 "BoltStabilizer",
91 "BoltStabilizer",
92 "ArrowStabilizer"
93 ];
94
95 public static int[] m_stabilizerTextureSlots = [
96 15,
97 15,
98 15,
99 15,
100 15,
101 63,
102 63,
103 63,
104 15
105 ];
106
107 public static float[] m_offsets = [
108 -0.5f,
109 -0.5f,
110 -0.5f,
111 -0.5f,
112 -0.5f,
113 -0.3f,
114 -0.3f,
115 -0.3f,
116 -0.5f
117 ];
118
119 public static float[] m_weaponPowers = [
120 5f,
121 7f,
122 14f,
123 18f,
124 4f,
125 28f,
126 36f,
127 8f,
128 10f
129 ];
130
131 public static float[] m_iconViewScales = [
132 0.8f,
133 0.8f,
134 0.8f,
135 0.8f,
136 0.8f,
137 1.1f,
138 1.1f,
139 1.1f,
140 0.8f
141 ];
142
143 public static float[] m_explosionPressures = [
144 0f,
145 0f,
146 0f,
147 0f,
148 0f,
149 0f,
150 0f,
151 40f,
152 0f
153 ];
154
155 public override void Initialize() {
156 Model model = ContentManager.Get<Model>("Models/Arrows");
157 foreach (int enumValue in EnumUtils.GetEnumValues<ArrowType>()) {
158 if (enumValue > 15) {
159 throw new InvalidOperationException("Too many arrow types.");
160 }
161 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(m_shaftNames[enumValue]).ParentBone);
162 Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(m_stabilizerNames[enumValue]).ParentBone);
163 Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(m_tipNames[enumValue]).ParentBone);
164 BlockMesh blockMesh = new();
165 blockMesh.AppendModelMeshPart(
166 model.FindMesh(m_tipNames[enumValue]).MeshParts[0],
167 boneAbsoluteTransform3 * Matrix.CreateTranslation(0f, m_offsets[enumValue], 0f),
168 false,
169 false,
170 false,
171 false,
173 );
175 Matrix.CreateTranslation(m_tipTextureSlots[enumValue] % 16 / 16f, m_tipTextureSlots[enumValue] / 16 / 16f, 0f)
176 );
177 BlockMesh blockMesh2 = new();
178 blockMesh2.AppendModelMeshPart(
179 model.FindMesh(m_shaftNames[enumValue]).MeshParts[0],
180 boneAbsoluteTransform * Matrix.CreateTranslation(0f, m_offsets[enumValue], 0f),
181 false,
182 false,
183 false,
184 false,
186 );
188 Matrix.CreateTranslation(m_shaftTextureSlots[enumValue] % 16 / 16f, m_shaftTextureSlots[enumValue] / 16 / 16f, 0f)
189 );
190 BlockMesh blockMesh3 = new();
191 blockMesh3.AppendModelMeshPart(
192 model.FindMesh(m_stabilizerNames[enumValue]).MeshParts[0],
193 boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, m_offsets[enumValue], 0f),
194 false,
195 false,
196 true,
197 false,
199 );
201 Matrix.CreateTranslation(m_stabilizerTextureSlots[enumValue] % 16 / 16f, m_stabilizerTextureSlots[enumValue] / 16 / 16f, 0f)
202 );
203 BlockMesh blockMesh4 = new();
204 blockMesh4.AppendBlockMesh(blockMesh);
205 blockMesh4.AppendBlockMesh(blockMesh2);
206 blockMesh4.AppendBlockMesh(blockMesh3);
207 m_standaloneBlockMeshes.Add(blockMesh4);
208 }
209 base.Initialize();
210 }
211
212 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) { }
213
214 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
215 int value,
216 Color color,
217 float size,
218 ref Matrix matrix,
219 DrawBlockEnvironmentData environmentData) {
220 int arrowType = (int)GetArrowType(Terrain.ExtractData(value));
221 if (arrowType >= 0
222 && arrowType < m_standaloneBlockMeshes.Count) {
223 BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMeshes[arrowType], color, 2f * size, ref matrix, environmentData);
224 }
225 }
226
227 public override float GetProjectilePower(int value) {
228 int arrowType = (int)GetArrowType(Terrain.ExtractData(value));
229 if (arrowType < 0
230 || arrowType >= m_weaponPowers.Length) {
231 return 0f;
232 }
233 return m_weaponPowers[arrowType];
234 }
235
236 public override float GetExplosionPressure(int value) {
237 int arrowType = (int)GetArrowType(Terrain.ExtractData(value));
238 if (arrowType < 0
239 || arrowType >= m_explosionPressures.Length) {
240 return 0f;
241 }
242 return m_explosionPressures[arrowType];
243 }
244
245 public override float GetIconViewScale(int value, DrawBlockEnvironmentData environmentData) {
246 int arrowType = (int)GetArrowType(Terrain.ExtractData(value));
247 if (arrowType < 0
248 || arrowType >= m_iconViewScales.Length) {
249 return 1f;
250 }
251 return m_iconViewScales[arrowType];
252 }
253
254 public override IEnumerable<int> GetCreativeValues() {
255 int i = 0;
256 while (i < m_order.Length) {
258 int num = i + 1;
259 i = num;
260 }
261 }
262
263 public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
264 int arrowType = (int)GetArrowType(Terrain.ExtractData(value));
265 if (arrowType < 0
266 || arrowType >= Enum.GetValues<ArrowType>().Length) {
267 return string.Empty;
268 }
269 return LanguageControl.Get("ArrowBlock", arrowType);
270 }
271
272 public static ArrowType GetArrowType(int data) => (ArrowType)(data & 0xF);
273
274 public static int SetArrowType(int data, ArrowType arrowType) => (data & -16) | (int)(arrowType & (ArrowType)15);
275 }
276}
void Initialize(ModelData modelData, bool keepSourceVertexDataInTags)
override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
override IEnumerable< int > GetCreativeValues()
static string[] m_shaftNames
override float GetExplosionPressure(int value)
static float[] m_explosionPressures
static float[] m_iconViewScales
static int SetArrowType(int data, ArrowType arrowType)
static int[] m_stabilizerTextureSlots
override void Initialize()
static int[] m_tipTextureSlots
static string[] m_stabilizerNames
override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
static int[] m_shaftTextureSlots
static int[] m_order
override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
override float GetIconViewScale(int value, DrawBlockEnvironmentData environmentData)
static ArrowType GetArrowType(int data)
List< BlockMesh > m_standaloneBlockMeshes
static float[] m_offsets
static string[] m_tipNames
override float GetProjectilePower(int value)
static float[] m_weaponPowers
int BlockIndex
定义 Block.cs:6
virtual void TransformTextureCoordinates(Matrix matrix, int facesMask=-1)
static Matrix GetBoneAbsoluteTransform(ModelBone modelBone)
virtual void AppendBlockMesh(BlockMesh blockMesh)
virtual void AppendModelMeshPart(ModelMeshPart meshPart, Matrix matrix, bool makeEmissive, bool flipWindingOrder, bool doubleSided, bool flipNormals, Color color)
static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
static object Get(Type type, string name)
static IList< int > GetEnumValues(Type type)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static Color White
static Matrix CreateTranslation(float x, float y, float z)