1+ // ProCraft Copyright 2014-2016 Joseph Beauvais <123DMWM@gmail.com>
2+ using System ;
3+ using System . Text ;
4+
5+ namespace fCraft {
6+
7+ /// <summary> Stores default properties for blocks in Minecraft Classic. (and CPE blocks). </summary>
8+ public static class DefaultSet {
9+
10+ /// <summary> Constructs a custom block, with the default properties of the given classic/CPE block. </summary>
11+ public static BlockDefinition MakeCustomBlock ( Block b ) {
12+ BlockDefinition def = new BlockDefinition ( ) ;
13+ byte raw = ( byte ) b ;
14+ def . BlockID = raw ;
15+ def . Name = Name ( raw ) ;
16+ def . CollideType = Collide ( b ) ;
17+ def . Speed = 1 ;
18+ def . BlocksLight = BlocksLight ( b ) ;
19+
20+ def . TopTex = topTex [ raw ] ;
21+ def . BottomTex = bottomTex [ raw ] ;
22+ def . SetSidesTex ( sideTex [ raw ] ) ;
23+ def . WalkSound = ( byte ) StepSound ( b ) ;
24+
25+ def . FullBright = FullBright ( b ) ;
26+ def . Shape = Draw ( b ) == DrawType . Sprite ? ( byte ) 0 : ( byte ) 1 ;
27+ def . BlockDraw = Draw ( b ) ;
28+ if ( def . BlockDraw == DrawType . Sprite )
29+ def . BlockDraw = DrawType . Transparent ;
30+
31+ def . FogDensity = FogDensity ( b ) ;
32+ CustomColor fog = FogColor ( b ) ;
33+ def . FogR = fog . R ; def . FogG = fog . G ; def . FogB = fog . B ;
34+ def . FallBack = raw ;
35+
36+ def . MaxX = 16 ; def . MaxZ = Height ( b ) ; def . MaxY = 16 ;
37+ def . Version2 = true ;
38+ return def ;
39+ }
40+
41+ /// <summary> Gets the default height of a block. A value of 16 is full height. </summary>
42+ public static byte Height ( Block b ) {
43+ if ( b == Block . Slab ) return 8 ;
44+ if ( b == Block . CobbleSlab ) return 8 ;
45+ if ( b == Block . Snow ) return 2 ;
46+ return 16 ;
47+ }
48+
49+ /// <summary> Gets whether a block is full bright / light emitting by default. </summary>
50+ public static bool FullBright ( Block b ) {
51+ return b == Block . Lava || b == Block . StillLava
52+ || b == Block . Magma || b == Block . Fire ;
53+ }
54+
55+ /// <summary> Gets the default fog density of a block, in packed form. </summary>
56+ public static byte FogDensity ( Block b ) {
57+ if ( b == Block . Water || b == Block . StillWater )
58+ return 11 ; // (128 * 0.1f - 1);
59+ if ( b == Block . Lava || b == Block . StillLava )
60+ return 255 ; // (128 * 2 - 1);
61+ return 0 ;
62+ }
63+
64+ /// <summary> Gets the default fog color of a block. </summary>
65+ public static CustomColor FogColor ( Block b ) {
66+ if ( b == Block . Water || b == Block . StillWater )
67+ return new CustomColor ( 5 , 5 , 51 ) ;
68+ if ( b == Block . Lava || b == Block . StillLava )
69+ return new CustomColor ( 153 , 25 , 0 ) ;
70+ return default ( CustomColor ) ;
71+ }
72+
73+ /// <summary> Gets the default collide type of a block, see CollideType class. </summary>
74+ public static byte Collide ( Block b ) {
75+ if ( b >= Block . Water && b <= Block . StillLava )
76+ return CollideType . SwimThrough ;
77+ if ( b == Block . Snow || b == Block . Air || Draw ( b ) == DrawType . Sprite )
78+ return CollideType . WalkThrough ;
79+ return CollideType . Solid ;
80+ }
81+
82+ /// <summary> Gets whether a block blocks light (prevents light passing through) by default. </summary>
83+ public static bool BlocksLight ( Block b ) {
84+ return ! ( b == Block . Glass || b == Block . Leaves
85+ || b == Block . Air || Draw ( b ) == DrawType . Sprite ) ;
86+ }
87+
88+
89+ /// <summary> Gets the default step sound of a block. </summary>
90+ public static SoundType StepSound ( Block b ) {
91+ if ( b == Block . Glass ) return SoundType . Stone ;
92+ if ( b == Block . Rope ) return SoundType . Cloth ;
93+ if ( Draw ( b ) == DrawType . Sprite ) return SoundType . None ;
94+
95+ if ( b >= Block . Red && b <= Block . White )
96+ return SoundType . Cloth ;
97+ if ( b >= Block . LightPink && b <= Block . Turquoise )
98+ return SoundType . Cloth ;
99+ if ( b == Block . Iron || b == Block . Gold )
100+ return SoundType . Metal ;
101+
102+ if ( b == Block . Books || b == Block . Wood
103+ || b == Block . Log || b == Block . Crate || b == Block . Fire )
104+ return SoundType . Wood ;
105+
106+ if ( b == Block . Rope ) return SoundType . Cloth ;
107+ if ( b == Block . Sand ) return SoundType . Sand ;
108+ if ( b == Block . Snow ) return SoundType . Snow ;
109+ if ( b == Block . Glass ) return SoundType . Glass ;
110+ if ( b == Block . Dirt || b == Block . Gravel )
111+ return SoundType . Gravel ;
112+
113+ if ( b == Block . Grass || b == Block . Sapling || b == Block . TNT
114+ || b == Block . Leaves || b == Block . Sponge )
115+ return SoundType . Grass ;
116+
117+ if ( b >= Block . YellowFlower && b <= Block . RedMushroom )
118+ return SoundType . Grass ;
119+ if ( b >= Block . Water && b <= Block . StillLava )
120+ return SoundType . None ;
121+ if ( b >= Block . Stone && b <= Block . StoneBrick )
122+ return SoundType . Stone ;
123+ return SoundType . None ;
124+ }
125+
126+
127+ /// <summary> Gets the default draw type of a block, see Draw class. </summary>
128+ public static byte Draw ( Block b ) {
129+ if ( b == Block . Air || b == Block . None ) return DrawType . Gas ;
130+ if ( b == Block . Leaves ) return DrawType . TransparentThick ;
131+
132+ if ( b == Block . Ice || b == Block . Water || b == Block . StillWater )
133+ return DrawType . Translucent ;
134+ if ( b == Block . Glass || b == Block . Leaves )
135+ return DrawType . Transparent ;
136+
137+ if ( b >= Block . YellowFlower && b <= Block . RedMushroom )
138+ return DrawType . Sprite ;
139+ if ( b == Block . Sapling || b == Block . Rope || b == Block . Fire )
140+ return DrawType . Sprite ;
141+ return DrawType . Opaque ;
142+ }
143+
144+
145+ const string Names = "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava" +
146+ " StillLava Sand Gravel GoldOre IronOre CoalOre Log Leaves Sponge Glass Red Orange Yellow Lime Green" +
147+ " Teal Aqua Cyan Blue Indigo Violet Magenta Pink Black Gray White Dandelion Rose BrownMushroom RedMushroom" +
148+ " Gold Iron DoubleSlab Slab Brick TNT Bookshelf MossyRocks Obsidian CobblestoneSlab Rope Sandstone" +
149+ " Snow Fire LightPink ForestGreen Brown DeepBlue Turquoise Ice CeramicTile Magma Pillar Crate StoneBrick" ;
150+
151+ static string Name ( int block ) {
152+ // Find start and end of this particular block name
153+ int start = 0 ;
154+ for ( int i = 0 ; i < block ; i ++ )
155+ start = Names . IndexOf ( ' ' , start ) + 1 ;
156+ int end = Names . IndexOf ( ' ' , start ) ;
157+ if ( end == - 1 ) end = Names . Length ;
158+
159+ StringBuilder buffer = new StringBuilder ( ) ;
160+ SplitUppercase ( buffer , start , end ) ;
161+ return buffer . ToString ( ) ;
162+ }
163+
164+ static void SplitUppercase ( StringBuilder buffer , int start , int end ) {
165+ for ( int i = start ; i < end ; i ++ ) {
166+ char c = Names [ i ] ;
167+ bool upper = Char . IsUpper ( c ) && i > start ;
168+ bool nextLower = i < end - 1 && ! Char . IsUpper ( Names [ i + 1 ] ) ;
169+
170+ if ( upper && nextLower ) {
171+ buffer . Append ( ' ' ) ;
172+ buffer . Append ( Char . ToLower ( c ) ) ;
173+ } else {
174+ buffer . Append ( c ) ;
175+ }
176+ }
177+ }
178+
179+
180+ static byte [ ] topTex = new byte [ ] { 0 , 1 , 0 , 2 , 16 , 4 , 15 , 17 , 14 , 14 ,
181+ 30 , 30 , 18 , 19 , 32 , 33 , 34 , 21 , 22 , 48 , 49 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 ,
182+ 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 13 , 12 , 29 , 28 , 24 , 23 , 6 , 6 , 7 , 9 , 4 ,
183+ 36 , 37 , 16 , 11 , 25 , 50 , 38 , 80 , 81 , 82 , 83 , 84 , 51 , 54 , 86 , 26 , 53 , 52 , } ;
184+ static byte [ ] sideTex = new byte [ ] { 0 , 1 , 3 , 2 , 16 , 4 , 15 , 17 , 14 , 14 ,
185+ 30 , 30 , 18 , 19 , 32 , 33 , 34 , 20 , 22 , 48 , 49 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 ,
186+ 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 13 , 12 , 29 , 28 , 40 , 39 , 5 , 5 , 7 , 8 , 35 ,
187+ 36 , 37 , 16 , 11 , 41 , 50 , 38 , 80 , 81 , 82 , 83 , 84 , 51 , 54 , 86 , 42 , 53 , 52 , } ;
188+ static byte [ ] bottomTex = new byte [ ] { 0 , 1 , 2 , 2 , 16 , 4 , 15 , 17 , 14 , 14 ,
189+ 30 , 30 , 18 , 19 , 32 , 33 , 34 , 21 , 22 , 48 , 49 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 ,
190+ 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 13 , 12 , 29 , 28 , 56 , 55 , 6 , 6 , 7 , 10 , 4 ,
191+ 36 , 37 , 16 , 11 , 57 , 50 , 38 , 80 , 81 , 82 , 83 , 84 , 51 , 54 , 86 , 58 , 53 , 52 } ;
192+ }
193+
194+ public static class DrawType {
195+ public const byte Opaque = 0 ;
196+ public const byte Transparent = 1 ;
197+ public const byte TransparentThick = 2 ; // e.g. leaves render all neighbours
198+ public const byte Translucent = 3 ;
199+ public const byte Gas = 4 ;
200+ public const byte Sprite = 5 ;
201+ }
202+
203+ public static class CollideType {
204+ public const byte WalkThrough = 0 ; // Gas (usually also used by sprite)
205+ public const byte SwimThrough = 1 ; // Liquid
206+ public const byte Solid = 2 ; // Solid
207+ public const byte Ice = 3 ; // Solid and partially slidable on.
208+ public const byte SlipperyIce = 4 ; // Solid and fully slidable on.
209+ public const byte LiquidWater = 5 ; // Water style 'swimming'/'bobbing'
210+ public const byte LiquidLava = 6 ; // Lava style 'swimming'/'bobbing'
211+
212+ public static bool IsSolid ( byte collide ) {
213+ return collide >= Solid && collide <= SlipperyIce ;
214+ }
215+ }
216+
217+ public enum SoundType : byte {
218+ None , Wood , Gravel , Grass , Stone ,
219+ Metal , Glass , Cloth , Sand , Snow ,
220+ }
221+ }
0 commit comments