-
Notifications
You must be signed in to change notification settings - Fork 0
Emote Location
Rijam edited this page Aug 2, 2024
·
2 revisions
Obsolete: tModLoader now has a native hook for changing the emote location along with the chat bubble location! Use ModNPC.EmoteBubblePosition(ref Vector2 position, ref SpriteEffects spriteEffects)
or GlobalNPC.EmoteBubblePosition(NPC npc, ref Vector2 position, ref SpriteEffects spriteEffects)
We can change the location that the emote will appear on our Town NPC. This may be desirable if your Town NPC is a different size than the standard player size. To do this, we need to use a Detour. This is an advanced technique, make sure you read about Detours here. tModLoader does not have a built in hook for this that we can override, so a detour is necessary.
public override void Load()
{
// Here we load our other hook. Note: You can have only one Load() override in the same class.
Terraria.GameContent.UI.On_EmoteBubble.GetPosition += EmoteBubble_Hook_GetPosition;
}
private delegate void orig_EmoteBubble_GetPosition(EmoteBubble self);
private static Vector2 EmoteBubble_Hook_GetPosition(Terraria.GameContent.UI.On_EmoteBubble.orig_GetPosition orig, EmoteBubble self, out SpriteEffects effect)
{
// Only change for our Town NPC.
if (self.anchor.type == WorldUIAnchor.AnchorType.Entity && self.anchor.entity is NPC npc && npc.type == ModContent.NPCType<TutorialTownNPC>())
{
// Flip the bubble to the opposite side of where it is normally.
effect = ((self.anchor.entity.direction == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None);
// Move it to the front of the entity and move it out more.
float distance = 2f; // The 0.75f multiplier in the original code moves it closer (bigger numbers move it away).
return new Vector2(self.anchor.entity.Top.X, self.anchor.entity.VisualPosition.Y) + new Vector2((float)(self.anchor.entity.direction * self.anchor.entity.width), distance) - Main.screenPosition;
// Original vanilla code:
// effect = ((anchor.entity.direction != -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None);
// return new Vector2(anchor.entity.Top.X, anchor.entity.VisualPosition.Y) + new Vector2((float)(-anchor.entity.direction * anchor.entity.width) * 0.75f, 2f) - Main.screenPosition;
}
// Do the original code if not our Town NPC.
return orig(self, out effect);
}
- Home: Home
Basic Guides
Intermediate Guides
Advanced Guides
- Preliminaries and What are Town NPCs?
- Spriting
- Create Your Town NPC's Class
- Spawn Condition
- Names
- Chat
- Buttons
- Shop
- Attacking
- Bestiary
- Happiness
- Profile
- Gore
- Misc
- Editing Vanilla NPCs with Global NPC