Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1.  
  2. protected override void RenderTile(int index) {
  3. if (BlockInfo.Draw[curBlock] == DrawType.Sprite) {
  4. this.fullBright = BlockInfo.FullBright[curBlock];
  5. this.tinted = BlockInfo.Tinted[curBlock];
  6. int count = counts[index + Side.Top];
  7. if (count != 0) DrawSprite(count);
  8. return;
  9. }
  10.  
  11. int leftCount = counts[index++], rightCount = counts[index++],
  12. frontCount = counts[index++], backCount = counts[index++],
  13. bottomCount = counts[index++], topCount = counts[index++];
  14. if (leftCount == 0 && rightCount == 0 && frontCount == 0 &&
  15. backCount == 0 && bottomCount == 0 && topCount == 0) return;
  16.  
  17. bool fullBright = BlockInfo.FullBright[curBlock];
  18. bool isTranslucent = BlockInfo.Draw[curBlock] == DrawType.Translucent;
  19. bool isLava = IsBlockLiquid(curBlock);
  20. #if ALPHA
  21. bool isCactus = (curBlock == Block.Cactus);
  22. bool isRedstone = (curBlock == Block.Redstone);
  23. bool isRedstoneTorch = (curBlock == Block.RedstoneTorchOn);
  24. bool leftRedstone = (game.World.SafeGetBlock(X + 1, Y, Z) == Block.Redstone);
  25. bool rightRedstone = (game.World.SafeGetBlock(X - 1, Y, Z) == Block.Redstone);
  26. bool frontRedstone = (game.World.SafeGetBlock(X, Y, Z + 1) == Block.Redstone);
  27. bool backRedstone = (game.World.SafeGetBlock(X, Y, Z - 1) == Block.Redstone);
  28. #endif
  29. int lightFlags = BlockInfo.LightOffset[curBlock];
  30.  
  31. drawer.minBB = BlockInfo.MinBB[curBlock]; drawer.minBB.Y = 1 - drawer.minBB.Y;
  32. drawer.maxBB = BlockInfo.MaxBB[curBlock]; drawer.maxBB.Y = 1 - drawer.maxBB.Y;
  33.  
  34. Vector3 min = BlockInfo.RenderMinBB[curBlock], max = BlockInfo.RenderMaxBB[curBlock];
  35. drawer.x1 = X + min.X; drawer.y1 = Y + min.Y; drawer.z1 = Z + min.Z;
  36. drawer.x2 = X + max.X; drawer.y2 = Y + max.Y; drawer.z2 = Z + max.Z;
  37.  
  38. drawer.Tinted = BlockInfo.Tinted[curBlock];
  39. drawer.TintColour = BlockInfo.FogColour[curBlock];
  40.  
  41. if (leftCount != 0) {
  42. int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Left];
  43. int i = texLoc / elementsPerAtlas1D;
  44. int offset = (lightFlags >> Side.Left) & 1;
  45. DrawInfo part;
  46.  
  47. if (isLava && !isTranslucent) {
  48. part = liquidParts[i];
  49. } else {
  50. part = isTranslucent ? translucentParts[i] : normalParts[i];
  51. }
  52. #if ALPHA
  53. if (isCactus) {
  54. drawer.z1 -= 1/16f;
  55. drawer.z2 += 1/16f;
  56. drawer.minBB.Z -= 1/16f;
  57. drawer.maxBB.Z += 1/16f;
  58. } else if (isRedstoneTorch) {
  59. drawer.z1 -= 1/16f;
  60. drawer.z2 += 1/16f;
  61. drawer.y2 += 1/16f;
  62. drawer.minBB.Z -= 1/16f;
  63. drawer.maxBB.Z += 1/16f;
  64. drawer.maxBB.Y -= 1/16f;
  65. }
  66. #endif
  67. int col = fullBright ? FastColour.WhitePacked :
  68. X >= offset ? light.LightCol_XSide_Fast(X - offset, Y, Z) : light.OutsideXSide;
  69. drawer.Left(leftCount, col, texLoc, part.vertices, ref part.vIndex[Side.Left]);
  70. /*drawer.z1 += 1;
  71. drawer.z2 += 1;
  72. drawer.Left(leftCount, col, texLoc, part.vertices, ref part.vIndex[Side.Left]);
  73. drawer.z1 -= 1;
  74. drawer.z2 -= 1;*/
  75. #if ALPHA
  76. if (isCactus) {
  77. drawer.z1 += 1/16f;
  78. drawer.z2 -= 1/16f;
  79. drawer.minBB.Z += 1/16f;
  80. drawer.maxBB.Z -= 1/16f;
  81. } else if (isRedstoneTorch) {
  82. drawer.z1 += 1/16f;
  83. drawer.z2 -= 1/16f;
  84. drawer.y2 -= 1/16f;
  85. drawer.minBB.Z += 1/16f;
  86. drawer.maxBB.Z -= 1/16f;
  87. drawer.maxBB.Y += 1/16f;
  88. }
  89. #endif
  90. }
  91.  
  92. if (rightCount != 0) {
  93. int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Right];
  94. int i = texLoc / elementsPerAtlas1D;
  95. int offset = (lightFlags >> Side.Right) & 1;
  96. DrawInfo part;
  97.  
  98. if (isLava && !isTranslucent) {
  99. part = liquidParts[i];
  100. } else {
  101. part = isTranslucent ? translucentParts[i] : normalParts[i];
  102. }
  103. #if ALPHA
  104. if (isCactus) {
  105. drawer.z1 -= 1/16f;
  106. drawer.z2 += 1/16f;
  107. drawer.minBB.Z -= 1/16f;
  108. drawer.maxBB.Z += 1/16f;
  109. } else if (isRedstoneTorch) {
  110. drawer.z1 -= 1/16f;
  111. drawer.z2 += 1/16f;
  112. drawer.y2 += 1/16f;
  113. drawer.minBB.Z -= 1/16f;
  114. drawer.maxBB.Z += 1/16f;
  115. drawer.maxBB.Y -= 1/16f;
  116. }
  117. #endif
  118. int col = fullBright ? FastColour.WhitePacked :
  119. X <= (maxX - offset) ? light.LightCol_XSide_Fast(X + offset, Y, Z) : light.OutsideXSide;
  120. drawer.Right(rightCount, col, texLoc, part.vertices, ref part.vIndex[Side.Right]);
  121. #if ALPHA
  122. if (isCactus) {
  123. drawer.z1 += 1/16f;
  124. drawer.z2 -= 1/16f;
  125. drawer.minBB.Z += 1/16f;
  126. drawer.maxBB.Z -= 1/16f;
  127. } else if (isRedstoneTorch) {
  128. drawer.z1 += 1/16f;
  129. drawer.z2 -= 1/16f;
  130. drawer.y2 -= 1/16f;
  131. drawer.minBB.Z += 1/16f;
  132. drawer.maxBB.Z -= 1/16f;
  133. drawer.maxBB.Y += 1/16f;
  134. }
  135. #endif
  136. }
  137.  
  138. if (frontCount != 0) {
  139. int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Front];
  140. int i = texLoc / elementsPerAtlas1D;
  141. int offset = (lightFlags >> Side.Front) & 1;
  142. DrawInfo part;
  143.  
  144. if (isLava && !isTranslucent) {
  145. part = liquidParts[i];
  146. } else {
  147. part = isTranslucent ? translucentParts[i] : normalParts[i];
  148. }
  149. #if ALPHA
  150. if (isCactus) {
  151. drawer.x1 -= 1/16f;
  152. drawer.x2 += 1/16f;
  153. drawer.minBB.X -= 1/16f;
  154. drawer.maxBB.X += 1/16f;
  155. } else if (isRedstoneTorch) {
  156. drawer.x1 -= 1/16f;
  157. drawer.x2 += 1/16f;
  158. drawer.y2 += 1/16f;
  159. drawer.minBB.X -= 1/16f;
  160. drawer.maxBB.X += 1/16f;
  161. drawer.maxBB.Y -= 1/16f;
  162. }
  163. #endif
  164. int col = fullBright ? FastColour.WhitePacked :
  165. Z >= offset ? light.LightCol_ZSide_Fast(X, Y, Z - offset) : light.OutsideZSide;
  166. drawer.Front(frontCount, col, texLoc, part.vertices, ref part.vIndex[Side.Front]);
  167. #if ALPHA
  168. if (isCactus) {
  169. drawer.x1 += 1/16f;
  170. drawer.x2 -= 1/16f;
  171. drawer.minBB.X += 1/16f;
  172. drawer.maxBB.X -= 1/16f;
  173. } else if (isRedstoneTorch) {
  174. drawer.x1 += 1/16f;
  175. drawer.x2 -= 1/16f;
  176. drawer.y2 -= 1/16f;
  177. drawer.minBB.X += 1/16f;
  178. drawer.maxBB.X -= 1/16f;
  179. drawer.maxBB.Y += 1/16f;
  180. }
  181. #endif
  182. }
  183.  
  184. if (backCount != 0) {
  185. int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Back];
  186. int i = texLoc / elementsPerAtlas1D;
  187. int offset = (lightFlags >> Side.Back) & 1;
  188. DrawInfo part;
  189.  
  190. if (isLava && !isTranslucent) {
  191. part = liquidParts[i];
  192. } else {
  193. part = isTranslucent ? translucentParts[i] : normalParts[i];
  194. }
  195. #if ALPHA
  196. if (isCactus) {
  197. drawer.x1 -= 1/16f;
  198. drawer.x2 += 1/16f;
  199. drawer.minBB.X -= 1/16f;
  200. drawer.maxBB.X += 1/16f;
  201. } else if (isRedstoneTorch) {
  202. drawer.x1 -= 1/16f;
  203. drawer.x2 += 1/16f;
  204. drawer.y2 += 1/16f;
  205. drawer.minBB.X -= 1/16f;
  206. drawer.maxBB.X += 1/16f;
  207. drawer.maxBB.Y -= 1/16f;
  208. }
  209. #endif
  210. int col = fullBright ? FastColour.WhitePacked :
  211. Z <= (maxZ - offset) ? light.LightCol_ZSide_Fast(X, Y, Z + offset) : light.OutsideZSide;
  212. drawer.Back(backCount, col, texLoc, part.vertices, ref part.vIndex[Side.Back]);
  213. #if ALPHA
  214. if (isCactus) {
  215. drawer.x1 += 1/16f;
  216. drawer.x2 -= 1/16f;
  217. drawer.minBB.X += 1/16f;
  218. drawer.maxBB.X -= 1/16f;
  219. } else if (isRedstoneTorch) {
  220. drawer.x1 += 1/16f;
  221. drawer.x2 -= 1/16f;
  222. drawer.y2 -= 1/16f;
  223. drawer.minBB.X += 1/16f;
  224. drawer.maxBB.X -= 1/16f;
  225. drawer.maxBB.Y += 1/16f;
  226. }
  227. #endif
  228. }
  229.  
  230. if (bottomCount != 0) {
  231. int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Bottom];
  232. int i = texLoc / elementsPerAtlas1D;
  233. int offset = (lightFlags >> Side.Bottom) & 1;
  234. DrawInfo part;
  235.  
  236. if (isLava && !isTranslucent) {
  237. part = liquidParts[i];
  238. } else {
  239. part = isTranslucent ? translucentParts[i] : normalParts[i];
  240. }
  241. int col = fullBright ? FastColour.WhitePacked : light.LightCol_YBottom_Fast(X, Y - offset, Z);
  242. drawer.Bottom(bottomCount, col, texLoc, part.vertices, ref part.vIndex[Side.Bottom]);
  243. }
  244.  
  245. if (topCount != 0) {
  246. int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Top];
  247. int i = texLoc / elementsPerAtlas1D;
  248. int offset = (lightFlags >> Side.Top) & 1;
  249. DrawInfo part;
  250.  
  251. if (isLava && !isTranslucent) {
  252. part = liquidParts[i];
  253. } else {
  254. part = isTranslucent ? translucentParts[i] : normalParts[i];
  255. }
  256. #if ALPHA
  257. if (isRedstoneTorch || curBlock == Block.RedstoneTorchOff || curBlock == Block.Torch) {
  258. drawer.minBB.Z -= 1/16f;
  259. drawer.maxBB.Z -= 1/16f;
  260. } else if (isRedstone) {
  261. int numRedstone = (leftRedstone? 1:0) + (rightRedstone? 1:0) + (frontRedstone? 1:0) +
  262. (backRedstone? 1:0);
  263. if (numRedstone == 2) {
  264. Console.WriteLine("line");
  265. Console.WriteLine(rightRedstone);
  266. Console.WriteLine(leftRedstone);
  267. Console.WriteLine(X);
  268. if (leftRedstone) {
  269. drawer.maxBB.X -= 5/16f;
  270. drawer.x2 -= 5/16f;
  271. }
  272. }
  273. }
  274. #endif
  275. int col = fullBright ? FastColour.WhitePacked : light.LightCol_YTop_Fast(X, (Y + 1) - offset, Z);
  276. drawer.Top(topCount, col, texLoc, part.vertices, ref part.vIndex[Side.Top]);
  277. #if ALPHA
  278. if (isRedstoneTorch || curBlock == Block.RedstoneTorchOff || curBlock == Block.Torch) {
  279. drawer.minBB.Z += 1/16f;
  280. drawer.maxBB.Z += 1/16f;
  281. } else if (isRedstone) {
  282. int numRedstone = (leftRedstone? 1:0) + (rightRedstone? 1:0) + (frontRedstone? 1:0) +
  283. (backRedstone? 1:0);
  284. if (numRedstone == 2) {
  285. if (leftRedstone) {
  286. drawer.maxBB.X += 5/16f;
  287. drawer.x2 += 5/16f;
  288. }
  289. }
  290. }
  291. #endif
  292. }
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement