Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SoilBlock.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class SoilBlock : CubeBlock {
6 public static int Index = 168;
7
8 public static string fName = "SoilBlock";
9
10 public static BoundingBox[] m_collisionBoxes = [new(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.9375f, 1f))];
11
12 public override bool IsFaceNonAttachable(SubsystemTerrain subsystemTerrain, int face, int value, int attachBlockValue) {
13 Block block = BlocksManager.Blocks[Terrain.ExtractContents(attachBlockValue)];
14 if (block is BasePumpkinBlock) {
15 return false;
16 }
17 return base.IsFaceNonAttachable(subsystemTerrain, face, value, attachBlockValue);
18 }
19
20 public override int GetFaceTextureSlot(int face, int value) {
21 int nitrogen = GetNitrogen(Terrain.ExtractData(value));
22 if (face != 4) {
23 return 2;
24 }
25 if (nitrogen <= 0) {
26 return 37;
27 }
28 return 53;
29 }
30
31 public static bool GetHydration(int data) => (data & 1) != 0;
32
33 public static int GetNitrogen(int data) => (data >> 1) & 3;
34
35 public static int SetHydration(int data, bool hydration) {
36 if (!hydration) {
37 return data & -2;
38 }
39 return data | 1;
40 }
41
42 public static int SetNitrogen(int data, int nitrogen) {
43 nitrogen = Math.Clamp(nitrogen, 0, 3);
44 return (data & -7) | ((nitrogen & 3) << 1);
45 }
46
47 public override IEnumerable<int> GetCreativeValues() {
48 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetHydration(0, false));
49 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetHydration(0, true));
50 yield return Terrain.MakeBlockValue(BlockIndex, 0, SetHydration(SetNitrogen(0, 3), true));
51 }
52
53 public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value) {
54 int data = Terrain.ExtractData(value);
55 int nitrogen = GetNitrogen(data);
56 bool hydration = GetHydration(data);
57 if (nitrogen > 0 && hydration) {
58 return LanguageControl.Get(fName, 1);
59 }
60 if (nitrogen > 0) {
61 return LanguageControl.Get(fName, 2);
62 }
63 if (hydration) {
64 return LanguageControl.Get(fName, 3);
65 }
66 return LanguageControl.Get(fName, 4);
67 }
68
69 public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z) {
70 Color color = GetHydration(Terrain.ExtractData(value)) ? new Color(180, 170, 150) : Color.White;
71 generator.GenerateCubeVertices(
72 this,
73 value,
74 x,
75 y,
76 z,
77 0.9375f,
78 0.9375f,
79 0.9375f,
80 0.9375f,
81 color,
82 color,
83 color,
84 color,
85 color,
86 -1,
87 geometry.OpaqueSubsetsByFace
88 );
89 }
90
91 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,
92 int value,
93 Color color,
94 float size,
95 ref Matrix matrix,
96 DrawBlockEnvironmentData environmentData) {
97 Color c = GetHydration(Terrain.ExtractData(value)) ? new Color(180, 170, 150) : Color.White;
98 base.DrawBlock(primitivesRenderer, value, color * c, size, ref matrix, environmentData);
99 }
100
102
103 public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value) => face != 5;
104
105 public override bool IsCollapseSupportBlock(SubsystemTerrain subsystemTerrain, int value) => true;
106
107 public override bool IsSuitableForPlants(int value, int plantValue) {
108 int plantContent = Terrain.ExtractContents(plantValue);
109 Block plantBlock = BlocksManager.Blocks[plantContent];
110 if (plantBlock is SaplingBlock) {
111 return false;
112 }
113 return true;
114 }
115 }
116}
Engine.Color Color
Engine.Vector3 Vector3
virtual void GenerateCubeVertices(Block block, int value, int x, int y, int z, Color color, TerrainGeometrySubset[] subsetsByFace)
int BlockIndex
定义 Block.cs:6
virtual bool IsFaceNonAttachable(SubsystemTerrain subsystemTerrain, int face, int value, int attachBlockValue)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
override bool IsFaceNonAttachable(SubsystemTerrain subsystemTerrain, int face, int value, int attachBlockValue)
override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
static int GetNitrogen(int data)
override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
override BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
static int SetHydration(int data, bool hydration)
static int Index
override int GetFaceTextureSlot(int face, int value)
override bool IsCollapseSupportBlock(SubsystemTerrain subsystemTerrain, int value)
static bool GetHydration(int data)
override bool IsSuitableForPlants(int value, int plantValue)
static BoundingBox[] m_collisionBoxes
static int SetNitrogen(int data, int nitrogen)
static string fName
override IEnumerable< int > GetCreativeValues()
override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
TerrainGeometrySubset[] OpaqueSubsetsByFace
static int ExtractContents(int value)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static Color White