Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WaterfallManager.cs
Go to the documentation of this file.
1using System;
6using Terraria.ID;
7using Terraria.IO;
8
9namespace Terraria;
10
11public class WaterfallManager
12{
13 public struct WaterfallData
14 {
15 public int x;
16
17 public int y;
18
19 public int type;
20
21 public int stopAtStep;
22 }
23
24 private const int minWet = 160;
25
26 private const int maxWaterfallCountDefault = 1000;
27
28 private const int maxLength = 100;
29
30 private const int maxTypes = 26;
31
32 public int maxWaterfallCount = 1000;
33
34 private int qualityMax;
35
36 private int currentMax;
37
38 private WaterfallData[] waterfalls = new WaterfallData[1000];
39
41
42 private int wFallFrCounter;
43
44 private int regularFrame;
45
46 private int wFallFrCounter2;
47
48 private int slowFrame;
49
50 private int rainFrameCounter;
51
53
55
56 private int snowFrameCounter;
57
59
60 private int findWaterfallCount;
61
62 private int waterfallDist = 100;
63
64 public void BindTo(Preferences preferences)
65 {
66 preferences.OnLoad += Configuration_OnLoad;
67 }
68
69 private void Configuration_OnLoad(Preferences preferences)
70 {
71 maxWaterfallCount = Math.Max(0, preferences.Get("WaterfallDrawLimit", 1000));
73 }
74
75 public void LoadContent()
76 {
77 for (int i = 0; i < 26; i++)
78 {
79 waterfallTexture[i] = Main.Assets.Request<Texture2D>("Images/Waterfall_" + i, (AssetRequestMode)2);
80 }
81 }
82
83 public bool CheckForWaterfall(int i, int j)
84 {
85 for (int k = 0; k < currentMax; k++)
86 {
87 if (waterfalls[k].x == i && waterfalls[k].y == j)
88 {
89 return true;
90 }
91 }
92 return false;
93 }
94
95 public void FindWaterfalls(bool forced = false)
96 {
98 if (findWaterfallCount < 30 && !forced)
99 {
100 return;
101 }
103 waterfallDist = (int)(75f * Main.gfxQuality) + 25;
105 currentMax = 0;
106 int num = (int)(Main.screenPosition.X / 16f - 1f);
107 int num2 = (int)((Main.screenPosition.X + (float)Main.screenWidth) / 16f) + 2;
108 int num3 = (int)(Main.screenPosition.Y / 16f - 1f);
109 int num4 = (int)((Main.screenPosition.Y + (float)Main.screenHeight) / 16f) + 2;
110 num -= waterfallDist;
111 num2 += waterfallDist;
112 num3 -= waterfallDist;
113 num4 += 20;
114 if (num < 0)
115 {
116 num = 0;
117 }
118 if (num2 > Main.maxTilesX)
119 {
120 num2 = Main.maxTilesX;
121 }
122 if (num3 < 0)
123 {
124 num3 = 0;
125 }
126 if (num4 > Main.maxTilesY)
127 {
128 num4 = Main.maxTilesY;
129 }
130 for (int i = num; i < num2; i++)
131 {
132 for (int j = num3; j < num4; j++)
133 {
134 Tile tile = Main.tile[i, j];
135 if (tile == null)
136 {
137 tile = new Tile();
138 Main.tile[i, j] = tile;
139 }
140 if (!tile.active())
141 {
142 continue;
143 }
144 if (tile.halfBrick())
145 {
146 Tile tile2 = Main.tile[i, j - 1];
147 if (tile2 == null)
148 {
149 tile2 = new Tile();
150 Main.tile[i, j - 1] = tile2;
151 }
152 if (tile2.liquid < 16 || WorldGen.SolidTile(tile2))
153 {
154 Tile tile3 = Main.tile[i - 1, j];
155 if (tile3 == null)
156 {
157 tile3 = new Tile();
158 Main.tile[i - 1, j] = tile3;
159 }
160 Tile tile4 = Main.tile[i + 1, j];
161 if (tile4 == null)
162 {
163 tile4 = new Tile();
164 Main.tile[i + 1, j] = tile4;
165 }
166 if ((tile3.liquid > 160 || tile4.liquid > 160) && ((tile3.liquid == 0 && !WorldGen.SolidTile(tile3) && tile3.slope() == 0) || (tile4.liquid == 0 && !WorldGen.SolidTile(tile4) && tile4.slope() == 0)) && currentMax < qualityMax)
167 {
169 if (tile2.lava() || tile4.lava() || tile3.lava())
170 {
172 }
173 else if (tile2.honey() || tile4.honey() || tile3.honey())
174 {
176 }
177 else if (tile2.shimmer() || tile4.shimmer() || tile3.shimmer())
178 {
180 }
181 else
182 {
184 }
187 currentMax++;
188 }
189 }
190 }
191 if (tile.type == 196)
192 {
193 Tile tile5 = Main.tile[i, j + 1];
194 if (tile5 == null)
195 {
196 tile5 = new Tile();
197 Main.tile[i, j + 1] = tile5;
198 }
199 if (!WorldGen.SolidTile(tile5) && tile5.slope() == 0 && currentMax < qualityMax)
200 {
203 waterfalls[currentMax].y = j + 1;
204 currentMax++;
205 }
206 }
207 if (tile.type == 460)
208 {
209 Tile tile6 = Main.tile[i, j + 1];
210 if (tile6 == null)
211 {
212 tile6 = new Tile();
213 Main.tile[i, j + 1] = tile6;
214 }
215 if (!WorldGen.SolidTile(tile6) && tile6.slope() == 0 && currentMax < qualityMax)
216 {
219 waterfalls[currentMax].y = j + 1;
220 currentMax++;
221 }
222 }
223 }
224 }
225 }
226
227 public void UpdateFrame()
228 {
230 if (wFallFrCounter > 2)
231 {
232 wFallFrCounter = 0;
233 regularFrame++;
234 if (regularFrame > 15)
235 {
236 regularFrame = 0;
237 }
238 }
240 if (wFallFrCounter2 > 6)
241 {
242 wFallFrCounter2 = 0;
243 slowFrame++;
244 if (slowFrame > 15)
245 {
246 slowFrame = 0;
247 }
248 }
250 if (rainFrameCounter > 0)
251 {
253 if (rainFrameForeground > 7)
254 {
256 }
257 if (rainFrameCounter > 2)
258 {
261 if (rainFrameBackground < 0)
262 {
264 }
265 }
266 }
267 if (++snowFrameCounter > 3)
268 {
270 if (++snowFrameForeground > 7)
271 {
273 }
274 }
275 }
276
277 private void DrawWaterfall(int Style = 0, float Alpha = 1f)
278 {
279 Main.tileSolid[546] = false;
280 float num = 0f;
281 float num2 = 99999f;
282 float num3 = 99999f;
283 int num4 = -1;
284 int num5 = -1;
285 float num6 = 0f;
286 float num7 = 99999f;
287 float num8 = 99999f;
288 int num9 = -1;
289 int num10 = -1;
290 for (int i = 0; i < currentMax; i++)
291 {
292 int num11 = 0;
293 int num12 = waterfalls[i].type;
294 int num13 = waterfalls[i].x;
295 int num14 = waterfalls[i].y;
296 int num15 = 0;
297 int num16 = 0;
298 int num17 = 0;
299 int num18 = 0;
300 int num19 = 0;
301 int num20 = 0;
302 int num21;
303 int num22;
304 if (num12 == 1 || num12 == 14 || num12 == 25)
305 {
306 if (Main.drewLava || waterfalls[i].stopAtStep == 0)
307 {
308 continue;
309 }
310 num21 = 32 * slowFrame;
311 }
312 else
313 {
314 switch (num12)
315 {
316 case 11:
317 case 22:
318 {
319 if (Main.drewLava)
320 {
321 continue;
322 }
323 num22 = waterfallDist / 4;
324 if (num12 == 22)
325 {
326 num22 = waterfallDist / 2;
327 }
328 if (waterfalls[i].stopAtStep > num22)
329 {
330 waterfalls[i].stopAtStep = num22;
331 }
332 if (waterfalls[i].stopAtStep == 0 || (float)(num14 + num22) < Main.screenPosition.Y / 16f || (float)num13 < Main.screenPosition.X / 16f - 20f || (float)num13 > (Main.screenPosition.X + (float)Main.screenWidth) / 16f + 20f)
333 {
334 continue;
335 }
336 int num23;
337 int num24;
338 if (num13 % 2 == 0)
339 {
340 num23 = rainFrameForeground + 3;
341 if (num23 > 7)
342 {
343 num23 -= 8;
344 }
345 num24 = rainFrameBackground + 2;
346 if (num24 > 7)
347 {
348 num24 -= 8;
349 }
350 if (num12 == 22)
351 {
352 num23 = snowFrameForeground + 3;
353 if (num23 > 7)
354 {
355 num23 -= 8;
356 }
357 }
358 }
359 else
360 {
361 num23 = rainFrameForeground;
362 num24 = rainFrameBackground;
363 if (num12 == 22)
364 {
365 num23 = snowFrameForeground;
366 }
367 }
368 Rectangle value = new Rectangle(num24 * 18, 0, 16, 16);
369 Rectangle value2 = new Rectangle(num23 * 18, 0, 16, 16);
370 Vector2 origin = new Vector2(8f, 8f);
371 Vector2 position = ((num14 % 2 != 0) ? (new Vector2(num13 * 16 + 8, num14 * 16 + 8) - Main.screenPosition) : (new Vector2(num13 * 16 + 9, num14 * 16 + 8) - Main.screenPosition));
372 Tile tile = Main.tile[num13, num14 - 1];
373 if (tile.active() && tile.bottomSlope())
374 {
375 position.Y -= 16f;
376 }
377 bool flag = false;
378 float rotation = 0f;
379 for (int j = 0; j < num22; j++)
380 {
381 Color color = Lighting.GetColor(num13, num14);
382 float num25 = 0.6f;
383 float num26 = 0.3f;
384 if (j > num22 - 8)
385 {
386 float num27 = (float)(num22 - j) / 8f;
387 num25 *= num27;
388 num26 *= num27;
389 }
390 Color color2 = color * num25;
391 Color color3 = color * num26;
392 if (num12 == 22)
393 {
394 Main.spriteBatch.Draw(waterfallTexture[22].Value, position, value2, color2, 0f, origin, 1f, SpriteEffects.None, 0f);
395 }
396 else
397 {
398 Main.spriteBatch.Draw(waterfallTexture[12].Value, position, value, color3, rotation, origin, 1f, SpriteEffects.None, 0f);
399 Main.spriteBatch.Draw(waterfallTexture[11].Value, position, value2, color2, rotation, origin, 1f, SpriteEffects.None, 0f);
400 }
401 if (flag)
402 {
403 break;
404 }
405 num14++;
406 Tile tile2 = Main.tile[num13, num14];
407 if (WorldGen.SolidTile(tile2))
408 {
409 flag = true;
410 }
411 if (tile2.liquid > 0)
412 {
413 int num28 = (int)(16f * ((float)(int)tile2.liquid / 255f)) & 0xFE;
414 if (num28 >= 15)
415 {
416 break;
417 }
418 value2.Height -= num28;
419 value.Height -= num28;
420 }
421 if (num14 % 2 == 0)
422 {
423 position.X += 1f;
424 }
425 else
426 {
427 position.X -= 1f;
428 }
429 position.Y += 16f;
430 }
431 waterfalls[i].stopAtStep = 0;
432 continue;
433 }
434 case 0:
435 num12 = Style;
436 break;
437 case 2:
438 if (Main.drewLava)
439 {
440 continue;
441 }
442 break;
443 }
444 num21 = 32 * regularFrame;
445 }
446 int num29 = 0;
447 num22 = waterfallDist;
448 Color color4 = Color.White;
449 for (int k = 0; k < num22; k++)
450 {
451 if (num29 >= 2)
452 {
453 break;
454 }
455 AddLight(num12, num13, num14);
456 Tile tile3 = Main.tile[num13, num14];
457 if (tile3 == null)
458 {
459 tile3 = new Tile();
460 Main.tile[num13, num14] = tile3;
461 }
462 if (tile3.nactive() && Main.tileSolid[tile3.type] && !Main.tileSolidTop[tile3.type] && !TileID.Sets.Platforms[tile3.type] && tile3.blockType() == 0)
463 {
464 break;
465 }
466 Tile tile4 = Main.tile[num13 - 1, num14];
467 if (tile4 == null)
468 {
469 tile4 = new Tile();
470 Main.tile[num13 - 1, num14] = tile4;
471 }
472 Tile tile5 = Main.tile[num13, num14 + 1];
473 if (tile5 == null)
474 {
475 tile5 = new Tile();
476 Main.tile[num13, num14 + 1] = tile5;
477 }
478 Tile tile6 = Main.tile[num13 + 1, num14];
479 if (tile6 == null)
480 {
481 tile6 = new Tile();
482 Main.tile[num13 + 1, num14] = tile6;
483 }
484 if (WorldGen.SolidTile(tile5) && !tile3.halfBrick())
485 {
486 num11 = 8;
487 }
488 else if (num16 != 0)
489 {
490 num11 = 0;
491 }
492 int num30 = 0;
493 int num31 = num18;
494 int num32 = 0;
495 int num33 = 0;
496 bool flag2 = false;
497 if (tile5.topSlope() && !tile3.halfBrick() && tile5.type != 19)
498 {
499 flag2 = true;
500 if (tile5.slope() == 1)
501 {
502 num30 = 1;
503 num32 = 1;
504 num17 = 1;
505 num18 = num17;
506 }
507 else
508 {
509 num30 = -1;
510 num32 = -1;
511 num17 = -1;
512 num18 = num17;
513 }
514 num33 = 1;
515 }
516 else if ((!WorldGen.SolidTile(tile5) && !tile5.bottomSlope() && !tile3.halfBrick()) || (!tile5.active() && !tile3.halfBrick()))
517 {
518 num29 = 0;
519 num33 = 1;
520 num32 = 0;
521 }
522 else if ((WorldGen.SolidTile(tile4) || tile4.topSlope() || tile4.liquid > 0) && !WorldGen.SolidTile(tile6) && tile6.liquid == 0)
523 {
524 if (num17 == -1)
525 {
526 num29++;
527 }
528 num32 = 1;
529 num33 = 0;
530 num17 = 1;
531 }
532 else if ((WorldGen.SolidTile(tile6) || tile6.topSlope() || tile6.liquid > 0) && !WorldGen.SolidTile(tile4) && tile4.liquid == 0)
533 {
534 if (num17 == 1)
535 {
536 num29++;
537 }
538 num32 = -1;
539 num33 = 0;
540 num17 = -1;
541 }
542 else if (((!WorldGen.SolidTile(tile6) && !tile3.topSlope()) || tile6.liquid == 0) && !WorldGen.SolidTile(tile4) && !tile3.topSlope() && tile4.liquid == 0)
543 {
544 num33 = 0;
545 num32 = num17;
546 }
547 else
548 {
549 num29++;
550 num33 = 0;
551 num32 = 0;
552 }
553 if (num29 >= 2)
554 {
555 num17 *= -1;
556 num32 *= -1;
557 }
558 int num34 = -1;
559 if (num12 != 1 && num12 != 14 && num12 != 25)
560 {
561 if (tile5.active())
562 {
563 num34 = tile5.type;
564 }
565 if (tile3.active())
566 {
567 num34 = tile3.type;
568 }
569 }
570 switch (num34)
571 {
572 case 160:
573 num12 = 2;
574 break;
575 case 262:
576 case 263:
577 case 264:
578 case 265:
579 case 266:
580 case 267:
581 case 268:
582 num12 = 15 + num34 - 262;
583 break;
584 }
585 Color color5 = Lighting.GetColor(num13, num14);
586 if (k > 50)
587 {
588 TrySparkling(num13, num14, num17, color5);
589 }
590 float alpha = GetAlpha(Alpha, num22, num12, num14, k, tile3);
591 color5 = StylizeColor(alpha, num22, num12, num14, k, tile3, color5);
592 if (num12 == 1)
593 {
594 float num35 = Math.Abs((float)(num13 * 16 + 8) - (Main.screenPosition.X + (float)(Main.screenWidth / 2)));
595 float num36 = Math.Abs((float)(num14 * 16 + 8) - (Main.screenPosition.Y + (float)(Main.screenHeight / 2)));
596 if (num35 < (float)(Main.screenWidth * 2) && num36 < (float)(Main.screenHeight * 2))
597 {
598 float num37 = (float)Math.Sqrt(num35 * num35 + num36 * num36);
599 float num38 = 1f - num37 / ((float)Main.screenWidth * 0.75f);
600 if (num38 > 0f)
601 {
602 num6 += num38;
603 }
604 }
605 if (num35 < num7)
606 {
607 num7 = num35;
608 num9 = num13 * 16 + 8;
609 }
610 if (num36 < num8)
611 {
612 num8 = num35;
613 num10 = num14 * 16 + 8;
614 }
615 }
616 else if (num12 != 1 && num12 != 14 && num12 != 25 && num12 != 11 && num12 != 12 && num12 != 22)
617 {
618 float num39 = Math.Abs((float)(num13 * 16 + 8) - (Main.screenPosition.X + (float)(Main.screenWidth / 2)));
619 float num40 = Math.Abs((float)(num14 * 16 + 8) - (Main.screenPosition.Y + (float)(Main.screenHeight / 2)));
620 if (num39 < (float)(Main.screenWidth * 2) && num40 < (float)(Main.screenHeight * 2))
621 {
622 float num41 = (float)Math.Sqrt(num39 * num39 + num40 * num40);
623 float num42 = 1f - num41 / ((float)Main.screenWidth * 0.75f);
624 if (num42 > 0f)
625 {
626 num += num42;
627 }
628 }
629 if (num39 < num2)
630 {
631 num2 = num39;
632 num4 = num13 * 16 + 8;
633 }
634 if (num40 < num3)
635 {
636 num3 = num39;
637 num5 = num14 * 16 + 8;
638 }
639 }
640 int num43 = tile3.liquid / 16;
641 if (flag2 && num17 != num31)
642 {
643 int num44 = 2;
644 if (num31 == 1)
645 {
646 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16 + 16 - num44) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43 - num44), color5, SpriteEffects.FlipHorizontally);
647 }
648 else
649 {
650 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + 16 - num44) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43 - num44), color5, SpriteEffects.None);
651 }
652 }
653 if (num15 == 0 && num30 != 0 && num16 == 1 && num17 != num18)
654 {
655 num30 = 0;
656 num17 = num18;
657 color5 = Color.White;
658 if (num17 == 1)
659 {
660 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16 + 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color5, SpriteEffects.FlipHorizontally);
661 }
662 else
663 {
664 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16 + 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color5, SpriteEffects.FlipHorizontally);
665 }
666 }
667 if (num19 != 0 && num32 == 0 && num33 == 1)
668 {
669 if (num17 == 1)
670 {
671 if (num20 != num12)
672 {
673 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11 + 8) - Main.screenPosition, new Rectangle(num21, 0, 16, 16 - num43 - 8), color4, SpriteEffects.FlipHorizontally);
674 }
675 else
676 {
677 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11 + 8) - Main.screenPosition, new Rectangle(num21, 0, 16, 16 - num43 - 8), color5, SpriteEffects.FlipHorizontally);
678 }
679 }
680 else
681 {
682 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11 + 8) - Main.screenPosition, new Rectangle(num21, 0, 16, 16 - num43 - 8), color5, SpriteEffects.None);
683 }
684 }
685 if (num11 == 8 && num16 == 1 && num19 == 0)
686 {
687 if (num18 == -1)
688 {
689 if (num20 != num12)
690 {
691 DrawWaterfall(num20, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 8), color4, SpriteEffects.None);
692 }
693 else
694 {
695 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 8), color5, SpriteEffects.None);
696 }
697 }
698 else if (num20 != num12)
699 {
700 DrawWaterfall(num20, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 8), color4, SpriteEffects.FlipHorizontally);
701 }
702 else
703 {
704 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 8), color5, SpriteEffects.FlipHorizontally);
705 }
706 }
707 if (num30 != 0 && num15 == 0)
708 {
709 if (num31 == 1)
710 {
711 if (num20 != num12)
712 {
713 DrawWaterfall(num20, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color4, SpriteEffects.FlipHorizontally);
714 }
715 else
716 {
717 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color5, SpriteEffects.FlipHorizontally);
718 }
719 }
720 else if (num20 != num12)
721 {
722 DrawWaterfall(num20, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color4, SpriteEffects.None);
723 }
724 else
725 {
726 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color5, SpriteEffects.None);
727 }
728 }
729 if (num33 == 1 && num30 == 0 && num19 == 0)
730 {
731 if (num17 == -1)
732 {
733 if (num16 == 0)
734 {
735 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11) - Main.screenPosition, new Rectangle(num21, 0, 16, 16 - num43), color5, SpriteEffects.None);
736 }
737 else if (num20 != num12)
738 {
739 DrawWaterfall(num20, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color4, SpriteEffects.None);
740 }
741 else
742 {
743 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color5, SpriteEffects.None);
744 }
745 }
746 else if (num16 == 0)
747 {
748 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11) - Main.screenPosition, new Rectangle(num21, 0, 16, 16 - num43), color5, SpriteEffects.FlipHorizontally);
749 }
750 else if (num20 != num12)
751 {
752 DrawWaterfall(num20, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color4, SpriteEffects.FlipHorizontally);
753 }
754 else
755 {
756 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 - 16, num14 * 16) - Main.screenPosition, new Rectangle(num21, 24, 32, 16 - num43), color5, SpriteEffects.FlipHorizontally);
757 }
758 }
759 else
760 {
761 switch (num32)
762 {
763 case 1:
764 if (Main.tile[num13, num14].liquid > 0 && !Main.tile[num13, num14].halfBrick())
765 {
766 break;
767 }
768 if (num30 == 1)
769 {
770 for (int m = 0; m < 8; m++)
771 {
772 int num48 = m * 2;
773 int num49 = 14 - m * 2;
774 int num50 = num48;
775 num11 = 8;
776 if (num15 == 0 && m < 2)
777 {
778 num50 = 4;
779 }
780 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 + num48, num14 * 16 + num11 + num50) - Main.screenPosition, new Rectangle(16 + num21 + num49, 0, 2, 16 - num11), color5, SpriteEffects.FlipHorizontally);
781 }
782 }
783 else
784 {
785 int height2 = 16;
786 if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num13, num14].type])
787 {
788 height2 = 8;
789 }
790 else if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num13, num14 + 1].type])
791 {
792 height2 = 8;
793 }
794 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11) - Main.screenPosition, new Rectangle(16 + num21, 0, 16, height2), color5, SpriteEffects.FlipHorizontally);
795 }
796 break;
797 case -1:
798 if (Main.tile[num13, num14].liquid > 0 && !Main.tile[num13, num14].halfBrick())
799 {
800 break;
801 }
802 if (num30 == -1)
803 {
804 for (int l = 0; l < 8; l++)
805 {
806 int num45 = l * 2;
807 int num46 = l * 2;
808 int num47 = 14 - l * 2;
809 num11 = 8;
810 if (num15 == 0 && l > 5)
811 {
812 num47 = 4;
813 }
814 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16 + num45, num14 * 16 + num11 + num47) - Main.screenPosition, new Rectangle(16 + num21 + num46, 0, 2, 16 - num11), color5, SpriteEffects.FlipHorizontally);
815 }
816 }
817 else
818 {
819 int height = 16;
820 if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num13, num14].type])
821 {
822 height = 8;
823 }
824 else if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num13, num14 + 1].type])
825 {
826 height = 8;
827 }
828 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11) - Main.screenPosition, new Rectangle(16 + num21, 0, 16, height), color5, SpriteEffects.None);
829 }
830 break;
831 case 0:
832 if (num33 == 0)
833 {
834 if (Main.tile[num13, num14].liquid <= 0 || Main.tile[num13, num14].halfBrick())
835 {
836 DrawWaterfall(num12, num13, num14, alpha, new Vector2(num13 * 16, num14 * 16 + num11) - Main.screenPosition, new Rectangle(16 + num21, 0, 16, 16), color5, SpriteEffects.None);
837 }
838 k = 1000;
839 }
840 break;
841 }
842 }
843 if (tile3.liquid > 0 && !tile3.halfBrick())
844 {
845 k = 1000;
846 }
847 num16 = num33;
848 num18 = num17;
849 num15 = num32;
850 num13 += num32;
851 num14 += num33;
852 num19 = num30;
853 color4 = color5;
854 if (num20 != num12)
855 {
856 num20 = num12;
857 }
858 if ((tile4.active() && (tile4.type == 189 || tile4.type == 196)) || (tile6.active() && (tile6.type == 189 || tile6.type == 196)) || (tile5.active() && (tile5.type == 189 || tile5.type == 196)))
859 {
860 num22 = (int)(40f * ((float)Main.maxTilesX / 4200f) * Main.gfxQuality);
861 }
862 }
863 }
864 Main.ambientWaterfallX = num4;
865 Main.ambientWaterfallY = num5;
866 Main.ambientWaterfallStrength = num;
867 Main.ambientLavafallX = num9;
868 Main.ambientLavafallY = num10;
869 Main.ambientLavafallStrength = num6;
870 Main.tileSolid[546] = true;
871 }
872
873 private void DrawWaterfall(int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects)
874 {
875 Texture2D value = waterfallTexture[waterfallType].Value;
876 if (waterfallType == 25)
877 {
878 Lighting.GetCornerColors(x, y, out var vertices);
879 LiquidRenderer.SetShimmerVertexColors(ref vertices, opacity, x, y);
880 Main.tileBatch.Draw(value, position + new Vector2(0f, 0f), sourceRect, vertices, default(Vector2), 1f, effects);
881 sourceRect.Y += 42;
882 LiquidRenderer.SetShimmerVertexColors_Sparkle(ref vertices, opacity, x, y, top: true);
883 Main.tileBatch.Draw(value, position + new Vector2(0f, 0f), sourceRect, vertices, default(Vector2), 1f, effects);
884 }
885 else
886 {
887 Main.spriteBatch.Draw(value, position, sourceRect, color, 0f, default(Vector2), 1f, effects, 0f);
888 }
889 }
890
891 private static Color StylizeColor(float alpha, int maxSteps, int waterfallType, int y, int s, Tile tileCache, Color aColor)
892 {
893 float num = (float)(int)aColor.R * alpha;
894 float num2 = (float)(int)aColor.G * alpha;
895 float num3 = (float)(int)aColor.B * alpha;
896 float num4 = (float)(int)aColor.A * alpha;
897 switch (waterfallType)
898 {
899 case 1:
900 if (num < 190f * alpha)
901 {
902 num = 190f * alpha;
903 }
904 if (num2 < 190f * alpha)
905 {
906 num2 = 190f * alpha;
907 }
908 if (num3 < 190f * alpha)
909 {
910 num3 = 190f * alpha;
911 }
912 break;
913 case 2:
914 num = (float)Main.DiscoR * alpha;
915 num2 = (float)Main.DiscoG * alpha;
916 num3 = (float)Main.DiscoB * alpha;
917 break;
918 case 15:
919 case 16:
920 case 17:
921 case 18:
922 case 19:
923 case 20:
924 case 21:
925 num = 255f * alpha;
926 num2 = 255f * alpha;
927 num3 = 255f * alpha;
928 break;
929 }
930 aColor = new Color((int)num, (int)num2, (int)num3, (int)num4);
931 return aColor;
932 }
933
934 private static float GetAlpha(float Alpha, int maxSteps, int waterfallType, int y, int s, Tile tileCache)
935 {
936 float num = waterfallType switch
937 {
938 1 => 1f,
939 14 => 0.8f,
940 25 => 0.75f,
941 _ => (tileCache.wall != 0 || !((double)y < Main.worldSurface)) ? (0.6f * Alpha) : Alpha,
942 };
943 if (s > maxSteps - 10)
944 {
945 num *= (float)(maxSteps - s) / 10f;
946 }
947 return num;
948 }
949
950 private static void TrySparkling(int x, int y, int direction, Color aColor2)
951 {
952 if (aColor2.R > 20 || aColor2.B > 20 || aColor2.G > 20)
953 {
954 float num = (int)aColor2.R;
955 if ((float)(int)aColor2.G > num)
956 {
957 num = (int)aColor2.G;
958 }
959 if ((float)(int)aColor2.B > num)
960 {
961 num = (int)aColor2.B;
962 }
963 if ((float)Main.rand.Next(20000) < num / 30f)
964 {
965 int num2 = Dust.NewDust(new Vector2(x * 16 - direction * 7, y * 16 + 6), 10, 8, 43, 0f, 0f, 254, Color.White, 0.5f);
966 Main.dust[num2].velocity *= 0f;
967 }
968 }
969 }
970
971 private static void AddLight(int waterfallType, int x, int y)
972 {
973 switch (waterfallType)
974 {
975 case 1:
976 {
977 float r;
978 float num3 = (r = (0.55f + (float)(270 - Main.mouseTextColor) / 900f) * 0.4f);
979 float g = num3 * 0.3f;
980 float b = num3 * 0.1f;
981 Lighting.AddLight(x, y, r, g, b);
982 break;
983 }
984 case 2:
985 {
986 float r = (float)Main.DiscoR / 255f;
987 float g = (float)Main.DiscoG / 255f;
988 float b = (float)Main.DiscoB / 255f;
989 r *= 0.2f;
990 g *= 0.2f;
991 b *= 0.2f;
992 Lighting.AddLight(x, y, r, g, b);
993 break;
994 }
995 case 15:
996 {
997 float r = 0f;
998 float g = 0f;
999 float b = 0.2f;
1000 Lighting.AddLight(x, y, r, g, b);
1001 break;
1002 }
1003 case 16:
1004 {
1005 float r = 0f;
1006 float g = 0.2f;
1007 float b = 0f;
1008 Lighting.AddLight(x, y, r, g, b);
1009 break;
1010 }
1011 case 17:
1012 {
1013 float r = 0f;
1014 float g = 0f;
1015 float b = 0.2f;
1016 Lighting.AddLight(x, y, r, g, b);
1017 break;
1018 }
1019 case 18:
1020 {
1021 float r = 0f;
1022 float g = 0.2f;
1023 float b = 0f;
1024 Lighting.AddLight(x, y, r, g, b);
1025 break;
1026 }
1027 case 19:
1028 {
1029 float r = 0.2f;
1030 float g = 0f;
1031 float b = 0f;
1032 Lighting.AddLight(x, y, r, g, b);
1033 break;
1034 }
1035 case 20:
1036 Lighting.AddLight(x, y, 0.2f, 0.2f, 0.2f);
1037 break;
1038 case 21:
1039 {
1040 float r = 0.2f;
1041 float g = 0f;
1042 float b = 0f;
1043 Lighting.AddLight(x, y, r, g, b);
1044 break;
1045 }
1046 case 25:
1047 {
1048 float num = 0.7f;
1049 float num2 = 0.7f;
1050 num += (float)(270 - Main.mouseTextColor) / 900f;
1051 num2 += (float)(270 - Main.mouseTextColor) / 125f;
1052 Lighting.AddLight(x, y, num * 0.6f, num2 * 0.25f, num * 0.9f);
1053 break;
1054 }
1055 }
1056 }
1057
1058 public void Draw(SpriteBatch spriteBatch)
1059 {
1060 for (int i = 0; i < currentMax; i++)
1061 {
1063 }
1064 Main.drewLava = false;
1065 if (Main.liquidAlpha[0] > 0f)
1066 {
1068 }
1069 if (Main.liquidAlpha[2] > 0f)
1070 {
1072 }
1073 if (Main.liquidAlpha[3] > 0f)
1074 {
1076 }
1077 if (Main.liquidAlpha[4] > 0f)
1078 {
1080 }
1081 if (Main.liquidAlpha[5] > 0f)
1082 {
1084 }
1085 if (Main.liquidAlpha[6] > 0f)
1086 {
1088 }
1089 if (Main.liquidAlpha[7] > 0f)
1090 {
1092 }
1093 if (Main.liquidAlpha[8] > 0f)
1094 {
1096 }
1097 if (Main.liquidAlpha[9] > 0f)
1098 {
1100 }
1101 if (Main.liquidAlpha[10] > 0f)
1102 {
1104 }
1105 if (Main.liquidAlpha[12] > 0f)
1106 {
1108 }
1109 if (Main.liquidAlpha[13] > 0f)
1110 {
1112 }
1113 }
1114}
static double Sqrt(double d)
static double Abs(double value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static int NewDust(Vector2 Position, int Width, int Height, int Type, float SpeedX=0f, float SpeedY=0f, int Alpha=0, Color newColor=default(Color), float Scale=1f)
Definition Dust.cs:73
static void SetShimmerVertexColors(ref VertexColors colors, float opacity, int x, int y)
static VertexColors SetShimmerVertexColors_Sparkle(ref VertexColors colors, float opacity, int x, int y, bool top)
static bool[] BlocksWaterDrawingBehindSelf
Definition TileID.cs:259
static bool[] Platforms
Definition TileID.cs:163
static void GetCornerColors(int centerX, int centerY, out VertexColors vertices, float scale=1f)
Definition Lighting.cs:295
static Color GetColor(Point tileCoords)
Definition Lighting.cs:182
static void AddLight(Vector2 position, Vector3 rgb)
Definition Lighting.cs:137
static int maxTilesY
Definition Main.cs:1116
static bool[] tileSolidTop
Definition Main.cs:1469
static SpriteBatch spriteBatch
Definition Main.cs:974
static double worldSurface
Definition Main.cs:1272
static float[] liquidAlpha
Definition Main.cs:1206
static int DiscoR
Definition Main.cs:1062
static float gfxQuality
Definition Main.cs:1056
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static byte mouseTextColor
Definition Main.cs:1751
static int maxTilesX
Definition Main.cs:1114
static int DiscoG
Definition Main.cs:1066
static bool[] tileSolid
Definition Main.cs:1471
static Tile[,] tile
Definition Main.cs:1675
static TileBatch tileBatch
Definition Main.cs:976
static int DiscoB
Definition Main.cs:1064
static bool drewLava
Definition Main.cs:1204
static UnifiedRandom rand
Definition Main.cs:1387
static int screenWidth
Definition Main.cs:1719
static IAssetRepository Assets
Definition Main.cs:209
static Dust[] dust
Definition Main.cs:1677
bool bottomSlope()
Definition Tile.cs:317
bool nactive()
Definition Tile.cs:257
bool topSlope()
Definition Tile.cs:307
byte liquid
Definition Tile.cs:12
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
int blockType()
Definition Tile.cs:219
byte slope()
Definition Tile.cs:684
bool honey()
Definition Tile.cs:379
bool lava()
Definition Tile.cs:362
bool shimmer()
Definition Tile.cs:396
bool halfBrick()
Definition Tile.cs:650
static void TrySparkling(int x, int y, int direction, Color aColor2)
static float GetAlpha(float Alpha, int maxSteps, int waterfallType, int y, int s, Tile tileCache)
static void AddLight(int waterfallType, int x, int y)
void DrawWaterfall(int Style=0, float Alpha=1f)
void Draw(SpriteBatch spriteBatch)
void FindWaterfalls(bool forced=false)
Asset< Texture2D >[] waterfallTexture
void Configuration_OnLoad(Preferences preferences)
bool CheckForWaterfall(int i, int j)
void BindTo(Preferences preferences)
void DrawWaterfall(int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects)
static Color StylizeColor(float alpha, int maxSteps, int waterfallType, int y, int s, Tile tileCache, Color aColor)
static bool SolidTile(Tile testTile)