Skip to content

Commit 6aed7fa

Browse files
committed
Fix Pokémon pet jitter in multiplayer
1 parent 19259f1 commit 6aed7fa

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

Content/Projectiles/PokemonPet.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public override void OnSpawn(IEntitySource source)
122122
var owningPlayer = Main.player[Projectile.owner];
123123
Data = owningPlayer.GetModPlayer<TerramonPlayer>().GetActivePokemon();
124124
_cachedID = ID;
125-
Projectile.netUpdate = true; // Is this necessary?
126125
}
127126

128127
public override bool PreDraw(ref Color lightColor)
@@ -190,6 +189,24 @@ public static Color GrayscaleColor(Color color)
190189
var grayValue = (int)(0.299f * color.R + 0.587f * color.G + 0.114f * color.B);
191190
return new Color(grayValue, grayValue, grayValue, color.A); // Maintain original alpha
192191
}
192+
193+
public override void SendExtraAI(BinaryWriter writer)
194+
{
195+
Data.NetWrite(writer, PokemonData.BitIsShiny | PokemonData.BitPersonalityValue | PokemonData.BitVariant);
196+
writer.Write(CustomSpriteDirection.HasValue);
197+
if (CustomSpriteDirection.HasValue) writer.Write(CustomSpriteDirection.Value);
198+
}
199+
200+
public override void ReceiveExtraAI(BinaryReader reader)
201+
{
202+
Data ??= new PokemonData
203+
{
204+
ID = ID,
205+
Level = 5
206+
};
207+
Data.NetRead(reader);
208+
CustomSpriteDirection = reader.ReadBoolean() ? reader.ReadInt32() : null;
209+
}
193210

194211
public override void AI()
195212
{
@@ -210,7 +227,11 @@ public override void AI()
210227
if (!owningPlayer.dead && owningPlayer.HasBuff(ModContent.BuffType<PokemonCompanion>()) &&
211228
activePokemon == Data && activePokemon.ID == _cachedID) Projectile.timeLeft = 2;
212229

213-
if (Projectile.velocity.X != 0) CustomSpriteDirection = null;
230+
if (CustomSpriteDirection.HasValue && Projectile.velocity.X != 0)
231+
{
232+
CustomSpriteDirection = null;
233+
Projectile.netUpdate = true;
234+
}
214235

215236
if (isShiny) ShinyEffect();
216237
}

Content/Projectiles/ProjectileGenericPet.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ public override void SetDefaults(Projectile proj)
4040
petProj.FindFrame = FindFrame;
4141
}
4242

43-
public override void OnSpawn(Projectile projectile, IEntitySource source)
44-
{
45-
if (!Enabled) return;
46-
47-
// Hardcode the entity's height to 20 (cloned AI compatibility)
48-
projectile.height = 20;
49-
}
50-
5143
private void CustomAnimation(Projectile proj, bool walking)
5244
{
5345
var petProj = (PokemonPet)proj.ModProjectile;
@@ -62,10 +54,13 @@ public override void AI(Projectile projectile)
6254
{
6355
if (!Enabled) return;
6456

57+
// Hardcode the entity's height to 20 (cloned AI compatibility)
58+
projectile.height = 20;
59+
6560
var petProj = (PokemonPet)projectile.ModProjectile;
6661

67-
if (projectile.ai[0] != 1 && WalkSpeedModifier < 1f) // If not flying to catch up to player
68-
projectile.velocity.X *= WalkSpeedModifier + (1f - WalkSpeedModifier) / 1.5f;
62+
/*if (projectile.ai[0] != 1 && WalkSpeedModifier < 1f) // If not flying to catch up to player
63+
projectile.velocity.X *= WalkSpeedModifier + (1f - WalkSpeedModifier) / 1.5f;*/
6964

7065
// If the pet is moving, increase the frame counter.
7166
// If not moving, continue to increase the frame counter until it reaches the end of the current animation cycle.

0 commit comments

Comments
 (0)