Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SlabBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public abstract class SlabBlock : Block, IPaintableBlock {
7
8 public int m_fullBlockIndex;
9
11
13
15
17
19
20 public SlabBlock(int coloredTextureSlot, int fullBlockIndex) {
21 m_coloredTextureSlot = coloredTextureSlot;
22 m_fullBlockIndex = fullBlockIndex;
23 }
24
25 public override void Initialize() {
26 Model model = ContentManager.Get<Model>("Models/Slab");
27 ModelMeshPart meshPart = model.FindMesh("Slab").MeshParts[0];
28 Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Slab").ParentBone);
29 for (int i = 0; i < 2; i++) {
30 Matrix matrix = boneAbsoluteTransform * Matrix.CreateTranslation(0.5f, i == 0 ? 0f : 0.5f, 0.5f);
33 .AppendModelMeshPart(
34 meshPart,
35 matrix,
36 false,
37 false,
38 false,
39 false,
41 );
43 .TransformTextureCoordinates(Matrix.CreateTranslation(DefaultTextureSlot % 16 / 16f, DefaultTextureSlot / 16 / 16f, 0f));
44 m_uncoloredBlockMeshes[i].GenerateSidesData();
47 .AppendModelMeshPart(
48 meshPart,
49 matrix,
50 false,
51 false,
52 false,
53 false,
55 );
57 .TransformTextureCoordinates(Matrix.CreateTranslation(m_coloredTextureSlot % 16 / 16f, m_coloredTextureSlot / 16 / 16f, 0f));
58 m_coloredBlockMeshes[i].GenerateSidesData();
59 }
60 m_standaloneUncoloredBlockMesh.AppendModelMeshPart(
61 meshPart,
62 boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f),
63 false,
64 false,
65 false,
66 false,
68 );
69 m_standaloneUncoloredBlockMesh.TransformTextureCoordinates(
71 );
72 m_standaloneColoredBlockMesh.AppendModelMeshPart(
73 meshPart,
74 boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f),
75 false,
76 false,
77 false,
78 false,
80 );
81 m_standaloneColoredBlockMesh.TransformTextureCoordinates(
83 );
84 m_collisionBoxes[0] = [new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f))];
85 m_collisionBoxes[1] = [new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f))];
86 base.Initialize();
87 }
88
89 public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value) {
90 if (GetIsTop(Terrain.ExtractData(value))) {
91 return face != 4;
92 }
93 return face != 5;
94 }
95
96 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
97 int data = Terrain.ExtractData(value);
98 int num = GetIsTop(data) ? 1 : 0;
99 int? color = GetColor(data);
100 if (color.HasValue) {
102 this,
103 x,
104 y,
105 z,
107 SubsystemPalette.GetColor(generator, color),
108 null,
109 null,
110 geometry.SubsetOpaque
111 );
112 }
113 else {
115 this,
116 x,
117 y,
118 z,
120 Color.White,
121 null,
122 null,
123 geometry.SubsetOpaque
124 );
125 }
126 }
127
128 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain,
129 ComponentMiner componentMiner,
130 int value,
131 TerrainRaycastResult raycastResult) {
132 int num = Terrain.ExtractContents(value);
133 int data = Terrain.ExtractData(value);
134 int num2 = Terrain.ExtractContents(raycastResult.Value);
135 int data2 = Terrain.ExtractData(raycastResult.Value);
136 BlockPlacementData result;
137 if (num2 == num
138 && ((GetIsTop(data2) && raycastResult.CellFace.Face == 5) || (!GetIsTop(data2) && raycastResult.CellFace.Face == 4))) {
139 int value2 = Terrain.MakeBlockValue(m_fullBlockIndex, 0, 0);
140 if (BlocksManager.Blocks[m_fullBlockIndex] is IPaintableBlock paintableBlock) {
141 int? color = GetColor(data);
142 value2 = paintableBlock.Paint(subsystemTerrain, value2, color);
143 }
144 CellFace cellFace = raycastResult.CellFace;
145 cellFace.Point -= CellFace.FaceToPoint3(cellFace.Face);
146 result = default;
147 result.Value = value2;
148 result.CellFace = cellFace;
149 return result;
150 }
151 bool isTop = raycastResult.CellFace.Face >= 4
152 ? raycastResult.CellFace.Face == 5
153 : raycastResult.HitPoint().Y - raycastResult.CellFace.Y > 0.5f;
154 result = default;
155 result.Value = Terrain.MakeBlockValue(BlockIndex, 0, SetIsTop(data, isTop));
156 result.CellFace = raycastResult.CellFace;
157 return result;
158 }
159
160 public override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value) {
161 int num = GetIsTop(Terrain.ExtractData(value)) ? 1 : 0;
162 return m_collisionBoxes[num];
163 }
164
165 public override void GetDropValues(SubsystemTerrain subsystemTerrain,
166 int oldValue,
167 int newValue,
168 int toolLevel,
169 List<BlockDropValue> dropValues,
170 out bool showDebris) {
171 if (Terrain.ExtractContents(newValue) != m_fullBlockIndex) {
172 int data = Terrain.ExtractData(oldValue);
173 int data2 = SetColor(0, GetColor(data));
174 int value = Terrain.MakeBlockValue(BlockIndex, 0, data2);
175 dropValues.Add(new BlockDropValue { Value = value, Count = 1 });
176 showDebris = true;
177 }
178 else {
179 showDebris = false;
180 }
181 }
182
184 Vector3 position,
185 int value,
186 float strength) {
187 int? color = GetColor(Terrain.ExtractData(value));
188 if (color.HasValue) {
189 return new BlockDebrisParticleSystem(
190 subsystemTerrain,
191 position,
192 strength,
194 SubsystemPalette.GetColor(subsystemTerrain, color),
196 );
197 }
198 return new BlockDebrisParticleSystem(
199 subsystemTerrain,
200 position,
201 strength,
203 Color.White,
204 GetFaceTextureSlot(0, value)
205 );
206 }
207
208 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
209 int value,
210 Color color,
211 float size,
212 ref Matrix matrix,
213 DrawBlockEnvironmentData environmentData) {
214 int? color2 = GetColor(Terrain.ExtractData(value));
215 if (color2.HasValue) {
217 primitivesRenderer,
219 color * SubsystemPalette.GetColor(environmentData, color2),
220 size,
221 ref matrix,
222 environmentData
223 );
224 }
225 else {
226 BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneUncoloredBlockMesh, color, size, ref matrix, environmentData);
227 }
228 }
229
230 public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
231 int? color = GetColor(Terrain.ExtractData(value));
232 return SubsystemPalette.GetName(subsystemTerrain, color, base.GetDisplayName(subsystemTerrain, value));
233 }
234
235 public override string GetCategory(int value) {
236 if (!GetColor(Terrain.ExtractData(value)).HasValue) {
237 return base.GetCategory(value);
238 }
239 return "Painted";
240 }
241
242 public override IEnumerable<int> GetCreativeValues() {
243 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetColor(0, null));
244 int i = 0;
245 while (i < 16) {
246 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetColor(0, i));
247 int num = i + 1;
248 i = num;
249 }
250 }
251
252 public virtual int? GetPaintColor(int value) => GetColor(Terrain.ExtractData(value));
253
254 public virtual int Paint(SubsystemTerrain terrain, int value, int? color) {
255 int data = Terrain.ExtractData(value);
256 return Terrain.MakeBlockValue(BlockIndex, 0, SetColor(data, color));
257 }
258
259 public static bool GetIsTop(int data) => (data & 1) != 0;
260
261 public static int SetIsTop(int data, bool isTop) => (data & -2) | (isTop ? 1 : 0);
262
263 public static int? GetColor(int data) {
264 if ((data & 2) != 0) {
265 return (data >> 2) & 0xF;
266 }
267 return null;
268 }
269
270 public static int SetColor(int data, int? color) {
271 if (color.HasValue) {
272 return (data & -63) | 2 | ((color.Value & 0xF) << 2);
273 }
274 return data & -63;
275 }
276 }
277}
Engine.Vector3 Vector3
ModelMesh FindMesh(string name, bool throwIfNotFound=true)
ReadOnlyList< ModelMeshPart > MeshParts
virtual void GenerateShadedMeshVertices(Block block, int x, int y, int z, BlockMesh blockMesh, Color color, Matrix? matrix, int[] facesMap, TerrainGeometrySubset subset)
int BlockIndex
定义 Block.cs:6
float DestructionDebrisScale
int DefaultTextureSlot
virtual int GetFaceTextureSlot(int face, int value)
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 SetIsTop(int data, bool isTop)
override IEnumerable< int > GetCreativeValues()
override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
方块放置方向
BoundingBox[][] m_collisionBoxes
override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
static bool GetIsTop(int data)
override string GetCategory(int value)
BlockMesh m_standaloneUncoloredBlockMesh
override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List< BlockDropValue > dropValues, out bool showDebris)
override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
BlockMesh[] m_uncoloredBlockMeshes
virtual ? int GetPaintColor(int value)
BlockMesh[] m_coloredBlockMeshes
BlockMesh m_standaloneColoredBlockMesh
static ? int GetColor(int data)
SlabBlock(int coloredTextureSlot, int fullBlockIndex)
override void Initialize()
static int SetColor(int data, int? color)
virtual int Paint(SubsystemTerrain terrain, int value, int? color)
override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
TerrainGeometrySubset SubsetOpaque
static int ExtractContents(int value)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static Color White
static Matrix CreateTranslation(float x, float y, float z)
static Point3 FaceToPoint3(int face)
Vector3 HitPoint(float offsetFromSurface=0f)