public virtual void OnNPCAtStockpile(BlockJobInstance blockJobInstance, ref NPCState state) { MinerJobInstance inst = (MinerJobInstance)blockJobInstance; inst.ShouldTakeItems = false; inst.GatheredItemCount = 0; state.Inventory.Dump(blockJobInstance.Owner.Stockpile); state.SetCooldown(0.3); state.JobIsDone = true; }
public virtual void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPCState state) { state.JobIsDone = true; MinerJobInstance instance = (MinerJobInstance)blockJobInstance; if (instance.BlockTypeBelow == null || instance.BlockTypeBelow == BuiltinBlocks.Types.air) { if (World.TryGetTypeAt(instance.Position.Add(0, -1, 0), out ItemTypes.ItemType foundType)) { if (foundType == BuiltinBlocks.Types.air) { ThreadManager.InvokeOnMainThread(() => ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner)); state.SetCooldown(3.0); // I don't know what's going on here, floating miner jobs return; } instance.BlockTypeBelow = foundType; } else { state.SetCooldown(5.0); return; } } if (instance.MiningCooldown <= 0f) { float cooldown = 0f; if (instance.BlockTypeBelow.CustomDataNode?.TryGetAs("minerMiningTime", out cooldown) ?? false) { instance.MiningCooldown = cooldown; } if (instance.MiningCooldown <= 0f) { ThreadManager.InvokeOnMainThread(() => ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner)); state.SetCooldown(3.0); // loaded block below, but it turned out to be non-mineable return; } } if (BlockTypes.ContainsByReference(instance.BlockType, out int index)) { Vector3 rotate = instance.NPC.Position.Vector; switch (index) { case 1: rotate.x += 1f; break; case 2: rotate.x -= 1f; break; case 3: rotate.z += 1f; break; case 4: rotate.z -= 1f; break; } instance.NPC.LookAt(rotate); } AudioManager.SendAudio(instance.Position.Vector, "stoneDelete"); GatherResults.Clear(); var itemList = instance.BlockTypeBelow.OnRemoveItems; for (int i = 0; i < itemList.Count; i++) { GatherResults.Add(itemList[i]); } ModLoader.Callbacks.OnNPCGathered.Invoke(instance, instance.Position.Add(0, -1, 0), GatherResults); InventoryItem toShow = ItemTypes.ItemTypeDrops.GetWeightedRandom(GatherResults); if (toShow.Amount > 0) { state.SetIndicator(new Shared.IndicatorState(instance.MiningCooldown, toShow.Type)); } else { state.SetCooldown(instance.MiningCooldown); } state.Inventory.Add(GatherResults); instance.GatheredItemCount++; if (instance.GatheredItemCount >= MaxCraftsPerRun) { instance.ShouldTakeItems = true; } }