Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BasePumpkinBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public abstract class BasePumpkinBlock : Block {
7
9
11
12 public bool m_isRotten;
13
14 public BasePumpkinBlock(bool isRotten) => m_isRotten = isRotten;
15
16 public override void Initialize() {
17 Model model = ContentManager.Get<Model>("Models/Pumpkins");
18 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Pumpkin").ParentBone);
19 for (int i = 0; i < 8; i++) {
20 float num = MathUtils.Lerp(0.2f, 1f, i / 7f);
21 float num2 = MathF.Min(0.3f * num, 0.7f * (1f - num));
22 Color color;
23 if (m_isRotten) {
24 color = Color.White;
25 }
26 else {
27 color = Color.Lerp(new Color(0, 128, 128), new Color(80, 255, 255), i / 7f);
28 if (i == 7) {
29 color.R = byte.MaxValue;
30 }
31 }
33 if (i >= 1) {
35 .AppendModelMeshPart(
36 model.FindMesh("Pumpkin").MeshParts[0],
37 boneAbsoluteTransform * Matrix.CreateScale(num) * Matrix.CreateTranslation(0.5f + num2, 0f, 0.5f + num2),
38 false,
39 false,
40 false,
41 false,
42 color
43 );
44 }
45 if (m_isRotten) {
46 m_blockMeshesBySize[i].TransformTextureCoordinates(Matrix.CreateTranslation(-0.375f, 0.25f, 0f));
47 }
50 .AppendModelMeshPart(
51 model.FindMesh("Pumpkin").MeshParts[0],
52 boneAbsoluteTransform * Matrix.CreateScale(num) * Matrix.CreateTranslation(0f, -0.23f, 0f),
53 false,
54 false,
55 false,
56 false,
57 color
58 );
59 if (m_isRotten) {
60 m_standaloneBlockMeshesBySize[i].TransformTextureCoordinates(Matrix.CreateTranslation(-0.375f, 0.25f, 0f));
61 }
62 }
63 for (int j = 0; j < 8; j++) {
64 BoundingBox boundingBox = m_blockMeshesBySize[j].Vertices.Count > 0
65 ? m_blockMeshesBySize[j].CalculateBoundingBox()
66 : new BoundingBox(new Vector3(0.5f, 0f, 0.5f), new Vector3(0.5f, 0f, 0.5f));
67 float num3 = boundingBox.Max.X - boundingBox.Min.X;
68 if (num3 < 0.8f) {
69 float num4 = (0.8f - num3) / 2f;
70 boundingBox.Min.X -= num4;
71 boundingBox.Min.Z -= num4;
72 boundingBox.Max.X += num4;
73 boundingBox.Max.Y = 0.4f;
74 boundingBox.Max.Z += num4;
75 }
76 m_collisionBoxesBySize[j] = [boundingBox];
77 }
78 base.Initialize();
79 }
80
81 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
82 int size = GetSize(Terrain.ExtractData(value));
83 return m_collisionBoxesBySize[size];
84 }
85
86 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
87 int data = Terrain.ExtractData(value);
88 int size = GetSize(data);
89 bool isDead = GetIsDead(data);
90 if (size >= 1) {
91 generator.GenerateMeshVertices(
92 this,
93 x,
94 y,
95 z,
98 null,
99 geometry.SubsetOpaque
100 );
101 }
102 if (size == 0) {
104 this,
105 value,
106 x,
107 y,
108 z,
109 new Color(160, 160, 160),
110 11,
111 geometry.SubsetAlphaTest
112 );
113 }
114 else if (size < 7
115 && !isDead) {
117 this,
118 value,
119 x,
120 y,
121 z,
122 Color.White,
123 28,
124 geometry.SubsetAlphaTest
125 );
126 }
127 }
128
129 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
130 int value,
131 Color color,
132 float size,
133 ref Matrix matrix,
134 DrawBlockEnvironmentData environmentData) {
135 int size2 = GetSize(Terrain.ExtractData(value));
136 BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMeshesBySize[size2], color, 2f * size, ref matrix, environmentData);
137 }
138
139 public override int GetShadowStrength(int value) => GetSize(Terrain.ExtractData(value));
140
141 public override float GetNutritionalValue(int value) {
142 if (GetSize(Terrain.ExtractData(value)) != 7) {
143 return 0f;
144 }
145 return base.GetNutritionalValue(value);
146 }
147
148 public override void GetDropValues(SubsystemTerrain subsystemTerrain,
149 int oldValue,
150 int newValue,
151 int toolLevel,
152 List<BlockDropValue> dropValues,
153 out bool showDebris) {
154 int size = GetSize(Terrain.ExtractData(oldValue));
155 if (size >= 1) {
156 int value = SetDamage(Terrain.MakeBlockValue(BlockIndex, 0, SetSize(SetIsDead(0, true), size)), GetDamage(oldValue));
157 dropValues.Add(new BlockDropValue { Value = value, Count = 1 });
158 }
159 showDebris = true;
160 }
161
163 Vector3 position,
164 int value,
165 float strength) {
166 int size = GetSize(Terrain.ExtractData(value));
167 float num = MathUtils.Lerp(0.2f, 1f, size / 7f);
168 Color color = size == 7 ? Color.White : new Color(0, 128, 128);
169 return new BlockDebrisParticleSystem(
170 subsystemTerrain,
171 position,
172 1.5f * strength,
174 color,
176 );
177 }
178
179 public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
180 string str = "BasePumpkinBlock";
181 int size = GetSize(Terrain.ExtractData(value));
182 if (m_isRotten) {
183 if (size >= 7) {
184 return string.Format(LanguageControl.Get(str, "2"), LanguageControl.Get(str, "4"));
185 }
186 return string.Format(LanguageControl.Get(str, "3"), LanguageControl.Get(str, "4"), LanguageControl.Get(str, "5"));
187 }
188 if (size >= 7) {
189 return LanguageControl.Get(str, "1");
190 }
191 return string.Format(LanguageControl.Get(str, "2"), LanguageControl.Get(str, "5"));
192 }
193
194 public override IEnumerable<int> GetCreativeValues() {
195 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetSize(SetIsDead(0, true), 1));
196 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetSize(SetIsDead(0, true), 3));
197 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetSize(SetIsDead(0, true), 5));
198 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetSize(SetIsDead(0, true), 7));
199 }
200
201 public static int GetSize(int data) => 7 - (data & 7);
202
203 public static int SetSize(int data, int size) => (data & -8) | (7 - (size & 7));
204
205 public static bool GetIsDead(int data) => (data & 8) != 0;
206
207 public static int SetIsDead(int data, bool isDead) {
208 if (!isDead) {
209 return data & -9;
210 }
211 return data | 8;
212 }
213
214 public override int GetDamage(int value) => (Terrain.ExtractData(value) & 0x10) >> 4;
215
216 public override int SetDamage(int value, int damage) {
217 int num = Terrain.ExtractData(value);
218 return Terrain.ReplaceData(value, (num & -17) | ((damage & 1) << 4));
219 }
220
221 public override int GetDamageDestructionValue(int value) {
222 if (m_isRotten) {
223 return 0;
224 }
225 int data = Terrain.ExtractData(value);
226 return SetDamage(Terrain.MakeBlockValue(244, 0, data), 0);
227 }
228
229 public override int GetRotPeriod(int value) {
230 if (!GetIsDead(Terrain.ExtractData(value))) {
231 return 0;
232 }
233 return DefaultRotPeriod;
234 }
235
236 public override bool IsSuitableForPlants(int value, int plantValue) => false;
237 }
238}
Engine.Color Color
Engine.Vector3 Vector3
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
static float Lerp(float x1, float x2, float f)
override int GetDamageDestructionValue(int value)
override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
static int GetSize(int data)
static int SetIsDead(int data, bool isDead)
override int GetShadowStrength(int value)
override int GetRotPeriod(int value)
override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
static bool GetIsDead(int data)
override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List< BlockDropValue > dropValues, out bool showDebris)
override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
override int SetDamage(int value, int damage)
BoundingBox[][] m_collisionBoxesBySize
static int SetSize(int data, int size)
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
override float GetNutritionalValue(int value)
override bool IsSuitableForPlants(int value, int plantValue)
override IEnumerable< int > GetCreativeValues()
override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
BlockMesh[] m_standaloneBlockMeshesBySize
override int GetDamage(int value)
virtual void GenerateCrossfaceVertices(Block block, int value, int x, int y, int z, Color color, int textureSlot, TerrainGeometrySubset subset)
virtual void GenerateMeshVertices(Block block, int x, int y, int z, BlockMesh blockMesh, Color color, Matrix? matrix, TerrainGeometrySubset subset)
int BlockIndex
定义 Block.cs:6
float DestructionDebrisScale
int DefaultRotPeriod
int DefaultTextureSlot
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 string Get(string className, int key)
获取在当前语言类名键对应的字符串
TerrainGeometrySubset SubsetAlphaTest
TerrainGeometrySubset SubsetOpaque
static int ReplaceData(int value, int data)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static Color Lerp(Color c1, Color c2, float f)
static Color White
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreateScale(float scale)