Skip to content

Commit 42dec5f

Browse files
committed
fix: restore npc spawning via the otapi create hook
1 parent f64b87e commit 42dec5f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • TerrariaServerAPI/TerrariaApi.Server/Hooking

‎TerrariaServerAPI/TerrariaApi.Server/Hooking/NpcHooks.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static void AttachTo(HookManager hookManager)
2222
HookEvents.Terraria.NPC.Transform += OnTransform;
2323
HookEvents.Terraria.NPC.AI += OnAI;
2424

25+
Hooks.NPC.Create += OnCreate;
2526
Hooks.NPC.Spawn += OnSpawn;
2627
Hooks.NPC.DropLoot += OnDropLoot;
2728
Hooks.NPC.BossBag += OnBossBagItem;
@@ -70,6 +71,16 @@ static void OnTransform(NPC npc, HookEvents.Terraria.NPC.TransformEventArgs args
7071
args.ContinueExecution = false;
7172
}
7273

74+
static void OnCreate(object sender, Hooks.NPC.CreateEventArgs e)
75+
{
76+
// OTAPI 3.3.12 moved slot assignment into this hook, but its fallback returns a bare
77+
// `new NPC()` that never reaches Main.npc, so every spawn is discarded. NewNPCInstanceInSlot
78+
// is the engine's own factory: it stores the instance, sets whoAmI and bumps the slot
79+
// generation clients use to tell recycled NPCs apart.
80+
if (e.Npc == null && e.Slot >= 0 && e.Slot < Main.npc.Length)
81+
e.Npc = NPC.NewNPCInstanceInSlot(e.Slot, (byte)e.Generation);
82+
}
83+
7384
static void OnSpawn(object sender, Hooks.NPC.SpawnEventArgs e)
7485
{
7586
if (e.Result == HookResult.Cancel)

0 commit comments

Comments
 (0)