TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ UpdateNPC_UpdateGravity()

void Terraria.NPC.UpdateNPC_UpdateGravity ( )
inlineprivate

Updates P:Terraria.NPC.maxFallSpeed and P:Terraria.NPC.gravity in line with vanilla behavior and resets F:Terraria.NPC.GravityMultiplier. Behavior can be modified with F:Terraria.NPC.GravityIgnoresType, F:Terraria.NPC.GravityIgnoresSpace, and F:Terraria.NPC.GravityIgnoresLiquid.
Certain NPC type ids may also cap velocity, see F:Terraria.NPC.GravityIgnoresType.

Definition at line 107733 of file NPC.cs.

107734 {
107735 maxFallSpeed = 10f;
107736 gravity = 0.3f;
107737 if (!GravityIgnoresType)
107738 {
107739 if (type == 258)
107740 {
107741 gravity = 0.1f;
107742 if (velocity.Y > 3f)
107743 {
107744 velocity.Y = 3f;
107745 }
107746 }
107747 else if (type == 425 && ai[2] == 1f)
107748 {
107749 gravity = 0.1f;
107750 }
107751 else if ((type == 576 || type == 577) && ai[0] > 0f && ai[1] == 2f)
107752 {
107753 gravity = 0.45f;
107754 if (velocity.Y > 32f)
107755 {
107756 velocity.Y = 32f;
107757 }
107758 }
107759 else if (type == 427 && ai[2] == 1f)
107760 {
107761 gravity = 0.1f;
107762 if (velocity.Y > 4f)
107763 {
107764 velocity.Y = 4f;
107765 }
107766 }
107767 else if (type == 426)
107768 {
107769 gravity = 0.1f;
107770 if (velocity.Y > 3f)
107771 {
107772 velocity.Y = 3f;
107773 }
107774 }
107775 else if (type == 541)
107776 {
107777 gravity = 0f;
107778 }
107779 else if (aiStyle == 7 && ai[0] == 25f)
107780 {
107781 gravity = 0f;
107782 }
107783 }
107784 if (!GravityIgnoresSpace)
107785 {
107786 float num = (float)Main.maxTilesX / 4200f;
107787 num *= num;
107788 float num2 = (float)((double)(position.Y / 16f - (60f + 10f * num)) / (Main.worldSurface / 6.0));
107789 if ((double)num2 < 0.25)
107790 {
107791 num2 = 0.25f;
107792 }
107793 if (num2 > 1f)
107794 {
107795 num2 = 1f;
107796 }
107797 gravity *= num2;
107798 }
107799 if (!GravityIgnoresLiquid && wet)
107800 {
107801 if (shimmerWet)
107802 {
107803 gravity = 0.15f;
107804 maxFallSpeed = 5.5f;
107805 }
107806 else if (honeyWet)
107807 {
107808 gravity = 0.1f;
107809 maxFallSpeed = 4f;
107810 }
107811 else
107812 {
107813 gravity = 0.2f;
107814 maxFallSpeed = 7f;
107815 }
107816 }
107817 }
bool wet
The Entity is currently in water. Projectile: Affects movement speed and some projectiles die when ...
Definition Entity.cs:57
bool honeyWet
Definition Entity.cs:61
bool shimmerWet
Definition Entity.cs:59
Vector2 velocity
The velocity of this Entity in world coordinates per tick.
Definition Entity.cs:33
float maxFallSpeed
The current fall speed cap in velocity applied every frame. Multiply F:Terraria....
Definition NPC.cs:1636
int aiStyle
Selects which vanilla code to use for the AI method. Vanilla NPC AI styles are enumerated in the T:Te...
Definition NPC.cs:1013
float gravity
The current change in velocity due to gravity applied every frame. Multiply F:Terraria....
Definition NPC.cs:1619
float[] ai
An array with 4 slots used for any sort of data storage, which is occasionally synced from the server...
Definition NPC.cs:997
int type
The NPC ID of this NPC. The NPC ID is a unique number assigned to each NPC loaded into the game....
Definition NPC.cs:990
bool GravityIgnoresSpace
Set to disable the effect of being in space on NPC gravity.
Definition NPC.cs:1316
bool GravityIgnoresLiquid
Set to disable the effect of being submerged in liquid on NPC gravity. Note that being submerged in...
Definition NPC.cs:1322
bool GravityIgnoresType
Set to disable vanilla type and AI based NPC gravity calculations. Affects types 258,...
Definition NPC.cs:1311

References Terraria.Main.maxTilesX.